:root {
  --bg: #0b1120;
  --panel: #101a2e;
  --panel2: #14223a;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary2: #1d4ed8;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --surface: #f6f8fb;
  --shadow: 0 18px 45px rgba(15, 23, 42, .10);
  --radius: 18px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, Segoe UI, Arial, sans-serif;
  background: var(--surface);
  color: var(--text);
}
button, input, select, textarea { font: inherit; }
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 280px;
  background: radial-gradient(circle at top left, #1e3a8a 0, #0f172a 46%, #060914 100%);
  color: #fff;
  padding: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.brand { display: flex; gap: 14px; align-items: center; }
.brand-mark {
  width: 54px;
  height: 54px;
  min-width: 54px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: #ffffff;
  color: #08111f;
  font-weight: 900;
  letter-spacing: -.04em;
  box-shadow: 0 12px 30px rgba(37, 99, 235, .35);
  overflow: hidden;
  padding: 6px;
}
.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.brand h1 { margin: 0; font-size: 21px; letter-spacing: -.04em; }
.brand p { margin: 3px 0 0; color: #b6c2d5; font-size: 13px; }
.nav { display: grid; gap: 8px; }
.nav-btn {
  color: #dbeafe; background: transparent; border: 1px solid rgba(255,255,255,.08);
  border-radius: 14px; padding: 12px 14px; text-align: left; cursor: pointer;
  transition: .2s ease;
}
.nav-btn:hover { background: rgba(255,255,255,.07); }
.nav-btn.active { background: #fff; color: #0f172a; font-weight: 700; }
.sidebar-footer { margin-top: auto; color: #b6c2d5; display: grid; gap: 10px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 99px; padding: 7px 11px; font-size: 12px;
  background: rgba(255,255,255,.10); color: #e2e8f0; width: fit-content;
}
.pill.ok { background: rgba(22,163,74,.18); color: #bbf7d0; }
.pill.warn { background: rgba(217,119,6,.18); color: #fed7aa; }
.main { flex: 1; min-width: 0; padding: 26px; }
.topbar { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 22px; }
.topbar h2 { margin: 0; font-size: 30px; letter-spacing: -.05em; }
.topbar p { margin: 6px 0 0; color: var(--muted); }
.top-actions, .filter-actions, .form-actions, .button-stack { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.view { display: none; }
.view.active { display: block; }
.card, .filter-card, .report-preview {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px;
}
.filter-card { display: grid; grid-template-columns: repeat(4, minmax(130px, 1fr)) auto; gap: 12px; align-items: end; }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.kpi-grid { display: grid; grid-template-columns: repeat(5, minmax(140px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 16px;
  box-shadow: 0 10px 24px rgba(15,23,42,.06); position: relative; overflow: hidden;
}
.kpi:before { content: ''; position: absolute; inset: 0 0 auto 0; height: 4px; background: linear-gradient(90deg, #2563eb, #facc15); }
.kpi small { display: block; color: var(--muted); font-weight: 650; }
.kpi strong { display: block; font-size: 25px; margin-top: 8px; letter-spacing: -.04em; }
.kpi span { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }

.movement-kpi-grid { grid-template-columns: repeat(3, minmax(210px, 1fr)); }
.movement-kpi strong { font-size: 24px; }
.kpi-lines { display: grid; gap: 4px; margin-top: 8px; color: var(--muted); font-size: 12px; }
.kpi-lines span { display: block; margin: 0; color: var(--muted); }
.kpi-lines b { color: #0f172a; font-weight: 800; }
@media (max-width: 1000px) { .movement-kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 720px) { .movement-kpi-grid { grid-template-columns: 1fr; } }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.card-head h3 { margin: 0; font-size: 18px; letter-spacing: -.03em; }
.card-head span { color: var(--muted); font-size: 13px; }
.field { display: grid; gap: 6px; }
.field.wide { grid-column: span 2; }
.field label { font-size: 12px; font-weight: 750; color: #475569; }
input, select, textarea {
  width: 100%; border: 1px solid #d7dde8; border-radius: 12px; padding: 11px 12px;
  background: #fff; color: var(--text); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37, 99, 235, .10); }
input[readonly] { background: #f8fafc; }
.btn, .file-btn {
  border: 0; border-radius: 12px; padding: 11px 14px; cursor: pointer; font-weight: 750;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary2); }
.btn.secondary, .file-btn { background: #e8eef9; color: #0f172a; }
.btn.ghost { background: #f1f5f9; color: #0f172a; }
.btn.danger { background: #fee2e2; color: #991b1b; }
.file-btn input { display: none; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(120px, 1fr)); gap: 12px; align-items: end; }
.form-grid.compact { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
.form-actions { grid-column: 1 / -1; }
.chart { height: 300px; min-height: 260px; overflow: hidden; }
.chart svg { width: 100%; height: 100%; display: block; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 11px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { background: #f8fafc; color: #475569; font-size: 12px; position: sticky; top: 0; z-index: 1; }
tr:hover td { background: #fbfdff; }
.table-actions { display: flex; gap: 6px; }
.mini-btn { border: 1px solid #d7dde8; background: #fff; border-radius: 9px; padding: 6px 8px; cursor: pointer; font-weight: 700; }
.mini-btn.danger { color: #b91c1c; background: #fff5f5; }
.badge { display: inline-flex; border-radius: 999px; padding: 5px 8px; font-size: 12px; font-weight: 800; }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.danger { background: #fee2e2; color: #991b1b; }
.badge.info { background: #dbeafe; color: #1e40af; }
.info-panel { display: grid; gap: 10px; }
.info-row { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.info-row:last-child { border-bottom: 0; }
.info-row b { font-size: 18px; }
.report-text { height: 280px; resize: vertical; font-family: Consolas, monospace; line-height: 1.5; }
.report-preview {
  min-height: 520px; margin-bottom: 18px;
  background: linear-gradient(145deg, #0f172a, #111827 60%, #1e3a8a);
  color: #fff; position: relative; overflow: hidden;
}
.report-preview:before { content:''; position:absolute; width:240px; height:240px; border-radius:999px; background:rgba(250,204,21,.18); right:-80px; top:-80px; filter: blur(2px); }
.report-card { position: relative; z-index: 1; display: grid; gap: 14px; }
.report-card h2 { margin: 0; letter-spacing: -.05em; }
.report-card .report-date { color: #bfdbfe; }
.report-metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.report-metric { background: rgba(255,255,255,.10); border: 1px solid rgba(255,255,255,.12); border-radius: 16px; padding: 13px; }
.report-metric small { color: #cbd5e1; display: block; }
.report-metric strong { font-size: 22px; display: block; margin-top: 4px; }
.report-list { background: rgba(255,255,255,.08); border-radius: 16px; padding: 12px 14px; }
.report-list h4 { margin: 0 0 8px; }
.report-list ol { margin: 0; padding-left: 20px; }
.notes { color: #475569; line-height: 1.6; }
code { background: #eef2ff; border-radius: 6px; padding: 2px 5px; }
.toast {
  position: fixed; right: 22px; bottom: 22px; background: #0f172a; color: #fff;
  border-radius: 14px; padding: 12px 14px; box-shadow: 0 18px 40px rgba(15,23,42,.25);
  transform: translateY(20px); opacity: 0; pointer-events: none; transition: .2s;
}
.toast.show { transform: translateY(0); opacity: 1; }
@media (max-width: 1100px) {
  .app-shell { flex-direction: column; }
  .sidebar { position: static; height: auto; width: 100%; }
  .nav { grid-template-columns: repeat(4, 1fr); }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid.two { grid-template-columns: 1fr; }
  .filter-card, .form-grid { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
}
@media (max-width: 720px) {
  .main { padding: 16px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .nav { grid-template-columns: repeat(2, 1fr); }
  .filter-card, .form-grid, .form-grid.compact, .kpi-grid { grid-template-columns: 1fr; }
  .field.wide { grid-column: span 1; }
  .chart { height: 250px; }
}

/* Dashboard redesign: spreadsheet-inspired, web-native */
body.dashboard-mode .topbar { display: none; }
.dashboard-view { max-width: 1480px; margin: 0 auto; }
.dashboard-hero {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  background: linear-gradient(90deg, #ffffff 0%, #f8fbff 55%, #eff6ff 100%);
  border: 1px solid #dbe7f7; border-radius: 20px; padding: 18px 22px; margin-bottom: 16px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, .06);
}
.hero-title { display: flex; align-items: center; gap: 14px; }
.hero-icon {
  width: 74px; height: 74px; border-radius: 18px; display: grid; place-items: center;
  background: linear-gradient(145deg, #1d4ed8, #0b56c5); color: #fff; font-size: 36px;
  box-shadow: 0 16px 30px rgba(37, 99, 235, .28);
}
.hero-title h1 { margin: 0; color: #0a2d64; font-size: 30px; line-height: 1; letter-spacing: -.04em; }
.hero-title p { margin: 6px 0 0; color: #334155; font-size: 15px; }
.date-card {
  min-width: 240px; display: flex; align-items: center; gap: 14px;
  border: 1px solid #d9e5f4; border-radius: 16px; background: #fff; padding: 12px 14px;
}
.date-card > span { font-size: 24px; color: #1559c9; }
.compact-field label { color: #64748b; font-size: 12px; }
.compact-field input { border: 0; padding: 0; color: #0b56c5; font-weight: 800; background: transparent; }
.hidden-control { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; border: 0 !important; overflow: hidden !important; clip: rect(0 0 0 0) !important; white-space: nowrap !important; }
.dashboard-kpis { grid-template-columns: repeat(3, minmax(220px, 1fr)); gap: 18px; }
.kpi-icon {
  display: flex; align-items: center; gap: 16px; min-height: 104px; padding: 22px;
  border-color: #dfe8f5; border-radius: 18px; box-shadow: 0 12px 30px rgba(15, 23, 42, .07);
}
.kpi-icon:before { display: none; }
.kpi-symbol {
  width: 66px; height: 66px; border-radius: 14px; display: grid; place-items: center;
  background: #eaf3ff; color: #0b56c5; font-size: 32px; flex: 0 0 auto;
}
.kpi-icon small { font-size: 14px; color: #475569; font-weight: 700; }
.kpi-icon strong { font-size: 32px; color: #0a3b85; margin-top: 8px; }
.table-card { padding: 18px 18px 14px; }
.left-head { justify-content: flex-start; align-items: center; }
.left-head h3 { color: #0a3b85; font-size: 20px; }
.left-head span { margin-left: auto; }
.dashboard-table-wrap { max-height: none; overflow: visible; border-color: #b8c9df; }
.dashboard-table-wrap table { font-size: 11.7px; }
.dashboard-table-wrap th {
  background: #dfeeff; color: #0a3b85; text-align: center; border-right: 1px solid #b8c9df;
}
.dashboard-table-wrap th, .dashboard-table-wrap td { padding: 7px 8px; }
.dashboard-table-wrap td { border-right: 1px solid #d5e0ee; }
.dashboard-table-wrap td:not(:first-child) { text-align: center; }
.ratio-card { padding: 18px; }
.category-tabs { display: flex; gap: 12px; flex-wrap: wrap; margin: 4px 0 14px; }
.category-tab {
  border: 1px solid #d7e1ef; background: #f8fbff; color: #334155; padding: 10px 18px;
  border-radius: 11px; cursor: pointer; font-weight: 800; min-width: 150px;
  box-shadow: 0 4px 10px rgba(15,23,42,.04);
}
.category-tab.active { background: #0b56c5; border-color: #0b56c5; color: #fff; box-shadow: 0 12px 22px rgba(37,99,235,.22); }
.ratio-chart { min-height: 390px; height: 430px; overflow: visible; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin: 6px 0 8px; color: #334155; font-size: 13px; }
.legend-item { display: inline-flex; align-items: center; gap: 7px; font-weight: 700; }
.legend-item i { width: 18px; height: 4px; display: inline-block; border-radius: 99px; }
.compact-dashboard-extra { margin-top: 18px; }
.anomaly-full-card { width: 100%; }
.anomaly-full-card .table-wrap { overflow: visible; }
.equipment-filter { margin-bottom: 14px; }

@media (max-width: 1100px) {
  .dashboard-hero { flex-direction: column; align-items: flex-start; }
  .date-card { width: 100%; }
  .dashboard-kpis { grid-template-columns: repeat(2, minmax(160px, 1fr)); }
}
@media (max-width: 720px) {
  .hero-icon { width: 60px; height: 60px; font-size: 28px; }
  .hero-title h1 { font-size: 23px; }
  .dashboard-kpis { grid-template-columns: 1fr; }
  .kpi-icon strong { font-size: 26px; }
  .category-tab { flex: 1 1 100%; }
  .ratio-chart { height: 360px; }
}

.correction-help { color:#92400e; font-size:12px; }


/* Supabase and PDF report controls */
.supabase-config-grid { grid-template-columns: repeat(4, minmax(120px, 1fr)); }
.compact-note { margin-top: 10px; font-size: 13px; }
@media (max-width: 900px) { .supabase-config-grid { grid-template-columns: 1fr; } }
input:disabled, select:disabled, textarea:disabled { background: #f1f5f9; color: #64748b; cursor: not-allowed; }


.report-preview{overflow:auto;display:grid;align-content:start}.report-preview>.wa-report-image{transform:scale(.6);transform-origin:top left;margin-bottom:-35%;}
@media (max-width: 1600px){.report-preview>.wa-report-image{transform:scale(.48);margin-bottom:-52%;}}
@media (max-width: 1200px){.report-preview>.wa-report-image{transform:scale(.4);margin-bottom:-60%;}}

.wa-report-image{width:1400px;box-sizing:border-box;background:#eef4fb;padding:24px;border-radius:22px;color:#0f172a;font-family:Segoe UI,Arial,sans-serif}.wa-report-head{display:flex;justify-content:space-between;align-items:flex-start;gap:18px;margin-bottom:18px}.wa-report-title{font-size:36px;font-weight:800;color:#0f2f6b;letter-spacing:-.03em}.wa-report-sub{font-size:18px;color:#4b5563;margin-top:4px}.wa-report-date{background:#fff;border:1px solid #d7e3f4;border-radius:18px;padding:14px 18px;min-width:200px;text-align:right;box-shadow:0 6px 16px rgba(15,23,42,.08)}.wa-report-date span{display:block;font-size:14px;color:#64748b;margin-bottom:4px}.wa-report-date strong{font-size:24px;color:#0f2f6b}.wa-kpi-row{display:grid;grid-template-columns:repeat(3,1fr);gap:16px;margin-bottom:18px}.wa-kpi-card{background:#fff;border:1px solid #d7e3f4;border-radius:20px;padding:18px 18px 16px;box-shadow:0 8px 18px rgba(15,23,42,.08)}.wa-kpi-label{font-size:16px;color:#334155;font-weight:700;margin-bottom:10px}.wa-kpi-value{font-size:42px;line-height:1;font-weight:900;color:#0f2f6b}.wa-kpi-unit{font-size:15px;color:#64748b;margin-top:8px}.wa-table-grid{display:grid;grid-template-columns:1fr 1fr;gap:18px;margin-bottom:18px}.wa-table-card,.wa-chart-card{background:#fff;border:1px solid #d7e3f4;border-radius:20px;padding:14px 14px 16px;box-shadow:0 8px 18px rgba(15,23,42,.08);overflow:hidden}.wa-section-title{font-size:20px;font-weight:800;color:#0f2f6b;margin-bottom:10px}.wa-table-card table{width:100%;border-collapse:collapse;font-size:11px;background:#fff}.wa-table-card th,.wa-table-card td{border:1px solid #dbe7f5;padding:4px 5px;text-align:left;vertical-align:top}.wa-table-card th{background:#eaf2ff;color:#1d4ed8;font-size:11px;font-weight:800}.wa-table-card td{color:#0f172a;line-height:1.25}.wa-charts-stack{display:grid;gap:16px}.wa-chart-box{width:100%;overflow:hidden}.wa-chart-card .chart-legend{margin-bottom:8px}.wa-chart-card .legend-item{font-size:11px}.wa-report-foot{margin-top:14px;font-size:13px;color:#475569}


/* v21 WA report preview overrides */
.report-preview{overflow:auto;display:grid;align-content:start;padding:14px;background:#f5f8fe}
.report-preview>.wa-report-image{transform:scale(.54);transform-origin:top left;margin-bottom:-44%;}
@media (max-width: 1700px){.report-preview>.wa-report-image{transform:scale(.48);margin-bottom:-52%;}}
@media (max-width: 1300px){.report-preview>.wa-report-image{transform:scale(.38);margin-bottom:-65%;}}
.wa-report-image{width:1600px;box-sizing:border-box;background:linear-gradient(180deg,#f7fbff 0%,#eef5ff 100%);padding:18px;border-radius:24px;color:#0f172a;font-family:Segoe UI,Arial,sans-serif;border:2px solid #dbe8fb}.wa-hero{display:grid;grid-template-columns:140px 1fr auto;gap:18px;align-items:center;background:linear-gradient(180deg,#ffffff 0%,#f1f6ff 100%);border:1px solid #d8e6fb;border-radius:20px;padding:18px 20px;margin-bottom:16px;position:relative;overflow:hidden}.wa-hero:after{content:'';position:absolute;right:-30px;bottom:-50px;width:520px;height:180px;background:radial-gradient(circle at center,rgba(59,130,246,.12),rgba(59,130,246,0) 70%)}.wa-logo-panel{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px}.wa-logo-img{width:100px;height:100px;object-fit:contain}.wa-logo-text{font-size:28px;font-weight:900;letter-spacing:.12em;color:#111827}.wa-title-panel{min-width:0}.wa-report-title{font-size:38px;font-weight:900;color:#123a8f;line-height:1.05;letter-spacing:-.02em}.wa-report-sub{font-size:20px;color:#35548c;margin-top:6px;font-weight:700}.wa-date-badge{display:flex;align-items:center;gap:10px;background:linear-gradient(135deg,#1756d8,#2257c7);color:#fff;border-radius:18px;padding:14px 18px;box-shadow:0 12px 22px rgba(37,99,235,.25)}.wa-date-badge span{font-size:24px}.wa-date-badge strong{font-size:20px;font-weight:800;white-space:nowrap}.wa-kpi-row{display:grid;grid-template-columns:repeat(3,1fr);gap:16px;margin-bottom:16px}.wa-kpi-card{display:grid;grid-template-columns:74px 1fr;gap:14px;align-items:center;background:#fff;border:1px solid #d6e3f8;border-radius:20px;padding:18px;box-shadow:0 8px 20px rgba(15,23,42,.08)}.wa-kpi-icon{width:74px;height:74px;border-radius:999px;display:grid;place-items:center;background:linear-gradient(135deg,#1d4ed8,#1e40af);color:#fff;font-size:38px;box-shadow:0 10px 18px rgba(37,99,235,.28)}.wa-kpi-label{font-size:18px;color:#22407a;font-weight:800;margin-bottom:6px}.wa-kpi-value{font-size:34px;font-weight:900;color:#0f2f6b;line-height:1}.wa-kpi-value span{font-size:.62em;color:#5b6b8a;margin-left:6px}.wa-table-grid{display:grid;grid-template-columns:1fr 1fr;gap:16px;margin-bottom:16px}.wa-table-card,.wa-chart-card{background:#fff;border:1px solid #d6e3f8;border-radius:20px;padding:0 0 12px;box-shadow:0 8px 20px rgba(15,23,42,.08);overflow:hidden}.wa-table-head{display:flex;align-items:center;gap:10px;background:linear-gradient(180deg,#1450c3,#123a8f);color:#fff;padding:10px 14px}.wa-table-head span{font-size:22px}.wa-section-title{font-size:18px;font-weight:900;margin:0;color:inherit}.wa-table-card table{width:100%;border-collapse:collapse;font-size:9.4px;background:#fff}.wa-table-card th,.wa-table-card td{border:1px solid #d8e4f4;padding:4px 5px;text-align:center;vertical-align:middle}.wa-table-card th{background:#ecf4ff;color:#123a8f;font-size:9.4px;font-weight:900}.wa-table-card td:first-child,.wa-table-card th:first-child{text-align:left;padding-left:9px;font-weight:700}.wa-table-card td{color:#0f172a;line-height:1.22}.wa-table-card tbody tr:last-child td{font-weight:900;color:#123a8f;background:#f1f6ff}.wa-charts-grid{display:grid;grid-template-columns:1fr 1fr;gap:16px}.wa-chart-title-row{display:flex;align-items:center;gap:10px;padding:12px 14px 4px}.wa-chart-miniicon{font-size:22px;color:#123a8f}.wa-chart-card .wa-section-title{color:#123a8f}.wa-chart-box{padding:4px 10px 0;overflow:hidden}.wa-chart-card svg{width:100%;height:auto}.wa-chart-card .chart-legend{padding:0 8px 6px}.wa-chart-card .legend-item{font-size:11px}.wa-report-foot{margin-top:14px;border:1px solid #c8daf7;background:linear-gradient(180deg,#f7fbff,#edf4ff);color:#123a8f;padding:12px 16px;border-radius:16px;font-size:14px;font-style:italic;font-weight:700}


/* v31 - Logo watermark on every page + responsive hardening */
.main {
  position: relative;
  isolation: isolate;
  overflow-x: hidden;
}
.main::before {
  content: '';
  position: fixed;
  right: clamp(18px, 4vw, 62px);
  bottom: clamp(18px, 4vw, 62px);
  width: min(42vw, 520px);
  height: min(42vw, 520px);
  background: url('logo.png') center / contain no-repeat;
  opacity: .20;
  pointer-events: none;
  z-index: 0;
  filter: grayscale(5%);
}
.main > * {
  position: relative;
  z-index: 1;
}
.card,
.filter-card,
.report-preview,
.dashboard-hero,
.kpi {
  background-clip: padding-box;
}

/* Keep the sidebar logo perfectly inside its box */
.brand-mark {
  flex: 0 0 54px;
  padding: 7px;
}
.brand-mark img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}
.brand-mark span {
  font-weight: 900;
  color: #0f172a;
  font-size: 16px;
}

/* General responsive hardening */
img, svg, canvas, video {
  max-width: 100%;
}
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-wrap table {
  min-width: 680px;
}
.dashboard-table-wrap {
  overflow-x: auto;
}
.dashboard-table-wrap table {
  min-width: 720px;
}
.form-grid.compact-filter,
.anomaly-filter-grid,
.distribution-filter,
.equipment-filter,
.daily-list-filter,
.refuel-list-filter {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.top-actions .btn,
.form-actions .btn {
  white-space: nowrap;
}

@media (max-width: 1100px) {
  .app-shell {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    padding: 16px;
    gap: 14px;
  }
  .brand {
    align-items: center;
  }
  .nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    scroll-snap-type: x proximity;
  }
  .nav-btn {
    flex: 0 0 auto;
    min-width: 145px;
    text-align: center;
    scroll-snap-align: start;
  }
  .sidebar-footer {
    margin-top: 0;
  }
  .main {
    padding: 18px;
  }
  .main::before {
    width: min(55vw, 420px);
    height: min(55vw, 420px);
    right: 16px;
    bottom: 16px;
    opacity: .16;
  }
  .kpi-grid,
  .dashboard-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid.two,
  .dashboard-tables,
  .wa-table-grid,
  .wa-charts-grid {
    grid-template-columns: 1fr;
  }
  .filter-card,
  .form-grid,
  .supabase-config-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .main {
    padding: 12px;
  }
  .main::before {
    width: 72vw;
    height: 72vw;
    left: 50%;
    right: auto;
    bottom: 18px;
    transform: translateX(-50%);
    opacity: .12;
  }
  .brand h1 {
    font-size: 18px;
  }
  .brand p {
    font-size: 12px;
  }
  .brand-mark {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    flex-basis: 46px;
  }
  .nav-btn {
    min-width: 132px;
    padding: 10px 12px;
    font-size: 13px;
  }
  .topbar,
  .card-head,
  .dashboard-hero,
  .hero-title,
  .wa-report-head,
  .wa-hero {
    align-items: flex-start;
  }
  .topbar {
    gap: 12px;
  }
  .topbar h2 {
    font-size: 24px;
  }
  .top-actions,
  .form-actions,
  .filter-actions {
    width: 100%;
  }
  .top-actions .btn,
  .form-actions .btn,
  .filter-actions .btn {
    flex: 1 1 150px;
  }
  .card,
  .filter-card,
  .report-preview,
  .dashboard-hero {
    padding: 14px;
    border-radius: 16px;
  }
  .card-head {
    flex-direction: column;
    gap: 4px;
  }
  .left-head span {
    margin-left: 0;
  }
  .kpi-grid,
  .dashboard-kpis,
  .filter-card,
  .form-grid,
  .form-grid.compact,
  .supabase-config-grid,
  .report-metrics,
  .wa-kpi-row {
    grid-template-columns: 1fr;
  }
  .field.wide {
    grid-column: auto;
  }
  .kpi-icon {
    min-height: auto;
    padding: 16px;
  }
  .kpi-icon strong {
    font-size: 24px;
  }
  .kpi-symbol {
    width: 54px;
    height: 54px;
    font-size: 27px;
  }
  .hero-title {
    flex-direction: row;
  }
  .hero-title h1 {
    font-size: 21px;
    line-height: 1.15;
  }
  .date-card {
    min-width: 0;
  }
  input, select, textarea {
    min-height: 44px;
  }
  .chart {
    height: 240px;
    min-height: 220px;
  }
  .ratio-chart {
    height: 320px;
    min-height: 300px;
  }
  th, td {
    padding: 8px 9px;
  }
  .report-preview>.wa-report-image {
    transform: scale(.24);
    margin-bottom: -110%;
  }
}

@media (max-width: 420px) {
  .main {
    padding: 10px;
  }
  .sidebar {
    padding: 12px;
  }
  .brand {
    gap: 10px;
  }
  .nav-btn {
    min-width: 118px;
    font-size: 12px;
  }
  .topbar h2 {
    font-size: 22px;
  }
  .table-wrap table {
    min-width: 620px;
  }
  .dashboard-table-wrap table {
    min-width: 700px;
  }
}

/* v32 chart gap note */
.chart-note {
  margin: -2px 0 8px;
  color: #64748b;
  font-size: 12px;
  font-weight: 650;
}
.wa-chart-card .chart-note {
  padding: 0 10px 4px;
  font-size: 10.5px;
}


/* v34: multiline catatan pengawas */
.report-note-input { min-height: 96px; resize: vertical; line-height: 1.45; }
.wa-report-foot { white-space: pre-line; line-height: 1.45; }

/* v36: Dashboard ratio coloring, tanpa pill/rounded border agar tabel tetap rapi */
.ratio-text{
  display:inline;
  font-weight:900;
  padding:0 3px;
  border-radius:0;
  border:0;
  box-shadow:none;
}
.ratio-warn{
  background:#fef08a;
  color:#854d0e;
}
.ratio-danger{
  background:#fecaca;
  color:#991b1b;
}

/* v43 user patch: dashboard table titles + no inner scroll + clearer text */
.dashboard-table-wrap {
  overflow: visible !important;
  max-height: none !important;
  border-color: #9fb5d1;
  border-radius: 16px;
}
.dashboard-table-wrap table {
  width: 100%;
  min-width: 0 !important;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 14.5px;
}
.dashboard-table-wrap th,
.dashboard-table-wrap td {
  white-space: normal !important;
  word-break: normal;
  overflow-wrap: anywhere;
  line-height: 1.32;
  padding: 11px 10px;
  vertical-align: middle;
}
.dashboard-table-wrap th {
  position: static;
  background: #dbeafe;
  color: #082f6f;
  font-size: 13.5px;
  font-weight: 900;
  letter-spacing: .01em;
}
.dashboard-table-wrap td {
  color: #0f172a;
  font-weight: 750;
  border-right: 1px solid #cbd8ea;
}
.dashboard-table-wrap td:first-child,
.dashboard-table-wrap th:first-child {
  text-align: left;
  font-weight: 900;
}
#tblDashDaily th:nth-child(1), #tblDashDaily td:nth-child(1) { width: 18%; }
#tblDashDaily th:nth-child(2), #tblDashDaily td:nth-child(2) { width: 15%; }
#tblDashDaily th:nth-child(3), #tblDashDaily td:nth-child(3) { width: 17%; }
#tblDashDaily th:nth-child(4), #tblDashDaily td:nth-child(4) { width: 16%; }
#tblDashDaily th:nth-child(5), #tblDashDaily td:nth-child(5) { width: 16%; }
#tblDashDaily th:nth-child(6), #tblDashDaily td:nth-child(6) { width: 18%; }
#tblDashMonthly th:nth-child(1), #tblDashMonthly td:nth-child(1) { width: 26%; }
#tblDashMonthly th:nth-child(2), #tblDashMonthly td:nth-child(2) { width: 24%; }
#tblDashMonthly th:nth-child(3), #tblDashMonthly td:nth-child(3) { width: 26%; }
#tblDashMonthly th:nth-child(4), #tblDashMonthly td:nth-child(4) { width: 24%; }
.dashboard-table-wrap small {
  font-size: 12.5px;
  color: #334155;
  font-weight: 750;
}
.dashboard-tables {
  align-items: start;
}
.table-card {
  overflow: visible;
}

@media (max-width: 1280px) {
  .dashboard-tables.grid.two {
    grid-template-columns: 1fr;
  }
  .dashboard-table-wrap table {
    font-size: 15px;
  }
  .dashboard-table-wrap th {
    font-size: 14px;
  }
}

@media (max-width: 760px) {
  .dashboard-table-wrap {
    border: 0;
  }
  .dashboard-table-wrap table,
  .dashboard-table-wrap thead,
  .dashboard-table-wrap tbody,
  .dashboard-table-wrap th,
  .dashboard-table-wrap td,
  .dashboard-table-wrap tr {
    display: block;
    width: 100% !important;
  }
  .dashboard-table-wrap thead {
    display: none;
  }
  .dashboard-table-wrap tr {
    margin: 0 0 12px;
    border: 1px solid #b8c9df;
    border-radius: 16px;
    background: #ffffff;
    box-shadow: 0 8px 18px rgba(15,23,42,.06);
    overflow: hidden;
  }
  .dashboard-table-wrap td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    text-align: right !important;
    border-right: 0;
    border-bottom: 1px solid #e2e8f0;
    padding: 12px 14px;
    font-size: 15px;
  }
  .dashboard-table-wrap td:last-child {
    border-bottom: 0;
  }
  .dashboard-table-wrap td::before {
    content: attr(data-label);
    flex: 0 0 46%;
    color: #0a3b85;
    font-weight: 900;
    text-align: left;
  }
  .dashboard-table-wrap td:first-child {
    background: #eff6ff;
    color: #082f6f;
    font-size: 16px;
  }
}

/* v43 fix-2: stable dashboard tables (no card conversion, clearer text) */
.dashboard-tables.grid.two {
  grid-template-columns: 1fr !important;
  gap: 18px !important;
}
.dashboard-tables .table-card {
  width: 100%;
  overflow: visible !important;
}
.dashboard-table-wrap {
  width: 100%;
  overflow: visible !important;
  max-height: none !important;
  border: 1px solid #aec1dc !important;
  border-radius: 14px !important;
  background: #ffffff;
}
.dashboard-table-wrap table,
.dashboard-table-wrap thead,
.dashboard-table-wrap tbody,
.dashboard-table-wrap tr,
.dashboard-table-wrap th,
.dashboard-table-wrap td {
  display: revert !important;
}
.dashboard-table-wrap table {
  width: 100% !important;
  min-width: 0 !important;
  table-layout: fixed !important;
  border-collapse: collapse !important;
  font-size: 14px !important;
}
.dashboard-table-wrap thead {
  display: table-header-group !important;
}
.dashboard-table-wrap tbody {
  display: table-row-group !important;
}
.dashboard-table-wrap tr {
  display: table-row !important;
  margin: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}
.dashboard-table-wrap th,
.dashboard-table-wrap td {
  display: table-cell !important;
  width: auto !important;
  white-space: normal !important;
  overflow-wrap: break-word !important;
  word-break: normal !important;
  line-height: 1.28 !important;
  padding: 10px 9px !important;
  border-bottom: 1px solid #d8e3f2 !important;
  border-right: 1px solid #d8e3f2 !important;
  vertical-align: middle !important;
}
.dashboard-table-wrap th {
  background: #dbeafe !important;
  color: #082f6f !important;
  font-size: 13px !important;
  font-weight: 900 !important;
  text-align: center !important;
}
.dashboard-table-wrap td {
  color: #0f172a !important;
  font-weight: 750 !important;
  text-align: center !important;
}
.dashboard-table-wrap th:first-child,
.dashboard-table-wrap td:first-child {
  text-align: left !important;
  font-weight: 900 !important;
  background: inherit !important;
  color: #0f172a !important;
}
.dashboard-table-wrap td::before {
  content: none !important;
  display: none !important;
}
#tblDashDaily th:nth-child(1), #tblDashDaily td:nth-child(1) { width: 17% !important; }
#tblDashDaily th:nth-child(2), #tblDashDaily td:nth-child(2) { width: 14% !important; }
#tblDashDaily th:nth-child(3), #tblDashDaily td:nth-child(3) { width: 18% !important; }
#tblDashDaily th:nth-child(4), #tblDashDaily td:nth-child(4) { width: 16% !important; }
#tblDashDaily th:nth-child(5), #tblDashDaily td:nth-child(5) { width: 16% !important; }
#tblDashDaily th:nth-child(6), #tblDashDaily td:nth-child(6) { width: 19% !important; }
#tblDashMonthly th:nth-child(1), #tblDashMonthly td:nth-child(1) { width: 28% !important; }
#tblDashMonthly th:nth-child(2), #tblDashMonthly td:nth-child(2) { width: 24% !important; }
#tblDashMonthly th:nth-child(3), #tblDashMonthly td:nth-child(3) { width: 26% !important; }
#tblDashMonthly th:nth-child(4), #tblDashMonthly td:nth-child(4) { width: 22% !important; }

@media (max-width: 900px) {
  .dashboard-table-wrap table { font-size: 12.5px !important; }
  .dashboard-table-wrap th { font-size: 11.8px !important; }
  .dashboard-table-wrap th,
  .dashboard-table-wrap td { padding: 8px 6px !important; }
}
@media (max-width: 560px) {
  .dashboard-table-wrap table { font-size: 11px !important; }
  .dashboard-table-wrap th { font-size: 10.5px !important; }
  .dashboard-table-wrap th,
  .dashboard-table-wrap td { padding: 7px 4px !important; }
  .table-card { padding-left: 10px !important; padding-right: 10px !important; }
}

/* v43 final dashboard table fix: compact, readable, side-by-side like user reference */
body.dashboard-mode .main {
  padding: 22px 26px !important;
  overflow-x: hidden !important;
}
.dashboard-view {
  max-width: 1500px !important;
  margin: 0 auto !important;
}
.dashboard-tables.grid.two {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
  gap: 20px !important;
  align-items: start !important;
}
.dashboard-tables .table-card {
  width: 100% !important;
  min-width: 0 !important;
  padding: 8px 0 0 !important;
  margin: 0 !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  overflow: visible !important;
}
.dashboard-tables .card-head {
  margin: 0 0 4px !important;
  padding: 0 2px !important;
  min-height: 0 !important;
}
.dashboard-tables .card-head h3 {
  margin: 0 !important;
  color: #111827 !important;
  font-size: 17px !important;
  font-weight: 750 !important;
  letter-spacing: 0 !important;
}
.dashboard-tables .card-head h3::first-letter {
  color: inherit !important;
}
.dashboard-tables .card-head span {
  display: none !important;
}
.dashboard-table-wrap {
  width: 100% !important;
  max-height: none !important;
  overflow: hidden !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
}
.dashboard-table-wrap table,
.dashboard-table-wrap thead,
.dashboard-table-wrap tbody,
.dashboard-table-wrap tr,
.dashboard-table-wrap th,
.dashboard-table-wrap td {
  display: revert !important;
}
.dashboard-table-wrap table {
  width: 100% !important;
  min-width: 0 !important;
  table-layout: fixed !important;
  border-collapse: collapse !important;
  background: #ffffff !important;
  font-family: Arial, 'Segoe UI', sans-serif !important;
  font-size: clamp(12px, 0.78vw, 14px) !important;
  line-height: 1.18 !important;
}
.dashboard-table-wrap thead { display: table-header-group !important; }
.dashboard-table-wrap tbody { display: table-row-group !important; }
.dashboard-table-wrap tr { display: table-row !important; }
.dashboard-table-wrap th,
.dashboard-table-wrap td {
  display: table-cell !important;
  border: 1px solid #cbd8e8 !important;
  padding: 5px 6px !important;
  text-align: center !important;
  vertical-align: middle !important;
  white-space: normal !important;
  overflow-wrap: normal !important;
  word-break: normal !important;
  hyphens: none !important;
  height: 24px !important;
}
.dashboard-table-wrap th {
  position: static !important;
  background: #174464 !important;
  color: #ffffff !important;
  font-size: clamp(11px, 0.7vw, 12.5px) !important;
  font-weight: 900 !important;
  line-height: 1.15 !important;
}
.dashboard-table-wrap td {
  color: #0f172a !important;
  font-weight: 800 !important;
  background: rgba(255,255,255,.92) !important;
}
.dashboard-table-wrap td:first-child,
.dashboard-table-wrap th:first-child {
  text-align: left !important;
  padding-left: 10px !important;
  font-weight: 900 !important;
  white-space: nowrap !important;
}
.dashboard-table-wrap td:not(:first-child),
.dashboard-table-wrap th:not(:first-child) {
  text-align: center !important;
}
.dashboard-table-wrap td::before {
  content: none !important;
  display: none !important;
}
#tblDashDaily th:nth-child(1), #tblDashDaily td:nth-child(1) { width: 25% !important; }
#tblDashDaily th:nth-child(2), #tblDashDaily td:nth-child(2) { width: 16% !important; }
#tblDashDaily th:nth-child(3), #tblDashDaily td:nth-child(3) { width: 18% !important; }
#tblDashDaily th:nth-child(4), #tblDashDaily td:nth-child(4) { width: 15% !important; }
#tblDashDaily th:nth-child(5), #tblDashDaily td:nth-child(5) { width: 13% !important; }
#tblDashDaily th:nth-child(6), #tblDashDaily td:nth-child(6) { width: 13% !important; }
#tblDashMonthly th:nth-child(1), #tblDashMonthly td:nth-child(1) { width: 34% !important; }
#tblDashMonthly th:nth-child(2), #tblDashMonthly td:nth-child(2) { width: 23% !important; }
#tblDashMonthly th:nth-child(3), #tblDashMonthly td:nth-child(3) { width: 24% !important; }
#tblDashMonthly th:nth-child(4), #tblDashMonthly td:nth-child(4) { width: 19% !important; }

/* keep charts below clear and full width */
.ratio-card,
.compact-dashboard-extra {
  margin-top: 18px !important;
}

@media (max-width: 1180px) {
  .dashboard-tables.grid.two {
    grid-template-columns: 1fr !important;
  }
  .dashboard-table-wrap table {
    font-size: 13px !important;
  }
  .dashboard-table-wrap th { font-size: 12px !important; }
}
@media (max-width: 640px) {
  body.dashboard-mode .main { padding: 12px 10px !important; }
  .dashboard-table-wrap table {
    font-size: 10.8px !important;
    table-layout: fixed !important;
  }
  .dashboard-table-wrap th { font-size: 9.8px !important; }
  .dashboard-table-wrap th,
  .dashboard-table-wrap td {
    padding: 4px 3px !important;
  }
  .dashboard-table-wrap td:first-child,
  .dashboard-table-wrap th:first-child {
    padding-left: 5px !important;
    white-space: normal !important;
  }
}

/* Password modal untuk menu Master Unit dan Data & Backup */
.protected-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(15, 23, 42, .56);
  backdrop-filter: blur(8px);
  z-index: 9999;
}
.protected-modal.show { display: flex; }
.protected-dialog {
  width: min(420px, 100%);
  background: #ffffff;
  border: 1px solid rgba(148, 163, 184, .35);
  border-radius: 22px;
  box-shadow: 0 28px 70px rgba(15, 23, 42, .28);
  padding: 26px;
  text-align: center;
}
.protected-icon {
  width: 54px;
  height: 54px;
  margin: 0 auto 10px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: #e0f2fe;
  font-size: 26px;
}
.protected-dialog h3 {
  margin: 4px 0 8px;
  color: #0f172a;
  font-size: 22px;
  font-weight: 900;
}
.protected-dialog p {
  margin: 0 0 16px;
  color: #475569;
  line-height: 1.45;
  font-size: 14px;
}
.protected-dialog input {
  width: 100%;
  min-height: 46px;
  border: 1px solid #cbd5e1;
  border-radius: 14px;
  padding: 0 14px;
  font-size: 16px;
  font-weight: 700;
  outline: none;
}
.protected-dialog input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .14);
}
.protected-error {
  min-height: 22px;
  margin-top: 8px;
  color: #dc2626;
  font-weight: 800;
  font-size: 13px;
}
.protected-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 6px;
}
.protected-actions .btn { min-width: 98px; }

