/* ============================================================
   Apple Style Design System for 奇兹储能电站报表
   仅包含主题变量与核心组件样式，保留原文件所有功能。
   ============================================================ */

:root {
  /* Light (default) — high-contrast clean energy */
  --bg-base: #f5f6f8;
  --bg-deep: #edeff3;
  --bg-surface: #ffffff;
  --bg-surface-2: #ffffff;
  --bg-elevated: #ffffff;
  --bg-hover: rgba(0, 0, 0, 0.04);
  --bg-input: #ffffff;
  --grid-line: rgba(0, 0, 0, 0.18);

  --text-primary: #0d0d0d;
  --text-secondary: #3a3a3c;
  --text-tertiary: #545457;
  --text-faint: #8e8e93;

  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.22);

  --accent: #0051d5;
  --accent-2: #1e9e44;
  --accent-3: #e67e00;
  --accent-glow: rgba(0, 81, 213, 0.18);
  --success: #1e7a34;
  --collector-rte: #ff9f0a;
  --warn: #e67e00;
  --danger: #ff3b30;
  --charge: #0052cc;
  --discharge: #1a7d3a;
  --text-on-accent: #ffffff;
  --text-on-success: #ffffff;
  --status-saved: #1a7d3a;
  --status-unsaved: #e67e00;

  --grad-accent: linear-gradient(135deg, #0051d5 0%, #0077ed 100%);
  --grad-charge: linear-gradient(135deg, #0052cc 0%, #2488ff 100%);
  --grad-discharge: linear-gradient(135deg, #1a7d3a 0%, #35a856 100%);
  --grad-card: linear-gradient(160deg, rgba(255,255,255,0.5), rgba(255,255,255,0));
  --grad-metal: linear-gradient(160deg, rgba(255,255,255,0.9) 0%, rgba(255,255,255,0.45) 40%, rgba(255,255,255,0.75) 100%);

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 6px 18px rgba(0,0,0,0.07);
  --shadow-lg: 0 18px 38px rgba(0,0,0,0.10);
  --shadow-glow: 0 0 0 1px rgba(0,102,255,0.12), 0 6px 18px rgba(0,102,255,0.10);

  --r-xs: 10px; --r-sm: 14px; --r-md: 20px; --r-lg: 28px; --r-xl: 36px;
  --font-display: "SF Pro Display", "SF Pro", -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-body: "SF Pro Text", "SF Pro", -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", Consolas, monospace;
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --t: 0.35s var(--ease);
}

[data-theme="dark"] {
  --bg-base: #121214;
  --bg-deep: #0d0d0f;
  --bg-surface: rgba(28, 28, 30, 0.78);
  --bg-surface-2: rgba(44, 44, 46, 0.72);
  --bg-elevated: rgba(48, 48, 50, 0.86);
  --bg-hover: rgba(255, 255, 255, 0.06);
  --bg-input: rgba(28, 28, 30, 0.85);
  --grid-line: rgba(255, 255, 255, 0.04);

  --text-primary: #f5f5f7;
  --text-secondary: #a1a1a6;
  --text-tertiary: #86868b;
  --text-faint: #48484a;

  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);

  --accent: #0a84ff;
  --accent-2: #30d158;
  --accent-3: #ff9f0a;
  --accent-glow: rgba(10, 132, 255, 0.28);
  --charge: #0a84ff;
  --discharge: #30d158;

  --grad-accent: linear-gradient(135deg, #0a84ff 0%, #5ac8fa 100%);
  --grad-charge: linear-gradient(135deg, #0a84ff 0%, #64d2ff 100%);
  --grad-discharge: linear-gradient(135deg, #30d158 0%, #60e085 100%);

  --grad-card: linear-gradient(160deg, rgba(255,255,255,0.06), rgba(255,255,255,0.0));
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 12px 40px rgba(0,0,0,0.45);
  --shadow-lg: 0 28px 70px rgba(0,0,0,0.55);
  --shadow-glow: 0 0 0 1px rgba(10,132,255,0.16), 0 10px 40px rgba(10,132,255,0.12);
}

* , *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font-body);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.55;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background var(--t), color var(--t);
}

.bg-field {
  position: fixed; inset: 0; z-index: -2; pointer-events: none;
  background:
    radial-gradient(1200px 700px at 8% -8%, rgba(0,113,227,0.035), transparent 60%),
    radial-gradient(1000px 700px at 98% 2%, rgba(52,199,89,0.025), transparent 55%),
    radial-gradient(900px 600px at 70% 115%, rgba(255,159,10,0.02), transparent 60%),
    var(--bg-base);
}
[data-theme="dark"] .bg-field {
  background:
    radial-gradient(1200px 700px at 8% -8%, rgba(10,132,255,0.08), transparent 60%),
    radial-gradient(1000px 700px at 98% 2%, rgba(48,209,88,0.05), transparent 55%),
    radial-gradient(900px 600px at 70% 115%, rgba(255,159,10,0.03), transparent 60%),
    var(--bg-base);
}
.bg-grid {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 64px 64px;
  -webkit-mask-image: radial-gradient(ellipse at 50% 25%, #000 0%, transparent 75%);
  mask-image: radial-gradient(ellipse at 50% 25%, #000 0%, transparent 75%);
}
.bg-noise {
  position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.shell { max-width: 1500px; margin: 0 auto; padding: 0 34px 80px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 26px 0 22px; gap: 20px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 16px; }
.brand-mark {
  width: 48px; height: 48px; border-radius: 15px;
  background: var(--grad-accent);
  display: grid; place-items: center;
  box-shadow: 0 8px 28px var(--accent-glow);
  position: relative; overflow: hidden;
}
.brand-mark svg { width: 26px; height: 26px; }
.brand-text h1 { font-family: var(--font-display); font-size: 22px; font-weight: 700; letter-spacing: -0.5px; }
.brand-text p { font-size: 11px; color: var(--text-tertiary); letter-spacing: 1.5px; text-transform: uppercase; font-weight: 600; margin-top: 2px; }

.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.realtime-clock {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-surface); border: 1px solid var(--border);
  padding: 9px 16px; border-radius: 100px; font-size: 13px; font-weight: 600;
  color: var(--text-primary); font-family: var(--font-mono);
  letter-spacing: 0.4px; box-shadow: var(--shadow-sm); transition: border-color var(--t);
  backdrop-filter: blur(12px) saturate(1.6); -webkit-backdrop-filter: blur(12px) saturate(1.6);
}
.realtime-clock:hover { border-color: var(--border-strong); }
.live-pill {
  display: flex; align-items: center; gap: 9px;
  background: var(--bg-surface); border: 1px solid var(--border);
  padding: 9px 16px; border-radius: 100px; font-size: 12.5px; font-weight: 600;
  color: var(--text-secondary); letter-spacing: .2px; box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px) saturate(1.6); -webkit-backdrop-filter: blur(12px) saturate(1.6);
}
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-2); box-shadow: 0 0 0 0 rgba(52,199,89,0.35); animation: pulse 2s infinite; }
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(52,199,89,0.35)} 70%{box-shadow:0 0 0 8px transparent} 100%{box-shadow:0 0 0 0 transparent} }

.month-nav {
  display: flex; align-items: center; gap: 4px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 5px;
  backdrop-filter: blur(12px) saturate(1.6); -webkit-backdrop-filter: blur(12px) saturate(1.6);
}
.month-nav button {
  width: 34px; height: 34px; border: none; background: transparent; cursor: pointer;
  color: var(--text-secondary); border-radius: 11px; font-size: 16px;
  display: grid; place-items: center; transition: all .2s;
}
.month-nav button:hover { background: var(--bg-hover); color: var(--accent); }

.glass-select-wrap { position: relative; }
.glass-select-trigger {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px 7px 16px;
  border-radius: 12px;
  background: rgba(255,255,255,0.55);
  -webkit-backdrop-filter: blur(16px) saturate(1.6);
  backdrop-filter: blur(16px) saturate(1.6);
  border: 1px solid rgba(0,0,0,0.07);
  color: var(--text-primary);
  font-family: var(--font-body); font-weight: 600; font-size: 14px;
  cursor: pointer; -webkit-user-select: none; user-select: none;
  transition: all .25s var(--ease);
  min-width: 110px; justify-content: space-between;
  box-shadow: inset 0 1px 1px rgba(255,255,255,0.8);
}
.glass-select-trigger:hover {
  background: rgba(255,255,255,0.8);
  border-color: rgba(0,0,0,0.12);
  box-shadow: 0 4px 20px rgba(0,0,0,0.08), inset 0 1px 1px rgba(255,255,255,0.9);
}
.glass-select-trigger.active {
  background: rgba(255,255,255,0.92);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow), 0 8px 28px rgba(0,0,0,0.1);
}
.glass-chevron { transition: transform .3s var(--ease); color: var(--text-secondary); flex-shrink: 0; }
.glass-select-trigger.active .glass-chevron { transform: rotate(180deg); color: var(--accent); }

.glass-dropdown {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 200;
  min-width: 100%;
  background: rgba(255,255,255,0.88);
  -webkit-backdrop-filter: blur(24px) saturate(1.8);
  backdrop-filter: blur(24px) saturate(1.8);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 16px;
  padding: 8px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.14), 0 0 0 1px rgba(0,0,0,0.02);
  opacity: 0; transform: translateY(-8px) scale(0.96);
  pointer-events: none;
  transition: all .28s var(--ease);
  max-height: 340px; overflow-y: auto;
}
.glass-dropdown.show { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.glass-option {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-radius: 11px;
  color: var(--text-secondary); font-size: 13.5px; font-weight: 600;
  cursor: pointer; transition: all .18s var(--ease);
  white-space: nowrap;
}
.glass-option:hover { background: rgba(0,0,0,0.04); color: var(--text-primary); }
.glass-option.selected { background: rgba(0,113,227,0.10); color: var(--accent); }
.glass-option .check {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); display: grid; place-items: center;
  opacity: 0; transform: scale(0.6);
  transition: all .2s var(--ease);
}
.glass-option.selected .check { opacity: 1; transform: scale(1); }
.glass-option .check svg { width: 8px; height: 8px; }

[data-theme="dark"] .glass-select-trigger {
  background: rgba(40,40,42,0.55);
  border-color: rgba(255,255,255,0.10);
  color: var(--text-primary);
  box-shadow: inset 0 1px 1px rgba(255,255,255,0.04);
}
[data-theme="dark"] .glass-select-trigger:hover {
  background: rgba(50,50,52,0.75);
  border-color: rgba(255,255,255,0.16);
  box-shadow: 0 4px 24px rgba(0,0,0,0.35), inset 0 1px 1px rgba(255,255,255,0.06);
}
[data-theme="dark"] .glass-select-trigger.active {
  background: rgba(56,56,58,0.85);
  box-shadow: 0 0 0 3px rgba(10,132,255,0.12), 0 8px 28px rgba(0,0,0,0.35);
}
[data-theme="dark"] .glass-dropdown {
  background: rgba(34,34,36,0.88);
  border-color: rgba(255,255,255,0.10);
  box-shadow: 0 24px 60px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.02);
}
[data-theme="dark"] .glass-option:hover { background: rgba(255,255,255,0.06); }
[data-theme="dark"] .glass-option.selected { background: rgba(10,132,255,0.14); }

.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; cursor: pointer;
  background: var(--bg-surface); border: 1px solid var(--border);
  color: var(--text-secondary); font-size: 18px; display: grid; place-items: center;
  transition: all .25s var(--ease); box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px) saturate(1.6); -webkit-backdrop-filter: blur(12px) saturate(1.6);
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-2px); box-shadow: 0 8px 20px var(--accent-glow); }
.icon-btn:active { transform: translateY(0); }

.tabs {
  display: inline-flex; gap: 6px; margin: 10px 0 32px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 6px; box-shadow: var(--shadow-sm);
  backdrop-filter: blur(16px) saturate(1.6); -webkit-backdrop-filter: blur(16px) saturate(1.6);
}
.tab-btn {
  padding: 10px 22px; border: none; background: transparent; cursor: pointer;
  border-radius: 11px; font-family: var(--font-body); font-size: 14px; font-weight: 600;
  letter-spacing: .1px;
  color: var(--text-secondary); transition: all .3s var(--ease); position: relative;
  display: flex; align-items: center; gap: 8px;
}
.tab-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.tab-btn.active { color: var(--text-on-accent); background: var(--grad-accent); box-shadow: 0 6px 18px var(--accent-glow); }
.tab-btn.active:hover { color: var(--text-on-accent); background: var(--grad-accent); }

.tab-panel { display: none; animation: rise .5s var(--ease); }
.tab-panel.active { display: block; }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

.section-head { display: flex; align-items: center; gap: 14px; margin: 46px 2px 22px; }
.section-head h2 { font-family: var(--font-display); font-size: 18px; font-weight: 700; letter-spacing: -0.4px; }
.section-head .accent-bar { width: 4px; height: 18px; border-radius: 4px; background: var(--grad-accent); align-self: center; box-shadow: 0 0 12px var(--accent-glow); }
.section-head .hint {
  font-size: 12px; color: var(--text-tertiary); margin-left: auto; font-weight: 600;
  letter-spacing: .2px; padding: 6px 14px; border-radius: 100px;
  background: var(--bg-surface); border: 1px solid var(--border);
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 24px 26px;
  box-shadow: var(--shadow-sm);
  position: relative; overflow: hidden;
  transition: border-color var(--t), transform var(--t), box-shadow var(--t);
  backdrop-filter: blur(16px) saturate(1.6); -webkit-backdrop-filter: blur(16px) saturate(1.6);
}
.card::before { content:''; position:absolute; inset:0; background: var(--grad-card); pointer-events:none; z-index:-1; }
.card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; position: relative; }
.card-head .t { font-family: var(--font-display); font-size: 15px; font-weight: 700; letter-spacing: -.2px; display: flex; align-items: center; gap: 10px; }
.card-head .t .ico {
  width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center;
  background: var(--bg-elevated); border: 1px solid var(--border); font-size: 14px;
  box-shadow: var(--shadow-sm);
}
.card-head .sub { font-size: 11.5px; color: var(--text-tertiary); font-weight: 600; letter-spacing: .2px; }

.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px; margin-bottom: 10px;
}
.kpi {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 20px 22px 18px; position: relative; overflow: hidden;
  transition: transform var(--t), border-color var(--t), box-shadow var(--t);
  opacity: 0; animation: kpiIn .6s var(--ease) forwards;
  backdrop-filter: blur(16px) saturate(1.6); -webkit-backdrop-filter: blur(16px) saturate(1.6);
}
@keyframes kpiIn { from { opacity:0; transform: translateY(18px) scale(.98);} to {opacity:1; transform:none;} }
.kpi:hover { transform: translateY(-5px); border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.kpi .spark { position: absolute; right: 0; bottom: 0; width: 110px; height: 46px; opacity: .45; transition: opacity var(--t); }
.kpi:hover .spark { opacity: .8; }
.kpi .glyph {
  position: absolute; top: 16px; right: 16px; width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center; font-size: 15px; background: var(--bg-elevated);
  border: 1px solid var(--border); color: var(--accent);
  transition: transform var(--t), border-color var(--t);
}
.kpi:hover .glyph { transform: scale(1.1) rotate(-4deg); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.kpi .lbl { font-size: 12px; color: var(--text-secondary); font-weight: 600; letter-spacing: .2px; margin-bottom: 14px; max-width: 140px; }
.kpi .val { font-family: var(--font-mono); font-size: 28px; font-weight: 700; letter-spacing: -0.8px; line-height: 1; font-variant-numeric: tabular-nums; }
.kpi .val .u { font-family: var(--font-body); font-size: 12px; font-weight: 600; color: var(--text-tertiary); margin-left: 4px; letter-spacing: 0; }
.kpi .delta { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 700; margin-top: 12px; padding: 4px 10px; border-radius: 100px; letter-spacing: .2px; }
.kpi .delta.up { color: var(--accent-2); background: rgba(52,199,89,0.10); }
.kpi .delta.down { color: var(--danger); background: rgba(255,59,48,0.10); }
.kpi .delta.flat { color: var(--text-tertiary); background: rgba(0,0,0,0.03); }
[data-theme="dark"] .kpi .delta.flat { background: rgba(255,255,255,0.05); }
.kpi.hero {
  grid-column: span 2;
  background: linear-gradient(135deg, rgba(0,113,227,0.08), rgba(52,199,89,0.04) 60%, transparent);
  border-color: color-mix(in srgb, var(--accent) 22%, transparent);
}
.kpi.hero .val { font-size: 38px; letter-spacing: -1px; }
.kpi.hero .glyph { background: var(--grad-accent); border-color: transparent; color: var(--text-on-accent); box-shadow: 0 6px 18px var(--accent-glow); }
.kpi .topline { position:absolute; top:0; left:0; right:0; height: 2.5px; background: var(--grad-accent); opacity:.0; transition: opacity var(--t); }
.kpi:hover .topline { opacity: 1; }

.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-2-eq { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.mt { margin-top: 20px; }
canvas { display: block; width: 100%; }

.legend { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.legend span {
  display: inline-flex; align-items: center; gap: 7px; font-size: 12px;
  color: var(--text-secondary); font-weight: 600;
  background: var(--bg-elevated); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 100px;
}
.legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

.statline { display: flex; align-items: center; justify-content: space-between; padding: 13px 2px; border-bottom: 1px solid var(--border); transition: background .15s; border-radius: 8px; }
.statline:hover { background: var(--bg-hover); }
.statline:last-child { border-bottom: none; }
.statline .k { font-size: 13px; color: var(--text-secondary); font-weight: 600; display: flex; align-items: center; gap: 10px; }
.statline .k i { width: 9px; height: 9px; border-radius: 3px; }
.statline .v { font-family: var(--font-mono); font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.statline .v small { color: var(--text-tertiary); font-size: 11px; font-weight: 600; margin-left: 3px; }

.gauge-wrap { display: flex; align-items: center; gap: 20px; }
.gauge-num { font-family: var(--font-mono); font-size: 30px; font-weight: 700; }
.gauge-num small { font-size: 13px; color: var(--text-tertiary); }

.btn {
  padding: 10px 18px; border-radius: 12px; border: 1px solid var(--border);
  font-family: var(--font-body); font-size: 14px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px; transition: all .22s var(--ease);
  background: var(--bg-surface); color: var(--text-primary);
  backdrop-filter: blur(12px) saturate(1.6); -webkit-backdrop-filter: blur(12px) saturate(1.6);
}
.btn:hover { transform: translateY(-2px); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--grad-accent); color: var(--text-on-accent); border: none; box-shadow: 0 6px 18px var(--accent-glow); font-weight: 700; }
.btn-primary:hover { box-shadow: 0 10px 26px var(--accent-glow); }
.btn-success { background: var(--discharge); color: var(--text-on-success); border: none; font-weight: 700; }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--bg-hover); }

.form-section { margin-bottom: 20px; }
.fs-title { font-family: var(--font-display); font-size: 15px; font-weight: 700; letter-spacing: -.2px; display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.fs-title .badge { font-family: var(--font-mono); font-size: 10.5px; color: var(--accent); background: rgba(0,113,227,0.08); border: 1px solid rgba(0,113,227,0.14); padding: 4px 12px; border-radius: 100px; font-weight: 700; }
.form-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.fg { display: flex; flex-direction: column; gap: 8px; }
.fg label { font-size: 12px; color: var(--text-secondary); font-weight: 700; letter-spacing: .15px; }
.fg input, .fg textarea, .fg select {
  padding: 11px 14px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg-input); color: var(--text-primary);
  font-family: var(--font-mono); font-size: 13.5px; outline: none; transition: all .2s;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.02);
}
.fg input:hover, .fg textarea:hover, .fg select:hover { border-color: var(--border-strong); }
.fg input:focus, .fg textarea:focus, .fg select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow), inset 0 1px 2px rgba(0,0,0,0.02); }
.calc-out { display: flex; gap: 12px; margin-top: 16px; flex-wrap: wrap; }
.calc-out span { font-size: 12px; color: var(--text-tertiary); font-weight: 600; background: var(--bg-elevated); border: 1px solid var(--border); padding: 7px 14px; border-radius: 11px; }
.calc-out b { font-family: var(--font-mono); color: var(--accent); font-weight: 700; }

.table-wrap { overflow-x: auto; border-radius: var(--r-sm); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; }
.device-table th, table th {
  text-align: left; font-size: 10.5px; font-weight: 700; color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: .6px; padding: 13px 16px;
  background: var(--bg-elevated); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.device-table th:first-child, table th:first-child { border-top-left-radius: var(--r-sm); }
.device-table th:last-child, table th:last-child { border-top-right-radius: var(--r-sm); }
.device-table td, table td { padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.device-table input { width: 100%; min-width: 96px; padding: 8px 11px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-input); color: var(--text-primary); font-family: var(--font-mono); font-size: 13px; outline: none; transition: all .2s; }
.device-table input:hover { border-color: var(--border-strong); }
.device-table input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }
.dev-name { font-weight: 700 !important; color: var(--text-primary) !important; font-family: var(--font-display); font-size: 13px !important; }
.text-right { text-align: right; }
td.text-right, th.text-right { text-align: right; font-family: var(--font-mono); }

tbody tr { transition: background .15s; }
tbody tr:hover { background: var(--bg-hover); }
tbody tr:last-child td { border-bottom: none; }

.time-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.time-row .label { font-size: 13px; font-weight: 600; color: var(--text-secondary); min-width: 64px; }
.time-row select { padding: 8px 11px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-input); color: var(--text-primary); font-family: var(--font-mono); font-size: 12.5px; outline: none; }
.time-row .sep { color: var(--text-tertiary); }
.time-btn-add { background: transparent; border: 1px dashed var(--border-strong); color: var(--accent); padding: 7px 14px; border-radius: 10px; cursor: pointer; font-size: 12.5px; font-weight: 600; font-family: var(--font-body); }
.time-btn-remove { background: transparent; border: none; color: var(--danger); cursor: pointer; font-size: 14px; }

.report-out {
  width: 100%; padding: 18px; border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--bg-input); color: var(--text-primary); font-size: 13.5px; font-family: var(--font-mono);
  resize: vertical; line-height: 1.7; outline: none;
}
[data-theme="light"] .report-out { background: #ffffff; color: #0d0d0d; }

.chips { display: flex; gap: 14px; flex-wrap: wrap; }
.chip { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 18px 22px; min-width: 160px; transition: border-color var(--t), transform var(--t); }
.chip:hover { border-color: var(--border-strong); transform: translateY(-3px); }
.chip .k { font-size: 11px; color: var(--text-tertiary); font-weight: 700; letter-spacing: .3px; }
.chip .v { font-family: var(--font-mono); font-size: 24px; font-weight: 700; margin-top: 7px; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }

.heatstrip { display: flex; gap: 3px; flex-wrap: wrap; }
.heatcell { width: 100%; aspect-ratio: 1; border-radius: 3px; background: var(--bg-elevated); position: relative; }
.heat-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; }

/* Light-mode explicit form/report readability */
[data-theme="light"] .fg input,
[data-theme="light"] .fg textarea,
[data-theme="light"] .fg select,
[data-theme="light"] .device-table input {
  color: var(--text-primary);
  background: var(--bg-input);
}
[data-theme="light"] .report-date-bar { color: var(--text-secondary); }
[data-theme="light"] .report-date-bar .label { color: var(--text-tertiary); }
[data-theme="light"] .form-section label,
[data-theme="light"] .fg label { color: var(--text-secondary); }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); display: none; align-items: center; justify-content: center; z-index: 100; }
.modal-overlay.show { display: flex; animation: rise .3s var(--ease); }
.modal { background: var(--bg-elevated); border: 1px solid var(--border-strong); border-radius: var(--r-lg); padding: 30px; max-width: 460px; width: 90%; box-shadow: var(--shadow-lg); position: relative; overflow: hidden; }
.modal::before { content:''; position:absolute; top:0; left:0; right:0; height: 3px; background: var(--grad-accent); }
.modal-title { font-family: var(--font-display); font-size: 18px; font-weight: 700; letter-spacing: -.2px; margin-bottom: 14px; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }
.toast { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(80px); background: var(--bg-elevated); border: 1px solid var(--border-strong); color: var(--text-primary); padding: 14px 24px; border-radius: 16px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow-lg); opacity: 0; transition: all .4s var(--ease); z-index: 200; display: flex; align-items: center; gap: 10px; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

.report-date-bar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 26px; background: var(--bg-surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 13.5px; color: var(--text-secondary);
  font-family: var(--font-body);
  border-radius: 14px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}
.report-date-bar .label { font-weight: 700; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.5px; font-size: 11px; }
.report-date-bar .value { font-weight: 700; color: var(--accent); font-family: var(--font-mono); font-size: 14px; }
.report-date-bar .status { margin-left: auto; font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.report-date-bar .status .dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.report-date-bar .status .dot.saved { background: var(--status-saved); }
.report-date-bar .status .dot.unsaved { background: var(--status-unsaved); }

.save-btn-fixed {
  position: fixed; bottom: 86px; right: 28px;
  z-index: 150; padding: 15px 26px;
  border-radius: 50px; font-size: 14.5px; font-weight: 700;
  background: var(--grad-accent); color: var(--text-on-accent);
  border: none; cursor: pointer;
  box-shadow: 0 10px 34px rgba(0,113,227,0.32);
  transition: transform .3s var(--ease), box-shadow .3s var(--ease);
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-body);
}
.save-btn-fixed:hover { transform: translateY(-3px); box-shadow: 0 14px 44px rgba(0,113,227,0.42); }
.save-btn-fixed:active { transform: translateY(0); }
.toast::before { content:''; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.toast.error::before { background: var(--danger); }
.toast.info::before { background: var(--accent-2); }

@media (max-width: 1080px) {
  .grid-2, .grid-3, .grid-2-eq { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: repeat(2, 1fr); }
  .kpi.hero { grid-column: span 1; }
}

/* ============================================================
   RESPONSIVE DESIGN OPTIMIZATIONS
   ============================================================ */

/* Large Desktop (1920px+) */
@media (min-width: 1920px) {
  html { font-size: 16px; }
  .shell { max-width: 1800px; padding: 0 48px 100px; }
  .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 22px; }
  .kpi .val { font-size: 32px; }
  .kpi.hero .val { font-size: 44px; }
  .card { padding: 28px 32px; }
  .grid-2 { gap: 24px; }
  .grid-3 { gap: 24px; }
  .grid-2-eq { gap: 24px; }
  .section-head h2 { font-size: 20px; }
}

/* Desktop (1366px - 1919px) */
@media (min-width: 1366px) and (max-width: 1919px) {
  html { font-size: 15px; }
  .shell { max-width: 1400px; padding: 0 32px 80px; }
  .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
  .kpi .val { font-size: 26px; }
  .kpi.hero .val { font-size: 34px; }
}

/* Small Desktop / Laptop (1024px - 1365px) */
@media (min-width: 1024px) and (max-width: 1365px) {
  html { font-size: 14.5px; }
  .shell { max-width: 1200px; padding: 0 24px 60px; }
  .topbar { padding: 22px 0 18px; gap: 16px; }
  .brand-text h1 { font-size: 20px; }
  .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
  .kpi { padding: 18px 20px 16px; }
  .kpi .val { font-size: 24px; }
  .kpi.hero .val { font-size: 30px; }
  .grid-2 { grid-template-columns: 1.4fr 1fr; gap: 18px; }
  .grid-3 { grid-template-columns: repeat(3, 1fr); gap: 18px; }
  .grid-2-eq { grid-template-columns: 1fr 1fr; gap: 18px; }
  .card { padding: 20px 22px; }
  .form-row { gap: 14px; }
  .tabs { margin: 8px 0 24px; }
  .tab-btn { padding: 9px 18px; font-size: 13px; }
  .section-head { margin: 36px 2px 18px; }
  .section-head h2 { font-size: 17px; }
  canvas { max-height: 240px; }
}

/* Tablet (768px - 1023px) - iPad Pro 10.5", iPad Air */
@media (min-width: 768px) and (max-width: 1023px) {
  html { font-size: 14px; }
  .shell { max-width: 100%; padding: 0 20px 60px; }
  .topbar { padding: 20px 0 16px; gap: 14px; flex-wrap: wrap; }
  .brand { gap: 12px; }
  .brand-mark { width: 42px; height: 42px; border-radius: 13px; }
  .brand-mark svg { width: 22px; height: 22px; }
  .brand-text h1 { font-size: 18px; }
  .brand-text p { font-size: 10px; letter-spacing: 1.2px; }
  .topbar-right { gap: 10px; }
  .realtime-clock { padding: 8px 14px; font-size: 12px; }
  .live-pill { padding: 8px 14px; font-size: 12px; }
  .icon-btn { width: 38px; height: 38px; font-size: 16px; }
  
  .tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 22px; padding: 5px; }
  .tab-btn { padding: 9px 16px; font-size: 13px; flex: 1; min-width: 120px; justify-content: center; }
  
  .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
  .kpi { padding: 16px 18px 14px; }
  .kpi .val { font-size: 22px; }
  .kpi.hero { grid-column: span 2; }
  .kpi.hero .val { font-size: 28px; }
  .kpi .lbl { font-size: 11px; max-width: 120px; }
  .kpi .glyph { width: 30px; height: 30px; font-size: 13px; }
  
  .grid-2, .grid-3, .grid-2-eq { grid-template-columns: 1fr; gap: 16px; }
  .card { padding: 18px 20px; border-radius: var(--r-sm); }
  .card-head { margin-bottom: 16px; }
  .card-head .t { font-size: 14px; }
  .card-head .t .ico { width: 28px; height: 28px; font-size: 13px; }
  
  .section-head { margin: 32px 2px 16px; }
  .section-head h2 { font-size: 16px; }
  .section-head .hint { font-size: 11px; padding: 5px 12px; }
  
  .form-row { grid-template-columns: repeat(2, 1fr); gap: 14px; }
  .fg input, .fg textarea, .fg select { padding: 10px 12px; font-size: 13px; }
  .device-table input { min-width: 80px; padding: 7px 9px; font-size: 12px; }
  .device-table th, table th { padding: 11px 12px; font-size: 10px; }
  .device-table td, table td { padding: 9px 12px; font-size: 12.5px; }
  
  .chips { gap: 12px; }
  .chip { padding: 16px 18px; min-width: 140px; }
  .chip .v { font-size: 20px; }
  
  .report-date-bar { padding: 10px 16px; font-size: 12.5px; flex-wrap: wrap; }
  .save-btn-fixed { bottom: 70px; right: 20px; padding: 13px 22px; font-size: 13px; }
  
  .modal { padding: 24px; max-width: 420px; }
  .modal-title { font-size: 16px; }
  
  .heat-grid { grid-template-columns: repeat(7, 1fr); }
  canvas { max-height: 220px; }
  
  .gauge-wrap { gap: 14px; }
  .gauge-num { font-size: 26px; }
  
  .legend { gap: 10px; margin-top: 14px; }
  .legend span { font-size: 11px; padding: 5px 10px; }
  
  .statline { padding: 11px 2px; }
  .statline .k { font-size: 12px; }
  .statline .v { font-size: 14px; }
  
  .ref-title { font-size: 20px; margin: 18px 0 26px; }
  .ref-h1 { font-size: 16px; margin: 26px 0 12px; }
  .ref-h2 { font-size: 14px; margin: 18px 0 10px; }
  .ref-p, .ref-note { font-size: 12.5px; }
  .ref-chart-area { height: 280px; padding: 14px; }
  .ref-table { font-size: 11.5px; }
  .ref-table th, .ref-table td { padding: 9px 10px; font-size: 10.5px; }
}

/* Mobile (max-width: 767px) - iPhone 13/14, Android */
@media (max-width: 767px) {
  html { font-size: 13.5px; }
  .shell { max-width: 100%; padding: 0 14px 50px; }
  .bg-grid { background-size: 40px 40px; }
  
  .topbar { padding: 16px 0 14px; gap: 12px; flex-direction: column; align-items: flex-start; }
  .brand { gap: 10px; }
  .brand-mark { width: 38px; height: 38px; border-radius: 12px; }
  .brand-mark svg { width: 20px; height: 20px; }
  .brand-text h1 { font-size: 17px; letter-spacing: -0.3px; }
  .brand-text p { font-size: 9px; letter-spacing: 1px; }
  .topbar-right { width: 100%; gap: 8px; flex-wrap: wrap; }
  .realtime-clock { padding: 7px 12px; font-size: 11px; }
  .live-pill { padding: 7px 12px; font-size: 11px; }
  .live-dot { width: 7px; height: 7px; }
  .icon-btn { width: 36px; height: 36px; font-size: 15px; border-radius: 10px; }
  .month-nav { width: 100%; justify-content: space-between; }
  .month-nav button { width: 32px; height: 32px; font-size: 15px; }
  .glass-select-trigger { min-width: 90px; padding: 6px 10px 6px 12px; font-size: 13px; }
  #viewModeBtn { white-space: nowrap; font-size: 12px; width: auto; min-width: 44px; padding: 0 10px; }
  
  .tabs { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0 18px; padding: 4px; border-radius: 12px; }
  .tab-btn { padding: 8px 12px; font-size: 12px; gap: 6px; flex: 1; min-width: calc(50% - 4px); justify-content: center; border-radius: 9px; }
  
  .report-date-bar { padding: 10px 14px; font-size: 12px; margin-bottom: 18px; border-radius: 10px; gap: 10px; }
  .report-date-bar .label { font-size: 10px; }
  .report-date-bar .value { font-size: 12px; }
  .report-date-bar .status { font-size: 11px; margin-left: 0; }
  
  .section-head { margin: 26px 2px 14px; gap: 10px; }
  .section-head h2 { font-size: 15px; letter-spacing: -0.2px; }
  .section-head .accent-bar { width: 3px; height: 16px; }
  .section-head .hint { font-size: 10px; padding: 4px 10px; margin-left: auto; }
  
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi { padding: 14px 14px 12px; border-radius: var(--r-sm); }
  .kpi .lbl { font-size: 10px; margin-bottom: 10px; max-width: 100px; }
  .kpi .val { font-size: 19px; letter-spacing: -0.5px; }
  .kpi .val .u { font-size: 10px; }
  .kpi.hero { grid-column: span 2; }
  .kpi.hero .val { font-size: 26px; }
  .kpi .glyph { width: 28px; height: 28px; font-size: 12px; top: 12px; right: 12px; }
  .kpi .spark { width: 80px; height: 36px; }
  .kpi .delta { font-size: 10px; padding: 3px 8px; margin-top: 8px; }
  
  .grid-2, .grid-3, .grid-2-eq { grid-template-columns: 1fr; gap: 14px; }
  .card { padding: 16px 16px; border-radius: var(--r-sm); }
  .card:hover { transform: none; }
  .card-head { margin-bottom: 14px; flex-wrap: wrap; gap: 8px; }
  .card-head .t { font-size: 13px; }
  .card-head .t .ico { width: 26px; height: 26px; font-size: 12px; border-radius: 8px; }
  .card-head .sub { font-size: 10.5px; width: 100%; }
  
  .form-row { grid-template-columns: 1fr; gap: 12px; }
  .fg input, .fg textarea, .fg select { padding: 10px 12px; font-size: 13px; border-radius: 10px; }
  .fg label { font-size: 11.5px; }
  .calc-out { gap: 8px; margin-top: 12px; }
  .calc-out span { font-size: 11px; padding: 6px 10px; }
  
  .table-wrap { margin: 0 -4px; border-radius: 10px; }
  .device-table { font-size: 12px; }
  .device-table th, table th { padding: 10px 10px; font-size: 9.5px; letter-spacing: 0.4px; }
  .device-table td, table td { padding: 8px 10px; font-size: 12px; }
  .device-table input { min-width: 70px; padding: 6px 8px; font-size: 12px; border-radius: 8px; }
  .dev-name { font-size: 12px !important; }
  
  .btn { padding: 9px 14px; font-size: 13px; border-radius: 10px; gap: 6px; }
  .btn-primary, .btn-success { padding: 10px 16px; }
  
  .chips { gap: 10px; }
  .chip { padding: 14px 16px; min-width: calc(50% - 5px); flex: 1; border-radius: 12px; }
  .chip .k { font-size: 10px; }
  .chip .v { font-size: 18px; margin-top: 5px; }
  
  .heat-grid { grid-template-columns: repeat(7, 1fr); gap: 2px; }
  .heatcell { border-radius: 2px; }
  
  canvas { max-height: 200px; }
  
  .gauge-wrap { flex-direction: column; gap: 12px; }
  .gauge-num { font-size: 24px; }
  
  .legend { gap: 8px; margin-top: 12px; }
  .legend span { font-size: 10.5px; padding: 4px 9px; gap: 5px; }
  .legend i { width: 8px; height: 8px; }
  
  .statline { padding: 10px 2px; }
  .statline .k { font-size: 11.5px; gap: 8px; }
  .statline .v { font-size: 13px; }
  .statline .v small { font-size: 10px; }
  
  .time-row { gap: 8px; margin-bottom: 8px; }
  .time-row .label { font-size: 12px; min-width: 56px; }
  .time-row select { padding: 7px 9px; font-size: 12px; }
  
  .report-out { padding: 14px; font-size: 12.5px; }
  
  .modal { padding: 20px; max-width: 340px; width: 94%; border-radius: var(--r-md); }
  .modal::before { height: 2.5px; }
  .modal-title { font-size: 15px; margin-bottom: 12px; }
  .modal-actions { gap: 10px; margin-top: 20px; }
  .modal-actions .btn { padding: 8px 14px; font-size: 12.5px; }
  
  .toast { bottom: 20px; padding: 12px 18px; font-size: 13px; border-radius: 12px; max-width: 90vw; }
  .save-btn-fixed { bottom: 60px; right: 14px; padding: 12px 20px; font-size: 13px; border-radius: 40px; }
  
  .ref-title { font-size: 17px; margin: 14px 0 20px; }
  .ref-title span { font-size: 12px; }
  .ref-h1 { font-size: 14px; margin: 20px 0 10px; padding-bottom: 8px; }
  .ref-h2 { font-size: 13px; margin: 14px 0 8px; }
  .ref-h3 { font-size: 12.5px; margin: 12px 0 8px; }
  .ref-p, .ref-note { font-size: 12px; margin-bottom: 12px; }
  .ref-p i, .ref-note i { font-size: 11px; }
  .ref-chart-title { font-size: 11.5px; margin: 12px 0 8px; }
  .ref-chart-area { height: 220px; padding: 12px; border-radius: 10px; margin-bottom: 12px; }
  .ref-table-wrap { margin: 0 -4px 12px; border-radius: 10px; }
  .ref-table { font-size: 10.5px; }
  .ref-table th, .ref-table td { padding: 7px 8px; font-size: 9.5px; }
  
  #qiz-audit-modal { padding: 16px; }
  .qiz-audit-box { padding: 22px 20px; width: 100%; max-width: 320px; }
  .qiz-audit-box h3 { font-size: 16px; }
  .qiz-audit-box p { font-size: 13px; }
  #qiz-audit-input { padding: 10px 12px; font-size: 14px; }
  #qiz-audit-submit { padding: 9px 20px; font-size: 14px; }
  
  input[type="date"], input[type="number"], input[type="text"], input[type="password"], select, textarea {
    font-size: 16px !important; /* Prevents zoom on iOS */
  }
}

/* Small Mobile (max-width: 380px) - iPhone SE, small Android */
@media (max-width: 380px) {
  html { font-size: 13px; }
  .shell { padding: 0 10px 40px; }
  .topbar { padding: 14px 0 12px; }
  .brand-text h1 { font-size: 16px; }
  .brand-mark { width: 34px; height: 34px; border-radius: 10px; }
  .brand-mark svg { width: 18px; height: 18px; }
  
  .tab-btn { padding: 7px 10px; font-size: 11px; min-width: calc(50% - 4px); }
  
  .kpi-grid { grid-template-columns: 1fr; gap: 8px; }
  .kpi.hero { grid-column: span 1; }
  .kpi .val { font-size: 18px; }
  .kpi.hero .val { font-size: 24px; }
  
  .card { padding: 14px; }
  .card-head .t { font-size: 12px; }
  .card-head .sub { font-size: 10px; }
  
  .section-head h2 { font-size: 14px; }
  .section-head .hint { font-size: 9.5px; padding: 3px 8px; }
  
  .btn { padding: 8px 12px; font-size: 12px; }
  .device-table th, table th { padding: 8px 8px; font-size: 9px; }
  .device-table td, table td { padding: 7px 8px; font-size: 11px; }
  .device-table input { min-width: 60px; padding: 5px 6px; font-size: 11px; }
  
  .chip { padding: 12px 14px; min-width: 100%; }
  .chip .v { font-size: 16px; }
  
  .modal { padding: 16px; }
  .modal-title { font-size: 14px; }
  .modal-actions .btn { padding: 7px 12px; font-size: 11.5px; }
  
  .save-btn-fixed { bottom: 50px; right: 10px; padding: 10px 16px; font-size: 12px; }
  
  .heat-grid { grid-template-columns: repeat(5, 1fr); }
  
  .ref-table th, .ref-table td { padding: 6px 6px; font-size: 9px; }
}

/* Landscape Orientation Optimizations */
@media (max-height: 500px) and (orientation: landscape) {
  .topbar { padding: 12px 0 10px; }
  .section-head { margin: 20px 2px 12px; }
  .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
  .kpi { padding: 12px 14px 10px; }
  .kpi .val { font-size: 18px; }
  .kpi.hero .val { font-size: 22px; }
  .card { padding: 14px 16px; }
  .grid-2, .grid-3, .grid-2-eq { gap: 12px; }
  canvas { max-height: 180px; }
  .save-btn-fixed { bottom: 20px; right: 16px; padding: 10px 18px; }
  .ref-chart-area { height: 200px; }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
  .btn, .tab-btn, .icon-btn, .month-nav button, .glass-select-trigger, .time-btn-add {
    min-height: 44px;
    min-width: 44px;
  }
  .tab-btn { min-height: 40px; }
  .device-table input { min-height: 36px; }
  .fg input, .fg textarea, .fg select { min-height: 40px; }
  .card:hover { transform: none; }
  .kpi:hover { transform: none; }
  .kpi:hover .glyph { transform: none; }
  .icon-btn:hover { transform: none; }
  .btn:hover { transform: none; }
  .glass-select-trigger:hover { transform: none; }
  .chip:hover { transform: none; }
  .save-btn-fixed { min-height: 48px; }
}

/* High DPI / Retina Display Optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .bg-noise { opacity: 0.02; }
  .brand-mark { box-shadow: 0 6px 20px var(--accent-glow); }
}

/* Dark Mode Responsive Adjustments */
@media (max-width: 767px) {
  [data-theme="dark"] .glass-select-trigger,
  [data-theme="dark"] .glass-dropdown {
    backdrop-filter: blur(20px) saturate(1.8);
    -webkit-backdrop-filter: blur(20px) saturate(1.8);
  }
}

/* Print Optimizations */
@media print {
  .shell { max-width: 100%; padding: 0; }
  .card { break-inside: avoid; box-shadow: none; border: 1px solid #ddd; }
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
  .grid-2, .grid-3, .grid-2-eq { grid-template-columns: 1fr; }
  canvas { max-height: 300px; }
  .save-btn-fixed, .toast, .modal-overlay { display: none !important; }
}

/* Safe Area Insets for Notched Devices */
@supports (padding: max(0px)) {
  .shell {
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  .save-btn-fixed {
    right: max(14px, env(safe-area-inset-right));
    bottom: max(60px, env(safe-area-inset-bottom));
  }
  .toast {
    bottom: max(20px, env(safe-area-inset-bottom));
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   END RESPONSIVE DESIGN OPTIMIZATIONS
   ============================================================ */

.monthly-ref { line-height: 1.8; }
.ref-title { font-family: var(--font-display); font-size: 24px; font-weight: 700; text-align: center; margin: 22px 0 32px; letter-spacing: -.4px; }
.ref-title span { font-size: 14px; color: var(--text-secondary); font-weight: 500; }
.ref-h1 { font-family: var(--font-display); font-size: 18px; font-weight: 700; margin: 32px 0 14px; padding-bottom: 10px; border-bottom: 2px solid var(--border-strong); letter-spacing: -.2px; }
.ref-h2 { font-size: 15px; font-weight: 700; margin: 22px 0 12px; color: var(--accent); }
.ref-h3 { font-size: 14px; font-weight: 700; margin: 16px 0 10px; color: var(--text-secondary); }
.ref-p { font-size: 13.5px; color: var(--text-primary); margin-bottom: 14px; }
.ref-p i, .ref-note i { color: var(--text-secondary); font-size: 12.5px; }
.ref-chart-title { font-size: 13px; font-weight: 700; text-align: center; margin: 16px 0 10px; color: var(--text-secondary); }
.ref-chart-area { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 16px; margin-bottom: 16px; height: 340px; }
.ref-table-wrap { overflow-x: auto; border-radius: var(--r-sm); border: 1px solid var(--border); margin-bottom: 16px; }
.ref-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ref-table th { background: var(--bg-elevated); padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 11px; font-weight: 700; color: var(--text-secondary); white-space: nowrap; text-align: center; }
.ref-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); text-align: center; color: var(--text-primary); }
.ref-table tbody tr:last-child td { border-bottom: none; }
.ref-note { font-size: 12.5px; color: var(--text-secondary); background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 16px; margin-bottom: 16px; }
@media print {
  .tabs, .topbar, .btn { display: none !important; }
  .tab-panel { display: block !important; }
  .card { break-inside: avoid; }
}

#qiz-audit-modal{position:fixed;inset:0;z-index:999999;background:rgba(0,0,0,0.55);display:flex;align-items:center;justify-content:center;backdrop-filter:blur(4px);}
.qiz-audit-box{background:var(--bg-surface);padding:28px 32px;border-radius:20px;box-shadow:var(--shadow-lg);width:min(92vw,360px);text-align:center;}
.qiz-audit-box h3{margin:0 0 8px;font-size:18px;color:var(--text-primary);}
.qiz-audit-box p{margin:0 0 18px;font-size:14px;color:var(--text-secondary);}
#qiz-audit-input{width:100%;padding:12px 14px;font-size:15px;border:1px solid var(--border-strong);border-radius:12px;background:var(--bg-input);color:var(--text-primary);box-sizing:border-box;outline:none;}
#qiz-audit-input:focus{border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-glow);}
.qiz-audit-btns{margin-top:16px;}
#qiz-audit-submit{padding:10px 24px;border:none;border-radius:10px;background:var(--grad-accent);color:#fff;font-size:15px;cursor:pointer;}
#qiz-audit-submit:hover{opacity:0.92;}
#qiz-audit-msg{margin-top:10px;font-size:13px;min-height:20px;}


.qiz-monthly-editor { margin:0 0 22px;padding:20px;border:1px solid var(--border-strong);border-radius:14px;background:var(--bg-surface); }
.qiz-editor-heading { display:flex;gap:16px;align-items:center;flex-wrap:wrap;margin-bottom:10px; }
#qizMonthlyPeriod { color:var(--accent);font-weight:700; }
#qizMonthlySaveStatus,.qiz-editor-hint { color:var(--text-secondary);font-size:12px; }
.qiz-editor-hint { margin-bottom:14px;line-height:1.7; }
.qiz-editor-grid { display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:18px;margin:12px 0; }
.qiz-monthly-editor textarea { width:100%;box-sizing:border-box;resize:vertical;min-height:110px;padding:12px;font:13px/1.75 var(--font-body);border:1px solid var(--border-strong);border-radius:9px;background:var(--bg-input);color:var(--text-primary); }
.qiz-monthly-editor details { margin:14px 0; }
.qiz-english-heading { display:flex;align-items:center;justify-content:space-between;gap:10px;margin-top:14px; }
.qiz-english-heading .btn { font-size:11px;padding:5px 10px; }
.qiz-english-status { color:var(--text-secondary);font-size:11px;margin-top:4px; }
.qiz-monthly-editor summary { cursor:pointer;font-size:13px;font-weight:600;padding:7px 0; }
.qiz-manual-table .ref-table td[contenteditable] { min-width:65px;outline-color:var(--accent); }
@media(max-width:800px){.qiz-editor-grid{grid-template-columns:1fr;}}
@media print{.qiz-monthly-editor{display:none!important;}}
