:root {
  --bg: #fbfaf8;
  --surface: #ffffff;
  --line: #e5e1da;
  --ink: #1c1a17;
  --muted: #6f6a62;
  --accent: #2f5d50;
  --accent-soft: #eaf1ee;
  --warn: #a8531c;
  --warn-soft: #fbf0e6;
  --danger: #9b2c2c;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16150f;
    --surface: #1f1e18;
    --line: #34322a;
    --ink: #f0ede6;
    --muted: #9d978c;
    --accent: #7fb3a1;
    --accent-soft: #24322c;
    --warn: #e0a678;
    --warn-soft: #33271c;
    --danger: #e08585;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }

/* The `hidden` attribute must beat any author `display` rule below.
   Without this, `.gate{display:grid}` and `.drawer{display:flex}` override the
   UA stylesheet's [hidden]{display:none}, leaving the login screen stuck on
   and the drawer overlay permanently covering the page. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 ui-sans-serif, -apple-system, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------------------ gate */

.gate {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 2.5rem;
  padding: 2rem;
}

.wordmark {
  font-size: clamp(2rem, 7vw, 3.25rem);
  font-weight: 400;
  letter-spacing: .22em;
  text-transform: uppercase;
  margin: 0;
  text-indent: .22em;
}
.wordmark.small {
  font-size: .95rem;
  letter-spacing: .18em;
  text-indent: .18em;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  width: min(300px, 85vw);
}

input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .6rem .75rem;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
textarea { min-height: 5rem; resize: vertical; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: .55rem .9rem;
  background: none;
  color: var(--ink);
}
button.primary { background: var(--accent); color: #fff; }
button.ghost { border-color: var(--line); }
button.danger { color: var(--danger); border-color: var(--line); }
button:hover { filter: brightness(1.06); }
button:disabled { opacity: .5; cursor: default; }

.error { color: var(--danger); font-size: .85rem; margin: 0; text-align: center; }

/* ---------------------------------------------------------------- shell */

.topbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: .75rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
  flex-wrap: wrap;
}
.tabs { display: flex; gap: .25rem; margin-right: auto; flex-wrap: wrap; }
.tab { color: var(--muted); padding: .4rem .7rem; }
.tab.is-active { background: var(--accent-soft); color: var(--accent); }

main#views { padding: 1.5rem 1.25rem 4rem; max-width: 1180px; margin: 0 auto; }
.view { display: none; }
.view.is-active { display: block; }

h2 { font-size: 1.05rem; font-weight: 600; margin: 1.75rem 0 .35rem; }
.hint { color: var(--muted); font-size: .85rem; margin: 0 0 .9rem; }

.toolbar { display: flex; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1; min-width: 180px; }
.toolbar select { width: auto; }

/* ---------------------------------------------------------------- stats */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: .75rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .9rem 1rem;
}
.stat .n { font-size: 1.6rem; font-weight: 600; }
.stat .l { color: var(--muted); font-size: .8rem; }
.stat.alert .n { color: var(--warn); }

/* --------------------------------------------------------------- tables */

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--line); }
th { font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--accent-soft); }
tbody tr:last-child td { border-bottom: 0; }
td.wrap { max-width: 30ch; white-space: normal; color: var(--muted); }

.pill {
  display: inline-block;
  padding: .12rem .5rem;
  border-radius: 999px;
  font-size: .75rem;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.mute { background: transparent; color: var(--muted); border: 1px solid var(--line); }

.empty { color: var(--muted); padding: 1.5rem; text-align: center; }

/* --------------------------------------------------------------- notes */

.note {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: .75rem;
  cursor: pointer;
}
.note:hover { border-color: var(--accent); }
.note h4 { margin: 0 0 .2rem; font-size: .95rem; }
.note .meta { color: var(--muted); font-size: .8rem; margin-bottom: .5rem; }
.note p { margin: 0; font-size: .9rem; }

/* -------------------------------------------------------------- drawer */

.drawer {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  display: flex;
  justify-content: flex-end;
  z-index: 20;
}
.drawer-panel {
  background: var(--bg);
  width: min(460px, 100vw);
  height: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}
.drawer-head, .drawer-foot {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .9rem 1.1rem;
  border-bottom: 1px solid var(--line);
}
.drawer-head h3 { margin: 0; font-size: 1rem; margin-right: auto; }
.drawer-foot { border-bottom: 0; border-top: 1px solid var(--line); margin-top: auto; }
.drawer-foot .primary { margin-left: auto; }
#drawer-form { padding: 1.1rem; overflow-y: auto; flex: 1; }
#drawer-form label { display: block; margin-bottom: .9rem; }
#drawer-form span { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .25rem; }

@media (max-width: 600px) {
  th, td { padding: .5rem .6rem; }
  td.wrap { display: none; }
}
