:root{
  --bg:#0b0b0b;--card:#121212;--text:#ececec;--muted:#a4a4a4;
  --gold:#d4af37;--border:#1f1f1f;--warn:#ffd24d;--danger:#ff6b6b;--success:#4caf50;
}
*{box-sizing:border-box}
html,body{margin:0;background:var(--bg);color:var(--text);
  font-family:"Noto Naskh Arabic","Segoe UI",Tahoma,Arial,sans-serif;line-height:1.65}
.wrap{max-width:1200px;margin:0 auto;padding:18px}
header{background:#000;border-bottom:1px solid var(--border)}
.brand{display:flex;gap:12px;align-items:center;justify-content:center;padding:10px 0}
.brand img{height:72px;width:auto;border-radius:14px;object-fit:contain;background:transparent;padding:0}
.brand .word{font-weight:800;letter-spacing:.12em}
nav{display:flex;gap:10px;flex-wrap:wrap;justify-content:center;padding:8px 0 12px}
nav a{color:var(--muted);text-decoration:none;padding:6px 12px;border:1px solid var(--border);border-radius:18px}
nav a.active,nav a:hover{color:#fff;border-color:#333}

.actions{display:flex;gap:10px;justify-content:center;align-items:center;flex-wrap:wrap;margin:6px 0 12px}
.btn{
  display:inline-flex;align-items:center;justify-content:center;
  background:var(--gold);color:#000;font-weight:700;border:1px solid var(--gold);
  border-radius:12px;padding:0 16px;cursor:pointer;line-height:1;text-decoration:none;user-select:none
}
.actions .btn,.actions .file-label.btn{width:260px;height:54px}
.btn:active{transform:translateY(1px)}
.btn.secondary{background:transparent;color:var(--gold);border-color:var(--gold)}
.btn.danger{background:transparent;border-color:#444;color:#ff9090}
.file-input{display:none}
.file-label{cursor:pointer}

section{background:var(--card);border:1px solid var(--border);border-radius:16px;padding:16px;margin:18px 0}
h2{color:var(--gold);margin:0 0 12px;font-size:20px}
h3{color:var(--gold);margin:0 0 10px;font-size:18px}
label{display:block;font-size:13px;color:var(--muted);margin-bottom:6px}
input{width:100%;padding:10px;border-radius:12px;border:1px solid var(--border);background:#0e0e0e;color:#fff}
/* bigger & comfy for big numbers */
input.num-lg{height:46px;font-size:16px;letter-spacing:.3px;padding:12px}
/* name/ID fields = textarea that auto-grows */
textarea.name-cell{
  width:100%;min-height:38px;max-height:180px;resize:none;
  padding:10px;border-radius:12px;border:1px solid var(--border);background:#0e0e0e;color:#fff;
  line-height:1.5;font-size:14px
}
.grid{display:grid;gap:12px}

/* Mobile: Single column by default */
.grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

/* Small tablets and larger phones in landscape */
@media(min-width:640px){
  .grid-2{grid-template-columns:repeat(2,1fr)}
  .grid-3{grid-template-columns:repeat(2,1fr)} /* 2 cols on tablet */
  .grid-4{grid-template-columns:repeat(2,1fr)} /* 2 cols on tablet */
}

/* Large tablets and desktop */
@media(min-width:1024px){
  .grid-3{grid-template-columns:repeat(3,1fr)}
  .grid-4{grid-template-columns:repeat(4,1fr)}
}
.card{background:#0f0f0f;border:1px solid var(--border);border-radius:14px;padding:14px}
.card-head{display:flex;gap:10px;justify-content:space-between;align-items:center;margin-bottom:8px}
.out{display:flex;gap:10px;flex-wrap:wrap;margin-top:12px;justify-content:flex-start}
.out.left{justify-content:flex-end} /* RTL: flex-end = يسار بصريا */
.out .box{background:#0b0b0b;border:1px dashed #2a2a2a;border-radius:12px;padding:10px 12px;min-width:180px}
.out .title{font-size:12px;color:#aaa}
.out .val{font-size:18px;font-weight:800;color:var(--gold)}
.out .val.yellow{color:var(--warn)}
.out .val.red{color:var(--danger)}

/* Table wrapper for horizontal scrolling on mobile */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  margin-top: 10px;
  border-radius: 12px;
  background: #0f0f0f;
  /* Add scroll shadow indicators */
  background:
    linear-gradient(to right, #0f0f0f 30%, transparent),
    linear-gradient(to left, #0f0f0f 30%, transparent),
    radial-gradient(farthest-side at 0 50%, rgba(212, 175, 55, 0.3), transparent),
    radial-gradient(farthest-side at 100% 50%, rgba(212, 175, 55, 0.3), transparent);
  background-repeat: no-repeat;
  background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
  background-position: 0 0, 100% 0, 0 0, 100% 0;
  background-attachment: local, local, scroll, scroll;
}

table{width:100%;border-collapse:collapse;background:#0f0f0f;overflow:hidden}
th,td{border-bottom:2px solid #1f1f1f;border-right:3px solid #2a2a2a;padding:12px 14px;text-align:center;font-size:14px;vertical-align:middle}
th{background:#151515;color:#d0d0d0;font-weight:600}
/* Remove border-right from first column (rightmost in RTL) */
th:first-child, td:first-child{border-right:none}
/* wide cells for names & long numbers on small screens */
td.col-name{min-width:220px}
/* REMOVED: td.col-num input{min-width:140px} - conflicts with universal table input sizing */
.hidden{display:none}
.hint{color:#8b8b8b;font-size:12px;margin-top:6px}
.card-hint{color:#fff}
body.day-mode .card-hint{color:#333}

/* Loading state */
.loading-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Fade in animation for sections */
section:not(.hidden) {
  animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* DESIGN tweaks */
#design td.d_bottleW{ color: var(--warn); font-weight: 800; }
#design #d_cap.highlight{ color: var(--warn); font-weight: 800; }

/* Ensure vertical borders are visible in design table - ALL columns including between 10 and 11 */
#design table th:nth-child(2),
#design table th:nth-child(3),
#design table th:nth-child(4),
#design table th:nth-child(5),
#design table th:nth-child(6),
#design table th:nth-child(7),
#design table th:nth-child(8),
#design table th:nth-child(9),
#design table th:nth-child(10),
#design table th:nth-child(11),
#design table td:nth-child(2),
#design table td:nth-child(3),
#design table td:nth-child(4),
#design table td:nth-child(5),
#design table td:nth-child(6),
#design table td:nth-child(7),
#design table td:nth-child(8),
#design table td:nth-child(9),
#design table td:nth-child(10),
#design table td:nth-child(11) {
  border-right: 3px solid #2a2a2a !important;
}

/* First column (1) has no border (rightmost in RTL) */
#design table th:nth-child(1),
#design table td:nth-child(1) {
  border-right: none !important;
}

body.day-mode #design table th:nth-child(2),
body.day-mode #design table th:nth-child(3),
body.day-mode #design table th:nth-child(4),
body.day-mode #design table th:nth-child(5),
body.day-mode #design table th:nth-child(6),
body.day-mode #design table th:nth-child(7),
body.day-mode #design table th:nth-child(8),
body.day-mode #design table th:nth-child(9),
body.day-mode #design table th:nth-child(10),
body.day-mode #design table th:nth-child(11),
body.day-mode #design table td:nth-child(2),
body.day-mode #design table td:nth-child(3),
body.day-mode #design table td:nth-child(4),
body.day-mode #design table td:nth-child(5),
body.day-mode #design table td:nth-child(6),
body.day-mode #design table td:nth-child(7),
body.day-mode #design table td:nth-child(8),
body.day-mode #design table td:nth-child(9),
body.day-mode #design table td:nth-child(10),
body.day-mode #design table td:nth-child(11) {
  border-right: 3px solid #b0b0b0 !important;
}

body.day-mode #design table th:nth-child(1),
body.day-mode #design table td:nth-child(1) {
  border-right: none !important;
}

/* Red background for addition weight columns (4-8) */
#design th:nth-child(4), #design th:nth-child(5), #design th:nth-child(6),
#design th:nth-child(7), #design th:nth-child(8),
#design td:nth-child(4), #design td:nth-child(5), #design td:nth-child(6),
#design td:nth-child(7), #design td:nth-child(8) {
  background-color: #ff4444 !important;
  color: #fff !important;
}

/* Make inputs inside red columns have white background for visibility */
#design td:nth-child(4) input,
#design td:nth-child(5) input,
#design td:nth-child(6) input,
#design td:nth-child(7) input,
#design td:nth-child(8) input {
  background-color: #ffffff !important;
}

/* Apply alternating colors to inputs in red columns - NIGHT MODE */
#design tbody tr:nth-child(odd) td:nth-child(4) input,
#design tbody tr:nth-child(odd) td:nth-child(5) input,
#design tbody tr:nth-child(odd) td:nth-child(6) input,
#design tbody tr:nth-child(odd) td:nth-child(7) input,
#design tbody tr:nth-child(odd) td:nth-child(8) input {
  color: #ffffff !important;
}

#design tbody tr:nth-child(even) td:nth-child(4) input,
#design tbody tr:nth-child(even) td:nth-child(5) input,
#design tbody tr:nth-child(even) td:nth-child(6) input,
#design tbody tr:nth-child(even) td:nth-child(7) input,
#design tbody tr:nth-child(even) td:nth-child(8) input {
  color: #ff0000 !important;
}

/* Apply alternating colors to inputs in red columns - DAY MODE */
body.day-mode #design tbody tr:nth-child(odd) td:nth-child(4) input,
body.day-mode #design tbody tr:nth-child(odd) td:nth-child(5) input,
body.day-mode #design tbody tr:nth-child(odd) td:nth-child(6) input,
body.day-mode #design tbody tr:nth-child(odd) td:nth-child(7) input,
body.day-mode #design tbody tr:nth-child(odd) td:nth-child(8) input {
  color: #000000 !important;
}

body.day-mode #design tbody tr:nth-child(even) td:nth-child(4) input,
body.day-mode #design tbody tr:nth-child(even) td:nth-child(5) input,
body.day-mode #design tbody tr:nth-child(even) td:nth-child(6) input,
body.day-mode #design tbody tr:nth-child(even) td:nth-child(7) input,
body.day-mode #design tbody tr:nth-child(even) td:nth-child(8) input {
  color: #ff0000 !important;
}

/* ===== DAY MODE TABLE IMPROVEMENTS ===== */
body.day-mode table {
  background: #f8f8f8;
}

body.day-mode th {
  background: #e8e8e8;
  color: #333333;
}

body.day-mode th, body.day-mode td {
  border-bottom: 2px solid #d0d0d0;
  border-right: 3px solid #b0b0b0;
}

body.day-mode th:first-child, body.day-mode td:first-child {
  border-right: none;
}

body.day-mode .table-wrapper {
  background: #f8f8f8;
}

/* ===== RESPONSIVE TABLE STYLING ===== */

/* Mobile - optimized for portrait mode (9:16) */
@media (max-width: 639px) {
  /* Stronger vertical borders for better column separation on mobile */
  table th, table td {
    border-right: 3px solid #2a2a2a !important;
    border-bottom: 2px solid #1f1f1f !important;
  }
  table th:first-child, table td:first-child {
    border-right: none !important;
  }

  /* Day mode borders on mobile - even more visible */
  body.day-mode table th, body.day-mode table td {
    border-right: 3px solid #b0b0b0 !important;
    border-bottom: 2px solid #d0d0d0 !important;
  }
  body.day-mode table th:first-child, body.day-mode table td:first-child {
    border-right: none !important;
  }

  /* Smaller table headers and cells */
  table th {
    padding: 8px 4px !important;
    font-size: 11px !important;
    line-height: 1.3;
    font-weight: 700;
    white-space: normal;
    word-wrap: break-word;
  }

  table td {
    padding: 4px !important;
    font-size: 12px !important;
  }

  /* Compact inputs for mobile */
  table input[type="number"],
  table input[type="text"],
  table textarea {
    padding: 6px 4px !important;
    font-size: 12px !important;
    height: 32px !important;
    min-width: 70px !important;
  }

  table textarea {
    min-height: 32px !important;
    max-height: 60px !important;
  }

  /* Design table - extra strong borders on mobile - ALL columns */
  #design table th:nth-child(2),
  #design table th:nth-child(3),
  #design table th:nth-child(4),
  #design table th:nth-child(5),
  #design table th:nth-child(6),
  #design table th:nth-child(7),
  #design table th:nth-child(8),
  #design table th:nth-child(9),
  #design table th:nth-child(10),
  #design table th:nth-child(11),
  #design table td:nth-child(2),
  #design table td:nth-child(3),
  #design table td:nth-child(4),
  #design table td:nth-child(5),
  #design table td:nth-child(6),
  #design table td:nth-child(7),
  #design table td:nth-child(8),
  #design table td:nth-child(9),
  #design table td:nth-child(10),
  #design table td:nth-child(11) {
    border-right: 3px solid #2a2a2a !important;
  }

  #design table th:nth-child(1),
  #design table td:nth-child(1) {
    border-right: none !important;
  }

  body.day-mode #design table th:nth-child(2),
  body.day-mode #design table th:nth-child(3),
  body.day-mode #design table th:nth-child(4),
  body.day-mode #design table th:nth-child(5),
  body.day-mode #design table th:nth-child(6),
  body.day-mode #design table th:nth-child(7),
  body.day-mode #design table th:nth-child(8),
  body.day-mode #design table th:nth-child(9),
  body.day-mode #design table th:nth-child(10),
  body.day-mode #design table th:nth-child(11),
  body.day-mode #design table td:nth-child(2),
  body.day-mode #design table td:nth-child(3),
  body.day-mode #design table td:nth-child(4),
  body.day-mode #design table td:nth-child(5),
  body.day-mode #design table td:nth-child(6),
  body.day-mode #design table td:nth-child(7),
  body.day-mode #design table td:nth-child(8),
  body.day-mode #design table td:nth-child(9),
  body.day-mode #design table td:nth-child(10),
  body.day-mode #design table td:nth-child(11) {
    border-right: 3px solid #b0b0b0 !important;
  }

  body.day-mode #design table th:nth-child(1),
  body.day-mode #design table td:nth-child(1) {
    border-right: none !important;
  }

  /* Row number column - smaller on mobile */
  #design td:first-child,
  #design th:first-child {
    padding: 4px 2px !important;
    font-size: 11px !important;
    min-width: 30px;
  }

  /* Oil name column - enough space for Arabic text */
  #design td:nth-child(2),
  #design th:nth-child(2) {
    min-width: 120px;
  }

  /* Numeric columns */
  #design td:nth-child(3),
  #design td:nth-child(4),
  #design td:nth-child(5),
  #design td:nth-child(6),
  #design td:nth-child(7),
  #design td:nth-child(8),
  #design td:nth-child(9),
  #design td:nth-child(10),
  #design td:nth-child(11) {
    min-width: 90px;
  }

  /* Add subtle alternating row colors for better readability */
  table tbody tr:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.02);
  }

  /* Scroll hint text - only for wide tables with many columns */
  .table-wrapper.wide-table::after {
    content: '☜ اسحب الجدول يسارا لرؤية باقي الأعمدة ☜';
    display: block;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    color: var(--gold);
    padding: 12px 8px;
    background: linear-gradient(to top, rgba(212, 175, 55, 0.15), transparent);
    border-top: 1px solid rgba(212, 175, 55, 0.3);
    letter-spacing: 0.5px;
  }

  body.day-mode .table-wrapper.wide-table::after {
    color: #c9a961;
    background: linear-gradient(to top, rgba(201, 169, 97, 0.2), transparent);
    border-top: 1px solid rgba(201, 169, 97, 0.4);
  }
}

/* Tablet - same design */
@media (min-width: 640px) and (max-width: 1023px) {
  /* Ensure vertical borders are visible on tablet */
  table th, table td {
    border-right: 3px solid #2a2a2a !important;
  }
  table th:first-child, table td:first-child {
    border-right: none !important;
  }

  body.day-mode table th, body.day-mode table td {
    border-right: 3px solid #b0b0b0 !important;
  }
  body.day-mode table th:first-child, body.day-mode table td:first-child {
    border-right: none !important;
  }

  /* Design table borders on tablet */
  #design table th, #design table td {
    border-right: 3px solid #2a2a2a !important;
  }
  #design table th:first-child, #design table td:first-child {
    border-right: none !important;
  }

  body.day-mode #design table th, body.day-mode #design table td {
    border-right: 3px solid #b0b0b0 !important;
  }
  body.day-mode #design table th:first-child, body.day-mode #design table td:first-child {
    border-right: none !important;
  }

  table input[type="number"],
  table input[type="text"],
  table textarea {
    padding: 6px 4px !important;
    font-size: 13px !important;
    height: 32px !important;
  }
  table textarea {
    min-height: 32px !important;
    max-height: 32px !important;
  }
  table td {
    padding: 4px !important;
  }
  table th {
    padding: 7px 4px !important;
  }
}

/* Desktop - same design */
@media (min-width: 1024px) {
  /* Ensure vertical borders are visible on desktop */
  table th, table td {
    border-right: 3px solid #2a2a2a !important;
  }
  table th:first-child, table td:first-child {
    border-right: none !important;
  }

  body.day-mode table th, body.day-mode table td {
    border-right: 3px solid #b0b0b0 !important;
  }
  body.day-mode table th:first-child, body.day-mode table td:first-child {
    border-right: none !important;
  }

  /* Design table borders on desktop */
  #design table th, #design table td {
    border-right: 3px solid #2a2a2a !important;
  }
  #design table th:first-child, #design table td:first-child {
    border-right: none !important;
  }

  body.day-mode #design table th, body.day-mode #design table td {
    border-right: 3px solid #b0b0b0 !important;
  }
  body.day-mode #design table th:first-child, body.day-mode #design table td:first-child {
    border-right: none !important;
  }

  table input[type="number"],
  table input[type="text"],
  table textarea {
    padding: 6px 4px !important;
    font-size: 13px !important;
    height: 34px !important;
  }
  table textarea {
    min-height: 34px !important;
    max-height: 34px !important;
  }
  table td {
    padding: 4px !important;
  }
  table th {
    padding: 8px 4px !important;
  }
}

/* Yellow background for result cells */
td.d_addW, td.d_bottleW, td.d_inSamplePct,
td.jk_addW,
#r_w1, #r_w2, #r_w3, #r_w4, #r_w5, #r_w6, #r_w7, #r_w8 {
  background-color: #ffd24d !important;
  color: #000 !important;
  font-weight: 700;
}

/* EO-NET Right Table: Yellow for columns 5 and 6 (وزن صافي الزيت المطلوب and نسبة الزيت من بين إجمالي الزيوت) */
#eo_table_right tbody tr td:nth-child(5),
#eo_table_right tbody tr td:nth-child(6),
#eo_table_right tfoot tr th:nth-child(2),
#eo_table_right tfoot tr th:nth-child(3) {
  background-color: #ffd24d !important;
  color: #000 !important;
  font-weight: 700;
}

/* EO-NET Left Table: Yellow for columns 5 and 6 (سعر الغرام and سعر الزيت في الزجاجة) */
#eo_table_left tbody tr td:nth-child(5),
#eo_table_left tbody tr td:nth-child(6),
#eo_table_left tfoot tr th:nth-child(5),
#eo_table_left tfoot tr th:nth-child(6) {
  background-color: #ffd24d !important;
  color: #000 !important;
  font-weight: 700;
}

/* Traditional Design table - only layout, NO input size overrides */
#design table {
  max-width: 100%;
  width: 100%;
  table-layout: fixed;
}

/* Mobile: Traditional Design table horizontal scroll if needed */
@media (max-width: 639px) {
  #design table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }
}


/* ===== ENHANCED MOBILE UI IMPROVEMENTS ===== */

/* Mobile First - Base styles for small screens */
@media (max-width: 639px) {
  /* Better header spacing */
  header { padding-bottom: 4px; }
  .brand { padding: 12px 0 8px; gap: 10px; }
  .brand img { height: 52px; }
  .brand .word { font-size: 15px; letter-spacing: 0.08em; }

  /* Improved Navigation - More compact & touch-friendly */
  nav {
    gap: 6px;
    padding: 6px 8px 10px;
    justify-content: center;
  }
  nav a {
    padding: 10px 14px;
    font-size: 14px;
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
    font-weight: 500;
  }

  /* Section spacing - more breathing room */
  section {
    padding: 16px;
    margin: 14px 0;
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }
  .wrap { padding: 12px; }

  /* Buttons - optimized for touch */
  .btn {
    min-height: 48px;
    padding: 0 24px;
    font-size: 16px;
    font-weight: 700;
    border-radius: 14px;
    transition: transform 0.1s ease;
  }
  .btn:active {
    transform: scale(0.98);
  }
  .actions { gap: 12px; margin: 10px 0 16px; }
  .actions .btn, .actions .file-label.btn {
    width: 100%;
    max-width: 100%;
    height: 52px;
  }

  /* Cards - better visual hierarchy */
  .card {
    padding: 14px;
    border-radius: 14px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  }

  /* Typography - better readability */
  h2 {
    font-size: 20px;
    margin-bottom: 16px;
    font-weight: 800;
  }
  h3 {
    font-size: 17px;
    font-weight: 700;
  }
  label {
    font-size: 14px;
    margin-bottom: 8px;
    font-weight: 500;
  }

  /* Forms - enhanced touch targets */
  input, textarea, select {
    font-size: 16px !important;
    padding: 14px !important;
    min-height: 48px;
    border-radius: 12px;
    border-width: 1.5px;
  }
  input:focus, textarea:focus, select:focus {
    outline: 2px solid var(--gold);
    outline-offset: 1px;
    border-color: var(--gold);
  }

  /* Grid adjustments */
  .grid { gap: 14px; }
  .out { gap: 12px; }
  .out .box {
    min-width: calc(50% - 6px);
    padding: 12px;
  }

  /* Result boxes - better visibility */
  .out .title { font-size: 13px; }
  .out .val { font-size: 20px; }
}


/* ===== LANDSCAPE MOBILE OPTIMIZATIONS ===== */

@media (max-width: 926px) and (orientation: landscape) {
  /* Compact header for landscape */
  .brand { padding: 8px 0; }
  .brand img { height: 48px; }
  nav { padding: 6px 8px 8px; }
  nav a { padding: 8px 12px; font-size: 13px; min-height: 38px; }

  /* Reduce section padding to maximize viewport space */
  section { padding: 12px; margin: 10px 0; }
  .wrap { padding: 10px; }

  /* Compact cards */
  .card { padding: 10px; }

  /* Tighter grids */
  .grid { gap: 10px; }

  /* Theme toggle */
  #theme-toggle {
    top: 8px;
    right: 8px;
    width: 40px;
    height: 40px;
    font-size: 18px;
  }
}

/* ===== VERY SMALL SCREENS (320px - iPhone SE, small Android) ===== */

@media (max-width: 374px) {
  /* Further compact everything */
  .brand img { height: 48px; }
  .brand .word { font-size: 14px; }

  nav a {
    padding: 8px 10px;
    font-size: 13px;
    min-height: 40px;
  }

  h2 { font-size: 18px; }
  h3 { font-size: 16px; }

  .btn {
    min-height: 46px;
    font-size: 15px;
    padding: 0 20px;
  }

  .out .box {
    min-width: 100%;
    padding: 10px;
  }

  .card-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .card-head .btn {
    width: 100%;
    margin-top: 4px;
  }
}

/* ===== TABLET OPTIMIZATIONS ===== */

@media (min-width: 640px) and (max-width: 1023px) {
  /* Slightly larger touch targets than mobile */
  .btn { min-height: 46px; font-size: 15px; }

  /* Better spacing */
  section { padding: 18px; }
}


/* ===== DESKTOP ENHANCEMENTS ===== */

@media (min-width: 1024px) {
  /* Standard desktop sizing */
  .btn {
    min-height: 44px;
    padding: 0 20px;
  }

  /* Better hover states */
  .btn:hover {
    filter: brightness(1.1);
  }

  nav a:hover {
    background: rgba(255, 255, 255, 0.05);
  }
}

/* ===== LARGE DESKTOP (1440px+) ===== */

@media (min-width: 1440px) {
  .wrap { max-width: 1400px; padding: 24px; }

  section { padding: 24px; margin: 24px 0; }

  h2 { font-size: 24px; }
  h3 { font-size: 20px; }

  .card { padding: 18px; }

  /* More columns on very wide screens */
  .grid-4 { grid-template-columns: repeat(4, 1fr); }

  /* Better table spacing */
  table th, table td { padding: 14px 16px; }

  /* Ensure vertical borders are visible on large desktop */
  table th, table td {
    border-right: 3px solid #2a2a2a !important;
  }
  table th:first-child, table td:first-child {
    border-right: none !important;
  }

  body.day-mode table th, body.day-mode table td {
    border-right: 3px solid #b0b0b0 !important;
  }
  body.day-mode table th:first-child, body.day-mode table td:first-child {
    border-right: none !important;
  }

  /* Design table borders on large desktop */
  #design table th, #design table td {
    border-right: 3px solid #2a2a2a !important;
  }
  #design table th:first-child, #design table td:first-child {
    border-right: none !important;
  }

  body.day-mode #design table th, body.day-mode #design table td {
    border-right: 3px solid #b0b0b0 !important;
  }
  body.day-mode #design table th:first-child, body.day-mode #design table td:first-child {
    border-right: none !important;
  }
}

/* ===== PRINT STYLES ===== */

@media print{
  body *{visibility:hidden}
  .print-active,.print-active *{visibility:visible}
  .print-active{position:absolute;left:0;top:0;width:100%}
  .print-active button,.print-active .btn{display:none !important}
  header,#auth-gate,#pw-reset,#theme-toggle{display:none !important}

  /* Optimize for print */
  body {
    background: white !important;
    color: black !important;
  }

  section {
    page-break-inside: avoid;
    border: 1px solid #ddd !important;
    box-shadow: none !important;
  }

  table {
    page-break-inside: auto;
  }

  tr {
    page-break-inside: avoid;
    page-break-after: auto;
  }

  /* Ensure tables are readable */
  table, th, td {
    border: 1px solid #999 !important;
    color: black !important;
    background: white !important;
  }

  th {
    background: #f0f0f0 !important;
  }

  /* Show content */
  .hidden {
    display: none !important;
  }
}


/* ===== ACCESSIBILITY & TOUCH DEVICE SUPPORT ===== */

@media (hover: none) and (pointer: coarse) {
  /* Touch device enhancements */
  input, textarea, select, .btn, nav a {
    -webkit-tap-highlight-color: rgba(212, 175, 55, 0.2);
  }

  /* Larger touch targets */
  nav a {
    min-height: 44px;
    padding: 12px 16px;
  }

  .btn {
    min-height: 48px;
  }

  /* Better focus indication */
  input:focus, textarea:focus, select:focus {
    outline: 2px solid var(--gold);
    outline-offset: 1px;
  }
}

/* ===== Auth Gate (Supabase) ===== */
body.auth-check { visibility: hidden; } /* avoid flash before session check */
#auth-gate {
  position: fixed; inset: 0; z-index: 9999;
  display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,.9);
  padding: 20px;
}
#auth-gate.active { display: flex; }
#auth-gate .panel{
  width:min(520px, 100%);
  max-width: 520px;
  background:#121212;
  border:1px solid var(--border);
  border-radius:16px;
  padding:20px;
  box-shadow:0 10px 30px rgba(0,0,0,.45);
  max-height: 90vh;
  overflow-y: auto;
}
#auth-gate h1{margin:0 0 8px; color:var(--gold); font-size:22px; text-align:center}
#auth-gate p{margin:0 0 14px; color:#bdbdbd; text-align:center}
#auth-gate .row{display:grid; gap:10px; grid-template-columns:1fr}
#auth-gate input{
  width:100%; padding:12px;border-radius:12px;border:1px solid var(--border);
  background:#0e0e0e;color:#fff; font-size:16px;
}
#auth-gate .actions{display:flex; gap:10px; margin-top:10px; justify-content:center; flex-wrap: wrap}
#auth-gate .btn{height:46px; flex: 1; min-width: 120px}
#logoutBtn{ margin-inline-start:8px }

/* Mobile auth gate optimizations */
@media (max-width: 639px) {
  #auth-gate { padding: 16px; }
  #auth-gate .panel { padding: 18px; border-radius: 14px; }
  #auth-gate h1 { font-size: 20px; }
  #auth-gate .actions { flex-direction: column; }
  #auth-gate .btn { width: 100%; min-width: auto; }
}

/* ----- Password Reset Modal ----- */
#pw-reset{
  display:none;
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.85);
  z-index:10000;
  align-items:center;
  justify-content:center;
  padding: 20px;
}
#pw-reset .panel{
  width:min(460px,100%);
  max-width: 460px;
  background:#121212;
  border:1px solid #2a2a2a;
  border-radius:16px;
  padding:18px;
  max-height: 90vh;
  overflow-y: auto;
}
#pw-reset h2{margin:0 0 10px; color:#d4af37; text-align:center}
#pw-reset p{margin:0 0 14px; color:#bdbdbd; text-align:center}
#pw-reset input{
  width:100%;
  padding:12px;
  border-radius:12px;
  border:1px solid #2a2a2a;
  background:#0e0e0e;
  color:#fff;
  margin-bottom:10px;
  font-size: 16px;
}
#pw-reset .actions{display:flex; gap:10px; justify-content:center; margin-top:12px; flex-wrap: wrap}

/* Mobile password reset modal */
@media (max-width: 639px) {
  #pw-reset { padding: 16px; }
  #pw-reset .panel { padding: 16px; border-radius: 14px; }
  #pw-reset h2 { font-size: 19px; }
  #pw-reset .actions { flex-direction: column; }
  #pw-reset .actions .btn { width: 100%; }
}

/* ----- Day Mode Colors ----- */
body.day-mode {
  --bg: #ffffff;
  --card: #f5f5f5;
  --text: #000000;
  --muted: #666666;
  --gold: #FFD700;
  --border: #e0e0e0;
  --warn: #FFD700;
  --danger: #ff4444;
}

body.day-mode input,
body.day-mode textarea.name-cell {
  background: #ffffff;
  color: #000000;
  border-color: #e0e0e0;
}

body.day-mode .card,
body.day-mode table {
  background: #fafafa;
}

body.day-mode th {
  background: #f0f0f0;
  color: #333333;
}

body.day-mode .out .box {
  background: #ffffff;
  border-color: #d0d0d0;
}

body.day-mode #auth-gate .panel,
body.day-mode #pw-reset .panel {
  background: #f5f5f5;
  border-color: #e0e0e0;
}

body.day-mode #auth-gate input,
body.day-mode #pw-reset input {
  background: #ffffff;
  color: #000000;
  border-color: #e0e0e0;
}

body.day-mode header {
  background: #ffffff;
  border-bottom-color: #e0e0e0;
}

body.day-mode nav a {
  color: #666666;
  border-color: #e0e0e0;
}

body.day-mode nav a.active,
body.day-mode nav a:hover {
  color: #000000;
  border-color: #cccccc;
}

body.day-mode section {
  background: #f5f5f5;
  border-color: #e0e0e0;
}

body.day-mode label {
  color: #333333;
  font-weight: 500;
}

body.day-mode .hint {
  color: #000000;
}

body.day-mode .card .hint {
  color: #000000;
}

body.day-mode h2,
body.day-mode h3 {
  color: #000000;
  font-weight: 700;
}

body.day-mode .out .title {
  color: #666666;
}

body.day-mode .out .val {
  color: #000000;
  font-weight: 800;
}

body.day-mode .out .val.yellow {
  color: #000000;
}

body.day-mode .out .val.red {
  color: #ff4444;
}

body.day-mode td, body.day-mode th {
  color: #000000;
}

/* Day mode: alternating row colors - calculator tables only */
body.day-mode #ratios tbody tr:nth-child(odd),
body.day-mode #design tbody tr:nth-child(odd),
body.day-mode #johnkarl tbody tr:nth-child(odd),
body.day-mode #ifra tbody tr:nth-child(odd),
body.day-mode #eo-net tbody tr:nth-child(odd) {
  background-color: #d0d0d0 !important;
  color: #000000 !important;
}
body.day-mode #ratios tbody tr:nth-child(even),
body.day-mode #design tbody tr:nth-child(even),
body.day-mode #johnkarl tbody tr:nth-child(even),
body.day-mode #ifra tbody tr:nth-child(even),
body.day-mode #eo-net tbody tr:nth-child(even) {
  background-color: #e8e8e8 !important;
  color: #ff0000 !important;
}

body.day-mode #ratios tbody tr:nth-child(odd) td,
body.day-mode #design tbody tr:nth-child(odd) td,
body.day-mode #johnkarl tbody tr:nth-child(odd) td,
body.day-mode #ifra tbody tr:nth-child(odd) td,
body.day-mode #eo-net tbody tr:nth-child(odd) td {
  color: #000000 !important;
}
body.day-mode #ratios tbody tr:nth-child(even) td,
body.day-mode #design tbody tr:nth-child(even) td,
body.day-mode #johnkarl tbody tr:nth-child(even) td,
body.day-mode #ifra tbody tr:nth-child(even) td,
body.day-mode #eo-net tbody tr:nth-child(even) td {
  color: #ff0000 !important;
}

/* Match input text colors to row colors - calculator tables only */
body.day-mode #ratios tbody tr:nth-child(odd) input,
body.day-mode #ratios tbody tr:nth-child(odd) textarea,
body.day-mode #design tbody tr:nth-child(odd) input,
body.day-mode #design tbody tr:nth-child(odd) textarea,
body.day-mode #johnkarl tbody tr:nth-child(odd) input,
body.day-mode #johnkarl tbody tr:nth-child(odd) textarea,
body.day-mode #ifra tbody tr:nth-child(odd) input,
body.day-mode #ifra tbody tr:nth-child(odd) textarea,
body.day-mode #eo-net tbody tr:nth-child(odd) input,
body.day-mode #eo-net tbody tr:nth-child(odd) textarea {
  color: #000000 !important;
}
body.day-mode #ratios tbody tr:nth-child(even) input,
body.day-mode #ratios tbody tr:nth-child(even) textarea,
body.day-mode #design tbody tr:nth-child(even) input,
body.day-mode #design tbody tr:nth-child(even) textarea,
body.day-mode #johnkarl tbody tr:nth-child(even) input,
body.day-mode #johnkarl tbody tr:nth-child(even) textarea,
body.day-mode #ifra tbody tr:nth-child(even) input,
body.day-mode #ifra tbody tr:nth-child(even) textarea,
body.day-mode #eo-net tbody tr:nth-child(even) input,
body.day-mode #eo-net tbody tr:nth-child(even) textarea {
  color: #ff0000 !important;
}

/* Admin & non-calculator tables in day mode - clean black text */
body.day-mode #admin tbody tr td,
body.day-mode #admin tbody tr input,
body.day-mode #admin tbody tr textarea {
  color: #000000 !important;
}
body.day-mode #admin tbody tr {
  background-color: #f0f0f0 !important;
}
body.day-mode #admin tbody tr:nth-child(even) {
  background-color: #e8e8e8 !important;
}
body.day-mode #admin input,
body.day-mode #admin textarea {
  background: #ffffff !important;
  color: #000000 !important;
  border-color: #d0d0d0 !important;
}

/* Yellow background for output cells in day mode */
body.day-mode td.d_addW, body.day-mode td.d_bottleW, body.day-mode td.d_inSamplePct,
body.day-mode td.jk_addW,
body.day-mode td[id^="r_w"],
body.day-mode td[id^="eo_required_"], body.day-mode td[id^="eo_pctOfTotal_"],
body.day-mode td[id^="eo_req_left_"], body.day-mode td[id^="eo_pricePerGram_"], body.day-mode td[id^="eo_cost_"],
body.day-mode th#ifra_tox_sum {
  background-color: #FFD700 !important;
  font-weight: 700;
}

/* Apply alternating colors to yellow cells - DAY MODE (calculator tables only) */
body.day-mode #design tbody tr:nth-child(odd) td.d_addW, body.day-mode #design tbody tr:nth-child(odd) td.d_bottleW, body.day-mode #design tbody tr:nth-child(odd) td.d_inSamplePct,
body.day-mode #johnkarl tbody tr:nth-child(odd) td.jk_addW,
body.day-mode #ratios tbody tr:nth-child(odd) td[id^="r_w"],
body.day-mode #eo-net tbody tr:nth-child(odd) td[id^="eo_required_"], body.day-mode #eo-net tbody tr:nth-child(odd) td[id^="eo_pctOfTotal_"],
body.day-mode #eo-net tbody tr:nth-child(odd) td[id^="eo_req_left_"], body.day-mode #eo-net tbody tr:nth-child(odd) td[id^="eo_pricePerGram_"], body.day-mode #eo-net tbody tr:nth-child(odd) td[id^="eo_cost_"] {
  color: #000000 !important;
}

body.day-mode #design tbody tr:nth-child(even) td.d_addW, body.day-mode #design tbody tr:nth-child(even) td.d_bottleW, body.day-mode #design tbody tr:nth-child(even) td.d_inSamplePct,
body.day-mode #johnkarl tbody tr:nth-child(even) td.jk_addW,
body.day-mode #ratios tbody tr:nth-child(even) td[id^="r_w"],
body.day-mode #eo-net tbody tr:nth-child(even) td[id^="eo_required_"], body.day-mode #eo-net tbody tr:nth-child(even) td[id^="eo_pctOfTotal_"],
body.day-mode #eo-net tbody tr:nth-child(even) td[id^="eo_req_left_"], body.day-mode #eo-net tbody tr:nth-child(even) td[id^="eo_pricePerGram_"], body.day-mode #eo-net tbody tr:nth-child(even) td[id^="eo_cost_"] {
  color: #ff0000 !important;
}

/* Make text more visible in day mode */
body.day-mode {
  font-weight: 450;
}

body.day-mode .btn.secondary {
  background: transparent;
  color: #000000;
  border-color: #000000;
  font-weight: 700;
}

body.day-mode .btn.secondary:hover {
  background: rgba(0, 0, 0, 0.05);
}

body.day-mode .btn.danger {
  color: #ff4444;
  border-color: #ff4444;
}

/* ----- Theme Toggle Button ----- */
#theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  background: var(--gold);
  color: #000;
  border: 2px solid var(--gold);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  cursor: pointer;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

#theme-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 15px rgba(0,0,0,0.4);
}

#theme-toggle:active {
  transform: scale(0.95);
}

/* Mobile positioning for theme toggle */
@media (max-width: 639px) {
  #theme-toggle {
    top: 10px;
    right: 10px;
    width: 44px;
    height: 44px;
    font-size: 20px;
  }
}

/* Very small screens */
@media (max-width: 374px) {
  #theme-toggle {
    top: 8px;
    right: 8px;
    width: 40px;
    height: 40px;
    font-size: 18px;
  }
}

/* ===== FILE MANAGEMENT RESPONSIVE STYLES ===== */

/* Downloads Section */
body.day-mode .downloads-item h3 {
  color: #ffffff !important;
}

.downloads-item {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  background: #0f0f0f;
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-bottom: 12px;
}

@media (min-width: 640px) {
  .downloads-item {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
  .downloads-item .btn {
    width: auto;
    min-width: 160px;
  }
}

/* Videos Grid - Responsive */
.videos-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .videos-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .videos-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.video-card {
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.video-card:hover {
  transform: translateY(-4px);
  border-color: var(--gold);
}

.video-card:active {
  transform: translateY(-2px);
}

/* ===== Folders (videos + downloads) ===== */
.folder-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
  margin-bottom: 18px;
}

@media (min-width: 640px) {
  .folder-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1024px) {
  .folder-grid { grid-template-columns: repeat(3, 1fr); }
}

.folder-card {
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 18px 14px;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.folder-card:hover {
  transform: translateY(-4px);
  border-color: var(--gold);
}

.folder-card:active { transform: translateY(-2px); }

.folder-card:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.folder-card-icon { font-size: 40px; line-height: 1; }

.folder-card-name {
  margin: 4px 0 0;
  font-size: 16px;
  line-height: 1.4;
  color: var(--text);
}

.folder-card-meta {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.folder-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 14px;
}

.folder-breadcrumb .crumb {
  background: transparent;
  border: none;
  color: var(--gold);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}

.folder-breadcrumb .crumb:hover { text-decoration: underline; }

.folder-breadcrumb .crumb.current {
  color: var(--text);
  cursor: default;
  font-weight: 600;
}

.folder-breadcrumb .crumb-sep { color: var(--muted); }

/* Skeleton Loading Animation */
@keyframes skeleton-loading {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skeleton {
  background: linear-gradient(90deg, #1a1a1a 25%, #2a2a2a 50%, #1a1a1a 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
}

.skeleton-card {
  border-radius: 14px;
  padding: 0;
  overflow: hidden;
}

.skeleton-thumbnail {
  aspect-ratio: 16/9;
  background: linear-gradient(90deg, #1a1a1a 25%, #2a2a2a 50%, #1a1a1a 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: 8px;
  margin-bottom: 12px;
}

.skeleton-text {
  height: 16px;
  background: linear-gradient(90deg, #1a1a1a 25%, #2a2a2a 50%, #1a1a1a 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: 4px;
  margin-bottom: 8px;
}

.skeleton-text-short {
  width: 70%;
}

/* Fade-in animation for loaded content */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.fade-in {
  animation: fadeIn 0.3s ease-in;
}

/* Video Modal - Full responsive */
.video-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.96);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 8px;
  backdrop-filter: blur(4px);
}

.video-modal.active {
  display: flex;
  animation: fadeIn 0.2s ease;
}

.video-modal-content {
  position: relative;
  background: #000;
  border-radius: 16px;
  overflow: hidden;
  max-width: 96vw;
  max-height: 92vh;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8);
  animation: scaleIn 0.2s ease;
}

@keyframes scaleIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@media (min-width: 640px) {
  .video-modal {
    padding: 16px;
  }
  .video-modal-content {
    max-width: 92vw;
    border-radius: 20px;
  }
}

@media (min-width: 1024px) {
  .video-modal-content {
    max-width: 1200px;
  }
}

.video-close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10001;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  border: 2px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 28px;
  font-weight: 700;
  cursor: pointer;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
  transition: background 0.2s ease;
}

.video-close-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

@media (max-width: 639px) {
  .video-close-btn {
    width: 40px;
    height: 40px;
    font-size: 24px;
    top: 5px;
    right: 5px;
  }
}

/* Admin Panel Responsive */
.admin-table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #0f0f0f;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  /* Add scroll shadow indicators like table-wrapper */
  background:
    linear-gradient(to right, #0f0f0f 30%, transparent),
    linear-gradient(to left, #0f0f0f 30%, transparent),
    radial-gradient(farthest-side at 0 50%, rgba(212, 175, 55, 0.3), transparent),
    radial-gradient(farthest-side at 100% 50%, rgba(212, 175, 55, 0.3), transparent);
  background-repeat: no-repeat;
  background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
  background-position: 0 0, 100% 0, 0 0, 100% 0;
  background-attachment: local, local, scroll, scroll;
}

@media (max-width: 639px) {
  .admin-table-container {
    border-radius: 12px;
    margin-top: 14px;
  }

  .admin-table-container table {
    font-size: 13px;
  }

  .admin-table-container th,
  .admin-table-container td {
    padding: 10px 8px;
    min-width: 110px;
  }

  .admin-table-container th {
    background: #1a1a1a;
    font-size: 13px;
    font-weight: 700;
  }

  .admin-table-container .btn {
    padding: 8px 12px;
    font-size: 12px;
    white-space: nowrap;
    min-height: 38px;
    border-radius: 10px;
  }

  .admin-table-container select {
    font-size: 13px !important;
    padding: 8px !important;
    min-height: 38px;
  }
}

/* Admin Upload Form */
.admin-upload-form {
  display: grid;
  gap: 14px;
}

.admin-form-row {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .admin-form-row {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Touch improvements for mobile */
@media (hover: none) and (pointer: coarse) {
  /* Larger touch targets */
  button, .btn, a, input[type="button"], input[type="submit"] {
    min-height: 44px;
    min-width: 44px;
  }

  /* Remove hover effects on touch devices */
  .btn:hover, nav a:hover, .card:hover {
    opacity: 1;
    transform: none;
    border-color: inherit;
  }

  /* Active states for touch feedback */
  .btn:active {
    opacity: 0.8;
    transform: translateY(2px);
  }

  nav a:active {
    background: rgba(255,255,255,0.1);
  }
}

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
}

/* Better focus states for accessibility */
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* Flash animation on results */
@keyframes flash-result{
  0%{background:rgba(212,175,55,.35)}
  100%{background:transparent}
}
.out .val.flash{animation:flash-result .6s ease-out}

/* Input validation error styles */
.input-error{border-color:var(--danger) !important;box-shadow:0 0 0 2px rgba(255,107,107,.25)}
.validation-hint{color:var(--danger);font-size:11px;margin-top:2px;display:block}

/* Undo button for clear */
.undo-btn{
  background:transparent;border:1px dashed var(--gold);color:var(--gold);
  border-radius:8px;padding:6px 14px;cursor:pointer;font-size:13px;margin-top:8px
}
.undo-btn:hover{background:rgba(212,175,55,.1)}

/* Home card styles (extracted from inline) */
.home-card{background:linear-gradient(135deg,#1a1a1a 0%,#2a2a2a 100%);border:2px solid var(--gold);cursor:pointer}
body.day-mode .home-card{background:linear-gradient(135deg,#f5f5f5 0%,#e8e8e8 100%);border-color:#b8860b}
/* Admin input styles (extracted from inline) */
.admin-input{width:100%;padding:12px;border-radius:12px;border:1px solid var(--border);background:#0e0e0e;color:#fff;min-height:44px}
.admin-textarea{width:100%;min-height:80px;padding:12px;border-radius:12px;border:1px solid var(--border);background:#0e0e0e;color:#fff;font-size:16px;line-height:1.5}
body.day-mode .admin-input,body.day-mode .admin-textarea{background:#fff;color:#333;border-color:#ccc}

/* =====================================================================
   FUTURISTIC LAYER — Liquid Glass + Aurora (append-only, reversible)
   Heavy glass/aurora scoped to dark (default) mode via body:not(.day-mode);
   day-mode left untouched. Universal niceties (font, button glow, focus
   rings, motion) apply in both. Delete this block to fully revert.
   ===================================================================== */

:root{
  --glass-bg: rgba(22,19,13,0.55);
  --glass-brd: rgba(212,175,55,0.18);
  --glass-blur: 13px;
  --gold-glow: rgba(212,175,55,0.32);
  --gold-grad: linear-gradient(135deg,#f4d469 0%,#d4af37 52%,#b8902a 100%);
  --surface-shadow: 0 10px 34px rgba(0,0,0,0.46), inset 0 1px 0 rgba(255,255,255,0.05);
}

/* Modern Arabic + Latin face, original stack as graceful fallback */
html,body{
  font-family:"Readex Pro","Noto Naskh Arabic","Segoe UI",Tahoma,Arial,sans-serif;
  -webkit-font-smoothing:antialiased;
  text-rendering:optimizeLegibility;
}

/* ---- Aurora background (dark mode only) ---- */
body:not(.day-mode){ background:transparent; }
body:not(.day-mode)::before{
  content:"";
  position:fixed;
  inset:-25%;
  z-index:-1;
  pointer-events:none;
  background:
    radial-gradient(38% 32% at 18% 12%, rgba(212,175,55,0.20), transparent 60%),
    radial-gradient(42% 38% at 84% 22%, rgba(176,138,42,0.16), transparent 62%),
    radial-gradient(48% 44% at 50% 92%, rgba(120,92,24,0.18), transparent 66%);
  filter: blur(34px) saturate(125%);
  animation: lhAurora 20s ease-in-out infinite alternate;
  will-change: transform;
}
@keyframes lhAurora{
  0%  { transform: translate3d(0,0,0) scale(1); }
  50% { transform: translate3d(2.5%, -2%, 0) scale(1.08); }
  100%{ transform: translate3d(-2.5%, 2.5%, 0) scale(1.05); }
}

/* ---- Glass surfaces (dark mode only) ---- */
body:not(.day-mode) section,
body:not(.day-mode) .card{
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(135%);
  backdrop-filter: blur(var(--glass-blur)) saturate(135%);
  border: 1px solid var(--glass-brd);
  box-shadow: var(--surface-shadow);
}
body:not(.day-mode) section{ border-radius:18px; }
body:not(.day-mode) .card{ transition: transform .25s ease, border-color .25s ease, box-shadow .25s ease; }

/* Header + nav glass */
body:not(.day-mode) header{
  background: rgba(0,0,0,0.55);
  -webkit-backdrop-filter: blur(10px) saturate(130%);
  backdrop-filter: blur(10px) saturate(130%);
  border-bottom: 1px solid var(--glass-brd);
}
body:not(.day-mode) nav a{
  background: rgba(212,175,55,0.05);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border-color: var(--glass-brd);
  transition: color .2s ease, border-color .2s ease, box-shadow .2s ease, background .2s ease;
}
body:not(.day-mode) nav a.active,
body:not(.day-mode) nav a:hover{
  border-color: var(--gold);
  box-shadow: 0 0 0 1px rgba(212,175,55,0.35), 0 4px 18px var(--gold-glow);
}

/* ---- Buttons: gold gradient + glow (both modes) ---- */
.btn{
  background-image: var(--gold-grad);
  border-color: rgba(212,175,55,0.7);
  box-shadow: 0 4px 18px var(--gold-glow);
  transition: transform .18s ease, box-shadow .22s ease, filter .2s ease;
}
.btn:hover{
  transform: translateY(-1px);
  box-shadow: 0 7px 26px var(--gold-glow), 0 0 0 1px rgba(212,175,55,0.45);
  filter: brightness(1.04);
}
.btn:active{ transform: translateY(1px); }
.btn.secondary{
  background-image: none;
  background-color: rgba(212,175,55,0.07);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: var(--gold);
  box-shadow: none;
}
.btn.secondary:hover{ box-shadow: 0 0 0 1px rgba(212,175,55,0.4); }
.btn.danger{ background-image:none; background-color:transparent; box-shadow:none; }

/* ---- Inputs: focus glow ---- */
input:focus,select:focus,textarea:focus{
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-glow);
}

/* ---- Folder cards: glass + gold halo (dark mode) ---- */
body:not(.day-mode) .folder-card{
  background: linear-gradient(160deg, rgba(212,175,55,0.08), rgba(22,19,13,0.55));
  border-color: var(--glass-brd);
}
body:not(.day-mode) .folder-card:hover{
  border-color: var(--gold);
  box-shadow: 0 10px 30px rgba(0,0,0,0.5), 0 0 0 1px rgba(212,175,55,0.35), 0 0 36px var(--gold-glow);
}
.folder-card-icon{ color: var(--gold); filter: drop-shadow(0 2px 8px var(--gold-glow)); }
.folder-card-icon svg{ width:42px; height:42px; display:block; }

/* Breadcrumb chip polish */
body:not(.day-mode) .folder-breadcrumb{
  background: rgba(212,175,55,0.05);
  border:1px solid var(--glass-brd);
  border-radius:14px;
  padding:8px 12px;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

/* Video card thumb + play glow */
body:not(.day-mode) .video-card:hover{
  box-shadow: 0 12px 32px rgba(0,0,0,0.5), 0 0 30px var(--gold-glow);
}
.video-card-play svg{ width:26px; height:26px; display:block; }

/* Video modal: deeper glass backdrop */
body:not(.day-mode) .video-modal{
  background: rgba(6,6,6,0.78);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  backdrop-filter: blur(10px) saturate(120%);
}
body:not(.day-mode) .video-modal-content{
  border: 1px solid var(--glass-brd);
  box-shadow: 0 20px 60px rgba(0,0,0,0.7), 0 0 60px rgba(212,175,55,0.12);
}

/* Headings: subtle gold sheen */
body:not(.day-mode) h2,
body:not(.day-mode) h3{
  text-shadow: 0 0 22px rgba(212,175,55,0.18);
  letter-spacing: .01em;
}

/* ---- Accessibility: respect reduced motion + low-end fallbacks ---- */
@media (prefers-reduced-motion: reduce){
  body:not(.day-mode)::before{ animation: none; }
  .btn, body:not(.day-mode) .card, body:not(.day-mode) nav a{ transition: none; }
}
/* Trim blur on small screens to protect scroll perf */
@media (max-width: 480px){
  :root{ --glass-blur: 9px; }
}

/* ---- admin: toolbars, bulk bar, group chips (2026-08-09) ---- */
.lh-toolbar { display:flex; gap:10px; flex-wrap:wrap; align-items:center; margin:12px 0; }
.lh-toolbar input, .lh-toolbar select {
  padding:8px 10px; border-radius:8px; border:1px solid var(--border);
  background:#0e0e0e; color:#fff; font-size:14px; min-height:38px;
}
.lh-toolbar input { min-width:220px; }
.lh-bulkbar {
  display:none; gap:10px; flex-wrap:wrap; align-items:center;
  padding:10px 12px; margin:12px 0; border-radius:10px;
  border:1px solid var(--border); background:rgba(255,255,255,.04);
}
.lh-bulkbar.is-visible { display:flex; }
.lh-muted { color:var(--muted); font-size:13px; }

/* ---- admin: <option> colours (2026-08-11) ------------------------------
   A <select multiple> renders as an inline listbox painted by the page, not
   as an OS popup. Its <option> children take the browser's DEFAULT (white)
   background while inheriting color:#fff from .admin-input / the inline
   select styles — white text on white, i.e. invisible. The only time an
   option was legible was while highlighted, which read as "it auto-selected
   my group". Nothing in this stylesheet styled `option` at all before now.
   Scoped to #admin so the calculator's own selects are untouched.          */
#admin select option {
  background: #0e0e0e;
  color: #fff;
}
#admin select option:checked {
  background: rgba(212, 175, 55, .28);
  color: #fff;
}
body.day-mode #admin select option {
  background: #fff;
  color: #333;
}
body.day-mode #admin select option:checked {
  background: rgba(212, 175, 55, .35);
  color: #111;
}
/* Multi-selects need room to show more than one row at a time. */
#admin select[multiple] {
  min-height: 84px;
  padding: 4px;
}

/* ---- admin: group-picker (dropdown + checkbox panel) (2026-08-11) ------
   Replaces the <select multiple> group control above with a closed trigger
   + checkbox panel (js/folders.js, LH.renderGroupPicker). Colours belong
   here, not in the widget's inline styles -- the bug that started this
   whole project was exactly a group control left unstyled for the active
   theme (white text on white; see the #admin select option note above).
   The panel is appended to <body> (it must escape the scrolling admin
   tables), so it is NOT a descendant of #admin -- these rules are
   unscoped, matched by class only. */
.lh-gp-trigger {
  background: #0e0e0e;
  color: #fff;
  border-color: var(--border);
}
.lh-gp-trigger:hover {
  border-color: #333;
}
.lh-gp-panel {
  background: #171717;
  color: #fff;
  border-color: var(--border);
}
body.day-mode .lh-gp-trigger {
  background: #fff;
  color: #333;
  border-color: #ccc;
}
body.day-mode .lh-gp-trigger:hover {
  border-color: #999;
}
body.day-mode .lh-gp-panel {
  background: #fff;
  color: #333;
  border-color: #ccc;
}

/* The panel's per-group checkbox rows previously had no colour of their
   own -- the <label>/<span> text relied on inheriting .lh-gp-panel's
   `color`, but the SITE-WIDE `label{color:var(--muted)}` rule (top of this
   file) and `body.day-mode label{color:#333333}` (Day Mode Colors section)
   both declare `color` directly ON the <label> element, which always wins
   over an inherited value regardless of specificity. Today those two rules
   happen to compute to something legible, but the panel has zero control
   over that -- an unrelated future edit to either global rule (both apply
   to every <label> on the page, not just this widget) would silently break
   this picker's text again, exactly the "white-on-white options" defect
   class this project has already hit twice (see the #admin select option
   note above). Give the picker's own labels an explicit, scoped colour so
   they never again depend on a rule that isn't theirs. */
.lh-gp-panel label,
.lh-gp-panel label span {
  color: #fff;
}
body.day-mode .lh-gp-panel label,
body.day-mode .lh-gp-panel label span {
  color: #333;
}

/* ---- checkboxes must not inherit the global input width (2026-08-12) -------
   styles.css:34 sets `input{width:100%}` for text fields. Applied to a
   checkbox or radio it stretches the control to its container's full width —
   on the group picker that measured 148px, collapsing the label text beside
   it to 0px. Latent everywhere a checkbox sits next to text.               */
input[type="checkbox"],
input[type="radio"] {
  width: auto;
  padding: 0;
}
