:root {
  color-scheme: light;
  --ink: #1d252c;
  --muted: #6b7280;
  --line: #d9dee5;
  --paper: #ffffff;
  --wash: #f4f6f8;
  --sidebar: #20262d;
  --teal: #0f766e;
  --teal-weak: #d8f3ef;
  --amber: #b7791f;
  --amber-weak: #fff1cc;
  --rose: #be3b4a;
  --rose-weak: #ffe1e5;
  --green: #2f7d4f;
  --green-weak: #daf4e4;
  --blue: #2b5c9d;
  --shadow: 0 10px 28px rgba(29, 37, 44, 0.08);
  font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--wash);
  color: var(--ink);
}

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

button,
a.link-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.primary {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
}

.secondary,
a.secondary {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.ghost {
  background: transparent;
  color: inherit;
  border-color: rgba(255, 255, 255, 0.18);
}

.sidebar .ghost {
  color: #dfe6ee;
}

.danger {
  color: #ffd4d9;
}

.hidden {
  display: none !important;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.14), transparent 34%),
    linear-gradient(315deg, rgba(190, 59, 74, 0.1), transparent 28%),
    #f7f8fa;
}

.auth-panel {
  width: min(100%, 420px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

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

.brand-mark.compact {
  color: #fff;
  padding: 20px 18px 8px;
}

.mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 800;
  background: var(--teal);
  color: #fff;
  flex: 0 0 auto;
}

.compact .mark {
  width: 36px;
  height: 36px;
  background: #f2c14e;
  color: #1f2933;
}

.eyebrow,
.muted {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.compact .eyebrow {
  color: #b9c2ce;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: 32px;
}

h2 {
  font-size: 26px;
}

h3 {
  font-size: 16px;
}

.auth-copy {
  margin: 18px 0 22px;
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: #374151;
  font-size: 13px;
}

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

input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.form-message,
.toast {
  margin: 14px 0 0;
  min-height: 22px;
  color: var(--rose);
}

.toast {
  position: sticky;
  top: 12px;
  z-index: 10;
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--teal);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  color: var(--ink);
}

.toast.error {
  border-left-color: var(--rose);
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
}

.tabs {
  display: grid;
  gap: 6px;
  padding: 18px 12px;
}

.tab {
  width: 100%;
  justify-content: flex-start;
  color: #dfe6ee;
  background: transparent;
  border-color: transparent;
}

.tab.active,
.tab:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding: 14px 12px 18px;
}

.workspace {
  min-width: 0;
  padding: 26px;
}

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

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.view {
  display: none;
}

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

.layout {
  display: grid;
  gap: 18px;
}

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

.layout.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(29, 37, 44, 0.03);
  padding: 18px;
  min-width: 0;
}

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

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

.metric {
  background: #fff;
  border: 1px solid var(--line);
  border-top: 4px solid var(--teal);
  border-radius: 8px;
  padding: 14px;
  min-height: 96px;
}

.metric:nth-child(2) {
  border-top-color: var(--blue);
}

.metric:nth-child(3) {
  border-top-color: var(--amber);
}

.metric:nth-child(4) {
  border-top-color: var(--rose);
}

.metric:nth-child(5) {
  border-top-color: var(--green);
}

.metric p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  font-size: 26px;
  line-height: 1.1;
}

.metric span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

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

.bar-row {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) minmax(80px, 2fr) 64px;
  align-items: center;
  gap: 12px;
}

.bar-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

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

.bar-fill {
  height: 100%;
  min-width: 2px;
  background: var(--teal);
}

.bar-row:nth-child(2n) .bar-fill {
  background: var(--blue);
}

.bar-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.watch-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.watch-item strong {
  display: block;
  overflow-wrap: anywhere;
}

.watch-item span {
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.table-wrap.short {
  max-height: 340px;
}

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

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

th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  z-index: 1;
  color: #4b5563;
  font-weight: 700;
}

td {
  color: #29323a;
}

tbody tr:last-child td {
  border-bottom: 0;
}

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

.action-cell {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.search {
  max-width: 280px;
}

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

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

.span {
  grid-column: 1 / -1;
}

.check {
  display: flex;
  align-items: center;
  gap: 9px;
}

.check input {
  width: 18px;
  min-height: 18px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.pill.green {
  color: var(--green);
  background: var(--green-weak);
}

.pill.yellow {
  color: var(--amber);
  background: var(--amber-weak);
}

.pill.red,
.pill.expired {
  color: var(--rose);
  background: var(--rose-weak);
}

.pill.neutral {
  color: #4b5563;
  background: #eef2f7;
}

.batch-link {
  padding: 0;
  min-height: auto;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--blue);
  text-decoration: underline;
}

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

.api-grid a {
  display: flex;
  align-items: center;
  min-height: 64px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  background: #fff;
}

.empty {
  padding: 18px;
  color: var(--muted);
}

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

  .layout.three,
  .layout.two {
    grid-template-columns: 1fr;
  }

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

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

  .sidebar {
    position: relative;
    height: auto;
    display: block;
  }

  .brand-mark.compact {
    padding: 12px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }

  .tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 8px 10px;
  }

  .tab {
    min-width: 72px;
    min-height: 36px;
    justify-content: center;
  }

  .sidebar-footer {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 0;
    padding: 8px 10px 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }

  .workspace {
    padding: 18px;
  }

  .topbar {
    display: grid;
  }

  .actions {
    justify-content: stretch;
  }

  .actions > * {
    flex: 1;
  }

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

  .bar-row {
    grid-template-columns: minmax(0, 1fr) 74px;
  }

  .bar-track {
    grid-column: 1 / -1;
    order: 3;
  }
}
