/* ==========================================================================
   SimpleHome - style.css (v23.1: Crystal Clear + Mobile Native List - FIXED)
   "Desktop Table. Mobile Receipt. Perfect Layout."
   Changes:
   - ✅ Fixed .sh-check flex bug (flex-direction had no effect)
   - ✅ Prevented mobile table card hover glitches / border-bottom artifacts
   - ✅ Ensured mobile table cards fill width + stable spacing
   - ✅ Added tabular nums for totals + amounts
   - ✅ Kept desktop table intact
   ========================================================================== */

/* 1. THEME MATRIX */
:root {
  --page-width: 1280px;

  /* ANIMATION PHYSICS */
  --ease-spring: cubic-bezier(0.4, 0.0, 0.2, 1);
  --ease-snap: cubic-bezier(0.175, 0.885, 0.32, 1.1);

  /* LIGHT: "Morning Frost" */
  --bg-core: #f0f4f8;
  --bg-grad:
    radial-gradient(120% 120% at 50% 0%, #ffffff 0%, transparent 100%),
    radial-gradient(circle at 0% 0%, rgba(99, 102, 241, 0.08), transparent 40%),
    radial-gradient(circle at 100% 100%, rgba(6, 182, 212, 0.08), transparent 40%);

  --glass-surface: rgba(255, 255, 255, 0.65);
  --glass-border: 1px solid rgba(255, 255, 255, 0.8);
  --glass-shine: inset 0 1px 0 rgba(255, 255, 255, 0.9);
  --glass-blur: blur(40px) saturate(160%);

  --ink-100: #0f172a;
  --ink-200: #334155;
  --ink-300: #64748b;
  --ink-400: #94a3b8;

  /* ACCENT: "Electric Indigo" */
  --brand: #4f46e5;
  --brand-light: #818cf8;
  --brand-grad: linear-gradient(135deg, #4f46e5, #0ea5e9);
  --brand-glow: 0 10px 40px -10px rgba(79, 70, 229, 0.4);

  /* DEPTH */
  --shadow-sm: 0 2px 8px -2px rgba(15, 23, 42, 0.08);
  --shadow-card:
    0 4px 6px -1px rgba(15, 23, 42, 0.04),
    0 12px 32px -8px rgba(15, 23, 42, 0.08);
  --shadow-float:
    0 20px 50px -12px rgba(15, 23, 42, 0.15),
    0 0 0 1px rgba(255,255,255,0.6) inset;

  --radius-xl: 32px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-pill: 999px;

  --font-body: "Poppins", system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", monospace;
}

body.theme-dark {
  /* DARK: "Deep Orbit" */
  --bg-core: #020617;
  --bg-grad:
    radial-gradient(circle at 15% 0%, rgba(49, 46, 129, 0.25), transparent 50%),
    radial-gradient(circle at 85% 90%, rgba(6, 78, 59, 0.2), transparent 50%);

  --glass-surface: rgba(15, 23, 42, 0.6);
  --glass-border: 1px solid rgba(255, 255, 255, 0.08);
  --glass-shine: inset 0 1px 0 rgba(255, 255, 255, 0.1);
  --glass-blur: blur(40px) saturate(140%);

  --ink-100: #f8fafc;
  --ink-200: #cbd5e1;
  --ink-300: #94a3b8;
  --ink-400: #475569;

  --brand: #6366f1;
  --brand-grad: linear-gradient(135deg, #6366f1, #38bdf8);
  --brand-glow: 0 0 60px -15px rgba(99, 102, 241, 0.5);

  --shadow-card: 0 25px 60px -15px rgba(0,0,0,0.6);
  --shadow-float: 0 40px 80px -20px rgba(0,0,0,0.8);
}

/* 2. BASE PHYSICS */
* { box-sizing: border-box; margin: 0; padding: 0; outline: none; -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; font-size: 16px; }

body {
  font-family: var(--font-body);
  background-color: var(--bg-core);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--ink-100);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  font-kerning: normal;
}

/* Cinematic Grain */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: -1;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--ink-300); border-radius: 99px; border: 2px solid transparent; background-clip: content-box; }

.page {
  max-width: var(--page-width); margin: 0 auto;
  padding: 30px 20px 100px; position: relative; z-index: 1;
}

/* 3. FLOATING TOPBAR */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin: 0 auto 50px; padding: 12px 14px 12px 20px;
  background: var(--glass-surface);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border: var(--glass-border);
  box-shadow: var(--shadow-sm), var(--glass-shine);
  border-radius: var(--radius-pill);
  max-width: 960px;
  position: sticky; top: 20px; z-index: 100;
  transition: transform 0.3s var(--ease-spring);
}

.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; cursor: pointer; }
.brand-logo {
  width: 44px; height: 44px;
  background: var(--brand-grad);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 1.2rem; color: white;
  box-shadow: 0 10px 25px -5px rgba(79, 70, 229, 0.4);
  transition: transform 0.4s var(--ease-snap);
}
.brand:hover .brand-logo { transform: rotate(15deg) scale(1.05); }

.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-size: 1.1rem; font-weight: 800; letter-spacing: -0.02em; }
.brand-text span { font-size: 0.7rem; color: var(--ink-300); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; }

.topbar-right { display: flex; align-items: center; gap: 10px; }

/* THEME TOGGLE & LANG PILLS */
.theme-toggle {
  height: 40px; padding: 0 16px; border-radius: 99px;
  border: 1px solid var(--ink-400); background: rgba(255,255,255,0.05);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 600; color: var(--ink-200);
  font-family: var(--font-body); cursor: pointer; transition: 0.3s ease; white-space: nowrap;
}
select.theme-toggle {
  appearance: none; -webkit-appearance: none; padding-right: 32px;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 14px;
}
.theme-toggle:hover { background: var(--ink-100); color: var(--bg-core); border-color: var(--ink-100); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.1); }

/* 4. HERO SECTION */
.hero-shell {
  position: relative;
  background: var(--glass-surface);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border: var(--glass-border);
  border-radius: var(--radius-xl);
  padding: 60px 40px; margin-bottom: 32px;
  box-shadow: var(--shadow-card), var(--glass-shine);
  text-align: center; overflow: hidden;
}

.hero-shell::before {
  content: ''; position: absolute; top: -50%; left: 50%; transform: translateX(-50%);
  width: 600px; height: 300px; background: var(--brand);
  filter: blur(120px); opacity: 0.15; pointer-events: none;
}

.hero-main { position: relative; z-index: 2; max-width: 800px; margin: 0 auto; }

.hero-h1 {
  font-size: 3.2rem; line-height: 1.1; margin-bottom: 20px;
  font-weight: 900; letter-spacing: -0.04em;
  background: linear-gradient(180deg, var(--ink-100), var(--ink-300));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

.hero-copy p {
  font-size: 1.15rem; color: var(--ink-200); margin-bottom: 30px; font-weight: 400;
  max-width: 600px; margin-left: auto; margin-right: auto;
}

.hero-list { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.hero-pill {
  padding: 8px 16px; border-radius: var(--radius-pill);
  background: rgba(255,255,255,0.05); border: 1px solid var(--ink-400);
  color: var(--ink-200); font-size: 0.85rem; font-weight: 600;
  display: flex; align-items: center; gap: 8px; transition: 0.3s;
}
.hero-pill:hover { border-color: var(--brand); color: var(--brand); transform: translateY(-2px); }

.hero-side { display: none; }

/* 5. APP LAYOUT */
.layout {
  display: grid; grid-template-columns: 1.8fr 1.2fr; gap: 24px;
  align-items: start; margin-top: 24px;
}

.card {
  background: var(--glass-surface);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border: var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-sm), var(--glass-shine);
  transition: transform 0.3s var(--ease-spring), box-shadow 0.3s ease;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-card); }

.card h2 {
  font-size: 1.4rem; font-weight: 800; margin-bottom: 16px;
  display: flex; align-items: center; gap: 12px; letter-spacing: -0.02em;
}
.muted { font-size: 0.95rem; color: var(--ink-300); margin-bottom: 32px; }

/* 6. INPUTS */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.form-grid > div, .sh-check {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--ink-400);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  transition: 0.2s ease;
  position: relative;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

.form-grid > div:focus-within, .sh-check:hover {
  background: var(--bg-core); border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.15);
  transform: translateY(-1px); z-index: 10;
}

label {
  display: block; font-size: 0.72rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--ink-300); margin-bottom: 6px;
}

input, select {
  width: 100%; background: transparent; border: none;
  font-size: 1.05rem; color: var(--ink-100); font-weight: 600;
  font-family: inherit; padding: 4px 0;
}
select { cursor: pointer; }

input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.help-text { font-size: 0.8rem; color: var(--ink-300); margin-top: 6px; }

/* Elevator Checkbox (FIXED: add display:flex so flex-direction works) */
.sh-check {
  border-style: dashed;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: default;
}
.sh-check-row { display: flex; align-items: center; gap: 12px; }
.sh-check input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--brand); cursor: pointer; }
.sh-check-text { font-size: 1rem; font-weight: 600; color: var(--ink-100); }

/* 7. CONTROLS */
.btn-row { margin-top: 40px; display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }

.btn-secondary {
  background: transparent; border: 1px solid var(--ink-300);
  padding: 12px 24px; border-radius: var(--radius-pill);
  font-size: 0.9rem; font-weight: 600; color: var(--ink-200);
  cursor: pointer; transition: 0.2s;
}
.btn-secondary:hover { background: var(--ink-100); color: var(--bg-core); border-color: var(--ink-100); }

button.primary {
  background: var(--brand-grad); color: white;
  border: none; border-radius: var(--radius-pill);
  padding: 16px 40px; font-size: 1.05rem; font-weight: 700;
  cursor: pointer; box-shadow: var(--brand-glow);
  transition: transform 0.2s var(--ease-spring), box-shadow 0.2s;
  display: flex; align-items: center; gap: 10px;
}
button.primary:hover { transform: translateY(-3px); box-shadow: 0 15px 40px -10px rgba(79, 70, 229, 0.6); }
button.primary:active { transform: scale(0.97); }

/* Presets */
.preset-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 30px; }
.preset-btn {
  background: rgba(255,255,255,0.05); border: 1px solid var(--ink-400);
  padding: 10px 18px; border-radius: 12px;
  font-size: 0.85rem; font-weight: 600; color: var(--ink-200);
  cursor: pointer; transition: 0.2s;
}
.preset-btn:hover { border-color: var(--brand); color: var(--brand); transform: translateY(-1px); background: rgba(79,70,229,0.05); }

/* 8. RESULTS */
#results { display: none; margin-top: 32px; animation: pop-up 0.6s var(--ease-spring); }
@keyframes pop-up { from { opacity: 0; transform: scale(0.95) translateY(20px); } to { opacity: 1; transform: scale(1) translateY(0); } }

.total-shell {
  padding: 3px; border-radius: var(--radius-xl);
  background: linear-gradient(135deg, rgba(79,70,229,0.5), rgba(6,182,212,0.5));
  box-shadow: var(--shadow-float); margin-bottom: 24px;
}

.total-card {
  background: var(--glass-surface); border-radius: 29px; padding: 40px;
  backdrop-filter: blur(50px); text-align: center;
}

.total-label {
  font-size: 0.8rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.15em; color: var(--ink-300); margin-bottom: 12px;
}

/* ✅ SMART TOTAL VALUE */
.total-value {
  font-weight: 900; line-height: 1; margin-bottom: 12px;
  background: var(--brand-grad); -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  letter-spacing: -0.04em;
  font-size: clamp(2.4rem, 10vw, 3.8rem);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.total-subline { font-size: 1.1rem; color: var(--ink-200); }
.total-subline span { color: var(--brand); font-weight: 700; border-bottom: 1px dashed var(--brand); }

.pill, #rRatePill {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  background: rgba(255,255,255,0.1); border: 1px solid var(--ink-400);
  padding: 6px 14px; border-radius: var(--radius-pill);
  font-size: 0.85rem; margin-bottom: 20px; color: var(--ink-200); font-weight: 500;
}

.mini-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; text-align: left; }
.mini-grid div { background: rgba(255,255,255,0.05); padding: 12px; border-radius: 12px; border: 1px solid var(--ink-400); }
.mini-grid strong { display: block; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-300); margin-bottom: 4px; }
.mini-grid span { font-size: 1rem; font-weight: 700; color: var(--ink-100); font-family: var(--font-mono); }

/* 9. DATA TABLES (Desktop) */
table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  border: 1px solid var(--ink-400); border-radius: 16px;
  overflow: hidden; margin-top: 32px;
}
th {
  text-align: left; padding: 16px; background: rgba(255,255,255,0.05);
  font-size: 0.75rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-300);
}
td {
  padding: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 0.95rem; color: var(--ink-200); font-weight: 500;
  word-break: break-word;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(79, 70, 229, 0.03); color: var(--ink-100); }
td:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }

/* ✅ DESKTOP COLUMNS */
th:nth-child(1), td:nth-child(1) { width: 50%; }
th:nth-child(2), td:nth-child(2) { width: 15%; text-align: center; }
th:nth-child(3), td:nth-child(3) { width: 35%; white-space: nowrap; }

/* Bars */
#barsContainer { margin-top: 32px; }
.bar-row { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.bar-label { width: 160px; font-size: 0.9rem; font-weight: 600; color: var(--ink-200); }
.bar-track { flex: 1; height: 8px; background: rgba(0,0,0,0.05); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--brand-grad); border-radius: 99px; transition: width 1s var(--ease-spring); }
.bar-value { width: 50px; text-align: right; font-weight: 700; font-size: 0.9rem; color: var(--ink-100); font-family: var(--font-mono); }

/* Materials */
.materials-list {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px; list-style: none; margin-top: 32px;
}
.materials-list li {
  background: rgba(255,255,255,0.03); padding: 20px; border-radius: 16px;
  border: 1px solid var(--ink-400); transition: 0.2s;
}
.materials-list li:hover { background: var(--glass-surface); transform: translateY(-2px); border-color: var(--brand); }
.materials-label { display: block; font-size: 0.75rem; color: var(--ink-300); font-weight: 700; text-transform: uppercase; margin-bottom: 4px; }
.materials-list span:last-child { font-size: 1.25rem; font-weight: 700; color: var(--ink-100); font-family: var(--font-mono); }

/* 10. INFO & FOOTER */
.side-highlight-item {
  background: var(--glass-surface); padding: 16px; border-radius: 16px;
  border: 1px solid var(--ink-400); margin-bottom: 16px;
  display: flex; gap: 16px; transition: 0.2s;
}
.side-highlight-item:hover { border-color: var(--brand); transform: translateX(4px); }
.side-highlight-icon { font-size: 1.6rem; color: var(--brand); }
.side-highlight-item strong { display: block; font-size: 1rem; font-weight: 700; color: var(--ink-100); margin-bottom: 4px; }
.side-highlight-item div { font-size: 0.9rem; color: var(--ink-200); line-height: 1.5; }

.state-note-box {
  margin-top: 24px; padding: 20px; border-radius: 16px;
  background: rgba(79, 70, 229, 0.05); border: 1px solid rgba(79, 70, 229, 0.15);
  color: var(--ink-200); font-size: 0.95rem; line-height: 1.6;
}

.info-section {
  margin-top: 80px; padding: 60px;
  background: var(--glass-surface); border-radius: var(--radius-xl);
  border: 1px solid var(--ink-400); box-shadow: var(--shadow-sm);
}
.info-heading { font-size: 1.6rem; font-weight: 800; margin-bottom: 30px; letter-spacing: -0.02em; }

details { border-bottom: 1px solid var(--ink-400); padding: 20px 0; }
details summary { font-size: 1.1rem; font-weight: 600; cursor: pointer; display: flex; justify-content: space-between; color: var(--ink-100); transition: color 0.2s; list-style: none; }
details summary:hover { color: var(--brand); }
.details-body { margin-top: 16px; color: var(--ink-200); font-size: 1rem; line-height: 1.7; max-width: 800px; }

.footer { text-align: center; color: var(--ink-300); font-size: 0.85rem; margin-top: 80px; opacity: 0.8; font-weight: 500; }

/* 11. RESPONSIVE MOBILE */
@media (max-width: 640px) {
  .page { padding: 20px 12px 80px; }
  .topbar { margin-bottom: 30px; padding: 8px 12px; }
  .brand-text { display: none; }
  .theme-toggle { padding: 0 12px; font-size: 0.8rem; height: 36px; }

  .hero-shell { padding: 40px 20px; }
  .hero-h1 { font-size: 2.2rem; }

  .layout { grid-template-columns: 1fr; gap: 32px; }
  .form-grid { grid-template-columns: 1fr; }
  .btn-row { flex-direction: column-reverse; gap: 16px; }
  button.primary { width: 100%; justify-content: center; padding: 18px; }
  .materials-list { grid-template-columns: 1fr; }

  /* ✅ MOBILE LIST VIEW FOR TABLE */
  table { border: none; background: transparent; }
  table thead { display: none; }

  /* IMPORTANT: stop desktop hover/borders messing with cards */
  table tbody, table tr, table td { border: none !important; }
  tr:hover td { background: transparent; color: inherit; }

  table tr {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 4px 12px;
    padding: 16px;
    background: var(--glass-surface);
    border: 1px solid var(--ink-400) !important;
    border-radius: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
    width: 100%;
  }

  /* Name */
  table td:nth-child(1) {
    grid-column: 1 / -1; grid-row: 1;
    width: 100%; padding: 0 0 6px 0;
    font-size: 1rem; font-weight: 700; color: var(--ink-100);
  }

  /* Percent */
  table td:nth-child(2) {
    grid-column: 1; grid-row: 2;
    width: auto; padding: 0; text-align: left;
    font-size: 0.85rem; color: var(--ink-300);
    white-space: nowrap;
  }
  table td:nth-child(2)::after {
    content: " of total";
    opacity: 0.7;
    font-size: 0.75rem;
    margin-left: 4px;
  }

  /* Cost */
  table td:nth-child(3) {
    grid-column: 2; grid-row: 2;
    width: auto; padding: 0; text-align: right;
    font-size: 1rem; font-weight: 800; color: var(--brand);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }
}

/* 12. PRINT */
@media print {
  body { background: white !important; color: black !important; animation: none; }
  .no-print, .topbar, .hero-shell { display: none !important; }
  #results { display: block !important; margin-top: 0; }
  .total-shell, .card, .info-section { box-shadow: none !important; border: 1px solid #ccc !important; background: white !important; }
  .total-value { -webkit-text-fill-color: black !important; }
}
