/* ==========================================================================
   水質監控儀表板 — 工業樣式
   ========================================================================== */

:root {
  --primary:        #1a3d80;
  --primary-dark:   #11295a;
  --primary-light:  #2c5cb5;
  --accent-red:     #d32f2f;
  --accent-red-bg:  #fdecea;
  --bg:             #ffffff;
  --bg-soft:        #f5f7fb;
  --border:         #c7d2e6;
  --text:           #1f2937;
  --text-soft:      #4b5563;
  --table-head-bg:  #e8eef9;
  --group-bg:       #f0f4fb;
  --group-fg:       #11295a;
  --status-ok-bg:   #e6f4ea;
  --status-ok-fg:   #1b873b;
  --status-bad-bg:  #fdecea;
  --status-bad-fg:  #c62828;
  --shadow:         0 1px 3px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Microsoft JhengHei", "Segoe UI", Roboto, "Noto Sans TC", "Noto Sans", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ─── Header ────────────────────────────────────────────────────────────── */
.topbar {
  display: grid;
  grid-template-columns: 192px 1fr auto;
  gap: 20px;
  align-items: center;
  background: var(--primary);
  color: #fff;
  padding: 14px 20px;
  border-bottom: 3px solid var(--primary-dark);
}

.logo-img {
  display: block;
  width: 172px;
  height: 88px;
  object-fit: contain;
}

.company .company-name {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.3px;
  margin-bottom: 6px;
  line-height: 1.25;
}

.company .company-subtitle {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.35;
  color: #ffffff;
}

.topbar-actions {
  display: flex; gap: 8px;
}

.btn-action {
  background: rgba(255,255,255,0.95);
  color: var(--primary-dark);
  border: 1px solid rgba(255,255,255,0.4);
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px;
}
.btn-action:hover { background: #fff; }
.btn-action .icon { font-size: 14px; }

/* ─── Tabs ──────────────────────────────────────────────────────────────── */
.tabs {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: #fff;
  border-bottom: 2px solid var(--border);
}

.tab {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 18px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text-soft);
  text-decoration: none;
  border-right: 1px solid var(--border);
  background: var(--bg-soft);
  transition: background 0.15s;
  letter-spacing: 0.5px;
}

.tab:last-child { border-right: none; }

.tab.active {
  background: var(--primary);
  color: #fff;
}

.tab:hover:not(.active) { background: #eaeff8; }

/* ─── Main content ──────────────────────────────────────────────────────── */
.content {
  padding: 18px 22px 40px;
  max-width: 1500px;
  margin: 0 auto;
}

.page-title {
  margin: 8px 0 14px;
  text-align: center;
  color: var(--accent-red);
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.5px;
}
.page-title .branch { color: var(--accent-red); }

.time-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 600;
}
.time-row .time-label { color: var(--text); }
.time-row .time-value { color: var(--primary); font-weight: 700; }
.mock-badge {
  margin-left: 8px;
  background: #fff7e0;
  color: #b06900;
  border: 1px solid #f0c97a;
  padding: 2px 8px;
  font-size: 12px;
  border-radius: 3px;
  font-weight: 600;
}

.alert-banner {
  background: var(--status-bad-bg);
  color: var(--status-bad-fg);
  border: 1px solid #f5b3ad;
  border-radius: 4px;
  padding: 10px 14px;
  margin: 8px 0 12px;
  font-weight: 700;
}

/* ─── 填表逾時警示（紅底白字）──────────────────────────────────────── */
.overdue-banner {
  background: #b71c1c;
  color: #fff;
  border: 2px solid #7a0e0e;
  border-radius: 4px;
  padding: 10px 14px;
  margin: 8px 0 12px;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(183,28,28,0.25);
}

.overdue-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 800;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255,255,255,0.25);
}
.overdue-icon { font-size: 18px; }
.overdue-count { font-size: 17px; }

.overdue-row {
  display: grid;
  grid-template-columns: 110px 80px 1fr;
  gap: 8px;
  padding: 5px 0;
  align-items: center;
  font-size: 13.5px;
}

.overdue-slot {
  font-weight: 800;
  font-family: "Consolas", "Monaco", monospace;
  font-size: 14px;
}
.overdue-late {
  color: #ffd5d5;
  font-weight: 700;
  font-size: 12.5px;
}
.overdue-items {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.overdue-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 12.5px;
}
.overdue-sheet { font-weight: 700; }
.overdue-pill {
  background: #fff;
  border-radius: 8px;
  padding: 1px 8px;
  font-size: 11.5px;
  font-weight: 700;
}
.overdue-pill.st-empty   { color: #b71c1c; }
.overdue-pill.st-partial { color: #c97800; }

/* ─── Tables ───────────────────────────────────────────────────────────── */
.tables-row {
  display: grid;
  grid-template-columns: 1fr 1.05fr;
  gap: 18px;
  margin-bottom: 24px;
}

.table-block { min-width: 0; }

.table-caption {
  color: var(--primary);
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 6px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--border);
  font-size: 13px;
  table-layout: fixed;
}

.data-table th,
.data-table td {
  border: 1px solid var(--border);
  padding: 5px 6px;
  text-align: center;
  vertical-align: middle;
  word-break: break-word;
}

.data-table .col-idx   { width: 30px; }
.data-table .col-group { width: 70px; }
.data-table .col-loc   { width: 100px; }

.data-table th {
  background: var(--table-head-bg);
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 12.5px;
  line-height: 1.35;
}

/* 群組標題列 */
.data-table .group-row td {
  background: var(--group-bg);
  color: var(--group-fg);
  font-weight: 700;
  font-size: 13.5px;
  text-align: left;
  padding: 6px 10px;
  border-top: 2px solid var(--primary-light);
}

.data-table td.group-cell {
  background: var(--group-bg);
  color: var(--group-fg);
  font-weight: 700;
  vertical-align: middle;
}

.data-table td.loc {
  text-align: left;
  font-weight: 500;
  padding-left: 10px;
}
.data-table td.loc .vi {
  color: #6b7280;
  font-size: 11.5px;
  display: block;
  line-height: 1.2;
}

.data-table td.value {
  font-weight: 700;
  color: var(--text);
}
.data-table td.value.over {
  color: var(--status-bad-fg);
}

.data-table .status-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.data-table .status-pill.normal {
  background: var(--status-ok-bg);
  color: var(--status-ok-fg);
}
.data-table .status-pill.critical {
  background: var(--status-bad-bg);
  color: var(--status-bad-fg);
}
.data-table .status-pill.unknown {
  background: #eef0f3;
  color: #6b7280;
}

.data-table .loading {
  padding: 20px;
  color: #888;
  font-style: italic;
}

/* ─── Charts ───────────────────────────────────────────────────────────── */
.charts-title {
  color: var(--accent-red);
  font-size: 16px;
  font-weight: 700;
  margin: 18px 0 10px;
}

.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.chart-block {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px;
  min-width: 0;
}

.chart-subtitle {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 6px;
  text-align: center;
}

.chart-canvas-wrap {
  position: relative;
  height: 300px;
  width: 100%;
}

/* ─── Alert Panel ─────────────────────────────────────────────────────── */
.alert-panel {
  margin-top: 22px;
  background: #fff;
  border: 1px solid #f0c4c0;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.alert-panel-title {
  background: var(--accent-red);
  color: #fff;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.alert-icon {
  background: #fff;
  color: var(--accent-red);
  width: 22px; height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center; justify-content: center;
  font-size: 14px;
  font-weight: 800;
}

.alert-panel-body {
  padding: 6px 0;
}

.alert-row {
  display: grid;
  grid-template-columns: 200px 1fr;
  border-bottom: 1px solid #f5dad6;
  align-items: stretch;
}
.alert-row:last-child { border-bottom: none; }

.alert-row-label {
  background: #fff5f4;
  color: var(--status-bad-fg);
  padding: 8px 12px;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.alert-row-label .limit-mini {
  font-size: 11.5px;
  color: #8a4a47;
  font-weight: 500;
  margin-top: 2px;
}

.alert-row-strip {
  overflow-x: auto;
  display: flex;
  gap: 0;
  align-items: stretch;
  background: #fff;
  scrollbar-width: thin;
}

.alert-row-strip::-webkit-scrollbar {
  height: 8px;
}
.alert-row-strip::-webkit-scrollbar-thumb {
  background: #c7d2e6;
  border-radius: 4px;
}

.alert-cell {
  flex: 0 0 auto;
  padding: 6px 10px;
  text-align: center;
  border-right: 1px solid #f5dad6;
  min-width: 60px;
}
.alert-cell:last-child { border-right: none; }
.alert-cell .v {
  font-weight: 700;
  color: var(--status-bad-fg);
  font-size: 13.5px;
  line-height: 1.2;
}
.alert-cell .t {
  font-size: 11px;
  color: #2c5cb5;
  font-weight: 600;
  margin-top: 1px;
}

.alert-empty {
  padding: 16px;
  color: var(--status-ok-fg);
  font-weight: 600;
  text-align: center;
}

/* ─── 卡片版（手機用，桌面隱藏）──────────────────────────────────────── */
.mobile-only { display: none; }

.card-list { flex-direction: column; gap: 8px; }

.card-loading {
  padding: 20px; text-align: center; color: #888; font-style: italic;
  border: 1px solid var(--border); border-radius: 6px; background: #fff;
}

.data-card {
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary-light);
  border-radius: 6px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
}
.data-card.status-critical { border-left-color: var(--accent-red); background: #fffbfb; }
.data-card.status-unknown { border-left-color: #c7d2e6; }

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.card-idx {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  width: 22px; height: 22px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.card-title { flex: 1; min-width: 0; font-weight: 700; }
.card-group {
  color: var(--primary-dark);
  font-size: 14px;
}
.card-loc {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}
.card-loc .vi {
  color: #6b7280;
  font-size: 12px;
  font-weight: 500;
}

.card-body {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
.card-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
}
.card-value.over { color: var(--status-bad-fg); }
.card-unit { font-size: 13px; font-weight: 600; color: var(--text-soft); }
.card-meta { font-size: 12.5px; color: var(--text-soft); font-weight: 500; }
.card-time { margin-left: auto; }

.card-body-2 { flex-direction: column; gap: 4px; align-items: stretch; }
.card-body-2 > div { font-size: 14px; }
.card-body-2 strong { color: var(--text); font-weight: 700; }

/* ─── 響應式 ───────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .topbar { grid-template-columns: 140px 1fr; }
  .logo-img { width: 130px; height: 66px; }
  .topbar-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .tables-row, .charts-row { grid-template-columns: 1fr; }
  .company .company-name { font-size: 18px; }
  .company .company-subtitle { font-size: 14px; }
  .tab { font-size: 14px; padding: 10px 6px; }
  .alert-row { grid-template-columns: 140px 1fr; }
}

@media (max-width: 700px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: block; }
  .card-list { display: flex; }
  .overdue-row {
    grid-template-columns: 1fr;
    gap: 2px;
    padding: 6px 0;
    border-bottom: 1px dashed rgba(255,255,255,0.2);
  }
  .overdue-row:last-child { border-bottom: 0; }
  .content { padding: 12px 12px 30px; }
  .topbar { grid-template-columns: 100px 1fr; padding: 10px 12px; }
  .logo-img { width: 96px; height: 50px; }
  .company .company-name { font-size: 16px; line-height: 1.25; }
  .company .company-subtitle { font-size: 12.5px; line-height: 1.3; }
  .tabs { grid-template-columns: repeat(7, 1fr); }
  .tab { font-size: 13px; padding: 8px 0; letter-spacing: 0; }
  .table-caption { font-size: 13px; }
  .alert-banner { font-size: 13px; padding: 8px 10px; }
  .charts-title { font-size: 14px; }
  .chart-canvas-wrap { height: 240px; }
  .alert-row { grid-template-columns: 1fr; }
  .alert-row-label { padding: 6px 10px; }
}
