:root {
  --blue-950: #061d3c;
  --blue-900: #082d5d;
  --blue-800: #0b4385;
  --blue-700: #0e67c7;
  --blue-100: #eaf4ff;
  --gold: #ffb300;
  --gold-2: #ffd36b;
  --text: #0f2748;
  --muted: #6e7f95;
  --line: #dce7f4;
  --bg: #f4f8fd;
  --card: #ffffff;
  --danger: #d13b2f;
  --ok: #14a463;
  --warn: #c78300;
  --shadow: 0 16px 40px rgba(11, 49, 94, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
}

a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }

.sidebar {
  width: 280px;
  min-height: 100vh;
  background: linear-gradient(180deg, var(--blue-950), var(--blue-900));
  color: white;
  padding: 24px 18px;
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo {
  width: 76px;
  height: 76px;
  object-fit: contain;
  border-radius: 24px;
  filter: drop-shadow(0 12px 20px rgba(0,0,0,.22));
}
.brand-title { font-size: 23px; font-weight: 800; line-height: 1.05; }
.brand-subtitle { color: rgba(255,255,255,.70); margin-top: 4px; }
.nav { display: flex; flex-direction: column; gap: 8px; }
.nav-item {
  padding: 14px 16px;
  border-radius: 16px;
  color: rgba(255,255,255,.82);
  font-weight: 700;
  transition: .16s ease;
}
.nav-item:hover { background: rgba(255,255,255,.10); color: white; }
.nav-item.active {
  background: linear-gradient(90deg, var(--gold), #ffcb3f 5px, rgba(255,255,255,.12) 5px);
  color: white;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06);
}
.main { flex: 1; padding: 32px; min-width: 0; }
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 24px;
}
h1 { margin: 0; font-size: 36px; letter-spacing: -.03em; }
h2 { margin: 0 0 16px; font-size: 22px; letter-spacing: -.02em; }
h3 { margin: 0 0 10px; }
.muted { color: var(--muted); margin: 6px 0 0; }
.top-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 800;
  background: white;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.status-pill.ok { color: var(--ok); background: #eafaf2; border-color: #c5eedc; }
.status-pill.warn { color: var(--warn); background: #fff8df; border-color: #ffe39b; }
.status-pill.bad { color: var(--danger); background: #fff0ee; border-color: #ffc8c2; }
.status-pill.neutral { color: var(--blue-800); }

.grid { display: grid; gap: 18px; }
.grid.stats { grid-template-columns: repeat(4, minmax(150px, 1fr)); margin-bottom: 18px; }
.grid.two { grid-template-columns: minmax(0, 1.4fr) minmax(320px, .8fr); align-items: start; }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 22px;
}
.stat-card { min-height: 126px; }
.stat-title { color: var(--muted); font-weight: 800; }
.stat-value { font-size: 36px; font-weight: 900; margin-top: 10px; letter-spacing: -.03em; }
.stat-note { color: var(--muted); font-size: 14px; margin-top: 6px; }

.alert {
  border-radius: 20px;
  padding: 16px 18px;
  margin-bottom: 18px;
  border: 1px solid;
  font-weight: 700;
}
.alert-warning { background: #fff7df; border-color: #ffe09a; color: #7a4b00; }
.alert-danger { background: #fff1ef; border-color: #ffc7bf; color: #9d2217; }
.alert-success { background: #eafaf2; border-color: #bbe9d5; color: #087144; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
td { font-weight: 600; }
.badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 900;
  background: var(--blue-100);
  color: var(--blue-800);
}
.badge.new { background: #fff1c7; color: #8a5300; }
.badge.answered { background: #dff8eb; color: #087144; }
.badge.closed { background: #eef2f7; color: #627083; }

.form-grid { display: grid; gap: 16px; }
.field { display: grid; gap: 8px; }
label { font-weight: 900; }
.help { color: var(--muted); font-size: 14px; line-height: 1.45; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: #fbfdff;
  color: var(--text);
  outline: none;
}
textarea { min-height: 140px; resize: vertical; line-height: 1.45; }
input:focus, textarea:focus, select:focus { border-color: var(--blue-700); box-shadow: 0 0 0 4px rgba(14, 103, 199, .10); }
.actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.btn {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  font-weight: 900;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: .16s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }
.btn.primary { background: linear-gradient(180deg, #1682f2, #0d67c8); color: white; }
.btn.gold { background: linear-gradient(180deg, #ffc84d, var(--gold)); color: #1e2c3e; }
.btn.light { background: #eaf2fb; color: var(--blue-800); }
.btn.danger { background: #e95043; color: white; }
.btn.small { padding: 8px 10px; border-radius: 10px; font-size: 13px; }

.task-box {
  margin-top: 18px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: #fbfdff;
  padding: 16px;
}
.task-box.hidden { display: none; }
.progress-track {
  width: 100%;
  height: 12px;
  background: #e6eef8;
  border-radius: 99px;
  overflow: hidden;
  margin: 10px 0;
}
.progress-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--blue-700), var(--gold)); transition: width .3s ease; }
.task-log {
  margin: 10px 0 0;
  white-space: pre-wrap;
  max-height: 220px;
  overflow: auto;
  background: var(--blue-950);
  color: #dcecff;
  border-radius: 14px;
  padding: 14px;
  font-size: 13px;
}
.codebox, pre {
  white-space: pre-wrap;
  background: var(--blue-950);
  color: #dcecff;
  border-radius: 18px;
  padding: 18px;
  overflow: auto;
  line-height: 1.5;
}

.kv { display: grid; gap: 8px; }
.kv div { display: flex; justify-content: space-between; gap: 20px; border-bottom: 1px dashed var(--line); padding-bottom: 8px; }
.kv span:first-child { color: var(--muted); }
.empty { color: var(--muted); padding: 20px; border: 1px dashed var(--line); border-radius: 18px; }
.footer-note { margin-top: 20px; color: var(--muted); font-size: 14px; }

@media (max-width: 1040px) {
  body { display: block; }
  .sidebar { position: relative; width: auto; min-height: 0; border-radius: 0 0 24px 24px; }
  .nav { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .main { padding: 22px; }
  .grid.stats, .grid.two, .grid.three { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; }
}

@media (max-width: 560px) {
  h1 { font-size: 28px; }
  .brand-logo { width: 62px; height: 62px; }
  .nav { grid-template-columns: 1fr; }
  .card { padding: 18px; border-radius: 20px; }
  th, td { padding: 10px 8px; }
}

.link {
  color: var(--blue-700);
  font-weight: 900;
  text-decoration: none;
}
.link:hover { text-decoration: underline; }

.badge.in_work { background: #dbeafe; color: #1d4ed8; }
.badge.spam { background: #ffe0e0; color: #9d2217; }

.chat-history { display: grid; gap: 14px; }
.chat-message {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  background: #fbfdff;
}
.chat-message.user {
  border-color: #cfe3fb;
  background: #f4f9ff;
}
.chat-message.admin {
  border-color: #d7ecd8;
  background: #f5fff8;
}
.chat-message.system {
  border-color: #ffe1a8;
  background: #fff9e9;
}
.chat-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}
.chat-meta strong { color: var(--text); }
.chat-text {
  white-space: pre-wrap;
  line-height: 1.5;
  font-weight: 650;
}

/* Login screen */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 18% 18%, rgba(255, 179, 0, .20), transparent 26%),
    radial-gradient(circle at 82% 10%, rgba(14, 103, 199, .22), transparent 28%),
    linear-gradient(135deg, var(--blue-950), var(--blue-900) 52%, #041325);
  padding: 24px;
}
.login-shell {
  width: min(100%, 480px);
}
.login-card {
  background: rgba(255, 255, 255, .96);
  border: 1px solid rgba(255, 255, 255, .74);
  border-radius: 30px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, .26);
  padding: 30px;
  backdrop-filter: blur(10px);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}
.login-logo {
  width: 78px;
  height: 78px;
  object-fit: contain;
  border-radius: 22px;
  filter: drop-shadow(0 10px 18px rgba(6, 29, 60, .22));
}
.login-title {
  color: var(--blue-950);
  font-size: 26px;
  line-height: 1.05;
  font-weight: 950;
  letter-spacing: -.03em;
}
.login-subtitle {
  color: var(--muted);
  margin-top: 5px;
  font-weight: 700;
}
.login-heading {
  margin-bottom: 20px;
}
.login-heading h1 {
  font-size: 30px;
  margin: 0;
}
.login-heading p {
  color: var(--muted);
  margin: 8px 0 0;
}
.login-form {
  display: grid;
  gap: 16px;
}
.login-form .field span {
  font-weight: 900;
}
.login-form input {
  min-height: 50px;
  font-size: 17px;
  background: #fff;
}
.login-submit {
  min-height: 52px;
  width: 100%;
  font-size: 17px;
  margin-top: 4px;
}
.login-alert {
  margin-bottom: 16px;
}
.login-note {
  margin-top: 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  padding: 14px;
  border-radius: 16px;
  background: #f3f8fe;
  border: 1px solid var(--line);
}
.logout-form { margin: 0; }
.logout-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--blue-800);
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.logout-button:hover { transform: translateY(-1px); }

/* DCS Lite / Continuity Viewer */
.doc-nav { display: grid; gap: 10px; }
.doc-nav-item {
  display: grid;
  gap: 4px;
  padding: 13px 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fbfdff;
  font-weight: 900;
  color: var(--text);
}
.doc-nav-item span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.doc-nav-item.active {
  border-color: #ffda7b;
  background: #fff7df;
  box-shadow: inset 5px 0 0 var(--gold);
}
.continuity-content {
  margin-top: 18px;
  max-height: calc(100vh - 260px);
  min-height: 520px;
}
.continuity-layout { align-items: start; }
code {
  background: #edf4fb;
  color: var(--blue-800);
  padding: 2px 6px;
  border-radius: 8px;
  font-weight: 800;
}
pre code { background: transparent; color: inherit; padding: 0; }
