:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #dfe4ea;
  --text: #1f2933;
  --muted: #61707f;
  --accent: #1d6fb8;
  --accent-dark: #155a96;
  --ok: #1f8a4c;
  --warn: #b7791f;
  --err: #c53030;
  --sidebar: #101b26;
  --sidebar-text: #c8d3de;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--err); min-height: 20px; }
code {
  background: #eef2f5;
  padding: 1px 5px;
  border-radius: 4px;
  font: 12px/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace;
}

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  box-shadow: 0 18px 50px rgba(16, 27, 38, .12);
}
.login-card h1 { margin: 0 0 8px; font-size: 22px; }
.login-card p { margin: 0 0 18px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; margin-bottom: 14px; }
.login-card button { width: 100%; }

/* shell */
.app { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { font-weight: 600; font-size: 16px; color: #fff; display: flex; align-items: center; gap: 8px; margin-bottom: 22px; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: #48c78e; }
nav { display: grid; gap: 2px; }
nav button {
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--sidebar-text);
  padding: 9px 12px;
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
}
nav button:hover { background: rgba(255, 255, 255, .07); }
nav button.active { background: var(--accent); color: #fff; }
.sidebar-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; }
.badge { padding: 2px 8px; border-radius: 10px; background: rgba(72, 199, 142, .16); color: #7ee2b0; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
.sidebar .link { color: var(--sidebar-text); text-decoration: underline; }

main { padding: 22px 26px 40px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.topbar h1 { margin: 0; font-size: 20px; }

/* cards and panels */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 18px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: grid;
  gap: 4px;
}
.card span { color: var(--muted); font-size: 12px; }
.card strong { font-size: 24px; font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 16px; margin-bottom: 16px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
  overflow: auto;
}
.panel.narrow { max-width: 720px; }
.panel h2, .panel h3 { margin: 0 0 12px; font-size: 15px; }
.panel h3 { font-size: 13px; margin-top: 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.panel-head h2 { margin: 0; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td.mono, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.empty { color: var(--muted); padding: 14px 0; }
.docs-table td { vertical-align: top; }

/* badges */
.status { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; white-space: nowrap; }
.status.queued, .status.leased { background: #e8f0f8; color: var(--accent-dark); }
.status.processing { background: #fff4dd; color: var(--warn); }
.status.submitted, .status.online { background: #e3f4ea; color: var(--ok); }
.status.failed, .status.offline, .status.error { background: #fde8e8; color: var(--err); }
.status.unknown, .status.paused, .status.paper_out, .status.canceled { background: #eef2f5; color: var(--muted); }
.status.disabled { background: #eef2f5; color: var(--muted); }
.queue-state { font-size: 12px; color: var(--muted); white-space: nowrap; }
.queue-state.fault { color: var(--err); }
.queue-state.ok { color: var(--ok); }

/* forms */
button {
  padding: 8px 14px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  cursor: pointer;
}
button:hover { background: var(--accent-dark); }
button.secondary { background: #fff; color: var(--accent); }
button.secondary:hover { background: #eef5fb; }
button:disabled { opacity: .55; cursor: default; }
input, select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: #fff;
}
input:focus, select:focus { outline: 2px solid rgba(29, 111, 184, .22); border-color: var(--accent); }
label { display: grid; gap: 5px; font-size: 13px; }
label > span, label .muted { font-size: 12px; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.filters .row { grid-column: 1 / -1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .span-2 { grid-column: 1 / -1; }
label.checkbox { display: flex; align-items: center; gap: 8px; }
label.checkbox input { width: auto; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 12px; }

/* dialogs */
dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  width: min(640px, 94vw);
  box-shadow: 0 24px 70px rgba(16, 27, 38, .32);
}
dialog::backdrop { background: rgba(16, 27, 38, .38); }
dialog form, dialog .detail { padding: 22px; }
dialog h2 { margin: 0; font-size: 16px; }

/* code blocks */
pre.code {
  margin: 8px 0 18px;
  padding: 12px 14px;
  background: #0f1720;
  color: #d8e2ec;
  border-radius: 8px;
  overflow: auto;
  font: 12px/1.6 ui-monospace, "Cascadia Mono", Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

/* details */
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 12px; margin: 0 0 18px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.timeline { margin: 0; padding-left: 20px; }
.timeline li { margin-bottom: 8px; }
.timeline .when { color: var(--muted); font-size: 12px; margin-left: 6px; }

/* toast */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 420px;
  padding: 12px 16px;
  border-radius: 8px;
  background: #1f2933;
  color: #fff;
  box-shadow: 0 10px 30px rgba(16, 27, 38, .3);
  z-index: 50;
}
.toast.err { background: var(--err); }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .brand { margin: 0 12px 0 0; }
  nav { display: flex; flex-wrap: wrap; }
  .sidebar-foot { margin: 0; }
  main { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
}
