/* Dinari — styles.css
 * Forked from Captain Dollar dark theme.
 * Single source of truth for visuals.
 */

:root {
  /* Palette — dark, calm, financial */
  --bg:          #0f1419;
  --bg-elevated: #1a2028;
  --bg-card:     #1f2731;
  --border:      #2a323d;
  --text:        #e6edf3;
  --text-dim:    #8b96a3;
  --text-faint:  #5a6573;
  --accent:      #3fb950;
  --accent-dim:  #2ea043;
  --warn:        #f0883e;
  --danger:      #f85149;
  --info:        #58a6ff;

  --topbar-h:    48px;
  --bottomnav-h: 64px;
  --radius:      10px;
  --radius-sm:   6px;
  --gap:         12px;
  --gap-lg:      16px;
}

html[data-theme="light"] {
  --bg:          #f4f6f8;
  --bg-elevated: #ffffff;
  --bg-card:     #ffffff;
  --border:      #d8dde3;
  --text:        #1c2128;
  --text-dim:    #6b7480;
  --text-faint:  #aab1bc;
  --accent:      #2da44e;
  --accent-dim:  #2c974b;
  --warn:        #bc4c00;
  --danger:      #cf222e;
  --info:        #0969da;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ===== Top bar ===== */
#topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-h);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--gap-lg);
  z-index: 10;
}

/* Brand cluster: green accent bar + wordmark, sitting together. */
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

/* Echo of the icon's horizontal green bar — small pill to the left of
 * the wordmark. Same accent color as the launcher icon's bar. */
.topbar-accent-bar {
  display: inline-block;
  width: 14px;
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(63, 185, 80, 0.35);
  flex-shrink: 0;
}

/* Wordmark: bumped weight, tightened tracking, gradient-clipped fill
 * with a slow horizontal sweep. The base color (white) is the fallback
 * for browsers that don't support background-clip: text — they still
 * see a perfectly readable bold "Dinari". */
.topbar-title {
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.02em;
  color: var(--text);
  background: linear-gradient(
    100deg,
    var(--text) 0%,
    var(--text) 35%,
    var(--accent) 50%,
    var(--text) 65%,
    var(--text) 100%
  );
  background-size: 220% 100%;
  background-position: 100% 0;
  -webkit-background-clip: text;
          background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: topbarSheen 9s ease-in-out infinite;
  user-select: none;
}

@keyframes topbarSheen {
  0%   { background-position: 100% 0; }
  50%  { background-position: 0%   0; }
  100% { background-position: 100% 0; }
}

/* Status slot: subtle pill, lower visual weight than the wordmark. */
.topbar-status {
  color: var(--text-dim);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(63, 185, 80, 0.07);
  border: 1px solid rgba(63, 185, 80, 0.18);
  white-space: nowrap;
  transition: opacity 250ms ease;
}

/* Respect users who've opted out of motion — the sweep is decorative,
 * static gradient is still a perfectly fine brand treatment. */
@media (prefers-reduced-motion: reduce) {
  .topbar-title { animation: none; background-position: 50% 0; }
}

/* ===== Main view container ===== */
#viewContainer {
  flex: 1;
  padding: var(--gap-lg);
  padding-bottom: calc(var(--bottomnav-h) + var(--gap-lg));
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.loading, .error, .placeholder {
  padding: var(--gap-lg);
  text-align: center;
  color: var(--text-dim);
}
.error { color: var(--danger); }

/* ===== Bottom nav ===== */
#bottomnav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottomnav-h);
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  z-index: 10;
}
.navitem {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--text-dim);
  font-size: 11px;
  gap: 2px;
  -webkit-tap-highlight-color: transparent;
}
.navitem.active { color: var(--accent); }
.navicon { display: inline-flex; align-items: center; justify-content: center; line-height: 1; color: inherit; }
.navicon svg { display: block; }
.navitem-primary {
  position: relative;
}
.navitem-primary .navicon {
  display: inline-flex;
  width: 32px; height: 32px;
  align-items: center; justify-content: center;
  background: var(--accent);
  color: #0a0a0a;
  border-radius: 50%;
  margin-top: -2px;
}
.navitem-primary .navicon svg { stroke: #0a0a0a; width: 18px; height: 18px; }

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap-lg);
  margin-bottom: var(--gap);
}
.card-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 var(--gap) 0;
}
.card-value {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

/* ===== Buttons ===== */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
}
.btn:active { opacity: 0.7; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary   { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-ghost     { background: transparent; color: var(--text-dim); }
.btn-block     { display: block; width: 100%; }

/* ===== Forms ===== */
.form-row { margin-bottom: var(--gap); }
.form-label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 4px;
}
/* ===== CD-compat global form controls =====
   Used by transactions view (and other CD-ported views).
   Distinct from .form-input/.form-select which onboarding uses.
*/
.input, .select {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px; /* 16px prevents iOS zoom on focus */
  font-family: inherit;
  min-height: 44px;
  box-sizing: border-box;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}
.input:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
}
.label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 6px;
  margin-top: var(--gap);
}
/* Custom chevron for .select and datalist inputs */
.select,
input[list] {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M3 4.5L6 7.5L9 4.5' fill='none' stroke='%235a6573' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px;
  padding-right: 36px;
}

/* Calendar icon for .input[type=date] — appearance:none above strips the
   native indicator, so we draw our own and stretch the invisible native
   picker over the whole field so tapping anywhere opens it. */
.input[type="date"] {
  position: relative;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b96a3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><rect x='3' y='4' width='18' height='18' rx='2' ry='2'></rect><line x1='16' y1='2' x2='16' y2='6'></line><line x1='8' y1='2' x2='8' y2='6'></line><line x1='3' y1='10' x2='21' y2='10'></line></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  padding-right: 40px;
}
.input[type="date"]::-webkit-calendar-picker-indicator {
  opacity: 0;
  position: absolute;
  right: 0; top: 0;
  width: 100%; height: 100%;
  cursor: pointer;
}

/* ===== Form controls used by onboarding (.form-input etc) ===== */
.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* Custom chevron for selects (replaces ugly native arrow) */
.form-select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b96a3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'></polyline></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  padding-right: 36px;
}

/* Custom calendar icon for date inputs, hide native indicator */
.form-input[type="date"] {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b96a3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><rect x='3' y='4' width='18' height='18' rx='2' ry='2'></rect><line x1='16' y1='2' x2='16' y2='6'></line><line x1='8' y1='2' x2='8' y2='6'></line><line x1='3' y1='10' x2='21' y2='10'></line></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  padding-right: 36px;
}
.form-input[type="date"]::-webkit-calendar-picker-indicator {
  opacity: 0;
  position: absolute;
  right: 0;
  width: 36px;
  height: 100%;
  cursor: pointer;
}
.form-input[type="date"] { position: relative; }

/* Kill number input spinners (the up/down arrows) */
.form-input[type="number"]::-webkit-inner-spin-button,
.form-input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.form-input[type="number"] {
  -moz-appearance: textfield;
}
.form-help {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 4px;
}

/* ===== Lists ===== */
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-primary { font-weight: 500; }
.list-secondary { font-size: 12px; color: var(--text-dim); }

/* ===== Stats ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--gap);
}
.stat-block {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap);
}
.stat-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.stat-value {
  font-size: 20px;
  font-weight: 600;
  margin-top: 4px;
}
.stat-value.positive { color: var(--accent); }
.stat-value.negative { color: var(--danger); }

/* ===== Toasts ===== */
#toastHost {
  position: fixed;
  bottom: calc(var(--bottomnav-h) + 12px);
  left: 0; right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 1000;
  pointer-events: none;
}
.toast {
  background: var(--bg-elevated);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  pointer-events: auto;
  max-width: 80%;
  transition: opacity 0.25s;
}
.toast-success { border-color: var(--accent); }
.toast-error   { border-color: var(--danger); }
.toast-fade    { opacity: 0; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: var(--gap-lg);
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap-lg);
  max-width: 400px;
  width: 100%;
}
.modal h3 { margin: 0 0 12px 0; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--gap);
  margin-top: var(--gap-lg);
}

/* ===== Onboarding ===== */
.onboarding-step {
  max-width: 480px;
  margin: 0 auto;
  padding: var(--gap-lg);
}
.onboarding-step h2 { font-size: 22px; margin: 0 0 8px 0; }
.onboarding-step p  { color: var(--text-dim); margin: 0 0 var(--gap-lg) 0; }
.onboarding-nav {
  display: flex;
  justify-content: space-between;
  gap: var(--gap);
  margin-top: var(--gap-lg);
}
.onboarding-progress {
  display: flex;
  gap: 4px;
  margin-bottom: var(--gap-lg);
}
.onboarding-progress span {
  height: 4px;
  flex: 1;
  background: var(--border);
  border-radius: 2px;
}
.onboarding-progress span.active { background: var(--accent); }

/* ===== Tabs (used in log view and report views) ===== */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: var(--gap);
}
.tab {
  flex: 1;
  text-align: center;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
}
.tab.active { background: var(--bg-card); color: var(--text); }

/* ===== Misc ===== */
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.tiny  { font-size: 11px; }
.right { text-align: right; }
.row   { display: flex; align-items: center; justify-content: space-between; gap: var(--gap); }
.spacer-sm { height: 8px; }
.spacer    { height: var(--gap-lg); }
.amount-positive { color: var(--accent); }
.amount-negative { color: var(--danger); }
.divider { height: 1px; background: var(--border); margin: var(--gap) 0; }

/* Safe areas (iOS notch) */
@supports (padding: max(0px)) {
  #topbar { padding-top: env(safe-area-inset-top); height: calc(var(--topbar-h) + env(safe-area-inset-top)); }
  #bottomnav { padding-bottom: env(safe-area-inset-bottom); height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom)); }
}

/* ===== Animations (Batch 6a) ===== */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}
@keyframes view-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toast-slide-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Honor users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  .view-fade-in, .toast, .skeleton-line, .skeleton-block, .skeleton-circle { animation: none !important; }
}

.view-fade-in { animation: view-fade-in 0.18s ease-out; }

/* Toast now slides up on appear (was opacity-only). */
.toast { animation: toast-slide-up 0.22s ease-out; }

/* ===== Skeleton loaders (Batch 6a) ===== */
.skeleton-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
}
.skeleton-line {
  height: 12px;
  border-radius: 4px;
  background: var(--bg-elevated);
  animation: pulse 1.4s ease-in-out infinite;
  margin-bottom: 8px;
}
.skeleton-line:last-child { margin-bottom: 0; }
.skeleton-line.sk-w-30 { width: 30%; }
.skeleton-line.sk-w-50 { width: 50%; }
.skeleton-line.sk-w-70 { width: 70%; }
.skeleton-line.sk-w-90 { width: 90%; }
.skeleton-block {
  height: 60px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  animation: pulse 1.4s ease-in-out infinite;
  margin-bottom: 8px;
}
.skeleton-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-elevated);
  animation: pulse 1.4s ease-in-out infinite;
}

/* Initial app loading screen (replaces "Loading…" text). Mirrors the
   shape of a typical view (a balance grid + a couple of cards) so the
   first paint feels stable, not blank. Kept intentionally generic so
   it works whether home or onboarding lands next. */
.boot-skeleton {
  padding-top: 4px;
}
.boot-skeleton .sk-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

/* ===== Empty-state CTA button (Batch 6a — consumed by 6b) ===== */
.empty-cta {
  display: inline-block;
  margin-top: 12px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  background: var(--accent);
  color: #0a0a0a;
  text-decoration: none;
  font-family: inherit;
  line-height: 1.2;
}
.empty-cta:active { background: var(--accent-dim); }
.empty-cta.secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border);
}
.empty-cta.secondary:active { background: var(--bg); }

/* ===== Row flash (Batch 6a-v3 / 6b) =====
   Applied to a list row for ~3.5s after the user updates it elsewhere.
   Duration accounts for the smooth-scroll into view (~300-500ms) before
   the user's eye lands on the row — at 2s the strong phase was burning
   during scroll and only the fade-tail was visible.
   !important guards against view-scoped inline styles overriding. */
@keyframes row-flash {
  0%   { background-color: rgba(63, 185, 80, 0.45) !important; box-shadow: inset 6px 0 0 0 var(--accent) !important; }
  75%  { background-color: rgba(63, 185, 80, 0.35) !important; box-shadow: inset 6px 0 0 0 var(--accent) !important; }
  100% { background-color: transparent !important;             box-shadow: inset 6px 0 0 0 transparent !important; }
}
.row-flash {
  animation: row-flash 4.5s ease-out;
}
@media (prefers-reduced-motion: reduce) {
  .row-flash { animation: none !important; background-color: rgba(63, 185, 80, 0.30) !important; box-shadow: inset 6px 0 0 0 var(--accent) !important; }
}