:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #16202a;
  --muted: #637083;
  --line: #d8e0e8;
  --brand: #185a7d;
  --brand-dark: #123f59;
  --accent: #1f8a70;
  --warn: #be7a10;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(22, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background: var(--bg);
  font-family: Arial, "Noto Sans TC", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  background: #123f59;
  color: #fff;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: linear-gradient(135deg, #f9fafb 0%, #93d5c2 52%, #e8b34c 100%);
  position: relative;
  flex: 0 0 auto;
}

.brand-mark span {
  position: absolute;
  inset: 10px;
  border: 3px solid #123f59;
  border-top-color: transparent;
  transform: rotate(45deg);
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.brand p {
  margin: 4px 0 0;
  color: #c9d9e7;
  font-size: 13px;
}

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

.nav-tab {
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: #f8fafc;
  text-align: left;
  padding: 0 14px;
}

.nav-tab.active {
  background: #fff;
  color: var(--brand-dark);
  border-color: #fff;
  font-weight: 700;
}

.period-panel {
  margin-top: auto;
  display: grid;
  gap: 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.period-panel label {
  color: #d8e7f2;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 11px;
}

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

.view {
  display: none;
}

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

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

h2,
h3 {
  margin: 0;
}

h2 {
  font-size: 28px;
  line-height: 1.2;
}

h3 {
  font-size: 17px;
}

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

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

.metric-card {
  min-height: 104px;
  padding: 18px;
  display: grid;
  align-content: space-between;
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

.table-panel {
  overflow: hidden;
}

.panel-heading {
  min-height: 56px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

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

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

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child,
td:nth-child(2),
th:nth-child(2) {
  text-align: left;
}

th {
  background: #e6eef5;
  color: #213547;
  font-size: 13px;
}

tbody tr:hover {
  background: #f8fbfd;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr)) auto;
  gap: 12px;
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.compact-form {
  grid-template-columns: repeat(4, minmax(140px, 1fr)) auto;
}

.wide-field {
  min-width: 220px;
}

.primary-button,
.text-button,
.danger-icon {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 800;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.text-button {
  background: #fff;
  color: var(--brand);
  border-color: var(--line);
}

.text-button.danger,
.danger-icon {
  color: var(--danger);
}

.danger-icon {
  width: 38px;
  padding: 0;
  background: #fff;
  border-color: var(--line);
}

.rules-layout {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 16px;
}

.rules-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.rule-row {
  display: grid;
  grid-template-columns: minmax(80px, 1fr) minmax(90px, 0.8fr) minmax(90px, 0.8fr);
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.rule-row.four {
  grid-template-columns: minmax(80px, 1fr) minmax(80px, 0.8fr) minmax(90px, 0.8fr) minmax(90px, 0.8fr);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 74px;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.status-good {
  background: #e5f7ee;
  color: #176548;
}

.status-warn {
  background: #fff3d8;
  color: #8a5a00;
}

.empty-row {
  color: var(--muted);
  text-align: center;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 14px;
  }

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

  .nav-tab {
    text-align: center;
    padding: 0 8px;
  }

  .period-panel {
    margin-top: 0;
    grid-template-columns: 1fr 1fr;
  }

  .main {
    padding: 18px;
  }

  .metrics-grid,
  .rules-layout {
    grid-template-columns: 1fr 1fr;
  }

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

  .wide-field {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .brand {
    align-items: flex-start;
  }

  .nav-tabs,
  .metrics-grid,
  .rules-layout,
  .form-grid,
  .compact-form {
    grid-template-columns: 1fr;
  }

  .period-panel {
    grid-template-columns: 1fr 1fr;
  }

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

  h2 {
    font-size: 24px;
  }

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