:root {
  --black: #16130f;
  --black-2: #1d1a14;
  --sidebar: #17140f;
  --gold: #c9a24b;
  --gold-soft: #e8d9ae;
  --gold-dim: #8a7134;
  --bg: #f5f3ee;
  --card: #ffffff;
  --line: #e7e2d6;
  --ink: #211d17;
  --muted: #756f60;
  --danger: #a33636;
  --danger-bg: #fbeaea;
  --warn: #bf9000;
  --warn-bg: #fff7e0;
  --ok: #3c8a45;
  --ok-bg: #eaf6ec;
  --info: #1f3864;
  --info-bg: #eef3fb;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}

a { color: inherit; }

.app-shell {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: #efe9da;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 10px 8px 22px;
  border-bottom: 1px solid rgba(201,162,75,0.25);
  margin-bottom: 18px;
}

.brand .brand-logo {
  width: 100%;
  max-width: 200px;
  height: auto;
  display: block;
}

.brand .brand-tag {
  font-size: 12px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--gold-soft);
  font-weight: 700;
  text-align: center;
}
.brand .brand-tag span {
  display: block;
  margin-top: 3px;
  font-size: 10.3px;
  letter-spacing: .04em;
  text-transform: none;
  color: #a49c86;
  font-weight: 400;
}

.nav-group { margin-bottom: 18px; }
.nav-group .label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em;
  color: #8a8271; padding: 0 10px; margin-bottom: 6px;
}
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 9px; text-decoration: none;
  color: #d9d2bf; font-size: 13.3px; margin-bottom: 2px;
}
.nav-link:hover { background: rgba(255,255,255,0.06); }
.nav-link.active { background: rgba(201,162,75,0.16); color: #f3e8c8; font-weight: 600; }
.nav-link .badge-count {
  margin-left: auto; background: var(--gold); color: #17140f; border-radius: 999px;
  font-size: 10.5px; font-weight: 700; padding: 1px 7px;
}

.sidebar-foot {
  margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(201,162,75,0.2);
  font-size: 12px; color: #a49c86;
}

.main {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 14px 28px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 18px; margin: 0; color: var(--black); }
.topbar .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--gold);
  color: #17140f; display:flex; align-items:center; justify-content:center; font-weight:700; font-size:13px;
}
.user-chip { display:flex; align-items:center; gap:9px; font-size: 12.8px; }
.user-chip .role { color: var(--muted); font-size: 11.3px; }

.content { padding: 26px 28px 60px; flex: 1; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; margin-bottom: 18px;
}
.card h2 { margin: 0 0 14px; font-size: 15.5px; color: var(--black); }
.card h3 { margin: 0 0 8px; font-size: 13.5px; color: var(--black); }

.grid { display: grid; gap: 16px; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) { .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; } }

.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px;
}
.stat .n { font-size: 26px; font-weight: 700; color: var(--black); }
.stat .l { font-size: 12px; color: var(--muted); margin-top: 2px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
  font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn-primary { background: var(--black); color: #f3e8c8; }
.btn-primary:hover { background: #262019; }
.btn-gold { background: var(--gold); color: #17140f; }
.btn-gold:hover { background: #d8b768; }
.btn-outline { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-outline:hover { border-color: var(--gold); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: #eccaca; }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

label { display: block; font-size: 12.5px; font-weight: 600; color: var(--black); margin: 14px 0 6px; }
label:first-child { margin-top: 0; }
input[type=text], input[type=email], input[type=password], input[type=number],
select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 13.5px; font-family: inherit; background: #fff; color: var(--ink);
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: var(--gold); }
.hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.check-row { display: flex; align-items: flex-start; gap: 9px; margin: 12px 0; }
.check-row input { width: auto; margin-top: 3px; }
.check-row .t { font-size: 13px; }
.check-row .d { font-size: 11.8px; color: var(--muted); }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px;
  border-radius: 999px; font-size: 11.3px; font-weight: 700; white-space: nowrap;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; }

.pill { padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.pill-gold { background: #fbf3e0; color: var(--gold-dim); border-color: #ecdca8; }
.pill-danger { background: var(--danger-bg); color: var(--danger); border-color: #eccaca; }
.pill-info { background: var(--info-bg); color: var(--info); border-color: #cfdcf0; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; font-size: 12.8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 11.3px; text-transform: uppercase; letter-spacing: .04em; }
tr:hover td { background: #fbfaf7; }
.table-wrap { overflow-x: auto; }
.row-link { cursor: pointer; }

.alert { padding: 12px 16px; border-radius: 9px; font-size: 13px; margin-bottom: 16px; border: 1px solid transparent; }
.alert-error { background: var(--danger-bg); color: var(--danger); border-color: #eccaca; }
.alert-ok { background: var(--ok-bg); color: var(--ok); border-color: #cfe8d1; }
.alert-warn { background: var(--warn-bg); color: var(--warn); border-color: #f0dfa0; }
.alert-info { background: var(--info-bg); color: var(--info); border-color: #cfdcf0; }

.timeline { border-left: 2px solid var(--line); margin-left: 8px; padding-left: 20px; }
.tl-item { position: relative; margin-bottom: 18px; }
.tl-item::before {
  content: ""; position: absolute; left: -26px; top: 3px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--gold); border: 2px solid #fff;
}
.tl-meta { font-size: 11.3px; color: var(--muted); margin-bottom: 3px; }
.tl-body { font-size: 13.3px; white-space: pre-wrap; }
.tl-internal { background: var(--warn-bg); border: 1px dashed #e3cd7f; border-radius: 8px; padding: 10px 12px; }

.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at top, #221d15, #0f0d09 70%);
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 420px; background: #fff; border-radius: 16px;
  padding: 32px 30px; box-shadow: 0 30px 60px rgba(0,0,0,0.35);
}
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-brand .mark {
  width: 100%; max-width: 230px; height: auto; margin: 0 auto 14px; display: block;
}
.auth-brand h1 { font-size: 19px; margin: 0 0 2px; }
.auth-brand p { font-size: 12.3px; color: var(--muted); margin: 0; }
.auth-links { text-align: center; margin-top: 16px; font-size: 12.8px; color: var(--muted); }
.auth-links a { color: var(--gold-dim); font-weight: 600; text-decoration: none; }

.empty-state { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty-state .big { font-size: 34px; margin-bottom: 10px; }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.deadline { font-weight: 700; }
.deadline.ok { color: var(--ok); }
.deadline.warn { color: var(--warn); }
.deadline.over { color: var(--danger); }

.channel-tabs { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.channel-tab {
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line); background: #fff;
  text-decoration: none; color: var(--ink); font-size: 13px; font-weight: 600;
}
.channel-tab.active { background: var(--black); color: #f3e8c8; border-color: var(--black); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: end; }
.filters .f { min-width: 160px; }
.filters label { margin: 0 0 4px; }

form.inline { display: inline; }

.note-box { border-left: 4px solid var(--gold); background: var(--warn-bg); border-radius: 9px; padding: 14px 16px; font-size: 12.8px; line-height: 1.55; margin-bottom: 18px; }
.note-box.danger { border-color: var(--danger); background: var(--danger-bg); }
.note-box.info { border-color: var(--info); background: var(--info-bg); }

.protocol-box {
  background: #17140f; color: #f3e8c8; border-radius: 12px; padding: 18px 20px; margin-bottom: 18px;
}
.protocol-box .code { font-size: 20px; font-weight: 700; color: var(--gold-soft); letter-spacing: .02em; }
.protocol-box .tok { font-family: "Courier New", monospace; background: rgba(255,255,255,0.08); padding: 2px 8px; border-radius: 6px; }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
}
