:root {
  --bg: #f3f8fa;
  --bg-panel: #ffffff;
  --bg-sidebar: #0e2a3d;
  --text: #16232b;
  --text-muted: #5a7382;
  --accent: #1596b0;
  --accent-dark: #0d6d82;
  --border: #dbe7ec;
  --sidebar-text: #cfe6ee;
  --sidebar-text-dim: #7fa4b4;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(14, 42, 61, 0.08), 0 1px 2px rgba(14, 42, 61, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.6rem 1.2rem;
  background: linear-gradient(120deg, var(--accent-dark), var(--accent));
  color: white;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 1.15rem; }
.brand-icon { font-size: 1.4rem; }

.tabs {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  flex: 1;
}

.tab-btn {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: white;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s;
  white-space: nowrap;
}
.tab-btn:hover { background: rgba(255, 255, 255, 0.22); }
.tab-btn.active { background: white; color: var(--accent-dark); font-weight: 600; }

.sync { display: flex; align-items: center; gap: 0.6rem; font-size: 0.8rem; }
.sync-status { opacity: 0.85; }
.sync-btn {
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: white;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
}
.sync-btn:hover { background: rgba(255, 255, 255, 0.28); }
.sync-btn:disabled { opacity: 0.6; cursor: wait; }

.layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  color: var(--sidebar-text);
  padding: 1rem 0.6rem;
  overflow-y: auto;
}

.sidebar-group { margin-bottom: 0.4rem; }
.sidebar-group-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--sidebar-text-dim);
  padding: 0.5rem 0.6rem 0.25rem;
}

.sidebar-link {
  display: block;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.88rem;
  cursor: pointer;
}
.sidebar-link:hover { background: rgba(255, 255, 255, 0.08); }
.sidebar-link.active { background: var(--accent); color: white; font-weight: 600; }

.sidebar-link-special {
  margin-bottom: 0.6rem;
  border: 1px dashed rgba(255, 255, 255, 0.25);
}

.content {
  flex: 1;
  padding: 1.5rem 2rem 3rem;
  overflow-y: auto;
  max-width: 980px;
}

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

.doc {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem 2rem;
  box-shadow: var(--shadow);
}

.doc h1 { margin-top: 0; font-size: 1.6rem; color: var(--accent-dark); }
.doc h2 { font-size: 1.25rem; margin-top: 2rem; color: var(--accent-dark); border-bottom: 1px solid var(--border); padding-bottom: 0.3rem; }
.doc h3 { font-size: 1.05rem; margin-top: 1.5rem; }
.doc p, .doc li { line-height: 1.6; color: var(--text); }
.doc a { color: var(--accent-dark); }
.doc blockquote {
  margin: 1rem 0;
  padding: 0.5rem 1rem;
  border-left: 3px solid var(--accent);
  background: #eef7f9;
  color: var(--text-muted);
}

.doc table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0 1.5rem;
  font-size: 0.9rem;
}
.doc th, .doc td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.65rem;
  text-align: left;
  vertical-align: top;
}
.doc th { background: #eaf5f7; color: var(--accent-dark); }
.doc tr:nth-child(even) td { background: #f8fbfc; }

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 0 0.3rem;
}
.badge-warn { background: color-mix(in srgb, var(--warn) 18%, transparent); }
.badge-danger { background: color-mix(in srgb, var(--danger) 18%, transparent); }

.doc code {
  background: #eef3f5;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
}

.chart-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.chart-presets { display: flex; gap: 0.35rem; }
.chart-preset-btn {
  background: #eaf5f7;
  border: 1px solid var(--border);
  color: var(--accent-dark);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.82rem;
}
.chart-preset-btn:hover { background: #dcedf1; }
.chart-preset-btn.active { background: var(--accent); border-color: var(--accent); color: white; font-weight: 600; }

.chart-date-range {
  display: flex;
  gap: 0.9rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.chart-date-range label { display: flex; align-items: center; gap: 0.35rem; }
.chart-date-range input[type="date"] {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.4rem;
  font-size: 0.82rem;
  color: var(--text);
  font-family: inherit;
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.25rem;
  margin-top: 1rem;
}

.chart-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 0.75rem;
  background: #fbfdfe;
}
.chart-card h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  color: var(--accent-dark);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.chart-unit { font-weight: 400; color: var(--text-muted); font-size: 0.8rem; }
.chart-count { margin: 0.3rem 0 0; font-size: 0.78rem; color: var(--text-muted); }

.chart-last {
  margin-left: auto;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  color: white;
}
.chart-last.badge-ok { background: var(--accent); }
.chart-last.badge-warn { background: var(--warn); }
.chart-last.badge-danger { background: var(--danger); }

.chart-svg { width: 100%; height: auto; }
.chart-axis { stroke: var(--border); stroke-width: 1; }
.chart-line { stroke: var(--accent); stroke-width: 2; }
.chart-tick { font-size: 9px; fill: var(--text-muted); }

.error-box {
  background: #fdecea;
  border: 1px solid #f5c2c0;
  color: #7a1f1a;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; max-height: 220px; }
  .content { padding: 1rem; }
}
