/* Coda Control Room — Howling Whispers visual identity.
   Tokens mirror the roleplay app (app/globals.css :root). */

:root {
  --ink: #0b0a0d;
  --shadow: #141018;
  --panel: #1c1518;
  --raised: #24191a;
  --copper: #b7653f;
  --copper-bright: #d78a5e;
  --gold: #cfa15e;
  --cream: #f2dec2;
  --body: #cbb89d;
  --muted: #8f8284;
  --rune: #45b8b3;
  --line: rgba(183, 101, 63, 0.44);
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: "Inter", system-ui, sans-serif;

  --ok: #6fbf73;
  --warn: #d9a441;
  --danger: #d2603f;
  --info: var(--rune);
}

* { box-sizing: border-box; }

html { background: var(--ink); }

body {
  margin: 0;
  background: var(--ink);
  color: var(--cream);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
}

.app { min-height: 100svh; }

/* ---------- shared elements ---------- */

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--cream);
  padding: 9px 16px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  transition: background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}
.btn:hover { background: var(--raised); border-color: var(--copper-bright); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-gold {
  background: var(--gold);
  border-color: var(--gold);
  color: #21160d;
}
.btn-gold:hover { background: #d8b071; border-color: #d8b071; }

.btn-discord {
  background: #5865f2;
  border-color: #5865f2;
  color: #fff;
  width: 100%;
  justify-content: center;
}
.btn-discord:hover { background: #6b76f5; border-color: #6b76f5; }

.btn-danger {
  background: transparent;
  border-color: rgba(210, 96, 63, 0.6);
  color: var(--danger);
}
.btn-danger:hover { background: rgba(210, 96, 63, 0.12); }

.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }

.link-btn {
  background: none;
  border: none;
  color: var(--copper-bright);
  padding: 0;
  text-decoration: underline;
  font-size: inherit;
}
.link-btn:hover { color: var(--cream); }

.input, .textarea, select.input {
  width: 100%;
  background: var(--shadow);
  border: 1px solid var(--line);
  color: var(--cream);
  padding: 9px 12px;
  border-radius: 8px;
  font: inherit;
}
.input:focus, .textarea:focus {
  outline: none;
  border-color: var(--copper-bright);
}
.textarea { min-height: 110px; resize: vertical; font-family: ui-monospace, monospace; font-size: 13px; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; color: var(--body); margin-bottom: 6px; font-size: 12px; letter-spacing: 0.04em; }

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--body);
  font-size: 12px;
  letter-spacing: 0.03em;
}
.pill.ok { color: var(--ok); border-color: rgba(111, 191, 115, 0.5); }
.pill.warn { color: var(--warn); border-color: rgba(217, 164, 65, 0.5); }
.pill.danger { color: var(--danger); border-color: rgba(210, 96, 63, 0.5); }
.pill.info { color: var(--info); border-color: rgba(69, 184, 179, 0.5); }

.risk-low { color: var(--ok); }
.risk-medium { color: var(--warn); }
.risk-high { color: var(--danger); }
.risk-critical { color: #ff7a5c; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--raised);
  border: 1px solid var(--line);
  color: var(--cream);
  padding: 10px 18px;
  border-radius: 8px;
  z-index: 100;
  max-width: min(560px, 90vw);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
}
.toast.error { border-color: var(--danger); }

/* ---------- login / auth ---------- */

.auth-body {
  min-height: 100svh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1100px 500px at 78% -10%, rgba(183, 101, 63, 0.16), transparent 60%),
    radial-gradient(900px 460px at 12% 110%, rgba(69, 184, 179, 0.08), transparent 55%),
    var(--ink);
  padding: 32px;
}

.auth-center { width: min(420px, 100%); }

.brand { text-align: center; margin-bottom: 28px; }

.brand-glyph {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  display: grid;
  place-items: center;
  font-size: 30px;
  color: var(--gold);
  border: 1px solid var(--line);
  border-radius: 50%;
  box-shadow: 0 0 34px color-mix(in srgb, var(--gold) 20%, transparent);
}
.brand-glyph.small {
  width: 30px;
  height: 30px;
  font-size: 13px;
  margin: 0;
  box-shadow: none;
}

.brand-name {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 34px;
  margin: 0;
  color: var(--cream);
  letter-spacing: 0.02em;
}
.brand-tag { margin: 6px 0 0; color: var(--muted); font-size: 13px; letter-spacing: 0.06em; }

.login-panel {
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 26px;
  backdrop-filter: blur(6px);
}
.login-note { margin: 0 0 18px; color: var(--body); text-align: center; font-size: 13px; }
.login-msg { margin: 14px 0 0; text-align: center; font-size: 13px; }
.login-msg.ok { color: var(--ok); }
.login-msg.err { color: var(--danger); }

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

.shell-view { display: flex; min-height: 100svh; }

.sidebar {
  width: 224px;
  flex: none;
  background: var(--shadow);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100svh;
}

.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 16px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.sidebar-title { font-family: var(--serif); font-size: 20px; line-height: 1; color: var(--cream); }
.sidebar-sub { font-size: 11px; color: var(--muted); letter-spacing: 0.08em; margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--body);
  text-align: left;
  padding: 9px 12px;
  border-radius: 8px;
  font-weight: 500;
  transition: background 120ms ease, color 120ms ease;
}
.nav-btn:hover { background: var(--panel); color: var(--cream); }
.nav-btn[data-active] { background: var(--panel); color: var(--gold); border-color: var(--line); }

.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 12px 6px 0; border-top: 1px solid var(--line); }
.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--raised);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--gold);
  font-weight: 700;
  overflow: hidden;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-name { color: var(--cream); font-weight: 600; font-size: 13px; }
.user-meta { display: flex; flex-direction: column; gap: 2px; }
.user-meta .link-btn { font-size: 12px; text-align: left; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--ink) 60%, transparent);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(4px);
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.view-title { font-family: var(--serif); font-weight: 500; font-size: 24px; margin: 0; }

.view-body { padding: 24px 28px 60px; max-width: 1240px; width: 100%; }

/* ---------- cards / grids ---------- */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
}
.card + .card { margin-top: 16px; }
.card-title { font-family: var(--serif); font-size: 18px; margin: 0 0 12px; color: var(--cream); }
.card-title .sub { color: var(--muted); font-family: var(--sans); font-size: 12px; font-weight: 400; margin-left: 8px; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
.stat-label { color: var(--muted); font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; }
.stat-value { font-family: var(--serif); font-size: 30px; margin-top: 4px; color: var(--cream); }
.stat-value.small { font-size: 22px; }
.stat-foot { color: var(--body); font-size: 12px; margin-top: 2px; }

.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, monospace; font-size: 12px; }
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }

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

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--shadow);
  white-space: nowrap;
}
td { padding: 10px 14px; border-bottom: 1px solid rgba(183, 101, 63, 0.16); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: color-mix(in srgb, var(--raised) 35%, transparent); }

/* ---------- overview dashboard ---------- */

.overview-rail { display: grid; grid-template-columns: 1.1fr 1fr; gap: 14px; align-items: start; }

.kv { display: grid; gap: 8px; }
.kv-item { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 5px 0; border-bottom: 1px solid rgba(183, 101, 63, 0.14); }
.kv-item:last-child { border-bottom: 0; }
.kv-key { color: var(--muted); font-size: 12px; letter-spacing: 0.04em; }
.kv-val { color: var(--cream); font-weight: 500; text-align: right; }

.mini-list { display: grid; gap: 4px; }
.mini-item { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 6px 2px; border-bottom: 1px solid rgba(183, 101, 63, 0.12); }
.mini-item:last-child { border-bottom: 0; }
.mini-item .mini-main { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--cream); }
.mini-item .pill { flex: none; font-size: 11px; padding: 2px 8px; }
.pill-echo { background: var(--shadow); border-radius: 6px; padding: 1px 6px; font-size: 11px; }

.scroll-panel { max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.scroll-panel .table-wrap { border: none; border-radius: 0; }

@media (max-width: 900px) {
  .overview-rail { grid-template-columns: 1fr; }
}

/* ---------- plan detail / actions ---------- */

.action-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--shadow);
  padding: 12px 14px;
  margin-top: 8px;
}
.action-item:first-of-type { margin-top: 0; }
.action-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.action-type { font-family: ui-monospace, monospace; color: var(--gold); font-size: 12px; }
.action-meta { color: var(--muted); font-size: 12px; }

.issue {
  border-left: 3px solid var(--warn);
  background: var(--shadow);
  padding: 8px 12px;
  margin-top: 8px;
  border-radius: 0 8px 8px 0;
  font-size: 13px;
}
.issue.err { border-left-color: var(--danger); }
.issue.ok { border-left-color: var(--ok); }
.issue-code { color: var(--muted); font-family: ui-monospace, monospace; font-size: 11px; }

.channel-tree { display: flex; flex-direction: column; gap: 6px; }
.tree-category { border: 1px solid var(--line); border-radius: 10px; background: var(--shadow); padding: 10px 12px; }
.tree-cat-name { color: var(--cream); font-family: var(--serif); font-size: 16px; display: flex; justify-content: space-between; }
.tree-children { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.tree-child { display: flex; justify-content: space-between; color: var(--body); font-size: 13px; padding: 2px 4px; }
.tree-child .type { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }

/* ---------- filters ---------- */

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.filters .input { width: auto; min-width: 150px; }
.filters .input.small { min-width: 110px; }

.empty {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 26px;
  text-align: center;
  color: var(--muted);
}

.divider { border: none; border-top: 1px solid var(--line); margin: 18px 0; }

@media (max-width: 860px) {
  .shell-view { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .nav { flex-direction: row; overflow-x: auto; flex: 1; }
  .sidebar-user { border-top: none; padding: 0 6px; }
  .grid-4, .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .grid-2, .grid-4, .grid-3 { grid-template-columns: 1fr; }
  .view-body { padding: 16px; }
  .topbar { padding: 14px 16px; }
}