:root {
  color-scheme: light;
  --bg: #eef1ee;
  --surface: #ffffff;
  --surface-muted: #f7f8f6;
  --ink: #17201d;
  --muted: #5d6662;
  --line: #d8ded8;
  --primary: #126b4f;
  --primary-strong: #0d5340;
  --amber: #96590a;
  --amber-bg: #fff2da;
  --red: #a93126;
  --red-bg: #fbeae7;
  --blue: #295f88;
  --blue-bg: #e9f1f7;
  --green-bg: #e5f2ec;
  --neutral-bg: #edf0ed;
  --shadow: 0 14px 36px rgba(23, 32, 29, .13);
  --drawer-shadow: -18px 0 48px rgba(23, 32, 29, .18);
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--font);
  letter-spacing: 0;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
::selection { background: #c7e2d7; color: #17201d; }
:is(button, input, select):focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
:is(button, input, select):disabled { cursor: not-allowed; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { border: 2px solid var(--bg); border-radius: 999px; background: #b8c2bc; }
::-webkit-scrollbar-thumb:hover { background: #98a49e; }
::-webkit-scrollbar-track { background: var(--bg); }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(125deg, rgba(18, 107, 79, .12), transparent 36%),
    linear-gradient(315deg, rgba(150, 89, 10, .12), transparent 34%),
    var(--bg);
}

.login-panel {
  width: min(400px, 100%);
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-mark {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-bottom: 24px;
  font-size: 22px;
  font-weight: 750;
}

.login-mark span:first-child { color: var(--primary); }
.login-mark span:last-child {
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--ink);
  color: #fff;
}
.login-panel h1 { margin: 0 0 22px; font-size: 22px; }
.login-panel form { display: grid; gap: 16px; }
.login-panel button { width: 100%; justify-content: center; }

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 20px 12px;
  background: var(--ink);
  color: #e9efeb;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 750;
}

.brand-copy { font-size: 16px; font-weight: 700; }
.main-nav { display: grid; gap: 4px; }

.nav-item, .logout {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 9px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #c8d3cd;
  text-align: left;
}

.nav-item:hover, .logout:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.logout { margin-top: auto; color: #d9b9a7; }

.workspace-shell { min-width: 0; display: flex; flex-direction: column; }

.workspace-header {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 70px;
  padding: 14px 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(10px);
}

.workspace-name { margin: 0; font-size: 18px; font-weight: 700; }
.workspace-meta {
  display: flex;
  gap: 10px;
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}
.workspace-meta span:last-child { font-variant-numeric: tabular-nums; }
.header-actions { display: flex; align-items: center; gap: 10px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--neutral-bg);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}
.status-pill.ok { background: var(--green-bg); color: var(--primary); }
.status-pill.warn { background: var(--amber-bg); color: var(--amber); }
.status-pill.error { background: var(--red-bg); color: var(--red); }

.view-root {
  flex: 1;
  width: min(1460px, 100%);
  margin: 0 auto;
  padding: 24px 26px 44px;
  outline: none;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 16px;
}

.section-heading h2 { margin: 0; font-size: 19px; }
.section-heading p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.heading-actions { display: flex; gap: 8px; flex-wrap: wrap; }

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

.metric {
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric strong {
  display: block;
  margin-top: 7px;
  color: var(--ink);
  font-size: 23px;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.metric span { color: var(--muted); font-size: 12px; }

.layout-two {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 350px;
  gap: 16px;
  align-items: start;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.panel + .panel { margin-top: 16px; }
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 15px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-muted);
}
.panel-header h3 { margin: 0; font-size: 14px; }
.panel-header .count { color: var(--muted); font-size: 12px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}
th {
  position: sticky;
  top: 0;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}
td { font-variant-numeric: tabular-nums; }
tbody tr:hover { background: #f5f8f5; }
tbody tr:last-child td { border-bottom: 0; }
.cell-strong { font-weight: 650; }
.cell-muted { color: var(--muted); font-size: 12px; }
.wrap-cell { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
}
.badge.queued, .badge.claimed, .badge.submitting { background: var(--blue-bg); color: var(--blue); }
.badge.succeeded { background: var(--green-bg); color: var(--primary); }
.badge.failed { background: var(--red-bg); color: var(--red); }
.badge.submitted_unknown, .badge.reconciling { background: var(--amber-bg); color: var(--amber); }
.badge.created, .badge.authorized, .badge.cancelled, .badge.retry_scheduled { background: var(--neutral-bg); color: var(--muted); }

.button, .icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 34px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 620;
}
.button.primary { background: var(--primary); color: #fff; }
.button.primary:hover { background: var(--primary-strong); }
.button.ghost { border-color: var(--line); background: var(--surface); color: var(--ink); }
.button.ghost:hover { background: var(--surface-muted); }
.button.warning { background: var(--amber); color: #fff; }
.button.small { min-height: 29px; padding: 4px 9px; font-size: 12px; }
.button:disabled { opacity: .48; cursor: not-allowed; }
.icon-button { width: 36px; padding: 0; border-color: var(--line); background: var(--surface); color: var(--ink); }
.icon-button:hover { background: var(--surface-muted); }

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.toolbar input, .toolbar select {
  min-width: 150px;
  min-height: 34px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

.capacity-list { display: grid; }
.capacity-item { padding: 13px 15px; border-bottom: 1px solid var(--line); }
.capacity-item:last-child { border-bottom: 0; }
.capacity-top { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.capacity-top strong { font-size: 13px; }
.capacity-top span { color: var(--muted); font-size: 12px; }
.meter { height: 7px; border-radius: 99px; background: var(--neutral-bg); overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: inherit; background: var(--primary); }
.meter.high span { background: var(--amber); }

.empty-state { padding: 34px 16px; color: var(--muted); text-align: center; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 8;
  background: rgba(23, 32, 29, .38);
}

.drawer {
  position: fixed;
  z-index: 9;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(520px, 100%);
  overflow-y: auto;
  padding: 0;
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--drawer-shadow);
  animation: drawer-in .22s cubic-bezier(.2, .8, .2, 1);
}

@keyframes drawer-in {
  from { opacity: .72; transform: translateX(5%); }
  to { opacity: 1; transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
  .drawer { animation: none; }
}

.drawer-form, .detail-drawer {
  display: grid;
  gap: 16px;
  padding: 26px;
}
.drawer-form h2, .detail-drawer h2 { margin: 0; font-size: 20px; }
.drawer-form label, .field { display: grid; gap: 6px; }
.drawer-form label span, .field span { color: var(--muted); font-size: 12px; font-weight: 620; }
.drawer-form input, .drawer-form select {
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}
.drawer-form input:focus, .drawer-form select:focus, .toolbar input:focus, .toolbar select:focus {
  outline: 2px solid rgba(18,107,79,.28);
  border-color: var(--primary);
}
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.drawer-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.code-input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0; }

.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.detail-grid div { padding: 10px 11px; border-bottom: 1px solid var(--line); background: var(--surface-muted); }
.detail-grid div:nth-last-child(-n+2) { border-bottom: 0; }
.detail-grid span { display: block; color: var(--muted); font-size: 11px; }
.detail-grid strong { font-size: 13px; }
.event-list { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; }
.event-list li { padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.event-list li:last-child { border-bottom: 0; }
.event-list time { display: block; color: var(--muted); }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 12;
  max-width: min(420px, calc(100vw - 44px));
  padding: 12px 14px;
  border-top: 3px solid var(--primary);
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
}
.toast.error { border-top-color: var(--red); }

.skeleton-line {
  height: 12px;
  margin: 10px 15px;
  border-radius: 99px;
  background: linear-gradient(90deg, #e5eae6, #f4f6f3, #e5eae6);
}

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

@media (max-width: 780px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 9px;
  }
  .brand-copy, .main-nav span, .logout span { display: none; }
  .main-nav { grid-auto-flow: column; justify-content: start; }
  .logout { margin: 0 0 0 auto; }
  .nav-item, .logout { width: 40px; justify-content: center; padding: 0; }
  .workspace-header { padding: 11px 14px; }
  .workspace-meta span:last-child { display: none; }
  .view-root { padding: 14px 12px 32px; }
  .metric-grid, .field-grid, .detail-grid { grid-template-columns: 1fr; }
  .section-heading { align-items: start; flex-direction: column; }
  .drawer { width: 100%; }
}
