/* Apple iOS HIG Minimalist Privacy Bookkeeping PWA Styles */

:root {
  --bg-page: #F2F2F7;
  --bg-card: #FFFFFF;
  --bg-elevated: #F8F8FA;
  --bg-tabbar: rgba(249, 249, 251, 0.84);
  --bg-keypad: #E5E5EA;
  --bg-key: #FFFFFF;
  --bg-key-op: #EFEFF4;
  --text-primary: #1C1C1E;
  --text-secondary: #6E6E73;
  --text-tertiary: #8E8E93;
  --border-subtle: rgba(60, 60, 67, 0.12);
  --accent: #007AFF;
  --accent-soft: rgba(0, 122, 255, 0.12);
  --green: #34C759;
  --amber: #FF9500;
  --red: #FF3B30;
  --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.04);
  --radius-card: 18px;
  --radius-sm: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg-page: #000000;
    --bg-card: #1C1C1E;
    --bg-elevated: #2C2C2E;
    --bg-tabbar: rgba(28, 28, 30, 0.84);
    --bg-keypad: #141416;
    --bg-key: #2C2C2E;
    --bg-key-op: #3A3A3C;
    --text-primary: #F2F2F7;
    --text-secondary: #AEAEB2;
    --text-tertiary: #8E8E93;
    --border-subtle: rgba(255, 255, 255, 0.11);
    --accent: #0A84FF;
    --accent-soft: rgba(10, 132, 255, 0.2);
    --green: #30D158;
    --amber: #FF9F0A;
    --red: #FF453A;
    --shadow-card: 0 2px 14px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  --bg-page: #000000;
  --bg-card: #1C1C1E;
  --bg-elevated: #2C2C2E;
  --bg-tabbar: rgba(28, 28, 30, 0.84);
  --bg-keypad: #141416;
  --bg-key: #2C2C2E;
  --bg-key-op: #3A3A3C;
  --text-primary: #F2F2F7;
  --text-secondary: #AEAEB2;
  --text-tertiary: #8E8E93;
  --border-subtle: rgba(255, 255, 255, 0.11);
  --accent: #0A84FF;
  --accent-soft: rgba(10, 132, 255, 0.2);
  --green: #30D158;
  --amber: #FF9F0A;
  --red: #FF453A;
  --shadow-card: 0 2px 14px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

button, input, select {
  font-family: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

.app-shell {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-top: calc(var(--safe-top) + 10px);
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 18px);
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px 12px;
}

.page-title {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.privacy-pill {
  font-size: 11px;
  font-weight: 600;
  color: var(--green);
  background: rgba(52, 199, 89, 0.12);
  padding: 4px 10px;
  border-radius: 999px;
}

.tab-panel {
  display: none;
  padding: 0 14px;
}

.tab-panel.is-active {
  display: block;
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-card);
  border: 0.5px solid var(--border-subtle);
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.muted {
  color: var(--text-secondary);
  font-size: 12px;
}

/* Segmented Control (iOS Style) */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--bg-elevated);
  border-radius: 11px;
  padding: 3px;
  gap: 3px;
}

.seg-btn {
  border: none;
  background: transparent;
  padding: 7px 8px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  transition: background 0.16s, color 0.16s, box-shadow 0.16s;
}

.seg-btn.is-active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* Tab 1: Fast Entry */
.amount-display-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px;
}

.amount-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
}

.amount-expr {
  font-size: 13px;
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.amount-value {
  font-size: 34px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  text-align: right;
  margin-left: auto;
}

.amount-value.is-expense { color: var(--text-primary); }
.amount-value.is-income { color: var(--green); }
.amount-value.is-transfer { color: var(--accent); }

.category-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px 6px;
  margin-top: 4px;
}

.cat-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 4px;
  border-radius: 14px;
  border: 1.5px solid transparent;
  background: var(--bg-elevated);
  font-size: 12px;
  color: var(--text-secondary);
  transition: transform 0.1s, border-color 0.15s, background 0.15s;
}

.cat-chip:active {
  transform: scale(0.95);
}

.cat-chip.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text-primary);
  font-weight: 600;
}

.cat-chip-icon {
  font-size: 21px;
  line-height: 1;
}

.entry-meta-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.entry-meta-row.is-transfer {
  grid-template-columns: 1fr 1fr 1fr;
}

.field-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elevated);
  border-radius: 11px;
  padding: 7px 10px;
  border: 0.5px solid var(--border-subtle);
}

.field-pill select,
.field-pill input {
  width: 100%;
  border: none;
  background: transparent;
  font-size: 13px;
  outline: none;
}

.note-input-wrap {
  margin-top: 8px;
  display: flex;
  align-items: center;
  background: var(--bg-elevated);
  border-radius: 11px;
  padding: 8px 12px;
  border: 0.5px solid var(--border-subtle);
}

.note-input-wrap input {
  width: 100%;
  border: none;
  background: transparent;
  font-size: 14px;
  outline: none;
}

/* Custom iOS Numeric Keypad */
.keypad-card {
  background: var(--bg-keypad);
  border-radius: 18px;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin-bottom: 10px;
}

.key-btn {
  border: none;
  border-radius: 12px;
  background: var(--bg-key);
  color: var(--text-primary);
  font-size: 21px;
  font-weight: 600;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
  transition: transform 0.06s, opacity 0.1s;
}

.key-btn:active {
  transform: scale(0.95);
  opacity: 0.82;
}

.key-btn.is-op {
  background: var(--bg-key-op);
  font-size: 19px;
}

.key-btn.is-submit {
  background: var(--accent);
  color: #FFFFFF;
  font-size: 16px;
  font-weight: 700;
}

/* Tab 2: Timeline & Filters */
.month-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  border: none;
  background: var(--bg-elevated);
  color: var(--text-primary);
  width: 32px;
  height: 32px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.period-label {
  font-size: 15px;
  font-weight: 700;
  min-width: 82px;
  text-align: center;
}

.summary-trio {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.summary-box {
  background: var(--bg-elevated);
  border-radius: 12px;
  padding: 9px 10px;
}

.summary-box-label {
  font-size: 11px;
  color: var(--text-secondary);
}

.summary-box-val {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.filter-bar {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.filter-input, .filter-select {
  width: 100%;
  border: 0.5px solid var(--border-subtle);
  background: var(--bg-card);
  border-radius: 12px;
  padding: 9px 10px;
  font-size: 13px;
  outline: none;
}

.day-group {
  margin-bottom: 12px;
}

.day-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 6px;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
}

.tx-list {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  border: 0.5px solid var(--border-subtle);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.tx-row {
  width: 100%;
  border: none;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  text-align: left;
  border-bottom: 0.5px solid var(--border-subtle);
}

.tx-row:last-child {
  border-bottom: none;
}

.tx-row:active {
  background: var(--bg-elevated);
}

.tx-icon-circle {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.tx-main {
  flex: 1;
  min-width: 0;
}

.tx-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-sub {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-amt {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.tx-amt.is-expense { color: var(--text-primary); }
.tx-amt.is-income { color: var(--green); }
.tx-amt.is-transfer { color: var(--accent); }

.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* Tab 3: Analytics, Budget & Net Worth */
.budget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.budget-bar-track {
  height: 11px;
  background: var(--bg-elevated);
  border-radius: 999px;
  overflow: hidden;
}

.budget-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.25s ease;
}

.budget-bar-fill.is-ok { background: var(--green); }
.budget-bar-fill.is-warn { background: var(--amber); }
.budget-bar-fill.is-over { background: var(--red); }

.budget-foot {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.text-btn {
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 8px;
}

/* Charts */
.empty-chart {
  text-align: center;
  padding: 26px 0;
  color: var(--text-tertiary);
  font-size: 13px;
}

.donut-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.donut-svg-box {
  position: relative;
  width: 196px;
  height: 196px;
}

.donut-svg {
  width: 100%;
  height: 100%;
}

.donut-slice {
  cursor: pointer;
  transition: opacity 0.16s, stroke-width 0.16s;
}

.donut-slice.is-dim { opacity: 0.28; }
.donut-slice.is-active { stroke-width: 28; }

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  text-align: center;
  padding: 0 28px;
}

.donut-center-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.donut-center-value {
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.donut-center-sub {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.donut-legend {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.donut-legend-row {
  width: 100%;
  border: none;
  background: var(--bg-elevated);
  border-radius: 11px;
  padding: 8px 11px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.donut-legend-row.is-active {
  outline: 1.5px solid var(--accent);
  background: var(--accent-soft);
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-name {
  font-weight: 600;
}

.legend-pct {
  margin-left: auto;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.legend-amt {
  min-width: 78px;
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.bar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 12px;
}

.bar-tip {
  font-weight: 600;
  color: var(--accent);
}

.bar-unit {
  color: var(--text-tertiary);
}

.bar-svg {
  width: 100%;
  height: auto;
  display: block;
}

.bar-rect {
  fill: var(--accent);
  opacity: 0.78;
  transition: opacity 0.15s;
}

.bar-rect.is-zero {
  fill: var(--border-subtle);
  opacity: 0.7;
}

.bar-group.is-selected .bar-rect {
  opacity: 1;
  fill: var(--amber);
}

.bar-axis-label {
  fill: var(--text-tertiary);
  font-size: 9px;
}

/* Net Worth Card */
.networth-hero {
  background: linear-gradient(135deg, #007AFF, #5856D6);
  color: #FFFFFF;
  border-radius: var(--radius-card);
  padding: 16px 18px;
  margin-bottom: 12px;
}

.networth-label {
  font-size: 12px;
  opacity: 0.86;
}

.networth-total {
  font-size: 30px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  margin: 4px 0 10px;
  letter-spacing: -0.02em;
}

.networth-split {
  display: flex;
  gap: 16px;
  font-size: 12px;
  opacity: 0.94;
}

.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 0.5px solid var(--border-subtle);
}

.account-row:last-child {
  border-bottom: none;
}

.account-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.account-name {
  font-size: 14px;
  font-weight: 600;
}

.account-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.account-bal {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Tab 4: Settings & Import */
.action-btn {
  width: 100%;
  border: none;
  border-radius: 13px;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  margin-top: 8px;
}

.action-btn.is-primary {
  background: var(--accent);
  color: #FFFFFF;
}

.action-btn.is-danger {
  background: rgba(255, 59, 48, 0.12);
  color: var(--red);
}

.import-preview-box {
  margin-top: 12px;
  padding: 12px;
  border-radius: 13px;
  background: var(--bg-elevated);
  border: 0.5px solid var(--border-subtle);
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin: 8px 0;
}

.preview-table th, .preview-table td {
  text-align: left;
  padding: 6px 4px;
  border-bottom: 0.5px solid var(--border-subtle);
}

.preview-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* Bottom Frosted Glass Tab Bar */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: var(--bg-tabbar);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border-top: 0.5px solid var(--border-subtle);
  padding: 6px 8px calc(var(--safe-bottom) + 6px);
}

.tabbar-inner {
  max-width: 520px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

.tab-btn {
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 4px 0;
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 600;
}

.tab-btn.is-active {
  color: var(--accent);
}

.tab-icon {
  font-size: 20px;
  line-height: 1.1;
}

/* Modal Bottom Sheet */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 80;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop.is-open {
  display: flex;
}

.modal-sheet {
  width: 100%;
  max-width: 520px;
  background: var(--bg-card);
  border-radius: 22px 22px 0 0;
  padding: 18px 16px calc(var(--safe-bottom) + 18px);
  max-height: 85dvh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.form-group {
  margin-bottom: 10px;
}

.form-label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.form-control {
  width: 100%;
  padding: 10px 12px;
  border-radius: 11px;
  border: 0.5px solid var(--border-subtle);
  background: var(--bg-elevated);
  font-size: 15px;
  outline: none;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

/* Toast Notification */
.toast {
  position: fixed;
  top: calc(var(--safe-top) + 14px);
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: rgba(28, 28, 30, 0.92);
  color: #FFFFFF;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  white-space: nowrap;
}

.toast.is-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
