/* ===================================================================
   Design tokens
   Color is not decorative here - the status colors ARE the same 12
   named colors the physical andon lights use. A workcenter showing
   ORANGE on this screen matches the ORANGE light on the actual floor.
   =================================================================== */
:root {
  --charcoal: #171E27;
  --charcoal-light: #232D3A;
  --charcoal-lighter: #2C3847;
  --charcoal-border: #313E4C;
  --surface: #F4F6F9;
  --surface-card: #FFFFFF;
  --border: #E4E8EE;
  --border-soft: #EDF0F4;
  --text-primary: #161D26;
  --text-secondary: #5B6B7C;
  --text-muted: #8B98A6;
  --accent: #2E5C8A;
  --accent-dark: #234769;
  --accent-light: #3E74AB;
  --accent-tint: #EAF1F8;
  --danger: #C22C39;
  --danger-tint: #FCEBED;
  --success: #1F8A46;
  --success-tint: #E7F6EC;

  /* the real 12-color andon palette */
  --c-red: #E53935;
  --c-orange: #FB8C00;
  --c-yellow: #FDD835;
  --c-lime: #C0CA33;
  --c-green: #43A047;
  --c-teal: #00897B;
  --c-cyan: #00ACC1;
  --c-blue: #1E88E5;
  --c-indigo: #3949AB;
  --c-purple: #8E24AA;
  --c-pink: #D81B60;
  --c-brown: #6D4C41;

  --radius-sm: 7px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 100px;

  --shadow-xs: 0 1px 2px rgba(22, 29, 38, 0.05);
  --shadow-sm: 0 1px 3px rgba(22, 29, 38, 0.06), 0 1px 2px rgba(22, 29, 38, 0.04);
  --shadow-md: 0 8px 20px -6px rgba(22, 29, 38, 0.12), 0 2px 6px rgba(22, 29, 38, 0.06);
  --shadow-lg: 0 24px 48px -14px rgba(15, 20, 27, 0.28);

  --ease: cubic-bezier(.4, 0, .2, 1);
  --sidebar-w: 246px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--surface);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: "IBM Plex Mono", monospace;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--accent); color: #fff; }

/* thin, modern scrollbars wherever content scrolls */
.sidebar, .table-scroll, .workcenter-grid, .col-chart, .content {
  scrollbar-width: thin;
  scrollbar-color: rgba(140, 150, 165, 0.5) transparent;
}
.sidebar::-webkit-scrollbar, .table-scroll::-webkit-scrollbar,
.workcenter-grid::-webkit-scrollbar, .col-chart::-webkit-scrollbar {
  height: 8px; width: 8px;
}
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.14); border-radius: 8px; }
.table-scroll::-webkit-scrollbar-thumb, .workcenter-grid::-webkit-scrollbar-thumb,
.col-chart::-webkit-scrollbar-thumb { background: rgba(91,107,124,0.28); border-radius: 8px; }

:focus-visible {
  outline: 2px solid var(--accent-light);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ===================================================================
   Shell: sidebar + content
   =================================================================== */
.shell {
  display: flex;
  min-height: 100vh;
}

.mobile-topbar {
  display: none;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 60;
  background: var(--charcoal);
  color: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
}
.mobile-topbar-mark {
  flex-shrink: 0;
  border-radius: 6px;
}
.mobile-topbar .brand {
  font-weight: 600;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--charcoal-border);
  background: var(--charcoal-light);
  color: #fff;
  cursor: pointer;
}
.sidebar-toggle svg { width: 19px; height: 19px; }
.sidebar-toggle:hover { background: var(--charcoal-lighter); }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 13, 18, 0.5);
  z-index: 65;
  animation: fade-in .18s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--charcoal) 0%, #141A22 100%);
  color: #C7D0D9;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: transform .25s var(--ease);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px;
  border-bottom: 1px solid var(--charcoal-border);
}
.sidebar-brand-mark {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent-light), var(--accent-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(46, 92, 138, 0.4);
}
.sidebar-brand-mark svg { width: 19px; height: 19px; color: #fff; }
.sidebar-brand-text { min-width: 0; }
.sidebar-brand .name {
  font-weight: 600;
  font-size: 15px;
  color: #fff;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-brand .sub {
  font-size: 11.5px;
  color: #7E8C99;
  margin-top: 1px;
}

.sidebar-nav {
  padding: 12px;
  flex: 1;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: #C7D0D9;
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 2px;
  text-decoration: none;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.sidebar-nav a:hover {
  background: var(--charcoal-light);
  color: #fff;
  text-decoration: none;
}
.sidebar-nav a.active {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.sidebar-nav svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.9; }

.sidebar-user {
  padding: 14px 16px;
  border-top: 1px solid var(--charcoal-border);
}
.sidebar-user-who {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-light), var(--accent-dark));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
}
.sidebar-user-text { min-width: 0; }
.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  font-size: 11.5px;
  color: #8A96A3;
  margin-top: 1px;
}
.sidebar-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--charcoal-border);
  background: transparent;
  color: #C7D0D9;
  font-size: 12.5px;
  font-weight: 500;
  text-decoration: none;
  transition: background .15s, color .15s, border-color .15s;
}
.sidebar-logout svg { width: 14px; height: 14px; flex-shrink: 0; }
.sidebar-logout:hover {
  background: var(--charcoal-light);
  color: #fff;
  border-color: var(--charcoal-light);
  text-decoration: none;
}

.sidebar-foot {
  padding: 14px 20px;
  font-size: 11.5px;
  color: #6B7885;
  border-top: 1px solid var(--charcoal-border);
}

.content {
  flex: 1;
  min-width: 0;
  padding: 28px 32px;
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 22px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header h1 {
  font-size: 21px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.2px;
}
.page-header .desc {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 4px;
}

/* ===================================================================
   Cards / tiles
   =================================================================== */
.card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.card-pad { padding: 18px 20px; }

.dt-line-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
  align-items: start;
}

.dt-line-card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--tile-color, var(--c-orange));
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow .15s var(--ease), transform .15s var(--ease);
}
.dt-line-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.dt-line-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
}
.dt-line-code {
  font-size: 13px;
  color: var(--text-muted);
}
.dt-line-name { font-weight: 600; font-size: 15px; }
.dt-line-badge {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--border-soft);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}
.dt-line-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 6px 0;
  border-top: 1px solid var(--border);
}
.dt-line-item:first-of-type { border-top: none; padding-top: 0; }
.dt-line-item .dot {
  width: 9px; height: 9px; border-radius: 50%;
  flex-shrink: 0;
}
.dt-line-detail {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dt-line-elapsed { color: var(--text-secondary); font-size: 12px; flex-shrink: 0; }

/* ===================================================================
   Tables
   =================================================================== */
table.data {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface-card);
  font-size: 13px;
}
table.data th {
  text-align: left;
  padding: 11px 14px;
  background: #FAFBFD;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
table.data td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: #FBFCFE; }
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
}
.table-scroll table.data { border: none; border-radius: 0; box-shadow: none; }

/* ===================================================================
   Badges, pills, buttons
   =================================================================== */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.pill-input { background: #FFF3CD; color: #7A5B00; }
.pill-service { background: #E0EEF7; color: #1B4A6B; }
.pill-active { background: var(--success-tint); color: var(--success); }
.pill-unallocated { background: var(--border-soft); color: var(--text-secondary); }
.pill-inactive { background: var(--danger-tint); color: var(--danger); }
.pill-warn { background: #FFF3CD; color: #7A5B00; }
.pill-error { background: var(--danger-tint); color: var(--danger); }
.pill-webclosed { background: #EAE0F7; color: #5B2A8E; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s var(--ease), border-color .15s var(--ease), box-shadow .15s var(--ease), transform .05s var(--ease);
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(35, 71, 105, 0.25); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: #fff; color: var(--text-primary); border-color: var(--border); }
.btn-secondary:hover { background: var(--border-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #A32330; }
.btn-sm { padding: 5px 11px; font-size: 12px; }

.swatch {
  width: 14px; height: 14px; border-radius: 4px; display: inline-block;
  vertical-align: -2px; margin-right: 6px; border: 1px solid rgba(0,0,0,0.08);
}

/* ===================================================================
   Forms & filters
   =================================================================== */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: flex-end;
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 11.5px; font-weight: 600; color: var(--text-secondary); }
.field select, .field input {
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: var(--text-primary);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.field select:focus, .field input:focus {
  border-color: var(--accent-light);
  box-shadow: 0 0 0 3px var(--accent-tint);
  outline: none;
}
.field-search { width: 220px; max-width: 100%; }

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  margin: 28px 0 10px;
  text-transform: none;
}
.section-title:first-child { margin-top: 0; }

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13.5px;
}

.flash {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
}
.flash-success { background: var(--success-tint); color: var(--success); }
.flash-error { background: var(--danger-tint); color: var(--danger); }

/* ===================================================================
   KPI cards
   =================================================================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow .15s var(--ease), transform .15s var(--ease);
}
.kpi-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kpi-card .kpi-value {
  font-size: 27px;
  font-weight: 700;
  line-height: 1;
  font-family: "IBM Plex Mono", monospace;
  letter-spacing: -0.5px;
}
.kpi-card .kpi-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 7px;
}
.kpi-card.kpi-warn .kpi-value { color: #966B00; }
.kpi-card.kpi-danger .kpi-value { color: var(--danger); }
.kpi-card.kpi-accent .kpi-value { color: var(--accent); }

.kpi-compare {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  font-size: 11px;
  font-weight: 600;
}
.kpi-compare-up { color: var(--danger); }
.kpi-compare-down { color: var(--success); }
.kpi-compare-flat, .kpi-compare-new { color: var(--text-muted); font-weight: 500; }

/* ===================================================================
   Pareto chart (Top reason codes: ranked bars + cumulative-% line)
   =================================================================== */
.pareto-chart-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.pareto-note { margin-top: 8px; font-size: 11.5px; color: var(--text-muted); }

/* ===================================================================
   Simple bar charts (no charting library)
   =================================================================== */
.bar-row {
  display: grid;
  grid-template-columns: 140px 1fr 90px;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 13px;
}
.bar-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-track {
  display: block;
  background: var(--border-soft);
  border-radius: 4px;
  height: 10px;
  overflow: hidden;
}
.bar-fill {
  display: block;
  height: 100%;
  min-width: 3px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent-light), var(--accent));
}
.bar-value {
  text-align: right;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  color: var(--text-secondary);
}

/* ===================================================================
   Column chart (Reports: factory-wise / department-wise breakdowns)
   =================================================================== */
.col-chart {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 220px;
  padding: 10px 4px 0;
  overflow-x: auto;
}
.col-chart-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  flex: 1 0 46px;
  min-width: 46px;
}
.col-chart-value {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
  white-space: nowrap;
}
.col-chart-bar {
  width: 100%;
  max-width: 56px;
  min-height: 4px;
  border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, var(--accent-light), var(--accent));
  transition: height .3s ease;
}
.col-chart-label {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  white-space: nowrap;
}

/* ===================================================================
   Donut chart (dashboard "today by department")
   =================================================================== */
.donut-widget {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  gap: 32px;
}
.donut-chart-wrap {
  position: relative;
  width: 280px;
  height: 280px;
  max-width: 100%;
  margin: 0 auto;
}
.donut-chart-wrap svg { transform: rotate(-90deg); }
.donut-chart-wrap circle { transition: stroke-dasharray .3s ease; }
.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
}
.donut-center .val {
  font-family: "IBM Plex Mono", monospace;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.1;
}
.donut-center .lbl {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}
.donut-center .cnt {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.donut-legend {
  flex: 1;
  min-width: 280px;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.legend-row:last-child { border-bottom: none; }
.legend-row .swatch-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.legend-row .legend-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.legend-row .legend-time {
  font-weight: 600;
  width: 52px;
  text-align: right;
  flex-shrink: 0;
}
.legend-row .legend-pct {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
  color: var(--text-secondary);
  width: 38px;
  text-align: right;
  flex-shrink: 0;
}
.legend-row .legend-cnt {
  color: var(--text-secondary);
  font-size: 12px;
  width: 88px;
  text-align: right;
  flex-shrink: 0;
}

/* ===================================================================
   Dashboard "needs attention" list
   =================================================================== */
.attention-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.attention-row:last-child { border-bottom: none; }
.attention-row .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--tile-color, #C6CCD3);
  flex-shrink: 0;
}
.attention-row .wc { font-family: "IBM Plex Mono", monospace; font-size: 12.5px; color: var(--text-muted); width: 46px; flex-shrink: 0; }
.attention-row .detail { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attention-row .elapsed { color: var(--text-secondary); font-size: 12px; flex-shrink: 0; }

/* ===================================================================
   Reusable components: modals, toasts, tabs, pagination
   =================================================================== */
[hidden] { display: none !important; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(14, 18, 24, 0.55);
  backdrop-filter: blur(1px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
  animation: fade-in .15s ease;
}
.modal {
  background: var(--surface-card);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modal-in .18s var(--ease);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
/* Wider variant for forms that need horizontal room instead of a tall,
   scrolling single column - e.g. a workcenter picker with a full floor's
   worth of checkboxes. */
.modal-lg { max-width: 760px; }
.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.workcenter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  padding: 2px;
}
.workcenter-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 400;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface-card);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
}
.modal-header h2 { font-size: 15px; font-weight: 600; margin: 0; }
.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}
.modal-close:hover { color: var(--text-primary); background: var(--border-soft); }
.modal-body { padding: 18px 20px; }
.modal-body .field { margin-bottom: 14px; }
.modal-body .field:last-child { margin-bottom: 0; }
.modal-body .field label { display: block; margin-bottom: 5px; }
.modal-body .field select, .modal-body .field input { width: 100%; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  background: var(--surface-card);
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
}

.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  left: 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  z-index: 2000;
}
.toast {
  min-width: 240px;
  max-width: 360px;
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-out { animation: toast-out .25s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

.tabs { margin-bottom: 18px; }
.tab-bar {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 4px;
  margin-right: 20px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s var(--ease), border-color .15s var(--ease);
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.pagination {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 14px;
}
.pagination-status { font-size: 12.5px; color: var(--text-secondary); }
.pagination [disabled] { opacity: 0.45; cursor: default; }

.pill-online { background: var(--success-tint); color: var(--success); }
.pill-offline { background: var(--border-soft); color: var(--text-secondary); }

/* ===================================================================
   Sidebar collapsible group ("Device Management")
   =================================================================== */
.sidebar-group-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  color: #C7D0D9;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 2px;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.sidebar-group-toggle:hover { background: var(--charcoal-light); color: #fff; }
.sidebar-group-toggle svg:first-child { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.9; }
.sidebar-group-toggle .chevron { width: 13px; height: 13px; margin-left: auto; flex-shrink: 0; transition: transform .15s ease; }
.sidebar-group.open .sidebar-group-toggle .chevron { transform: rotate(90deg); }
.sidebar-subnav {
  display: none;
  padding-left: 27px;
}
.sidebar-group.open .sidebar-subnav { display: block; }
.sidebar-subnav a {
  display: block;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: #A9B3BD;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  margin-bottom: 2px;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.sidebar-subnav a:hover { background: var(--charcoal-light); color: #fff; }
.sidebar-subnav a.active { background: var(--accent); color: #fff; }

/* ===================================================================
   Device Status cards
   =================================================================== */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.device-card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow .15s var(--ease), transform .15s var(--ease);
}
.device-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.device-card .wc-code { font-family: "IBM Plex Mono", monospace; font-size: 12.5px; color: var(--text-muted); }
.device-card .wc-name { font-weight: 600; font-size: 15px; margin: 2px 0 10px; }
.device-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
}
.device-row:first-of-type { border-top: none; padding-top: 0; }
.device-row .device-type { font-weight: 600; flex-shrink: 0; }
.device-row .device-hwid { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); }

/* ===================================================================
   Responsive breakpoints
   Sidebar becomes an off-canvas drawer below 1080px; a mobile topbar
   with a hamburger button takes its place. Below that, spacing,
   grids and forms progressively tighten for phone widths.
   =================================================================== */
@media (max-width: 1080px) {
  .mobile-topbar { display: flex; }
  .sidebar-backdrop.open { display: block; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 70;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }

  .content { padding: 22px 20px; }
}

@media (max-width: 780px) {
  .content { padding: 18px 14px; }

  .page-header { align-items: flex-start; }
  .page-header h1 { font-size: 19px; }

  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
  .kpi-card { padding: 14px 15px; }
  .kpi-card .kpi-value { font-size: 23px; }

  .dt-line-list { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
  .device-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

  .donut-widget { grid-template-columns: 1fr; gap: 20px; }
  .donut-legend { min-width: 0; }

  .form-grid-2 { grid-template-columns: 1fr; }

  .modal-lg { max-width: 100%; }

  .bar-row { grid-template-columns: 96px 1fr 70px; gap: 8px; }

  .filter-bar { align-items: stretch; }
  .filter-bar .field { flex: 1 1 140px; }
  .field-search { width: 100%; }
}

@media (max-width: 480px) {
  .content { padding: 14px 12px; }
  body { font-size: 13.5px; }

  .sidebar { width: min(var(--sidebar-w), 84vw); }

  .page-header { flex-direction: column; align-items: stretch; }
  .page-header .btn { align-self: flex-start; }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .card-pad { padding: 14px; }

  .dt-line-list { grid-template-columns: 1fr; }
  .device-grid { grid-template-columns: 1fr; }

  .bar-row { grid-template-columns: 1fr; row-gap: 4px; }
  .bar-value { text-align: left; }

  .modal-body, .modal-header, .modal-footer { padding-left: 14px; padding-right: 14px; }

  .toast-container { left: 12px; right: 12px; bottom: 12px; align-items: stretch; }
  .toast { max-width: none; }

  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar .btn { width: 100%; }
}
