/* ============================================================
   CALCLY — shared design system (finance calculators)
   Zero-dependency. Pure CSS. Themes via [data-theme].
   Adapted from Forge — emerald accent for money/finance theme.
   ============================================================ */

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { min-height: 100vh; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
img, svg, canvas { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }

/* ---------- Tokens: Light (default) ---------- */
:root,
[data-theme="light"] {
  --bg: #ffffff;
  --bg-subtle: #f7f8f7;
  --bg-muted: #f0f2f0;
  --surface: #ffffff;
  --surface-2: #fafbfa;
  --border: #e6e9e6;
  --border-strong: #d1d6d1;
  --text: #14130f;
  --text-muted: #5c5a52;
  --text-subtle: #97938a;
  --accent: #059669;
  --accent-hover: #047857;
  --accent-soft: rgba(5,150,105,0.10);
  --accent-contrast: #ffffff;
  --gold: #d97706;
  --gold-soft: rgba(217,119,6,0.10);
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --ring: rgba(5,150,105,0.40);
  --shadow-sm: 0 1px 2px rgba(15,15,25,0.04), 0 1px 1px rgba(15,15,25,0.03);
  --shadow-md: 0 4px 16px rgba(15,15,25,0.06), 0 1px 3px rgba(15,15,25,0.04);
  --shadow-lg: 0 16px 48px rgba(15,15,25,0.10), 0 4px 12px rgba(15,15,25,0.05);
  color-scheme: light;
}

/* ---------- Tokens: Dark ---------- */
[data-theme="dark"] {
  --bg: #0a0c0a;
  --bg-subtle: #101210;
  --bg-muted: #161816;
  --surface: #131613;
  --surface-2: #181b18;
  --border: #242824;
  --border-strong: #343834;
  --text: #f4f6f4;
  --text-muted: #9ca09c;
  --text-subtle: #6a6e6a;
  --accent: #34d399;
  --accent-hover: #6ee7b7;
  --accent-soft: rgba(52,211,153,0.14);
  --accent-contrast: #0a0c0a;
  --gold: #fbbf24;
  --gold-soft: rgba(251,191,36,0.14);
  --success: #4ade80;
  --danger: #f87171;
  --warning: #fbbf24;
  --ring: rgba(52,211,153,0.45);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4), 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 16px 48px rgba(0,0,0,0.55), 0 4px 12px rgba(0,0,0,0.4);
  color-scheme: dark;
}

/* ---------- Base ---------- */
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  transition: background-color .2s ease, color .2s ease;
}
code, pre, .mono { font-family: "SF Mono", "JetBrains Mono", "Fira Code", ui-monospace, Menlo, Consolas, monospace; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- Layout ---------- */
.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 24px; }
.container-narrow { max-width: 760px; }
.stack > * + * { margin-top: 1rem; }
.stack-sm > * + * { margin-top: .5rem; }
.stack-lg > * + * { margin-top: 2rem; }
.row { display: flex; align-items: center; gap: .75rem; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.center { display: flex; align-items: center; justify-content: center; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; } .mt-4 { margin-top: 2rem; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.5rem; }
.text-muted { color: var(--text-muted); }
.text-subtle { color: var(--text-subtle); }
.text-sm { font-size: .85rem; }
.text-xs { font-size: .75rem; }
.text-center { text-align: center; }
.hidden { display: none !important; }

/* ---------- Header / Nav ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.nav { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--gold));
  display: grid; place-items: center; color: #fff; font-size: 14px; font-weight: 800;
  box-shadow: var(--shadow-sm);
}
.nav-links { display: flex; align-items: center; gap: .25rem; }
.nav-link {
  padding: .45rem .7rem; border-radius: 8px; font-size: .875rem; color: var(--text-muted);
  transition: background .15s, color .15s;
}
.nav-link:hover { color: var(--text); background: var(--bg-muted); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center;
  color: var(--text-muted); border: 1px solid var(--border); background: var(--surface);
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--bg-muted); }

/* ---------- Hero ---------- */
.hero { padding: 72px 0 40px; }
.eyebrow {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .78rem; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); padding: .3rem .7rem; border-radius: 999px;
}
.hero h1 {
  font-size: clamp(2.1rem, 5vw, 3.2rem); line-height: 1.08; letter-spacing: -.035em;
  font-weight: 800; margin-top: 1rem;
}
.hero p.lead { font-size: 1.15rem; color: var(--text-muted); max-width: 560px; margin-top: 1rem; }

/* ---------- Tool grid (index) ---------- */
.tool-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px;
  padding: 8px 0 64px;
}
.tool-card {
  display: block; padding: 20px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); box-shadow: var(--shadow-sm);
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.tool-card:hover { transform: translateY(-3px); border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.tool-card .tc-icon {
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); margin-bottom: 14px;
}
.tool-card h3 { font-size: 1.02rem; font-weight: 650; letter-spacing: -.01em; }
.tool-card p { font-size: .875rem; color: var(--text-muted); margin-top: .35rem; }
.tool-card .tc-tags { display: flex; gap: .4rem; margin-top: 14px; flex-wrap: wrap; }
.tag {
  font-size: .68rem; font-weight: 600; color: var(--text-muted);
  background: var(--bg-muted); padding: .2rem .5rem; border-radius: 6px; border: 1px solid var(--border);
}

/* ---------- Page header (tool pages) ---------- */
.tool-header { padding: 40px 0 8px; }
.tool-header .crumbs { font-size: .8rem; color: var(--text-subtle); }
.tool-header .crumbs a:hover { color: var(--accent); }
.tool-header h1 { font-size: clamp(1.7rem, 4vw, 2.3rem); letter-spacing: -.025em; font-weight: 750; margin-top: .5rem; }
.tool-header p { color: var(--text-muted); margin-top: .5rem; max-width: 620px; }

/* ---------- Cards / Panels ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 22px; }
.card-header { padding: 16px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.card-header h2, .card-header h3 { font-size: .95rem; font-weight: 650; letter-spacing: -.01em; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px; }

/* ---------- Tool layout ---------- */
.split {
  display: grid; grid-template-columns: minmax(320px, 420px) 1fr; gap: 20px; align-items: start;
}
@media (max-width: 860px) { .split { grid-template-columns: 1fr; } }

/* ---------- Result display ---------- */
.result-big {
  font-size: 2.2rem; font-weight: 800; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums; color: var(--accent);
}
.result-label { font-size: .8rem; color: var(--text-subtle); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; margin-bottom: .35rem; }
.result-row { display: flex; justify-content: space-between; align-items: baseline; padding: .55rem 0; border-bottom: 1px solid var(--border); }
.result-row:last-child { border-bottom: none; }
.result-row .rl-label { font-size: .875rem; color: var(--text-muted); }
.result-row .rl-value { font-size: .95rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.result-row.highlight { background: var(--accent-soft); border-radius: 9px; padding: .7rem .85rem; margin: .3rem 0; border-bottom: none; }
.result-row.highlight .rl-value { font-size: 1.1rem; color: var(--accent); }

/* ---------- Forms ---------- */
.field { margin-bottom: 1rem; }
.field:last-child { margin-bottom: 0; }
.label { display: block; font-size: .8rem; font-weight: 600; color: var(--text); margin-bottom: .4rem; }
.label .hint { font-weight: 400; color: var(--text-subtle); }
.input, .textarea, .select {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 9px; padding: .6rem .7rem; font-size: .9rem; color: var(--text);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.input:focus, .textarea:focus, .select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); background: var(--surface);
}
.textarea { resize: vertical; min-height: 120px; font-family: inherit; line-height: 1.5; }
.input.mono, .textarea.mono { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; font-size: .84rem; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .7rem center; padding-right: 2rem; }

/* currency input prefix */
.input-group { display: flex; align-items: center; }
.input-group .prefix { padding: .6rem .5rem .6rem .7rem; background: var(--bg-muted); border: 1px solid var(--border); border-right: none; border-radius: 9px 0 0 9px; color: var(--text-muted); font-size: .9rem; font-weight: 600; }
.input-group .input { border-radius: 0 9px 9px 0; }

/* range */
input[type="range"] { width: 100%; accent-color: var(--accent); height: 22px; }
.range-row { display: flex; align-items: center; gap: .75rem; }
.range-val { font-family: ui-monospace, monospace; font-size: .8rem; color: var(--text-muted); min-width: 42px; text-align: right; }

/* checkbox */
.check { display: flex; align-items: center; gap: .55rem; font-size: .875rem; cursor: pointer; user-select: none; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }

/* segment control */
.segments { display: inline-flex; background: var(--bg-muted); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 2px; }
.segments button { padding: .35rem .7rem; font-size: .8rem; border-radius: 7px; color: var(--text-muted); font-weight: 500; transition: background .15s, color .15s; }
.segments button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .6rem 1rem; border-radius: 9px; font-size: .88rem; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: background .15s, border-color .15s, transform .08s, box-shadow .15s;
}
.btn:hover { background: var(--bg-muted); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--bg-muted); }
.btn-sm { padding: .4rem .7rem; font-size: .8rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Chart (canvas-based, anti-snippet) ---------- */
.chart-wrap { position: relative; width: 100%; }
.chart-wrap canvas { width: 100% !important; height: auto !important; }
.chart-legend { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: .75rem; font-size: .8rem; }
.chart-legend .leg { display: flex; align-items: center; gap: .4rem; color: var(--text-muted); }
.chart-legend .leg .dot { width: 12px; height: 12px; border-radius: 3px; }

/* ---------- Amortization table ---------- */
.amort-table { width: 100%; border-collapse: collapse; font-size: .82rem; font-variant-numeric: tabular-nums; }
.amort-table th { text-align: right; padding: .5rem .6rem; border-bottom: 2px solid var(--border); font-weight: 600; color: var(--text-muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; }
.amort-table th:first-child { text-align: left; }
.amort-table td { text-align: right; padding: .45rem .6rem; border-bottom: 1px solid var(--border); }
.amort-table td:first-child { text-align: left; font-weight: 600; }
.amort-table tbody tr:hover { background: var(--bg-subtle); }
.table-scroll { max-height: 400px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  pointer-events: auto; background: var(--text); color: var(--bg);
  padding: .65rem 1rem; border-radius: 10px; font-size: .85rem; font-weight: 500;
  box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: .5rem;
  animation: toast-in .25s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); margin-top: 80px; padding: 32px 0; color: var(--text-subtle); font-size: .85rem; }
.footer-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.footer-links { display: flex; gap: 1rem; }
.footer-links a:hover { color: var(--text); }

/* ---------- SEO copy ---------- */
.seo-copy { max-width: 760px; padding-bottom: 48px; }
.seo-copy h2 { font-size: 1.3rem; font-weight: 700; letter-spacing: -.02em; margin-top: 2rem; margin-bottom: .5rem; }
.seo-copy h3 { font-size: 1.05rem; font-weight: 650; letter-spacing: -.01em; margin-top: 1.5rem; margin-bottom: .4rem; }
.seo-copy p { color: var(--text-muted); margin-bottom: .75rem; }
.seo-copy ul { list-style: disc; padding-left: 1.3rem; margin-bottom: .75rem; }
.seo-copy ul li { color: var(--text-muted); margin-bottom: .25rem; }
.seo-copy strong { color: var(--text); }

/* ---------- Misc ---------- */
.divider { height: 1px; background: var(--border); margin: 1.25rem 0; }
.note { font-size: .82rem; color: var(--text-muted); background: var(--bg-subtle); border: 1px solid var(--border); border-radius: 9px; padding: .7rem .85rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px){ .grid-2 { grid-template-columns: 1fr; } }

/* reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
