*, *::before, *::after { box-sizing: border-box; }
:root{
  --bg:#f4f5fb; --card:#ffffff; --ink:#1e2233; --muted:#6b7192;
  --line:#e6e8f2; --accent:#5b5bd6; --accent-d:#4747b8;
  --ok:#0f9d58; --warn:#b26a00; --err:#d23c3c; --info:#2f6fed;
  --radius:14px; --shadow:0 1px 3px rgba(20,24,60,.06),0 8px 24px rgba(20,24,60,.05);
}
html,body{margin:0;padding:0}
body{
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
  background:var(--bg); color:var(--ink); font-size:15px; line-height:1.5;
}
a{color:var(--accent); text-decoration:none}
a:hover{text-decoration:underline}
h1{font-size:22px;margin:0}
h2{font-size:16px;margin:0 0 12px}

/* ---------- layout ---------- */
.layout{display:flex; min-height:100vh}
.sidebar{
  width:238px; flex:0 0 238px; background:#161a2e; color:#c7cbe4;
  display:flex; flex-direction:column; padding:18px 12px; position:sticky; top:0; height:100vh;
}
.brand{font-weight:700; font-size:18px; color:#fff; padding:6px 10px 16px; display:flex; gap:8px; align-items:center}
.brand.big{font-size:22px; justify-content:center; padding-bottom:6px}
.menu{display:flex; flex-direction:column; gap:2px}
.menu a{
  color:#c7cbe4; padding:10px 12px; border-radius:10px; font-size:14px;
}
.menu a:hover{background:#222741; text-decoration:none; color:#fff}
.menu a.active{background:var(--accent); color:#fff}
.logout{margin-top:auto; color:#9aa0c4; padding:10px 12px; font-size:14px}
.logout:hover{color:#fff}

.content{flex:1; min-width:0; padding:24px 28px 60px; max-width:1000px}
.topbar{margin-bottom:18px}
.page{display:flex; flex-direction:column; gap:18px}

/* ---------- cards ---------- */
.card{background:var(--card); border:1px solid var(--line); border-radius:var(--radius); box-shadow:var(--shadow); padding:20px}
.card h2:first-child{margin-top:0}
.muted{color:var(--muted); font-size:14px}
.hint{color:var(--muted); font-size:13px; margin:-6px 0 0}
.link{font-size:14px}

/* ---------- grids ---------- */
.grid{display:grid; gap:16px}
.grid.stats{grid-template-columns:repeat(4,1fr)}
.grid.two{grid-template-columns:1fr 1fr}
.stat{text-align:center; padding:22px 12px}
.stat .num{font-size:30px; font-weight:700; color:var(--accent)}
.stat .lbl{font-size:13px; color:var(--muted); margin-top:4px}

.kv{list-style:none; margin:0; padding:0}
.kv li{display:flex; justify-content:space-between; gap:12px; padding:8px 0; border-bottom:1px solid var(--line)}
.kv li:last-child{border-bottom:0}
.kv span{color:var(--muted)}

/* ---------- forms ---------- */
form.stack{display:flex; flex-direction:column; gap:14px}
label{display:flex; flex-direction:column; gap:6px; font-size:14px; font-weight:600}
input,textarea,select{
  font:inherit; color:var(--ink); background:#fff; border:1px solid var(--line);
  border-radius:10px; padding:10px 12px; width:100%; font-weight:400;
}
textarea{resize:vertical; min-height:64px}
input:focus,textarea:focus,select:focus{outline:2px solid var(--accent); outline-offset:0; border-color:var(--accent)}
.row{display:flex; gap:10px}
.row input{flex:1}
.row2{display:grid; grid-template-columns:1fr 1fr; gap:14px}
.check{flex-direction:row; align-items:center; gap:8px; font-weight:400}
.check input{width:auto}

button{
  font:inherit; font-weight:600; cursor:pointer; border:0; border-radius:10px;
  background:var(--accent); color:#fff; padding:10px 18px;
}
button:hover{background:var(--accent-d)}
button.sm{padding:7px 12px; font-size:13px}
button.danger{background:#fdecec; color:var(--err)}
button.danger:hover{background:#f8d7d7}

.btn-link{display:inline-block; background:var(--accent); color:#fff; font-weight:600;
  padding:10px 18px; border-radius:10px; text-decoration:none}
.btn-link:hover{background:var(--accent-d); text-decoration:none}
.btn-link.big{font-size:16px; padding:14px 26px}
.row{align-items:center; flex-wrap:wrap}

details.card > summary{cursor:pointer; font-weight:600; list-style:revert}
details.card[open] > summary{margin-bottom:8px}

/* ---------- tables ---------- */
table{width:100%; border-collapse:collapse; font-size:14px}
th,td{text-align:left; padding:10px 8px; border-bottom:1px solid var(--line); vertical-align:top}
th{font-size:12px; text-transform:uppercase; letter-spacing:.03em; color:var(--muted)}
tr:last-child td{border-bottom:0}
.right{text-align:right}
.nowrap{white-space:nowrap}
.wrap{white-space:pre-wrap; word-break:break-word; color:var(--muted)}
table.tight td,table.tight th{padding:7px 6px}

.tag{display:inline-block; background:#eef0fb; color:var(--accent-d); border-radius:6px; padding:2px 7px; font-size:12px; font-weight:600}

.reply-row{display:flex; gap:10px; align-items:flex-start; padding:12px 0; border-bottom:1px solid var(--line)}
.reply-row:last-child{border-bottom:0}
.reply-row textarea{flex:1}
.reply-actions{display:flex; flex-direction:column; gap:6px}

.mono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; font-size:13px}
code.block, .mono.block{display:block; background:#12162a; color:#e7e9f7; padding:12px 14px; border-radius:10px; overflow-x:auto}
.steps,.pager{font-size:14px}
.steps li{margin:6px 0}
.pager{display:flex; gap:14px; align-items:center; margin-top:14px}

/* ---------- alerts ---------- */
.alert{border-radius:12px; padding:12px 16px; font-size:14px; border:1px solid transparent}
.alert.ok{background:#e8f6ee; color:#0b6b3a; border-color:#bce6cd}
.alert.info{background:#e9f1ff; color:#1c4fb0; border-color:#c6dbff}
.alert.warn{background:#fff3e0; color:#8a5300; border-color:#ffdca8}
.alert.error{background:#fdecec; color:#a62828; border-color:#f4c4c4}

/* ---------- login ---------- */
.login-body{display:flex; align-items:center; justify-content:center; min-height:100vh; background:var(--bg)}
.login-card{
  background:#fff; border:1px solid var(--line); border-radius:18px; box-shadow:var(--shadow);
  padding:32px; width:320px; display:flex; flex-direction:column; gap:12px; text-align:center;
}
.login-card .brand{justify-content:center}
.login-card input{text-align:center}

/* ---------- responsive ---------- */
@media (max-width:900px){
  .layout{flex-direction:column}
  .sidebar{width:auto; height:auto; position:static; flex-direction:row; flex-wrap:wrap; gap:6px; align-items:center}
  .brand{padding:6px 10px}
  .menu{flex-direction:row; flex-wrap:wrap}
  .logout{margin:0}
  .content{padding:18px}
  .grid.stats{grid-template-columns:1fr 1fr}
  .grid.two{grid-template-columns:1fr}
  .row2{grid-template-columns:1fr}
}
