:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e2e5ea;
  --text: #16181d;
  --muted: #667085;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --add: #15803d;
  --add-bg: #ecfdf3;
  --remove: #b42318;
  --remove-bg: #fef3f2;
  --warn: #b54708;
  --warn-bg: #fffaeb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1f232b;
    --border: #2b3039;
    --text: #e8eaee;
    --muted: #98a2b3;
    --accent: #4f8cff;
    --add: #4ade80;
    --add-bg: #10291a;
    --remove: #f97066;
    --remove-bg: #2d1412;
    --warn: #fdb022;
    --warn-bg: #2b2108;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--remove); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; }
.top nav { display: flex; gap: 4px; }
.top nav a { padding: 6px 10px; border-radius: 8px; color: var(--muted); }
.top nav a.active, .top nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.top-right form { margin: 0; }

.view { max-width: 1200px; margin: 0 auto; padding: 20px; }
.banner { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; background: var(--warn-bg); color: var(--warn); border: 1px solid currentColor; }

/* ---------- controls ---------- */
.btn {
  appearance: none; cursor: pointer;
  padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--remove); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.small { padding: 3px 8px; font-size: 12px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { width: auto; }
input[type=color] { padding: 2px; height: 34px; width: 48px; }
label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.row > * { flex: 1 1 160px; }
.row > .shrink { flex: 0 0 auto; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .grow { flex: 1 1 220px; }
.spacer { flex: 1; }

/* ---------- cards / tables ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.head h1 { margin: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.removed td { opacity: .55; text-decoration: line-through; }
td select { min-width: 140px; }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--surface-2); white-space: nowrap; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; }
.pill.planning { color: var(--muted); }
.pill.deployed { background: var(--add-bg); color: var(--add); }
.pill.returned { color: var(--muted); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pills { display: flex; flex-wrap: wrap; gap: 4px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- plan ---------- */
.plan-op { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; }
.plan-op.add { background: var(--add-bg); border-color: transparent; }
.plan-op.remove { background: var(--remove-bg); border-color: transparent; }
.plan-op .kind { font-weight: 700; }
.plan-op.add .kind { color: var(--add); }
.plan-op.remove .kind { color: var(--remove); }
.plan-op ul { margin: 6px 0 0; padding-left: 18px; }
.notice { padding: 8px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--warn); margin-bottom: 8px; }

/* ---------- blueprint picker ---------- */
.bp-list { display: grid; gap: 4px; max-height: 320px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 8px; }
.bp-list label { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; }

/* ---------- dialog / toast ---------- */
dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(680px, calc(100vw - 32px)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
.dlg-body { padding: 18px; max-height: 70vh; overflow: auto; }
.dlg-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--border); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); padding: 10px 16px; border-radius: 10px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); max-width: calc(100vw - 32px); z-index: 20; }
.toast.err { background: var(--remove); color: #fff; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: grid; gap: 12px; }

@media (max-width: 640px) {
  .view { padding: 16px; }
  .top { padding: 10px 16px; gap: 10px; }
  .top-right { margin-left: 0; width: 100%; }
  #sync-info { display: none; }
}
