/* CredBill Ledger — design tokens */
:root,
[data-theme="dark"] {
  --bg: #0f1419;
  --bg-elevated: #171e26;
  --bg-card: #1c2430;
  --border: rgba(255, 255, 255, 0.08);
  --text: #eef2f6;
  --text-muted: #8b98a8;
  --accent: #1a6b4a;
  --accent-hover: #22855d;
  --accent-soft: rgba(26, 107, 74, 0.18);
  --accent-text: #7dd3a8;
  --warn: #d4a017;
  --danger: #c0392b;
  --ok: #27ae60;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --radius-sm: 10px;
  --font: 'DM Sans', 'Noto Sans TC', system-ui, sans-serif;
  --nav-h: 72px;
  --header-h: 64px;
}

[data-theme="light"] {
  --bg: #f4f6f8;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --border: rgba(0, 0, 0, 0.08);
  --text: #1a2332;
  --text-muted: #5c6b7a;
  --accent-soft: rgba(26, 107, 74, 0.1);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body {
  overscroll-behavior: none;
}

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-h);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #0d4a32);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  display: grid;
  place-items: center;
  letter-spacing: -0.02em;
}

.brand-name {
  display: block;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.2;
}

.brand-tagline {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.icon-btn:hover { background: var(--accent-soft); }

/* Main */
.app-main {
  flex: 1;
  padding: 16px 16px calc(var(--nav-h) + 16px);
  overflow-y: auto;
}

.view-header h1 {
  margin: 0 0 6px;
  font-size: 1.5rem;
  font-weight: 700;
}

.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }

/* Hero */
.hero {
  margin-bottom: 20px;
}

.hero h1 {
  margin: 0 0 8px;
  font-size: 1.65rem;
  font-weight: 700;
  line-height: 1.25;
}

.hero-sub {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.55;
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent-text);
}

.stat-value.stat-small {
  font-size: 0.75rem;
  color: var(--text-muted);
  word-break: break-all;
}

.stat-label {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
}

.badge-ok {
  background: rgba(39, 174, 96, 0.15);
  color: var(--ok);
}

.badge-warn {
  background: rgba(212, 160, 23, 0.15);
  color: var(--warn);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, transform 0.1s;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--accent-soft); }

.btn-accent {
  background: var(--accent-soft);
  color: var(--accent-text);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
}

.btn-danger {
  background: rgba(192, 57, 43, 0.12);
  color: #e74c3c;
  border: 1px solid rgba(192, 57, 43, 0.25);
  width: 100%;
  margin-top: 8px;
}

.btn-sm { padding: 8px 14px; font-size: 0.82rem; }

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.btn-stack .btn,
.btn-row .btn { flex: 1; min-width: 120px; }

/* Features */
.feature-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.feature-chip {
  font-size: 0.78rem;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}

/* Forms */
.input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
  margin: 10px 0;
}

.input.textarea {
  min-height: 120px;
  resize: vertical;
}

.field-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.copy-field {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-top: 12px;
}

.copy-field .input { flex: 1; margin: 0; }

.code-inline {
  font-family: ui-monospace, monospace;
  font-size: 0.78rem;
  color: var(--accent-text);
  background: var(--bg);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-top: 12px;
  word-break: break-all;
}

/* Wizard */
.wizard-progress { margin-bottom: 16px; }
.wizard-progress-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.wizard-progress-bar {
  height: 6px;
  background: var(--bg-elevated);
  border-radius: 999px;
  overflow: hidden;
}

.wizard-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-text));
  border-radius: 999px;
  transition: width 0.25s ease;
}

.wizard-card { margin-bottom: 12px; }

.wizard-step-title {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.wizard-step-desc {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.55;
  font-size: 0.9rem;
}

.wizard-nav {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.wizard-nav .btn { flex: 1; }

.wizard-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding-bottom: 8px;
}

.wizard-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: none;
  padding: 0;
  background: var(--border);
  cursor: pointer;
}

.wizard-dot.active {
  background: var(--accent);
  transform: scale(1.25);
}

.wizard-test-result {
  margin-top: 10px;
  font-size: 0.88rem;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}

.wizard-test-result.ok {
  background: rgba(39, 174, 96, 0.12);
  color: var(--ok);
}

.wizard-test-result.err {
  background: rgba(192, 57, 43, 0.12);
  color: #e74c3c;
}

.done-badge {
  display: flex;
  justify-content: center;
  color: var(--ok);
  margin: 16px 0;
}

/* Transactions */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state p { margin-top: 16px; line-height: 1.6; }

.tx-list { display: flex; flex-direction: column; gap: 8px; }

.tx-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.tx-merchant { display: block; font-weight: 600; }
.tx-date { display: block; font-size: 0.78rem; color: var(--text-muted); }
.tx-amount { font-weight: 700; color: var(--accent-text); }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--nav-h);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
  z-index: 30;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.68rem;
  font-weight: 500;
  cursor: pointer;
  padding: 8px 4px;
}

.nav-item.active {
  color: var(--accent-text);
}

.nav-item svg { opacity: 0.85; }
.nav-item.active svg { opacity: 1; stroke: var(--accent-text); }

/* Toast */
.toast-host {
  position: fixed;
  bottom: calc(var(--nav-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s, transform 0.25s;
  font-size: 0.88rem;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (min-width: 481px) {
  .app-shell {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
