:root {
  --bg: #f4f6f6;
  --surface: #ffffff;
  --surface-2: #eef2f2;
  --border: #d5dcdc;
  --text: #16211f;
  --muted: #5d6b69;
  --brand: #00695c;
  --brand-text: #ffffff;
  --accent: #b85000;
  --danger: #b3261e;
  --ok: #1b7a3d;
  --warn: #9a6700;
  --code-bg: #f0f3f3;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101514;
    --surface: #18201f;
    --surface-2: #202a29;
    --border: #2f3c3a;
    --text: #e6eeec;
    --muted: #9aaba8;
    --brand: #4db6a6;
    --brand-text: #06201c;
    --accent: #ffb26b;
    --danger: #ff8a80;
    --ok: #7bd69a;
    --warn: #f0c060;
    --code-bg: #121918;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.muted { color: var(--muted); }
.error { color: var(--danger); }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 6px; padding: 10px; margin: 0; overflow: auto; max-height: 420px; white-space: pre-wrap; word-break: break-word; }

/* Layout */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100%; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px;
  display: flex; flex-direction: column; gap: 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { font-weight: 700; font-size: 17px; color: var(--text); text-decoration: none; padding: 0 8px; }
.brand span, .login-card h1 span { color: var(--brand); }
.tenant-picker { display: grid; gap: 4px; font-size: 12px; color: var(--muted); padding: 0 8px; }
nav { display: flex; flex-direction: column; gap: 1px; }
nav .group { margin: 10px 8px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
nav a {
  display: flex; justify-content: space-between; gap: 8px; padding: 6px 8px; border-radius: 6px;
  color: var(--text); text-decoration: none;
}
nav a:hover { background: var(--surface-2); }
nav a.active { background: var(--brand); color: var(--brand-text); }
nav a .count { font-variant-numeric: tabular-nums; opacity: .7; font-size: 12px; }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; padding: 8px; font-size: 13px; }
main { padding: 22px 26px 60px; min-width: 0; outline: none; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.page-head h1 { margin-right: auto; }
.page-head .sub { flex-basis: 100%; margin: -6px 0 0; color: var(--muted); }

/* Controls */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 9px; min-width: 0;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 1px;
}
button {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; cursor: pointer;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-text); font-weight: 600; }
button.danger { color: var(--danger); border-color: var(--danger); }
button.link { border: 0; background: none; padding: 0; color: var(--brand); text-align: left; }
button:disabled { opacity: .5; cursor: default; }
label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
label input, label select, label textarea { color: var(--text); font-size: 14px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 12px; }
.toolbar .grow { flex: 1 1 220px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; align-items: end; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.checks label { display: flex; gap: 6px; align-items: center; color: var(--text); font-size: 13px; }

/* Surfaces */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.card > h2 { margin-bottom: 10px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; text-decoration: none; color: var(--text); display: block; }
a.stat:hover { border-color: var(--brand); }
.stat .n { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12px; }
.cols { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 14px; align-items: start; }
.cols > div > .card:first-child { margin-top: 0; }
@media (max-width: 1000px) { .cols { grid-template-columns: 1fr; } }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.wrap { white-space: normal; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 10px; color: var(--muted); }

/* Key/value detail */
dl.kv { display: grid; grid-template-columns: minmax(120px, max-content) minmax(0, 1fr); gap: 6px 14px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 12.5px; padding-top: 1px; }
dl.kv dd { margin: 0; word-break: break-word; white-space: pre-wrap; }

/* Badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; border: 1px solid currentColor; white-space: nowrap; }
.badge.ok { color: var(--ok); }
.badge.warn { color: var(--warn); }
.badge.bad { color: var(--danger); }
.badge.info { color: var(--brand); }
.badge.dim { color: var(--muted); }

/* Schedule */
.day { margin-top: 18px; }
.day > h2 { margin-bottom: 8px; }
.task-row {
  display: grid; grid-template-columns: 110px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 6px;
  text-decoration: none; color: var(--text);
}
.task-row:hover { border-color: var(--brand); }
.task-row .when { font-variant-numeric: tabular-nums; color: var(--muted); }
.task-row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-row .meta { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-row .tags { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* Timeline, notes, chat */
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.timeline li { border-left: 2px solid var(--border); padding-left: 10px; }
.timeline .head { font-size: 12.5px; color: var(--muted); }
.chat { display: grid; gap: 8px; }
.bubble { background: var(--surface-2); border-radius: 10px; padding: 8px 12px; max-width: 720px; }
.bubble .head { font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.bubble .body { white-space: pre-wrap; word-break: break-word; }
.thumbs { display: flex; flex-wrap: wrap; gap: 10px; }
.thumb { width: 150px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); text-decoration: none; color: var(--text); font-size: 12px; }
.thumb img, .thumb video { display: block; width: 100%; height: 100px; object-fit: cover; background: #000; }
.thumb .ph { height: 100px; display: grid; place-items: center; font-size: 12px; color: var(--muted); }
.thumb .cap { padding: 5px 7px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview img, .preview video { max-width: 100%; max-height: 420px; border-radius: 8px; border: 1px solid var(--border); }
.signature { background: #fff; border: 1px solid var(--border); border-radius: 6px; max-width: 320px; width: 100%; height: auto; display: block; }
.secret { background: var(--code-bg); border: 1px dashed var(--accent); border-radius: 8px; padding: 12px; margin-top: 10px; }
.secret code { font-size: 14px; word-break: break-all; user-select: all; }

/* Login, drawer, toast */
.login { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.login-card { width: 340px; display: grid; gap: 12px; }
.drawer { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; justify-content: flex-end; z-index: 10; }
.drawer-panel { background: var(--bg); width: min(680px, 100%); height: 100%; overflow-y: auto; padding: 18px 20px 40px; box-shadow: -8px 0 30px rgba(0, 0, 0, .25); }
.drawer-panel header { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; }
.drawer-panel header h2 { word-break: break-all; }
.drawer-panel header button { font-size: 18px; color: var(--text); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px; z-index: 20; max-width: 90vw; }
.toast.bad { background: var(--danger); color: #fff; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  nav { flex-direction: row; flex-wrap: wrap; }
  nav .group { flex-basis: 100%; }
  main { padding: 16px 14px 60px; }
  .task-row { grid-template-columns: 1fr; gap: 4px; }
  .task-row .tags { justify-content: flex-start; }
}
