:root {
  color-scheme: dark;
  --font-body: 'Noto Sans Thai', 'Segoe UI', Arial, sans-serif;
  --bg-app: linear-gradient(135deg, #090e18 0%, #0d1627 50%, #05080f 100%);
  --bg-panel: rgba(16, 26, 46, 0.76);
  --bg-panel-strong: rgba(21, 32, 54, 0.92);
  --bg-input: rgba(9, 14, 25, 0.92);
  --border-color: rgba(148, 163, 184, 0.14);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-soft: #cbd5e1;
  --primary: #3b82f6;
  --success: #10b981;
  --warning: #f59e0b;
  --purple: #8b5cf6;
  --danger: #f87171;
  --cyan: #06b6d4;
  --radius-sm: 6px;
  --radius-md: 8px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.36);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.42);
}

[data-theme="light"] {
  color-scheme: light;
  --bg-app: linear-gradient(135deg, #eef4fb 0%, #f8fafc 48%, #eef8f5 100%);
  --bg-panel: rgba(255, 255, 255, 0.88);
  --bg-panel-strong: rgba(255, 255, 255, 0.98);
  --bg-input: rgba(255, 255, 255, 0.96);
  --border-color: rgba(15, 23, 42, 0.12);
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-soft: #334155;
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 10px 26px rgba(15, 23, 42, 0.10);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font-family: var(--font-body);
}

.dashboard-shell {
  width: min(1600px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 24px 20px;
}

.dashboard-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 14px;
}

.back-link,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  color: var(--text-main);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 12px;
  cursor: pointer;
  transition: 0.18s ease;
}

.back-link:hover,
.icon-btn:hover {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.12);
}

.title-block h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
  font-weight: 800;
}

.title-block p {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 11.5px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dashboard-main {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}

.metric-card,
.panel,
.filter-row {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px);
}

.metric-card {
  position: relative;
  min-height: 100px;
  padding: 12px 14px;
  overflow: hidden;
}

.metric-card::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--primary);
}

.metric-card strong {
  display: block;
  margin-top: 6px;
  font-size: 34px;
  line-height: 1;
  letter-spacing: 0;
}

.metric-card small,
.metric-label {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
}

.metric-label {
  color: var(--text-soft);
}

.accent-total::before { background: var(--text-muted); }
.accent-warning::before { background: var(--warning); }
.accent-danger::before { background: var(--danger); }
.accent-primary::before { background: var(--primary); }
.accent-purple::before { background: var(--purple); }
.accent-success::before { background: var(--success); }

.filter-row {
  display: grid;
  grid-template-columns: 1.7fr repeat(3, minmax(150px, 0.7fr)) auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
}

.filter-row label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
}

.filter-row input,
.filter-row select {
  min-height: 34px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-main);
  padding: 6px 10px;
  font-size: 12px;
  outline: none;
}

.filter-row input:focus,
.filter-row select:focus {
  border-color: rgba(59, 130, 246, 0.65);
}

.check-filter {
  flex-direction: row !important;
  align-items: center;
  min-height: 34px;
  padding: 0 4px;
  white-space: nowrap;
}

.check-filter input {
  min-height: auto;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr 0.9fr 1.2fr;
  gap: 14px;
}

.panel {
  min-width: 0;
  padding: 14px;
}

.sub-donut-panel {
  display: flex;
  flex-direction: column;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 14px;
  line-height: 1.25;
  font-weight: 800;
}

.panel-head span {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
}

.bar-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(92px, 0.8fr) minmax(110px, 1.7fr) 44px;
  gap: 9px;
  align-items: center;
  color: var(--text-soft);
  font-size: 11.5px;
  font-weight: 700;
}

.bar-list.compact .bar-row {
  grid-template-columns: minmax(70px, 0.8fr) minmax(100px, 1.4fr) 38px;
}

.bar-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.16);
}

.bar-fill {
  height: 100%;
  min-width: 3px;
  border-radius: inherit;
  background: var(--primary);
}

.donut-widget {
  display: grid;
  grid-template-columns: minmax(118px, 0.9fr) minmax(130px, 1fr);
  align-items: center;
  gap: 16px;
  min-height: 190px;
  flex: 1;
  align-content: center;
}

.donut-chart {
  position: relative;
  width: min(100%, 174px);
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 50%;
  background: conic-gradient(var(--text-muted) 0deg 360deg);
  box-shadow: inset 0 0 0 1px var(--border-color), var(--shadow-sm);
}

.donut-hit-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  border-radius: 50%;
}

.donut-hit-target {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.donut-tooltip {
  position: fixed;
  z-index: 50;
  min-width: 118px;
  padding: 7px 9px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-panel-strong);
  color: var(--text-main);
  box-shadow: var(--shadow-md);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.35;
  pointer-events: none;
  transform: translate(10px, 10px);
}

.donut-tooltip small {
  display: block;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 800;
  margin-top: 2px;
}

.donut-tooltip.hidden {
  display: none;
}

.donut-chart::after {
  content: '';
  position: absolute;
  inset: 24%;
  border-radius: 50%;
  background: var(--bg-panel-strong);
  box-shadow: inset 0 0 0 1px var(--border-color);
}

.donut-center {
  position: absolute;
  inset: 28%;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.donut-center strong {
  color: var(--text-main);
  font-size: 24px;
  line-height: 1;
}

.donut-center span {
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 800;
}

.donut-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.donut-legend-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  color: var(--text-soft);
  font-size: 11.5px;
  font-weight: 800;
}

.donut-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.donut-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.donut-value {
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

.bucket-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.bucket {
  min-height: 92px;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: rgba(15, 23, 42, 0.20);
}

[data-theme="light"] .bucket {
  background: rgba(241, 245, 249, 0.80);
}

.bucket span {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
}

.bucket strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
  line-height: 1;
}

.table-wrap {
  max-width: 100%;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 12px;
}

th,
td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--border-color);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--text-muted);
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
  white-space: nowrap;
}

td {
  color: var(--text-soft);
}

.num-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.bottleneck-table th:first-child,
.bottleneck-table td:first-child {
  width: 28%;
}

.bottleneck-table th:not(:first-child),
.bottleneck-table td:not(:first-child) {
  width: 10.3%;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.bottleneck-table th {
  white-space: nowrap;
  font-size: 10px;
}

.priority-panel {
  padding-bottom: 8px;
}

.priority-panel table {
  table-layout: auto;
  min-width: 980px;
}

.sap-link {
  color: var(--text-main);
  font-weight: 800;
  text-decoration: none;
}

.sap-link:hover {
  color: var(--primary);
}

.muted {
  color: var(--text-muted);
}

.risk-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.risk-overdue {
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.12);
}

.risk-due {
  color: #fed7aa;
  border-color: rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.12);
}

.risk-normal {
  color: #bfdbfe;
  border-color: rgba(59, 130, 246, 0.35);
  background: rgba(59, 130, 246, 0.10);
}

[data-theme="light"] .risk-overdue { color: #b91c1c; }
[data-theme="light"] .risk-due { color: #b45309; }
[data-theme="light"] .risk-normal { color: #1d4ed8; }

.empty-state {
  padding: 18px 8px;
  color: var(--text-muted);
  text-align: center;
  font-size: 12px;
}

@media (max-width: 1180px) {
  .metric-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .dashboard-shell {
    padding: 0 12px 16px;
  }

  .dashboard-header {
    grid-template-columns: 1fr auto;
    align-items: start;
  }

  .back-link {
    grid-column: 1 / -1;
    width: max-content;
  }

  .metric-grid,
  .dashboard-grid,
  .filter-row {
    grid-template-columns: 1fr;
  }

  .metric-card {
    min-height: 82px;
  }

  .metric-card strong {
    font-size: 28px;
  }

  .bucket-grid {
    grid-template-columns: 1fr;
  }

  .donut-widget {
    grid-template-columns: 1fr;
  }
}

.btn-edit {
  display: inline-block;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s ease;
}

.btn-edit:hover {
  border-color: var(--warning);
  color: var(--warning);
  background: rgba(245, 158, 11, 0.08);
}

