:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-soft: #eef3f0;
  --ink: #182021;
  --muted: #657174;
  --line: #dce2e4;
  --brand: #276c68;
  --brand-dark: #164c49;
  --accent: #b45d33;
  --warn: #b42318;
  --ok: #177245;
  --blue: #3867a6;
  --radius: 8px;
  font-family: "Segoe UI", "Noto Sans TC", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
}

button, input, select, textarea {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  background: #172223;
  color: #f5f7f7;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 54px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid #5c7677;
  border-radius: 8px;
  background: #233234;
  font-weight: 800;
}

.brand strong, .brand span {
  display: block;
}

.brand span {
  color: #b7c4c5;
  font-size: 13px;
  margin-top: 3px;
}

.nav-tabs {
  display: grid;
  gap: 6px;
}

.nav-tab {
  color: #e9eeee;
  background: transparent;
  border: 0;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  cursor: pointer;
  text-align: left;
}

.nav-tab:hover, .nav-tab.active {
  background: #2a3b3d;
}

.side-actions {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

.main {
  padding: 24px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

h1, h2, p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.25;
}

.topbar p {
  color: var(--muted);
  margin-top: 8px;
  max-width: 760px;
}

.toolbar, .filter-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.icon-upload input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.icon-upload, .primary-btn, .secondary-btn, .danger-btn, .tiny-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 38px;
  padding: 8px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.icon-upload, .primary-btn {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}

.primary-btn:hover, .icon-upload:hover {
  background: var(--brand-dark);
}

.secondary-btn {
  background: #263638;
  color: white;
  border-color: #43585a;
}

.danger-btn {
  background: #3a2524;
  color: #ffd9d6;
  border-color: #73413d;
}

.tiny-btn {
  min-height: 30px;
  padding: 4px 8px;
  background: #fff;
  color: var(--warn);
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 18px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 14px;
}

.metric-card, .panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.metric-card {
  padding: 16px;
  display: grid;
  gap: 8px;
}

.metric-card span, .metric-card small, .panel-heading span {
  color: var(--muted);
}

.metric-card strong {
  font-size: 30px;
  line-height: 1;
}

.analysis-layout, .intake-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.85fr);
  gap: 18px;
}

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

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.panel h2 {
  font-size: 18px;
}

.bar-list {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  gap: 6px;
}

.bar-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.bar-track {
  height: 12px;
  background: #e8edef;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: var(--w);
  background: var(--brand);
}

.donut-wrap {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  align-items: center;
  gap: 18px;
}

.donut-chart {
  width: 210px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(#d9e0e1 0 100%);
  position: relative;
}

.donut-chart::after {
  content: "";
  position: absolute;
  inset: 48px;
  border-radius: 50%;
  background: white;
  border: 1px solid var(--line);
}

.legend, .insight-list, .priority-list {
  display: grid;
  gap: 10px;
}

.legend-item, .insight-item, .priority-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfc;
}

.legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.swatch {
  inline-size: 12px;
  block-size: 12px;
  border-radius: 3px;
  display: inline-block;
  margin-right: 8px;
}

.form-panel {
  display: grid;
  gap: 13px;
}

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

label {
  display: grid;
  gap: 6px;
  color: #2e3a3c;
  font-weight: 600;
}

input, select, textarea {
  width: 100%;
  border: 1px solid #cdd6d8;
  border-radius: 8px;
  padding: 9px 10px;
  background: white;
  color: var(--ink);
  font-weight: 400;
}

textarea {
  resize: vertical;
}

.format-block {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

code {
  display: block;
  overflow-x: auto;
  padding: 10px;
  border-radius: 8px;
  background: #eef3f0;
  color: #243537;
}

.import-log {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  color: var(--muted);
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 850px;
}

th, td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 11px 10px;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 700;
  background: #f7f9f9;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  background: #edf2f2;
  color: #304144;
  white-space: nowrap;
}

.pill.good { background: #e4f4ea; color: var(--ok); }
.pill.warn { background: #fff0e6; color: var(--accent); }
.pill.bad { background: #ffe8e5; color: var(--warn); }

.empty-state {
  color: var(--muted);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .nav-tabs, .side-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar, .analysis-layout, .intake-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

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

@media (max-width: 640px) {
  .main {
    padding: 16px;
  }

  .metric-grid, .form-grid, .donut-wrap {
    grid-template-columns: 1fr;
  }

  .donut-chart {
    width: min(100%, 240px);
  }

  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }
}
