/* ============================================================
   CALCHUB – MAIN STYLESHEET
   Organized: Variables → Reset → Layout → Components → Pages → Responsive
   ============================================================ */

/* ============================================================
   1. DESIGN TOKENS (CSS Custom Properties)
   ============================================================ */
:root {
  /* Brand colours */
  --clr-primary:        #6366f1;
  --clr-primary-dark:   #4f46e5;
  --clr-primary-light:  #eef2ff;
  --clr-secondary:      #8b5cf6;

  /* Category accent colours */
  --clr-basic:      #6366f1;
  --clr-financial:  #10b981;
  --clr-math:       #f59e0b;
  --clr-health:     #ec4899;
  --clr-engineer:   #3b82f6;
  --clr-datetime:   #14b8a6;
  --clr-business:   #f97316;

  /* Surface */
  --bg:         #f1f5f9;
  --surface:    #ffffff;
  --surface-2:  #f8fafc;
  --surface-3:  #f1f5f9;

  /* Borders */
  --border:       #e2e8f0;
  --border-focus: #6366f1;

  /* Text */
  --text:       #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  /* Status */
  --success:    #22c55e;
  --success-bg: #f0fdf4;
  --error:      #ef4444;
  --error-bg:   #fef2f2;
  --warning:    #f59e0b;
  --warning-bg: #fffbeb;
  --info:       #3b82f6;
  --info-bg:    #eff6ff;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0,0,0,.05);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.09), 0 2px 4px -2px rgba(0,0,0,.07);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.10), 0 4px 6px -4px rgba(0,0,0,.07);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,.10), 0 8px 10px -6px rgba(0,0,0,.07);

  /* Spacing scale */
  --sp-1: 4px;   --sp-2: 8px;   --sp-3: 12px;  --sp-4: 16px;
  --sp-5: 20px;  --sp-6: 24px;  --sp-8: 32px;  --sp-10: 40px;
  --sp-12: 48px; --sp-16: 64px;

  /* Border radius */
  --r-sm: 6px;  --r-md: 10px;  --r-lg: 16px;
  --r-xl: 20px; --r-full: 9999px;

  /* Structural sizes */
  --header-h:  62px;
  --sidebar-w: 248px;

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', Consolas, monospace;

  /* Transitions */
  --ease:     cubic-bezier(.4,0,.2,1);
  --t-fast:   150ms var(--ease);
  --t-normal: 250ms var(--ease);
  --t-slow:   350ms var(--ease);
}

/* Dark theme overrides */
[data-theme="dark"] {
  --bg:         #0f172a;
  --surface:    #1e293b;
  --surface-2:  #162032;
  --surface-3:  #0f172a;
  --border:     #334155;
  --text:       #f1f5f9;
  --text-muted: #94a3b8;
  --text-light: #64748b;
  --clr-primary-light: #1e1b4b;

  --success-bg: #052e16;
  --error-bg:   #450a0a;
  --warning-bg: #451a03;
  --info-bg:    #0c2347;

  --shadow-xs: 0 1px 2px rgba(0,0,0,.3);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.35);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.35);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.4);
}

/* ============================================================
   2. RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--t-normal), color var(--t-normal);
  -webkit-font-smoothing: antialiased;
}

a            { color: var(--clr-primary); text-decoration: none; }
a:hover      { text-decoration: underline; }
button       { cursor: pointer; border: none; background: none; font-family: inherit; color: inherit; }
input, select, textarea { font-family: inherit; color: inherit; }
svg          { display: block; flex-shrink: 0; }
img          { max-width: 100%; }

/* Focus ring */
:focus-visible {
  outline: 2px solid var(--clr-primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ============================================================
   3. LAYOUT
   ============================================================ */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-4);
  z-index: 1000;
  box-shadow: var(--shadow-xs);
  transition: background var(--t-normal), border-color var(--t-normal);
}

.header-left  { display: flex; align-items: center; gap: var(--sp-3); flex-shrink: 0; }
.header-center{ flex: 1; min-width: 0; max-width: 520px; margin: 0 auto; }
.header-right { display: flex; align-items: center; gap: var(--sp-2); flex-shrink: 0; }

/* App layout: sidebar + main */
.app-layout {
  display: flex;
  padding-top: var(--header-h);
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform var(--t-normal), background var(--t-normal);
  z-index: 900;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 850;
  backdrop-filter: blur(2px);
}

/* ---- Main content ---- */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: var(--sp-8) var(--sp-8);
  min-width: 0;
  transition: margin var(--t-normal);
}

/* ============================================================
   4. LOGO & HEADER ELEMENTS
   ============================================================ */
.logo {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  text-decoration: none;
  color: var(--text);
}

.logo-symbol {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--clr-primary), var(--clr-secondary));
  color: #fff;
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  flex-shrink: 0;
}

.logo-name {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.02em;
}

/* Generic icon button */
.btn-icon {
  width: 38px; height: 38px;
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: background var(--t-fast), color var(--t-fast);
  font-size: 18px;
}
.btn-icon:hover { background: var(--surface-3); color: var(--text); }

/* Theme toggle: show correct icon based on theme */
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun  { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* ============================================================
   5. SEARCH
   ============================================================ */
.search-container {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: var(--sp-3);
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 40px;
  padding: 0 var(--sp-10) 0 var(--sp-10);
  border: 1.5px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface-2);
  font-size: .9rem;
  color: var(--text);
  transition: border-color var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
  /* Remove native search cancel button */
}
.search-input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-input::placeholder { color: var(--text-light); }
.search-input:focus {
  outline: none;
  border-color: var(--clr-primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(99,102,241,.18);
}

.search-kbd {
  position: absolute;
  right: var(--sp-3);
  font-size: .7rem;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-light);
  background: var(--surface-3);
  font-family: var(--font);
  pointer-events: none;
  white-space: nowrap;
}

/* Dropdown results */
.search-dropdown {
  position: absolute;
  top: calc(100% + var(--sp-2));
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xl);
  max-height: 400px;
  overflow-y: auto;
  z-index: 2000;
  padding: var(--sp-2);
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background var(--t-fast);
}
.search-result-item:hover,
.search-result-item[aria-selected="true"] { background: var(--clr-primary-light); }

.search-result-icon { font-size: 1.2rem; width: 28px; text-align: center; }
.search-result-info { flex: 1; min-width: 0; }
.search-result-name  { font-size: .9rem; font-weight: 600; color: var(--text); }
.search-result-cat   { font-size: .75rem; color: var(--text-muted); }
.search-empty        { padding: var(--sp-4); text-align: center; color: var(--text-muted); font-size: .9rem; }

/* ============================================================
   6. SIDEBAR NAV
   ============================================================ */
.sidebar-nav {
  padding: var(--sp-4) var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-home,
.nav-category {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  font-size: .9rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
  user-select: none;
}
.nav-home:hover,
.nav-category:hover { background: var(--surface-3); color: var(--text); }

.nav-home.active,
.nav-category.active { background: var(--clr-primary-light); color: var(--clr-primary); font-weight: 600; }

.nav-icon { font-size: 1.1rem; width: 22px; text-align: center; }

.nav-section-title {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-light);
  padding: var(--sp-4) var(--sp-3) var(--sp-1);
}

/* ============================================================
   7. HOME PAGE
   ============================================================ */
.home-hero {
  text-align: center;
  padding: var(--sp-10) var(--sp-4) var(--sp-8);
}

.home-hero-icon {
  width: 72px; height: 72px;
  background: linear-gradient(135deg, var(--clr-primary), var(--clr-secondary));
  border-radius: var(--r-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  margin: 0 auto var(--sp-5);
  box-shadow: 0 8px 24px rgba(99,102,241,.35);
}

.home-hero h1 {
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 800;
  letter-spacing: -.03em;
  margin-bottom: var(--sp-3);
  background: linear-gradient(135deg, var(--clr-primary), var(--clr-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.home-hero p {
  font-size: 1.05rem;
  color: var(--text-muted);
  max-width: 500px;
  margin: 0 auto;
}

/* Recent calculators */
.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.recent-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  margin-bottom: var(--sp-8);
}

.recent-chip {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t-fast);
  color: var(--text);
}
.recent-chip:hover {
  border-color: var(--clr-primary);
  background: var(--clr-primary-light);
  color: var(--clr-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

/* Category cards on home page */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--sp-5);
  margin-bottom: var(--sp-8);
}

.category-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  cursor: pointer;
  transition: all var(--t-normal);
  position: relative;
  overflow: hidden;
}
.category-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--cat-color, var(--clr-primary));
}
.category-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--cat-color, var(--clr-primary));
}

.category-card-icon {
  font-size: 2.2rem;
  margin-bottom: var(--sp-3);
}
.category-card-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--sp-1);
}
.category-card-desc {
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: var(--sp-4);
}
.category-card-count {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: .78rem;
  font-weight: 600;
  color: var(--cat-color, var(--clr-primary));
  background: color-mix(in srgb, var(--cat-color, var(--clr-primary)) 12%, transparent);
  padding: 3px var(--sp-2);
  border-radius: var(--r-full);
}

/* ============================================================
   8. CATEGORY PAGE
   ============================================================ */
.page-header {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  margin-bottom: var(--sp-8);
  padding-bottom: var(--sp-6);
  border-bottom: 1px solid var(--border);
}
.page-header-icon { font-size: 2.5rem; }
.page-header-info h2 { font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; }
.page-header-info p  { font-size: .9rem; color: var(--text-muted); margin-top: 4px; }

.calc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--sp-5);
}

/* Calculator cards on category page */
.calc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  cursor: pointer;
  transition: all var(--t-normal);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.calc-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--cat-color, var(--clr-primary));
}

.calc-card-icon  { font-size: 1.8rem; }
.calc-card-name  { font-size: 1rem; font-weight: 700; color: var(--text); }
.calc-card-desc  { font-size: .83rem; color: var(--text-muted); flex: 1; }
.calc-card-arrow {
  align-self: flex-end;
  width: 28px; height: 28px;
  border-radius: var(--r-full);
  background: var(--cat-color, var(--clr-primary));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: .9rem;
  margin-top: var(--sp-2);
  transition: transform var(--t-fast);
}
.calc-card:hover .calc-card-arrow { transform: translateX(3px); }

/* ============================================================
   9. CALCULATOR PAGE (breadcrumb + form)
   ============================================================ */
.calc-breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: .82rem;
  color: var(--text-muted);
  margin-bottom: var(--sp-6);
}
.calc-breadcrumb a     { color: var(--clr-primary); }
.calc-breadcrumb .sep  { color: var(--text-light); }

.calc-header {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-4);
  margin-bottom: var(--sp-8);
}
.calc-header-icon {
  width: 52px; height: 52px;
  background: color-mix(in srgb, var(--cat-color, var(--clr-primary)) 15%, transparent);
  border-radius: var(--r-lg);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
  flex-shrink: 0;
}
.calc-header-info h2 { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; }
.calc-header-info p  { font-size: .9rem; color: var(--text-muted); margin-top: 4px; }

/* Two-column layout: form | result */
.calc-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-6);
  align-items: start;
}

@media (max-width: 860px) {
  .calc-layout { grid-template-columns: 1fr; }
}

/* Form card */
.calc-form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
}

.form-group {
  margin-bottom: var(--sp-5);
}
.form-group:last-child { margin-bottom: 0; }

.form-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--sp-2);
}
.form-unit {
  font-size: .78rem;
  font-weight: 400;
  color: var(--text-muted);
  background: var(--surface-3);
  padding: 2px 7px;
  border-radius: var(--r-full);
}

.form-input {
  width: 100%;
  height: 44px;
  padding: 0 var(--sp-3);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  font-size: .95rem;
  color: var(--text);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.form-input:focus {
  outline: none;
  border-color: var(--clr-primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
.form-input.error { border-color: var(--error); }

.form-select {
  width: 100%;
  height: 44px;
  padding: 0 var(--sp-3);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  font-size: .95rem;
  color: var(--text);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
  padding-right: 36px;
  transition: border-color var(--t-fast);
}
.form-select:focus { outline: none; border-color: var(--clr-primary); box-shadow: 0 0 0 3px rgba(99,102,241,.15); }

.form-error { font-size: .78rem; color: var(--error); margin-top: var(--sp-1); }
.form-hint  { font-size: .78rem; color: var(--text-muted); margin-top: var(--sp-1); }

/* Radio tabs */
.radio-tabs {
  display: flex;
  gap: 0;
  background: var(--surface-3);
  border-radius: var(--r-md);
  padding: 4px;
}
.radio-tab {
  flex: 1;
  padding: var(--sp-2) var(--sp-3);
  text-align: center;
  border-radius: var(--r-sm);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t-fast);
  color: var(--text-muted);
}
.radio-tab.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow-xs);
}

/* Calc button */
.btn-calc {
  width: 100%;
  height: 48px;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--clr-primary), var(--clr-secondary));
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -.01em;
  transition: opacity var(--t-fast), transform var(--t-fast);
  margin-top: var(--sp-4);
}
.btn-calc:hover   { opacity: .93; transform: translateY(-1px); }
.btn-calc:active  { transform: translateY(0); }

/* ============================================================
   10. RESULTS CARD
   ============================================================ */
.calc-result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  position: sticky;
  top: calc(var(--header-h) + var(--sp-6));
}

.result-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-10) var(--sp-6);
  color: var(--text-light);
  text-align: center;
  gap: var(--sp-3);
}
.result-placeholder-icon { font-size: 2.5rem; opacity: .5; }
.result-placeholder p    { font-size: .875rem; }

.result-grid {
  display: grid;
  gap: var(--sp-3);
}

.result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-2);
  border-radius: var(--r-md);
  gap: var(--sp-3);
}
.result-item.highlight {
  background: var(--clr-primary-light);
  border: 1px solid color-mix(in srgb, var(--clr-primary) 25%, transparent);
}
.result-item.highlight .result-value {
  color: var(--clr-primary);
  font-size: 1.3rem;
}

.result-label { font-size: .85rem; color: var(--text-muted); font-weight: 500; }
.result-value { font-size: 1rem; font-weight: 700; color: var(--text); font-family: var(--font-mono); text-align: right; }

.result-note {
  margin-top: var(--sp-4);
  font-size: .82rem;
  color: var(--text-muted);
  line-height: 1.5;
  padding: var(--sp-3);
  background: var(--info-bg);
  border-radius: var(--r-md);
  border-left: 3px solid var(--info);
}

.result-error {
  padding: var(--sp-4);
  background: var(--error-bg);
  border-radius: var(--r-md);
  color: var(--error);
  font-size: .9rem;
  border-left: 3px solid var(--error);
}

/* ============================================================
   11. STANDARD CALCULATOR (custom UI)
   ============================================================ */
.std-calc {
  max-width: 340px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.std-calc-display {
  background: linear-gradient(160deg, #1e293b 0%, #0f172a 100%);
  padding: var(--sp-6) var(--sp-5) var(--sp-5);
  text-align: right;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
[data-theme="dark"] .std-calc-display {
  background: linear-gradient(160deg, #0f172a 0%, #020617 100%);
}

.std-calc-expr {
  font-size: .82rem;
  color: rgba(255,255,255,.45);
  min-height: 1.2em;
  margin-bottom: var(--sp-2);
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.std-calc-value {
  font-size: 2.4rem;
  font-weight: 300;
  color: #fff;
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: -.02em;
}

.std-calc-memory {
  font-size: .7rem;
  color: rgba(255,255,255,.4);
  margin-top: var(--sp-1);
  min-height: 1em;
}

.std-calc-buttons {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1px;
  background: var(--border);
}

.calc-btn {
  padding: 0;
  height: 56px;
  font-size: .9rem;
  font-weight: 600;
  background: var(--surface);
  color: var(--text);
  transition: background var(--t-fast), color var(--t-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
}
.calc-btn:hover  { background: var(--surface-3); }
.calc-btn:active { background: var(--border); }

.calc-btn.btn-op   { color: var(--clr-primary); font-size: 1.1rem; }
.calc-btn.btn-eq   { background: var(--clr-primary); color: #fff; }
.calc-btn.btn-eq:hover { background: var(--clr-primary-dark); }
.calc-btn.btn-clear { color: var(--error); }
.calc-btn.btn-mem   { font-size: .75rem; color: var(--text-muted); }
.calc-btn.btn-span2 { grid-column: span 2; }
.calc-btn.btn-span5 { grid-column: span 5; }
.calc-btn.btn-fn    { color: var(--clr-secondary); font-size: .82rem; }
.calc-btn.btn-active { background: var(--clr-primary-light); color: var(--clr-primary); }

/* ============================================================
   12. PROGRAMMER CALCULATOR
   ============================================================ */
.prog-calc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.prog-display {
  background: linear-gradient(160deg, #1e293b, #0f172a);
  padding: var(--sp-5);
  display: grid;
  gap: var(--sp-2);
}
[data-theme="dark"] .prog-display { background: linear-gradient(160deg, #0f172a, #020617); }

.prog-base-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-family: var(--font-mono);
}
.prog-base-label {
  width: 36px;
  font-size: .72rem;
  font-weight: 700;
  color: rgba(255,255,255,.35);
  text-transform: uppercase;
}
.prog-base-value {
  font-size: .95rem;
  color: rgba(255,255,255,.6);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.prog-base-row.active .prog-base-value { color: #fff; font-size: 1.1rem; }
.prog-base-row.active .prog-base-label { color: var(--clr-primary); }

.prog-bits {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  padding: var(--sp-3) 0 0;
  border-top: 1px solid rgba(255,255,255,.08);
  margin-top: var(--sp-2);
}
.prog-bit {
  width: 22px; height: 22px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem;
  font-family: var(--font-mono);
  color: rgba(255,255,255,.4);
  cursor: pointer;
  transition: all var(--t-fast);
}
.prog-bit.on { background: var(--clr-primary); border-color: var(--clr-primary); color: #fff; }

.prog-buttons {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 1px;
  background: var(--border);
}

/* ============================================================
   13. MATRIX CALCULATOR
   ============================================================ */
.matrix-grid-input {
  display: inline-grid;
  gap: var(--sp-1);
  margin: var(--sp-3) 0;
}

.matrix-cell-input {
  width: 62px; height: 40px;
  text-align: center;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: .9rem;
  color: var(--text);
  font-family: var(--font-mono);
  transition: border-color var(--t-fast);
}
.matrix-cell-input:focus { outline: none; border-color: var(--clr-primary); }

.matrix-result-grid {
  display: inline-grid;
  gap: var(--sp-1);
  background: var(--clr-primary-light);
  border-radius: var(--r-md);
  padding: var(--sp-3);
}
.matrix-result-cell {
  width: 62px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-size: .9rem;
  color: var(--clr-primary);
  font-weight: 600;
}

/* ============================================================
   14. UNIT CONVERTER
   ============================================================ */
.unit-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-bottom: var(--sp-5);
}
.unit-tab {
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-full);
  font-size: .82rem;
  font-weight: 500;
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: all var(--t-fast);
  color: var(--text-muted);
}
.unit-tab.active {
  background: var(--clr-primary);
  border-color: var(--clr-primary);
  color: #fff;
}

.unit-convert-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
}
.unit-swap-btn {
  width: 36px; height: 36px;
  border-radius: var(--r-full);
  background: var(--clr-primary-light);
  color: var(--clr-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  transition: all var(--t-fast);
}
.unit-swap-btn:hover { background: var(--clr-primary); color: #fff; transform: rotate(180deg); }

.unit-all-results {
  display: grid;
  gap: var(--sp-2);
  margin-top: var(--sp-5);
  max-height: 400px;
  overflow-y: auto;
}
.unit-result-row {
  display: flex;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  font-size: .875rem;
  transition: background var(--t-fast);
}
.unit-result-row:hover    { background: var(--surface-3); }
.unit-result-row.highlight { background: var(--clr-primary-light); font-weight: 600; }
.unit-result-name  { color: var(--text-muted); }
.unit-result-value { color: var(--text); font-family: var(--font-mono); }

/* ============================================================
   15. ANIMATIONS
   ============================================================ */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes pop {
  0%   { transform: scale(.95); opacity: 0; }
  100% { transform: scale(1);   opacity: 1; }
}

.animate-fade-in  { animation: fadeIn     var(--t-normal) both; }
.animate-slide-up { animation: fadeInUp   var(--t-normal) both; }
.animate-pop      { animation: pop        var(--t-fast) both; }

/* Stagger children */
.stagger-children > * { animation: fadeInUp var(--t-normal) both; }
.stagger-children > *:nth-child(1) { animation-delay: 0ms;   }
.stagger-children > *:nth-child(2) { animation-delay: 60ms;  }
.stagger-children > *:nth-child(3) { animation-delay: 120ms; }
.stagger-children > *:nth-child(4) { animation-delay: 180ms; }
.stagger-children > *:nth-child(5) { animation-delay: 240ms; }
.stagger-children > *:nth-child(6) { animation-delay: 300ms; }
.stagger-children > *:nth-child(7) { animation-delay: 360ms; }
.stagger-children > *:nth-child(8) { animation-delay: 420ms; }
.stagger-children > *:nth-child(9) { animation-delay: 480ms; }

/* ============================================================
   16. MISC UTILITIES
   ============================================================ */
.divider { border: none; border-top: 1px solid var(--border); margin: var(--sp-6) 0; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-size: .72rem;
  font-weight: 600;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-error   { background: var(--error-bg);   color: var(--error);   }
.badge-info    { background: var(--info-bg);     color: var(--info);    }
.badge-warn    { background: var(--warning-bg);  color: var(--warning); }

/* BMI / health colour indicators */
.bmi-bar {
  height: 8px;
  border-radius: var(--r-full);
  background: linear-gradient(to right, #3b82f6 0%, #22c55e 18.5%, #22c55e 25%, #f59e0b 30%, #ef4444 40%);
  position: relative;
  margin: var(--sp-3) 0;
}
.bmi-pointer {
  position: absolute;
  top: -5px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--text);
  transform: translateX(-50%);
  transition: left var(--t-normal);
}

/* Table for stats / amortisation */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
  margin-top: var(--sp-4);
}
.data-table th {
  background: var(--surface-3);
  padding: var(--sp-2) var(--sp-3);
  text-align: left;
  font-weight: 600;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-mono);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface-2); }

/* Heart rate zone bars */
.hr-zone {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
}
.hr-zone-bar {
  height: 8px;
  border-radius: var(--r-full);
  flex: 1;
}
.hr-zone-label { font-size: .8rem; width: 90px; font-weight: 600; color: var(--text-muted); }
.hr-zone-range { font-size: .8rem; width: 90px; text-align: right; font-family: var(--font-mono); color: var(--text-muted); }

/* ============================================================
   17. RESPONSIVE
   ============================================================ */

/* Tablet */
@media (max-width: 1024px) {
  .main-content { padding: var(--sp-6) var(--sp-5); }
}

/* Mobile (sidebar hidden by default) */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-xl);
  }
  .sidebar-overlay.visible { display: block; }

  .main-content {
    margin-left: 0;
    padding: var(--sp-5) var(--sp-4);
  }

  .search-kbd   { display: none; }
  .logo-name    { display: none; }
  .category-grid { grid-template-columns: 1fr 1fr; }
  .calc-grid    { grid-template-columns: 1fr; }

  .std-calc { max-width: 100%; }
  .calc-btn { height: 52px; }

  .unit-convert-row { grid-template-columns: 1fr; }
  .unit-swap-btn    { transform: rotate(90deg); margin: 0 auto; }
}

@media (max-width: 480px) {
  .category-grid { grid-template-columns: 1fr; }
  .header-center { max-width: none; }
}

/* ============================================================
   CURRENCY CONVERTER – LIVE
   ============================================================ */

/* ── Wrapper ── */
.curr-wrapper { max-width: 720px; margin: 0 auto; }

/* ── Status pill ── */
.curr-status {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  font-size: .75rem;
  color: var(--text-muted);
  background: var(--bg);
  margin-bottom: var(--sp-5);
  flex-wrap: wrap;
}
.curr-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-muted);
  transition: background .4s;
}
.curr-dot-live    { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.2); animation: currPulse 2.4s ease-in-out infinite; }
.curr-dot-cache   { background: #f59e0b; }
.curr-dot-offline { background: #94a3b8; }
.curr-dot-loading { background: var(--clr-primary); animation: currPulse 1s ease-in-out infinite; }
@keyframes currPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,.4); }
  50%       { box-shadow: 0 0 0 6px rgba(34,197,94,0); }
}
.curr-updated { margin-left: var(--sp-2); opacity: .6; }

/* ── Main card ── */
.curr-main {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--sp-7);
  box-shadow: var(--shadow-lg);
  margin-bottom: var(--sp-4);
}

/* ── Currency panel (from / to) ── */
.curr-panel { display: flex; flex-direction: column; gap: var(--sp-3); min-width: 0; }

.curr-panel-top {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.curr-flag { font-size: 1.7rem; line-height: 1; flex-shrink: 0; user-select: none; }

.curr-sel {
  flex: 1;
  min-width: 0;
  border: none;
  background: var(--bg);
  color: var(--text);
  font-size: .88rem;
  font-weight: 600;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  cursor: pointer;
}
.curr-sel:focus { outline: 2px solid var(--clr-primary); }

.curr-amount-input {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--text);
  border: none;
  border-bottom: 2px solid var(--border);
  background: transparent;
  width: 100%;
  padding: var(--sp-2) 0;
  transition: border-color .2s;
  font-variant-numeric: tabular-nums;
}
.curr-amount-input:focus { outline: none; border-bottom-color: var(--clr-primary); }
.curr-amount-input::-webkit-inner-spin-button,
.curr-amount-input::-webkit-outer-spin-button { opacity: .4; cursor: pointer; }

.curr-panel-name { font-size: .78rem; color: var(--text-muted); }

.curr-converted {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--clr-primary);
  padding: var(--sp-2) 0;
  border-bottom: 2px solid transparent;
  word-break: break-all;
  font-variant-numeric: tabular-nums;
}

@keyframes currFlash {
  from { opacity: .3; transform: translateY(6px); }
  to   { opacity: 1;  transform: translateY(0);   }
}
.curr-flash { animation: currFlash .28s ease-out; }

/* ── Middle column (swap + mini rate) ── */
.curr-mid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
}
.curr-swap {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--clr-primary);
  font-size: 1.4rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-md);
  transition: all .25s cubic-bezier(.34,1.56,.64,1);
}
.curr-swap:hover {
  background: var(--clr-primary);
  color: #fff;
  border-color: var(--clr-primary);
  transform: rotate(180deg) scale(1.1);
}
.curr-mini-rate {
  font-size: .7rem;
  color: var(--text-muted);
  text-align: center;
  white-space: nowrap;
  max-width: 90px;
  word-break: break-all;
  white-space: normal;
  line-height: 1.3;
}

/* ── Rate bar ── */
.curr-rate-bar {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-3) var(--sp-5);
  margin-bottom: var(--sp-5);
  font-size: .85rem;
  color: var(--text-muted);
  min-height: 44px;
}
.curr-rate-row {
  display: flex;
  align-items: center;
  gap: var(--sp-5);
  flex-wrap: wrap;
}
.curr-rate-row strong { color: var(--text); }
.curr-rate-sep { color: var(--border); font-size: 1.2rem; }

/* ── List header ── */
.curr-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-3);
}
.curr-list-title {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* ── Search input ── */
.curr-search {
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  padding: var(--sp-2) var(--sp-4);
  background: var(--bg);
  color: var(--text);
  font-size: .85rem;
  width: 200px;
  transition: border-color .2s, width .3s ease;
}
.curr-search:focus { outline: none; border-color: var(--clr-primary); width: 260px; }

/* ── Currency list ── */
.curr-list {
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  overflow: hidden;
  max-height: 420px;
  overflow-y: auto;
  background: var(--surface);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.curr-row {
  display: grid;
  grid-template-columns: 2.2rem 5.5rem 1fr auto;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .12s;
  user-select: none;
}
.curr-row:last-child { border-bottom: none; }
.curr-row:hover      { background: var(--bg); }
.curr-row:focus      { outline: 2px solid var(--clr-primary) inset; }
.curr-row-active     { background: color-mix(in srgb, var(--clr-primary) 8%, transparent) !important; }
.curr-row-flag  { font-size: 1.2rem; }
.curr-row-code  { font-size: .85rem; font-weight: 700; font-family: var(--font-mono); display: flex; align-items: center; gap: 4px; }
.curr-row-name  { font-size: .8rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.curr-row-val   { font-size: .88rem; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.curr-row-active .curr-row-code,
.curr-row-active .curr-row-val  { color: var(--clr-primary); }

.curr-badge {
  display: inline-block;
  font-size: .6rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  vertical-align: middle;
  letter-spacing: .03em;
  font-family: var(--font-sans);
}
.curr-badge-to   { background: var(--clr-primary); color: #fff; }
.curr-badge-from { background: var(--clr-secondary); color: #fff; }

.curr-empty {
  padding: var(--sp-6);
  text-align: center;
  color: var(--text-muted);
  font-size: .9rem;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .curr-main {
    grid-template-columns: 1fr;
    gap: var(--sp-3);
    padding: var(--sp-5);
  }
  .curr-mid { flex-direction: row; justify-content: center; }
  .curr-mini-rate { max-width: none; }
  .curr-swap:hover { transform: rotate(90deg) scale(1.1); }
  .curr-amount-input,
  .curr-converted { font-size: 1.6rem; }
  .curr-row { grid-template-columns: 2rem 4.5rem 1fr auto; }
  .curr-search { width: 150px; }
  .curr-search:focus { width: 180px; }
  .curr-rate-row { gap: var(--sp-2); }
  .curr-rate-sep { display: none; }
}
