/* =========================================================================
   123Calculator — stylesheet
   A single, dependency-free stylesheet. Organised as:
   1. Design tokens         2. Reset & base       3. Layout primitives
   4. Header / nav          5. Breadcrumbs        6. Home page
   7. Category & cards      8. Calculator page    9. Forms & results
   10. Search               11. Footer            12. Utilities & responsive
   ========================================================================= */

/* 1. Design tokens ------------------------------------------------------- */
:root {
  --brand:        #12324a;
  --brand-600:    #164064;
  --brand-700:    #0e2739;
  --accent:       #1f9d76;
  --accent-600:   #17835f;
  --ink:          #1f2a37;
  --ink-soft:     #4b5563;
  --muted:        #6b7280;
  --line:         #e5e7eb;
  --line-soft:    #eef1f4;
  --bg:           #f6f8fa;
  --card:         #ffffff;
  --card-alt:     #f9fafb;
  --ring:         rgba(31, 157, 118, .25);
  --danger:       #d64545;
  --radius:       12px;
  --radius-sm:    8px;
  --shadow:       0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
  --shadow-sm:    0 1px 2px rgba(16,24,40,.08);
  --maxw:         1232px;
  --font:         system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* 2. Reset & base -------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  font-size: 16px;
}
h1, h2, h3, h4 { line-height: 1.25; color: var(--ink); margin: 0 0 .5em; }
h1 { font-size: clamp(1.6rem, 3.5vw, 2.3rem); }
h2 { font-size: clamp(1.3rem, 2.6vw, 1.6rem); }
h3 { font-size: 1.15rem; }
p  { margin: 0 0 1rem; }
a  { color: var(--accent-600); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
ul { margin: 0; padding: 0; }
li { list-style: none; }

.skip-link {
  position: absolute; left: -999px; top: 0; background: var(--brand);
  color: #fff; padding: .6rem 1rem; z-index: 1000; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; border-radius: 4px; }

/* 3. Layout primitives --------------------------------------------------- */
.container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }
.site-main { min-height: 60vh; padding-bottom: 3rem; }
.section { padding: 2.5rem 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.section-head p { margin: 0; color: var(--muted); }
.grid { display: grid; gap: 1rem; }

/* 4. Header / nav -------------------------------------------------------- */
.site-header {
  background: var(--brand);
  color: #fff;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 1px 0 rgba(255,255,255,.06), 0 6px 18px rgba(8,20,32,.15);
}
.header-inner { display: flex; align-items: center; gap: 1.25rem; min-height: 64px; }
.brand { display: inline-flex; align-items: center; gap: .55rem; color: #fff; font-weight: 700; text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-mark {
  background: var(--accent); color: #fff; font-weight: 800;
  border-radius: 8px; padding: .12rem .4rem; letter-spacing: -.5px; font-size: 1.05rem;
}
.brand-name { font-size: 1.15rem; letter-spacing: -.2px; }
.main-nav { margin-left: .5rem; }
.main-nav ul { display: flex; gap: .35rem; }
.main-nav a {
  color: #dfe8ef; padding: .5rem .7rem; border-radius: 8px; font-weight: 500;
  font-size: .95rem; display: block; text-decoration: none;
}
.main-nav a:hover, .main-nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.header-search { margin-left: auto; position: relative; display: flex; }
.header-search input {
  border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.12);
  color: #fff; padding: .55rem 2.4rem .55rem .8rem; border-radius: 999px;
  width: 230px; font-size: .92rem;
}
.header-search input::placeholder { color: #c6d2dc; }
.header-search input:focus { background: #fff; color: var(--ink); outline: none; border-color: #fff; }
.header-search input:focus::placeholder { color: var(--muted); }
.header-search button {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: transparent; border: 0; color: #e6eef4; cursor: pointer;
  padding: .35rem; display: flex; border-radius: 999px;
}
.header-search input:focus + button { color: var(--brand); }
.nav-toggle { display: none; }

/* 5. Breadcrumbs --------------------------------------------------------- */
.breadcrumbs { background: #fff; border-bottom: 1px solid var(--line); font-size: .9rem; }
.breadcrumbs ol { display: flex; flex-wrap: wrap; gap: .35rem; padding: .7rem 0; }
.breadcrumbs li { display: flex; align-items: center; color: var(--muted); }
.breadcrumbs li + li::before { content: "/"; margin: 0 .5rem; color: var(--line); }
.breadcrumbs a { color: var(--ink-soft); }
.breadcrumbs [aria-current] { color: var(--muted); }

/* 6. Home / hero --------------------------------------------------------- */
.hero {
  background: linear-gradient(160deg, var(--brand) 0%, var(--brand-600) 60%, #185a7d 100%);
  color: #fff; padding: 3rem 0 3.5rem; text-align: center;
}
.hero h1 { color: #fff; margin-bottom: .5rem; }
.hero p { color: #d6e2ec; font-size: 1.1rem; max-width: 640px; margin: 0 auto 1.6rem; }
.hero-search { max-width: 560px; margin: 0 auto; display: flex; gap: .5rem; }
.hero-search input {
  flex: 1; border: 0; border-radius: 999px; padding: .9rem 1.2rem; font-size: 1rem;
  box-shadow: var(--shadow);
}
.hero-search input:focus { outline: 3px solid rgba(255,255,255,.5); }
.hero-stats { margin-top: 1.5rem; color: #bcd0de; font-size: .9rem; }

/* 7. Category & cards ---------------------------------------------------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }

.cat-card {
  display: flex; flex-direction: column; gap: .6rem; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem;
  box-shadow: var(--shadow-sm); transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
  text-decoration: none; color: inherit;
}
.cat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); text-decoration: none; border-color: #d5dbe1; }
.cat-icon {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center;
  color: #fff; flex: none;
}
.cat-card h3 { margin: 0; }
.cat-card p { margin: 0; color: var(--muted); font-size: .93rem; }
.cat-card .count { margin-top: auto; font-size: .82rem; color: var(--accent-600); font-weight: 600; }

/* compact calculator link cards */
.calc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .6rem; }
.calc-card {
  display: flex; align-items: flex-start; gap: .6rem; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .85rem 1rem;
  text-decoration: none; color: inherit; transition: border-color .12s, box-shadow .12s, transform .12s;
}
.calc-card:hover { border-color: var(--accent); box-shadow: var(--shadow-sm); transform: translateY(-1px); text-decoration: none; }
.calc-card .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: .5rem; flex: none; }
.calc-card .calc-card-body { min-width: 0; }
.calc-card strong { display: block; font-weight: 600; color: var(--ink); font-size: .97rem; }
.calc-card small { color: var(--muted); font-size: .82rem; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* pill list */
.pill-list { display: flex; flex-wrap: wrap; gap: .5rem; }
.pill {
  background: #fff; border: 1px solid var(--line); border-radius: 999px;
  padding: .4rem .9rem; font-size: .9rem; color: var(--ink-soft); text-decoration: none;
}
.pill:hover { border-color: var(--accent); color: var(--accent-600); text-decoration: none; }

/* 8. Calculator page ----------------------------------------------------- */
.calc-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 2rem; align-items: start; padding-top: 2rem; }
.calc-main { min-width: 0; }
.calc-title { margin-bottom: .25rem; }
.calc-lead { color: var(--muted); font-size: 1.05rem; margin-bottom: 1.5rem; }
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 1.5rem; margin-bottom: 1.5rem;
}
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }
.prose { max-width: 72ch; }
.prose h2 { margin-top: 1.75rem; }
.prose ul, .prose ol { padding-left: 1.25rem; margin: 0 0 1rem; }
.prose li { list-style: disc; margin-bottom: .3rem; }
.prose ol li { list-style: decimal; }
.prose code { background: var(--line-soft); padding: .12rem .4rem; border-radius: 5px; font-size: .92em; }

.aside-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.25rem; margin-bottom: 1.25rem; box-shadow: var(--shadow-sm);
}
.aside-card h4 { margin: 0 0 .7rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.aside-card ul li { margin-bottom: .1rem; }
.aside-card ul a { display: block; padding: .3rem 0; color: var(--ink-soft); font-size: .93rem; }
.aside-card ul a:hover { color: var(--accent-600); }

/* 9. Forms & results ----------------------------------------------------- */
.field-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem 1.25rem; }
.col.span-2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: .35rem; }
.field label, .field-label { font-weight: 600; font-size: .92rem; color: var(--ink); }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .6rem .75rem; font-size: 1rem; font-family: inherit; background: #fff; color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring);
}
.field .help { color: var(--muted); font-size: .8rem; }
.input-unit { position: relative; display: flex; align-items: center; }
.input-unit input { padding-right: 3rem; }
.input-unit .unit {
  position: absolute; right: .75rem; color: var(--muted); font-size: .9rem; pointer-events: none;
}
.radio-group { display: flex; flex-wrap: wrap; gap: .5rem; }
.radio {
  display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--line);
  border-radius: 999px; padding: .45rem .9rem; cursor: pointer; font-size: .92rem; background: #fff;
}
.radio input { width: auto; accent-color: var(--accent); }
.radio:has(input:checked) { border-color: var(--accent); background: #f0fbf6; color: var(--accent-600); font-weight: 600; }

.form-actions { display: flex; gap: .75rem; margin-top: 1.5rem; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 1px solid transparent; border-radius: var(--radius-sm); padding: .7rem 1.4rem;
  font-size: 1rem; font-weight: 600; cursor: pointer; text-decoration: none; font-family: inherit;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-600); text-decoration: none; }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink-soft); }
.btn-ghost:hover { border-color: var(--muted); text-decoration: none; }

.result-box {
  margin-top: 1.5rem; border: 1px solid var(--line); border-radius: var(--radius);
  background: linear-gradient(180deg, #f4fbf8, #ffffff); padding: 1.25rem 1.5rem;
}
.result-box.error { background: #fdf2f2; border-color: #f5c6c6; color: #922; }
.result-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; }
.result-item { display: flex; flex-direction: column; gap: .15rem; padding: .6rem .25rem; }
.result-item .result-label { font-size: .85rem; color: var(--muted); }
.result-item .result-value { font-size: 1.4rem; font-weight: 700; color: var(--ink); letter-spacing: -.3px; }
.result-item .result-note { font-size: .8rem; color: var(--muted); }
.result-item.primary {
  background: var(--accent); color: #fff; border-radius: var(--radius-sm); padding: .9rem 1.1rem;
  grid-column: span 1;
}
.result-item.primary .result-label { color: rgba(255,255,255,.85); }
.result-item.primary .result-value { color: #fff; font-size: 1.8rem; }
.result-item.primary .result-note { color: rgba(255,255,255,.85); }
.result-extra { margin-top: 1.25rem; }

/* Result tables */
.result-extra table, .data-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.result-extra th, .result-extra td, .data-table th, .data-table td {
  text-align: right; padding: .5rem .65rem; border-bottom: 1px solid var(--line-soft);
}
.result-extra th:first-child, .result-extra td:first-child,
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.result-extra thead th, .data-table thead th { color: var(--muted); font-weight: 600; border-bottom: 2px solid var(--line); }
.table-scroll { overflow-x: auto; }

/* breakdown bar */
.breakdown-bar { display: flex; height: 20px; border-radius: 999px; overflow: hidden; margin: 1rem 0 .75rem; background: var(--line-soft); }
.breakdown-bar span { display: block; height: 100%; }
.breakdown-legend { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; font-size: .88rem; color: var(--ink-soft); }
.legend-item { display: inline-flex; align-items: center; gap: .4rem; }
.legend-item i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* generic scientific calc keypad */
.keypad { display: grid; grid-template-columns: repeat(5, 1fr); gap: .5rem; margin-top: 1rem; }
.keypad button {
  padding: .85rem 0; font-size: 1.05rem; border: 1px solid var(--line); background: #fff;
  border-radius: var(--radius-sm); cursor: pointer; font-family: inherit; color: var(--ink);
}
.keypad button:hover { background: var(--card-alt); border-color: var(--muted); }
.keypad button.op { background: #eef4f8; color: var(--brand); }
.keypad button.eq { background: var(--accent); color: #fff; border-color: var(--accent); }
.keypad button.fn { font-size: .9rem; }
.calc-display {
  width: 100%; text-align: right; font-size: 1.8rem; padding: 1rem; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: #0e2739; color: #eafff6; font-variant-numeric: tabular-nums;
  overflow-x: auto;
}

/* 10. Search ------------------------------------------------------------- */
.search-header { padding: 2rem 0 0; }
.search-count { color: var(--muted); margin-bottom: 1rem; }

/* 11. Footer ------------------------------------------------------------- */
.site-footer { background: var(--brand-700); color: #c6d3dd; margin-top: 3rem; }
.footer-grid {
  display: grid; grid-template-columns: 1.4fr repeat(4, 1fr); gap: 2rem; padding: 2.5rem 0;
}
.footer-about p { color: #9fb2c0; font-size: .9rem; margin-top: .75rem; }
.footer-about .brand { color: #fff; }
.footer-col h4 { color: #fff; font-size: .95rem; margin-bottom: .7rem; }
.footer-col h4 a { color: #fff; }
.footer-col ul a { color: #a9bccb; font-size: .88rem; display: block; padding: .18rem 0; }
.footer-col ul a:hover { color: #fff; }
.footer-bottom { border-top: 1px solid rgba(255,255,255,.08); padding: 1.1rem 0; }
.footer-bottom .container { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: center; }
.footer-bottom p { margin: 0; font-size: .84rem; color: #8ea2b2; }
.footer-links a { color: #b7c8d5; margin-left: 1rem; font-size: .84rem; }

/* 12. Utilities & responsive -------------------------------------------- */
.text-muted { color: var(--muted); }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.tag { display: inline-block; background: var(--line-soft); color: var(--ink-soft); border-radius: 6px; padding: .1rem .5rem; font-size: .78rem; }
.notice { background: #fffbeb; border: 1px solid #fde68a; color: #92670c; padding: .75rem 1rem; border-radius: var(--radius-sm); font-size: .9rem; }

@media (max-width: 900px) {
  .calc-layout { grid-template-columns: 1fr; }
  .calc-aside { order: 2; }
  .footer-grid { grid-template-columns: repeat(2, 1fr); }
  .footer-about { grid-column: 1 / -1; }
}

@media (max-width: 720px) {
  .nav-toggle {
    display: inline-flex; flex-direction: column; gap: 4px; margin-left: auto;
    background: transparent; border: 0; cursor: pointer; padding: .5rem;
  }
  .nav-toggle span { width: 22px; height: 2px; background: #fff; border-radius: 2px; }
  .header-inner { flex-wrap: wrap; }
  .main-nav {
    order: 3; flex-basis: 100%; margin: 0; max-height: 0; overflow: hidden;
    transition: max-height .2s ease;
  }
  .main-nav.open { max-height: 320px; padding-bottom: .5rem; }
  .main-nav ul { flex-direction: column; gap: 0; }
  .main-nav a { padding: .7rem .5rem; border-radius: 0; }
  .header-search { order: 2; margin-left: 0; flex: 1; }
  .header-search input { width: 100%; }
  .field-grid { grid-template-columns: 1fr; }
  .footer-grid { grid-template-columns: 1fr; gap: 1.25rem; }
}
