:root {
  --font: "IBM Plex Sans", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --radius: 10px;
  --worker: #8b6914;
  --assets: #2563eb;
  --queues: #15803d;
  --pages: #0f766e;
  --kv: #7c3aed;
  --d1: #16a34a;
  --r2: #e11d48;
  --hatch: repeating-linear-gradient(-45deg, #d4d4d8 0 2px, #e4e4e7 2px 6px);
}

html[data-theme="light"] {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --text: #18181b;
  --muted: #71717a;
  --line: #e4e4e7;
  --soft: #f4f4f5;
  --accent: #18181b;
  --warn: #a16207;
  --warn-bg: #fef9c3;
  --warn-border: #fde047;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --shadow: 0 1px 2px rgba(24, 24, 27, 0.04), 0 8px 24px rgba(24, 24, 27, 0.04);
}

html[data-theme="dark"] {
  --bg: #09090b;
  --panel: #18181b;
  --text: #fafafa;
  --muted: #a1a1aa;
  --line: #27272a;
  --soft: #1f1f23;
  --accent: #fafafa;
  --warn: #fde047;
  --warn-bg: #422006;
  --warn-border: #854d0e;
  --danger: #fca5a5;
  --danger-bg: #450a0a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 28px rgba(0, 0, 0, 0.28);
  --hatch: repeating-linear-gradient(-45deg, #3f3f46 0 2px, #27272a 2px 6px);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 1120px; margin: 0 auto; padding: 20px 24px 56px; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.mark {
  width: 32px; height: 32px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--text); color: var(--bg);
  font-weight: 700; font-size: 12px; letter-spacing: -0.04em;
}
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -0.02em; }
.brand-sub { font-size: 12px; color: var(--muted); }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  appearance: none; font: inherit; font-size: 13px; font-weight: 600;
  border-radius: 8px; border: 1px solid var(--line); background: var(--panel);
  color: var(--text); padding: 8px 12px; cursor: pointer;
}
.btn.ghost:hover { background: var(--soft); }
.btn.link {
  border: 0; background: transparent; color: var(--muted); padding: 4px 6px;
  opacity: 0; pointer-events: none; transition: opacity 120ms var(--ease);
}
.row:hover .btn.link, .row:focus-within .btn.link { opacity: 1; pointer-events: auto; }
.btn.link:hover { color: var(--text); }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.layout-wrap, .sort-wrap {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--muted); font-weight: 600;
}
.layout-wrap select, .sort-wrap select {
  height: 38px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: inherit; font-size: 13px; padding: 0 10px;
  max-width: 180px;
}

.group-empty {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 18px;
  color: var(--muted);
  font-size: 13px;
  background: var(--panel);
  text-align: center;
}
body.editing .group-empty {
  border-color: #93c5fd;
  background: color-mix(in srgb, #eff6ff 70%, var(--panel));
}
.group-actions { display: flex; gap: 6px; align-items: center; }
.group-actions .btn {
  padding: 4px 8px;
  font-size: 12px;
}
h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.2;
}
.sub { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

.banner {
  margin-bottom: 14px; padding: 10px 12px; border-radius: 8px;
  font-size: 13px; font-weight: 500;
}
.banner.error { background: var(--danger-bg); color: var(--danger); }
.banner.edit {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}
html[data-theme="dark"] .banner.edit {
  background: #172554;
  color: #93c5fd;
  border-color: #1e3a8a;
}

body.editing .sort-wrap { opacity: 0.45; pointer-events: none; }
body.editing .row { cursor: grab; }
body.editing .row.dragging { opacity: 0.45; }
body.editing .group.drag-over > .grid,
body.editing .group.drag-over {
  outline: 2px dashed #60a5fa;
  outline-offset: 2px;
  border-radius: 10px;
}
body.editing .row-actions .btn.link { opacity: 1; pointer-events: auto; }

.grip {
  display: none;
  color: var(--muted);
  font-size: 14px;
  cursor: grab;
  user-select: none;
  padding: 0 2px;
}
body.editing .grip { display: inline-flex; }

.group-title-btn, .group-title-input, .tile-title-btn, .tile-title-input {
  font: inherit;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text);
  background: transparent;
  border: 0;
  padding: 0;
}
.group-title-btn, .tile-title-btn { cursor: text; text-align: left; }
.tile-title-btn {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}
body.editing .group-title-btn,
body.editing .tile-title-btn {
  border-bottom: 1px dashed var(--line);
  padding-bottom: 1px;
}
.group-title-input, .tile-title-input {
  border: 1px solid #60a5fa;
  border-radius: 6px;
  padding: 2px 8px;
  background: var(--panel);
  min-width: 120px;
  max-width: 100%;
}
.tile-title-input {
  font-size: 13px;
  flex: 1;
  min-width: 0;
}

.hide-btn {
  display: none;
  appearance: none;
  border: 0;
  background: var(--soft);
  color: var(--muted);
  width: 22px;
  height: 22px;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  margin-left: 4px;
}
body.editing .hide-btn { display: inline-flex; align-items: center; justify-content: center; }
.hide-btn:hover { background: var(--danger-bg); color: var(--danger); }

.hidden-panel {
  margin-bottom: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.hidden-panel h3 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.hidden-list { display: flex; flex-wrap: wrap; gap: 8px; }
.hidden-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  background: var(--soft);
}
.hidden-chip button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
}

.btn.active-edit {
  background: var(--text);
  color: var(--bg);
  border-color: transparent;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat.clickable { cursor: pointer; text-align: left; width: 100%; font: inherit; color: inherit; }
.stat.clickable.open, .stat.clickable:hover { border-color: var(--warn-border); background: var(--warn-bg); }
.stat .label {
  font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em;
  display: flex; justify-content: space-between; align-items: center;
}
.stat .value {
  margin-top: 6px; font-size: 28px; font-weight: 700;
  letter-spacing: -0.04em; font-variant-numeric: tabular-nums; line-height: 1;
}
.stat .chev { font-size: 12px; color: var(--muted); }

.warnings-panel {
  margin-bottom: 14px;
  border: 1px solid var(--warn-border);
  background: var(--warn-bg);
  border-radius: var(--radius);
  padding: 12px 14px;
  color: var(--warn);
}
.warnings-panel h3 {
  margin: 0 0 8px; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.05em; font-weight: 700;
}
.warnings-panel ul { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.55; }
.warnings-panel code { font-family: var(--mono); font-size: 12px; }

.coverage {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.coverage-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  margin-bottom: 10px;
}
.coverage-head h2 { margin: 0; font-size: 13px; font-weight: 650; }
.coverage-head p { margin: 0; font-size: 12px; color: var(--muted); }
.coverage-bar {
  display: flex; height: 14px; border-radius: 999px; overflow: hidden;
  background: var(--soft); border: 1px solid var(--line);
}
.coverage-bar .seg {
  height: 100%; min-width: 2px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 9px; font-weight: 700;
}
.coverage-bar .seg.missing { background: var(--hatch); color: transparent; }
.coverage-missing { margin: 8px 0 0; font-size: 12px; color: var(--muted); }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-bottom: 18px;
}
.search-wrap { flex: 1 1 220px; }
.search-wrap input {
  width: 100%; height: 38px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); padding: 0 12px; font: inherit; font-size: 13px;
}
.seg {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 3px;
}
.seg-label { font-size: 12px; color: var(--muted); padding: 0 8px; font-weight: 600; }
.seg-btn {
  appearance: none; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: 13px; font-weight: 600; padding: 7px 10px;
  border-radius: 6px; cursor: pointer;
}
.seg-btn.active { background: var(--soft); color: var(--text); }
.sort-wrap {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--muted); font-weight: 600;
}
.sort-wrap select {
  height: 38px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: inherit; font-size: 13px; padding: 0 10px;
}

.group { margin-bottom: 22px; }
.group-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px; margin-bottom: 8px;
}
.group-head h2 {
  margin: 0; font-size: 14px; font-weight: 650; letter-spacing: -0.01em;
  display: flex; align-items: center; gap: 8px;
}
.group-count {
  font-size: 12px; font-weight: 600; color: var(--muted);
  background: var(--soft); border-radius: 999px; padding: 2px 8px;
}
.locked-note {
  border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 12px 14px; color: var(--muted); font-size: 13px; background: var(--panel);
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.row {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 72px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 120ms var(--ease), box-shadow 120ms var(--ease);
}
.row:hover { border-color: #a1a1aa; box-shadow: var(--shadow); }
.row-top {
  display: flex; align-items: center; gap: 8px; min-width: 0;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  display: inline-block;
}
.dot.fresh { background: #16a34a; }
.dot.aging { background: #a16207; }
.dot.stale { background: #a1a1aa; }
.row-name {
  font-size: 13px; font-weight: 650; letter-spacing: -0.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.row-time {
  margin-left: auto; font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.env {
  font-size: 10px; font-weight: 600; color: var(--muted);
  background: var(--soft); border-radius: 999px; padding: 1px 6px;
  flex-shrink: 0;
}
.row-desc {
  margin: 0; font-size: 12px; color: var(--muted); line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.row-actions {
  position: absolute; right: 8px; bottom: 8px;
  display: flex; gap: 2px;
}

.legend {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: center;
  margin-top: 8px; font-size: 12px; color: var(--muted);
}
.legend .dot { margin-right: 4px; }
.muted { color: var(--muted); }

/* Login */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel {
  width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 24px; box-shadow: var(--shadow);
}
.login-panel h1 { font-size: 22px; margin: 16px 0 6px; }
.login-panel .lede { margin: 0; color: var(--muted); font-size: 13px; }
.login-panel form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.login-panel label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.login-panel input {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px;
}
.btn.primary {
  background: var(--text); color: var(--bg); border-color: transparent; width: 100%; padding: 11px 14px;
}
.form-error { margin: 0; color: var(--danger); font-size: 13px; font-weight: 600; }

@media (max-width: 960px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .app { padding: 16px; }
  .grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .row:hover .btn.link, .row .btn.link { opacity: 1; pointer-events: auto; }
}
