:root {
  --bg: #eef5fb;
  --bg-soft: #e4eef8;
  --bg-elev: #ffffff;
  --sidebar: #0b4f8a;
  --sidebar-2: #0a3f6e;
  --line: #c9dceb;
  --line-soft: #dce8f4;
  --text: #12324f;
  --muted: #5d7a96;
  --accent: #1a7fd4;
  --accent-strong: #0f6abb;
  --accent-dim: rgba(26, 127, 212, 0.12);
  --warn: #d97706;
  --danger: #dc4b5a;
  --info: #0ea5c6;
  --purple: #6d5ef0;
  --good: #0f9f6e;
  --radius: 11px;
  --shadow: 0 8px 24px rgba(18, 70, 120, 0.08);
  --font: "Plus Jakarta Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sidebar-w: 160px;
  --pad-x: 0.52rem;
  --pad-y: 0.33rem;
}

* { box-sizing: border-box; }
html {
  font-size: 95%; /* global −5% text/size scale */
}
html, body { margin: 0; padding: 0; height: 100%; min-height: 100%; }
body {
  font-family: var(--font);
  font-size: 0.875rem; /* ~14px at 95% root */
  line-height: 1.4;
  color: var(--text);
  background:
    linear-gradient(180deg, #f5f9fd 0%, var(--bg) 40%, #e8f1fa 100%);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-strong); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
}

.sidebar {
  background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-2) 100%);
  border-right: 1px solid rgba(255,255,255,0.08);
  padding: 0.55rem 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  z-index: 40;
  overflow: auto;
}
.brand-logo {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.4rem 0.45rem 0.55rem;
  border-bottom: 1px solid rgba(255,255,255,0.14);
  margin-bottom: 0.1rem;
  color: #fff;
}
.brand-logo .brand-mark {
  width: 32px; height: 32px;
  border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #7ec4ff, #2a8fe0);
  color: #fff;
  font-weight: 800;
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(0,0,0,0.18);
}
.brand-logo .brand-name {
  font-size: 0.86rem;
  font-weight: 760;
  letter-spacing: -0.01em;
  line-height: 1.1;
  white-space: nowrap;
}

.sidebar nav { display: flex; flex-direction: column; gap: 0.22rem; }
.sidebar nav a {
  color: rgba(255,255,255,0.78);
  padding: 0.48rem 0.55rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 0.8rem;
  font-weight: 560;
  transition: 0.15s ease;
}
.sidebar nav a:hover { color: #fff; background: rgba(255,255,255,0.1); }
.sidebar nav a.active {
  color: #fff;
  background: rgba(255,255,255,0.16);
  border-color: rgba(255,255,255,0.18);
}
.sidebar nav a.nav-logout {
  margin-top: 0.45rem;
  color: rgba(255, 214, 214, 0.92);
  border-top: 1px solid rgba(255,255,255,0.12);
  border-radius: 0 0 8px 8px;
  padding-top: 0.7rem;
}
.sidebar nav a.nav-logout:hover {
  color: #fff;
  background: rgba(220, 75, 90, 0.28);
}

.sidebar-foot {
  margin-top: auto;
  padding: 0.55rem 0.55rem;
  border-radius: 9px;
  background: rgba(0,0,0,0.18);
  color: rgba(255,255,255,0.72);
  font-size: 0.68rem;
  line-height: 1.35;
}
.sidebar-foot p { margin: 0; }

.mobile-bar {
  display: none;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem var(--pad-x);
  background: var(--sidebar);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 45;
}
.mobile-bar .menu-toggle {
  width: 36px; height: 36px;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 8px;
  background: rgba(255,255,255,0.1);
  color: #fff;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}
.mobile-bar strong { font-size: 0.92rem; }
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 35, 60, 0.35);
  z-index: 35;
}

.main {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 0.45rem 0.7rem;
  padding: 0.38rem var(--pad-x) 0.3rem;
  flex-wrap: nowrap;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(201, 220, 235, 0.65);
  background: linear-gradient(180deg, rgba(255,255,255,0.72) 0%, rgba(245,249,253,0.35) 100%);
}
.topbar-title {
  flex: 0 0 auto;
  min-width: 0;
  padding-bottom: 0.12rem;
}
.topbar h1 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: -0.025em;
  font-weight: 720;
  color: #0d3a63;
  white-space: nowrap;
}
.topbar-actions {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  justify-content: flex-end;
}
.muted { color: var(--muted); margin: 0.12rem 0 0; font-size: 0.76rem; }

.filter-bar {
  display: flex;
  flex-wrap: nowrap;
  align-items: end;
  justify-content: flex-end;
  gap: 0.35rem;
  width: 100%;
}
.filters-fields {
  display: flex;
  flex-wrap: nowrap;
  align-items: end;
  gap: 0.32rem;
  flex: 0 1 auto;
  justify-content: flex-end;
  min-width: 0;
}
.filters-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: end;
  gap: 0.32rem;
  flex: 0 0 auto;
}
.filters-actions .btn {
  min-height: 30px;
  padding: 0.32rem 0.75rem;
  font-size: 0.8rem;
}
.filter-bar .field label {
  font-size: 0.62rem;
  margin-bottom: 0;
}
.filter-bar .field input,
.filter-bar .field select {
  padding: 0.32rem 0.45rem;
  font-size: 0.8rem;
  border-radius: 8px;
  height: 30px;
}
.filter-bar .field-search input {
  min-width: 132px;
  width: 148px;
}
.filter-bar .field-date input,
.filter-bar .field-date .flatpickr-input,
.filter-bar .field-date .form-control {
  min-width: 98px;
  width: 98px;
}
.filter-bar .field input[type="month"],
.filter-bar .field select {
  min-width: 118px;
  width: 118px;
}

.content {
  padding: 0.25rem var(--pad-x) 0.35rem;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: auto;
}
.content-fill {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.panel-toolbar {
  flex-shrink: 0;
  margin-bottom: 0.35rem;
  padding: 0.35rem 0.65rem;
}
.panel-toolbar .toolbar { margin-bottom: 0; }
.panel-fill {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-bottom: 0;
}
.table-wrap-grow {
  flex: 1 1 auto;
  min-height: 220px;
  max-height: none !important;
  overflow: auto;
}
.site-footer {
  flex-shrink: 0;
  padding: 0.45rem var(--pad-x) 0.55rem;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
  background: rgba(255,255,255,0.55);
}
.site-footer span { letter-spacing: 0.01em; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: end;
}
.field { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; }
.field label {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.045em;
  font-weight: 650;
}
.field input, .field select, .field textarea,
.input, .select, .textarea {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 9px;
  padding: 0.42rem 0.58rem;
  min-width: 0;
  font-size: 0.86rem;
}
.field-date input,
.field-date .flatpickr-input,
.field-date .form-control {
  min-width: 118px;
  width: 118px;
}
#logSearch,
#prodSearch {
  min-width: 220px;
  width: min(280px, 100%);
}
.flatpickr-calendar {
  font-family: var(--font);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: #7eb8e8;
  box-shadow: 0 0 0 3px rgba(26, 127, 212, 0.15);
}
.field textarea, .textarea { min-height: 72px; resize: vertical; }

.btn {
  border: 0;
  border-radius: 8px;
  padding: 0.4rem 0.72rem;
  cursor: pointer;
  background: linear-gradient(180deg, #2a8fe0, var(--accent-strong));
  color: #fff;
  font-weight: 650;
  font-size: 0.8rem;
  transition: 0.15s ease;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn.secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
}
.btn.danger {
  background: #fff5f6;
  color: #b42336;
  border: 1px solid #f3c1c7;
}
.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
.btn.sm { padding: 0.32rem 0.55rem; font-size: 0.78rem; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 0.45rem;
  flex-wrap: wrap;
  margin-bottom: 0.4rem;
}
.toolbar h2 { margin: 0; font-size: 0.88rem; color: #0d3a63; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem;
  margin-bottom: 0.45rem;
}
.kpi {
  background: var(--bg-elev);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 0.8rem 0.85rem;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.kpi::after {
  content: "";
  position: absolute;
  inset: auto -18% -45% auto;
  width: 100px; height: 100px;
  border-radius: 50%;
  background: var(--accent-dim);
}
.kpi .label {
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 650;
  position: relative;
}
.kpi .value {
  font-family: var(--mono);
  font-size: 1.4rem;
  margin-top: 0.15rem;
  letter-spacing: -0.03em;
  font-weight: 600;
  position: relative;
  color: #0d3a63;
}
.kpi .sub { color: var(--muted); font-size: 0.72rem; margin-top: 0.15rem; position: relative; }
.kpi.oee .value { color: var(--accent-strong); }
.kpi.avail .value { color: var(--info); }
.kpi.perf .value { color: var(--warn); }
.kpi.qual .value { color: var(--purple); }

.grid-2 {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 0.45rem;
  margin-bottom: 0.45rem;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
  margin-bottom: 0.45rem;
}

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 0.55rem 0.65rem;
  box-shadow: var(--shadow);
}
.panel h2 {
  margin: 0 0 0.4rem;
  font-size: 0.84rem;
  font-weight: 700;
  color: #0d3a63;
}
.chart-wrap { position: relative; height: 240px; }
.chart-wrap.tall { height: 300px; }

.table-wrap {
  overflow: auto;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  max-height: calc(100vh - 160px);
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  min-width: 720px;
}
table.data th, table.data td {
  padding: 0.36rem 0.42rem;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  white-space: nowrap;
}
table.data th {
  background: #f3f8fc;
  color: #4d6b86;
  font-weight: 700;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: 0;
  z-index: 1;
}
table.data tr:hover td { background: #f7fbfe; }
table.data .mono { font-family: var(--mono); font-size: 0.8rem; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.14rem 0.42rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 650;
  background: #f1f6fb;
  border: 1px solid var(--line);
  color: var(--muted);
}
.badge.good { color: var(--good); border-color: #b7e4d1; background: #ecfbf4; }
.badge.warn { color: #b45309; border-color: #f5d39a; background: #fff7eb; }
.badge.bad { color: #b42336; border-color: #f3c1c7; background: #fff1f2; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
}
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-3 { grid-column: span 3; }
.form-actions { display: flex; gap: 0.45rem; margin-top: 0.75rem; flex-wrap: wrap; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 40, 70, 0.42);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 0.7rem;
  z-index: 80;
  overflow: auto;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: min(920px, 100%);
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--line);
  box-shadow: 0 20px 50px rgba(12, 50, 90, 0.22);
  margin: 0.4rem auto 1rem;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 0.9rem;
  border-bottom: 1px solid var(--line-soft);
}
.modal-header h3 {
  margin: 0;
  font-size: 1.05rem;
  color: #0d3a63;
  font-weight: 720;
}
.modal-body { padding: 0.85rem 0.9rem; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
  padding: 0.7rem 0.9rem 0.85rem;
  border-top: 1px solid var(--line-soft);
  background: #f8fbfe;
  border-radius: 0 0 14px 14px;
}
.icon-btn {
  width: 34px; height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
}

.action-btns {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
}
.action-icon {
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  text-decoration: none;
  transition: 0.15s ease;
}
.action-icon:hover { transform: translateY(-1px); }
.action-icon.view { color: #0f6abb; border-color: #b7d7f2; background: #eef6fc; }
.action-icon.edit { color: #0f766e; border-color: #b6e2da; background: #eefaf7; }
.action-icon.del { color: #b42336; border-color: #f3c1c7; background: #fff1f2; }
.action-icon svg { display: block; pointer-events: none; }

.sidebar nav { margin-top: 0.15rem; }

.kpi-grid-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.kpi.at .value, .kpi.at2 .value { color: #0f6abb; }
.kpi.best .value { color: var(--good); }
.kpi.worst .value { color: var(--danger); }

.btn.active-view {
  background: #0d3a63;
  color: #fff;
  border-color: #0d3a63;
}

/* Sheet | Overview segmented switch */
.view-switch {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  padding: 2px;
  border: 1px solid #b7d0e6;
  border-radius: 10px;
  background: linear-gradient(180deg, #f4f8fc 0%, #e8f1f9 100%);
  box-shadow: inset 0 1px 2px rgba(15, 70, 120, 0.06);
  flex-shrink: 0;
  min-width: 168px;
  height: 30px;
}
.view-switch-btn {
  border: 0;
  background: transparent;
  color: #5d7a96;
  padding: 0 0.5rem;
  font-size: 0.72rem;
  font-weight: 680;
  cursor: pointer;
  line-height: 1;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.28rem;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  height: 100%;
}
.view-switch-btn svg {
  display: block;
  opacity: 0.85;
  flex-shrink: 0;
  width: 12px;
  height: 12px;
}
.view-switch-btn:hover {
  color: #0d3a63;
  background: rgba(255,255,255,0.7);
}
.view-switch-btn.active {
  background: linear-gradient(180deg, #1a7fd4 0%, #0f6abb 100%);
  color: #fff;
  box-shadow: 0 2px 6px rgba(15, 106, 187, 0.26);
}
.view-switch-btn.active svg { opacity: 1; }

/* display:flex on .panel-fill must not override HTML hidden */
[hidden],
#sheetView[hidden],
#overviewView[hidden],
.panel-fill[hidden],
.view-panel[hidden] {
  display: none !important;
}

.excel-wrap {
  position: relative;
  display: inline-flex;
}
.btn.excel-btn {
  background: #eef8f1;
  color: #1d6f42;
  border: 1px solid #b7dfc4;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.42rem 0.7rem;
}
.btn.excel-btn:hover {
  background: #dff3e6;
  filter: none;
}
.btn.excel-btn svg { display: block; flex-shrink: 0; }
.btn.excel-btn .excel-caret {
  font-size: 0.7rem;
  opacity: 0.75;
  margin-left: 0.05rem;
}
.excel-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 25;
  min-width: 150px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0.25rem;
}
.excel-menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: #eef6fc;
  color: var(--text);
  padding: 0.45rem 0.6rem;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 560;
  margin-bottom: 0.15rem;
}
.excel-menu button:last-child {
  margin-bottom: 0;
  background: #f3faf4;
}
.excel-menu button:hover {
  background: #cfe6fb;
  color: #0a4f8a;
}

.field-search input {
  min-width: 132px;
  width: min(180px, 100%);
}
.kpi-value-sm {
  font-size: 0.95rem !important;
}

.th-interactive { position: relative; vertical-align: middle; }
.th-wrap {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  min-width: 0;
}
.th-sort {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  font-size: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  cursor: pointer;
  padding: 0;
  min-width: 0;
}
.th-label { white-space: nowrap; }
.th-arrows {
  display: inline-flex;
  flex-direction: column;
  line-height: 0.65;
  font-size: 0.55rem;
  opacity: 0.45;
}
.th-interactive.sort-asc .th-arrows .up,
.th-interactive.sort-desc .th-arrows .down {
  opacity: 1;
  color: #0f6abb;
}
.th-filter-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 6px;
  width: 20px;
  height: 20px;
  padding: 0;
  cursor: pointer;
  font-size: 0.7rem;
  line-height: 1;
  flex-shrink: 0;
}
.th-interactive.filtered .th-filter-btn {
  background: #eef6fc;
  color: #0f6abb;
  border-color: #b7d7f2;
}
.th-filter-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 20;
  min-width: 140px;
  max-height: 220px;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0.25rem;
}
.th-filter-menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  color: var(--text);
  padding: 0.42rem 0.55rem;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.8rem;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 560;
  margin-bottom: 0.15rem;
}
.th-filter-menu button:nth-child(odd) { background: #eef6fc; }
.th-filter-menu button:nth-child(even) { background: #f3faf4; }
.th-filter-menu button:nth-child(3n) { background: #fff7eb; }
.th-filter-menu button:hover {
  background: #cfe6fb !important;
  color: #0a4f8a;
}
.th-filter-menu button.active {
  background: #1a7fd4 !important;
  color: #fff;
}

/* Native select option tinting (where the browser allows it) */
select option:nth-child(odd) { background: #eef6fc; color: #16324f; }
select option:nth-child(even) { background: #f3faf4; color: #16324f; }
select option:nth-child(3n) { background: #fff7eb; color: #16324f; }
select option:checked,
select option:hover {
  background: #1a7fd4 linear-gradient(0deg, #1a7fd4 0%, #1a7fd4 100%);
  color: #fff;
}
select option:disabled {
  background: #f0f3f7;
  color: #8a97a8;
}

.stack-panels {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.table-wrap-fit {
  overflow-x: auto;
  max-height: 360px;
}
.stack-panels .table-wrap-fit table.data {
  min-width: 0;
  width: 100%;
}
.content, .stack-panels, .panel {
  min-width: 0;
  max-width: 100%;
}

.toast {
  position: fixed;
  right: 0.7rem;
  bottom: 0.7rem;
  background: #0d3a63;
  border: 1px solid rgba(255,255,255,0.12);
  color: #fff;
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 90;
  opacity: 0;
  transform: translateY(8px);
  transition: 0.2s ease;
  pointer-events: none;
  font-size: 0.88rem;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #9f1239; }

.empty {
  color: var(--muted);
  text-align: center;
  padding: 1.5rem 0.8rem;
}

.content > #overviewView:not([hidden]),
.content > #overviewView.view-active {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.content > #sheetView:not([hidden]),
.content > #sheetView.view-active {
  display: flex;
}

body.nav-open { overflow: hidden; }
body.nav-open .sidebar-backdrop { display: block; }

/* PIN login gate */
body.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1rem;
  background:
    radial-gradient(900px 420px at 15% 0%, rgba(126, 196, 255, 0.35), transparent 60%),
    radial-gradient(700px 380px at 90% 100%, rgba(14, 165, 198, 0.18), transparent 55%),
    linear-gradient(180deg, #f5f9fd 0%, var(--bg) 45%, #e8f1fa 100%);
}
.login-card {
  width: min(380px, 100%);
  background: #fff;
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 1.25rem 1.3rem 1rem;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 1rem;
}
.login-brand .brand-mark {
  width: 40px; height: 40px;
  border-radius: 11px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #7ec4ff, #2a8fe0);
  color: #fff;
  font-weight: 800;
  font-size: 0.75rem;
  box-shadow: 0 4px 10px rgba(0,0,0,0.12);
}
.login-brand strong {
  display: block;
  color: #0d3a63;
  font-size: 1.05rem;
}
.login-brand p {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}
.login-card h1 {
  margin: 0 0 0.75rem;
  font-size: 1.15rem;
  color: #0d3a63;
}
.login-error {
  background: #fff1f2;
  border: 1px solid #f3c1c7;
  color: #9f1239;
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  margin-bottom: 0.7rem;
  font-size: 0.85rem;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.login-form label {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.045em;
  font-weight: 650;
}
.login-form input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  background: #f8fbfe;
  letter-spacing: 0.25em;
  font-size: 1.15rem;
  margin-bottom: 0.45rem;
}
.login-form input:focus {
  outline: none;
  border-color: #7eb7e8;
  box-shadow: 0 0 0 3px rgba(26, 127, 212, 0.15);
}
.login-form .btn { width: 100%; justify-content: center; }
.login-foot {
  margin: 0.9rem 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
}

@media (max-width: 1200px) {
  .kpi-grid-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1100px) {
  .kpi-grid, .grid-2, .grid-3, .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .span-2, .form-grid .span-3 { grid-column: span 2; }
  .chart-wrap, .chart-wrap.tall { height: 228px; }
  .topbar { flex-wrap: wrap; align-items: stretch; }
  .topbar-actions { width: 100%; }
  .filter-bar, .filters-fields { flex-wrap: wrap; width: 100%; justify-content: flex-start; }
  .filter-bar .field-search input { width: min(180px, 100%); }
}

@media (max-width: 860px) {
  :root { --pad-x: 0.42rem; --pad-y: 0.28rem; }
  #logSearch,
  #prodSearch { min-width: 160px; width: 100%; }
  .field-date input,
  .field-date .flatpickr-input,
  .field-date .form-control { width: 100%; min-width: 0; }
  .mobile-bar { display: flex; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: min(210px, 82vw);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    height: 100vh;
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .kpi-grid, .grid-2, .grid-3, .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2, .form-grid .span-3 { grid-column: span 1; }
  .topbar { align-items: stretch; flex-wrap: wrap; }
  .topbar h1 { font-size: 1.05rem; }
  .topbar-actions { min-width: 0; width: 100%; justify-content: stretch; }
  .filter-bar, .filters-fields, .filters-actions { justify-content: stretch; width: 100%; flex-wrap: wrap; }
  .view-switch { width: 100%; min-width: 0; height: 32px; }
  .kpi .value { font-size: 1.3rem; }
  .table-wrap { max-height: none; }
  table.data { min-width: 640px; font-size: 0.78rem; }
  .filters .field input[type="month"],
  .filters .field input[type="date"],
  .filters .field select,
  .filter-bar .field input[type="month"],
  .filter-bar .field select,
  .filter-bar .field-date input { min-width: 0; width: 100%; }
  .filters { width: 100%; }
  .filters .field, .filters-fields .field { flex: 1 1  thr(120px); }
}

@media (max-width: 480px) {
  :root { --pad-x: 0.4rem; }
  .btn { padding: 0.45rem 0.7rem; }
  .modal { border-radius: 12px; }
  .modal-body, .modal-header, .modal-footer { padding-left: 0.65rem; padding-right: 0.65rem; }
}
