:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --line: #e3e8f0;
  --text: #17202e;
  --muted: #68748c;
  --accent: #1f6feb;
  --accent-dark: #1857b8;
  --accent-soft: #e9f1fd;
  --green: #15803d; --green-soft: #e6f5ec;
  --amber: #b45309; --amber-soft: #fdf2e1;
  --red: #b91c1c; --red-soft: #fdeaea;
  --sidebar-w: 248px;
  --shadow: 0 2px 10px rgba(23, 32, 46, 0.05);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button { cursor: pointer; font-family: inherit; }
input, select { font-family: inherit; }

/* ================= login ================= */
.login-shell { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; }
.offline-banner {
  max-width: 640px; width: 100%; background: var(--red-soft); border: 1px solid var(--red);
  color: var(--red); border-radius: 10px; padding: 12px 16px; margin-bottom: 16px; font-size: 14px;
}
.login-wrap { width: 100%; max-width: 470px; }
.login-card {
  position: relative; overflow: hidden; background: var(--card);
  border: 1px solid var(--line); border-radius: 16px; padding: 34px 34px 28px;
  box-shadow: 0 12px 40px rgba(23, 32, 46, 0.10);
}
.login-accent { position: absolute; top: 0; left: 0; right: 0; height: 5px;
  background: linear-gradient(90deg, var(--accent), #58a6ff, var(--accent)); }
.login-logo {
  width: 52px; height: 52px; border-radius: 12px; background: linear-gradient(135deg, var(--accent), #58a6ff);
  color: #fff; font-weight: 800; font-size: 17px; display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px; letter-spacing: 1px;
}
.login-brand { font-size: 12px; letter-spacing: 1.6px; color: var(--accent); font-weight: 700; }
.login-card h1 { font-size: 21px; margin: 6px 0 4px; }
.sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.login-card label { display: block; font-size: 12px; color: var(--muted); margin: 13px 0 5px; font-weight: 600; }
.login-card input {
  width: 100%; padding: 11px 13px; border-radius: 8px; border: 1px solid var(--line);
  background: #fbfcfe; color: var(--text); font-size: 14px; transition: border .15s, box-shadow .15s;
}
.login-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card button[type=submit] {
  width: 100%; margin-top: 20px; padding: 12px; border: none; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 600; transition: background .15s;
}
.login-card button[type=submit]:hover { background: var(--accent-dark); }
.login-card button[type=submit]:disabled { opacity: .6; }
.err { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; }
.demo-users { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 14px; }
.demo-title { font-size: 12px; color: var(--muted); margin-bottom: 8px; font-weight: 600; }
.chip {
  margin: 4px 5px 0 0; padding: 6px 11px; font-size: 12px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); transition: all .15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* ================= shell ================= */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--card); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.side-brand { display: flex; align-items: center; gap: 11px; padding: 20px 18px; border-bottom: 1px solid var(--line); }
.side-logo {
  width: 42px; height: 42px; border-radius: 10px; background: linear-gradient(135deg, var(--accent), #58a6ff);
  color: #fff; font-weight: 800; font-size: 14px; display: flex; align-items: center; justify-content: center; letter-spacing: 1px;
}
.side-title { font-weight: 700; font-size: 15px; }
.side-sub { font-size: 11px; color: var(--muted); }
.sidebar nav { padding: 14px 12px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: none; border: none; border-radius: 9px; padding: 11px 13px;
  font-size: 14px; color: var(--text); margin-bottom: 4px; transition: background .15s; font-weight: 500;
}
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-ico { width: 20px; text-align: center; font-size: 15px; }
.side-user {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-top: 1px solid var(--line);
}
.avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; flex-shrink: 0;
}
.avatar.sm { width: 26px; height: 26px; font-size: 11px; margin-top: 2px; background: var(--muted); }
.side-user-meta { flex: 1; min-width: 0; }
.side-user-meta b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user-meta span { font-size: 11px; color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  background: none; border: 1px solid var(--line); border-radius: 8px; width: 32px; height: 32px;
  color: var(--muted); font-size: 15px; transition: all .15s;
}
.icon-btn:hover { color: var(--red); border-color: var(--red); background: var(--red-soft); }

.main { flex: 1; padding: 0 26px 60px; min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 14px; flex-wrap: wrap;
  padding: 24px 0 16px;
}
.page-title { font-size: 22px; }
.page-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.period-select label { font-size: 12px; color: var(--muted); margin-right: 7px; font-weight: 600; }
.period-select select {
  background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 7px;
  padding: 8px 11px; font-size: 13px; box-shadow: var(--shadow);
}

/* ================= kpi ================= */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 13px; margin-bottom: 15px; }
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 15px 17px; box-shadow: var(--shadow);
  border-top: 3px solid var(--line);
}
.kpi.good { border-top-color: var(--green); }
.kpi.warn { border-top-color: var(--amber); }
.kpi.bad { border-top-color: var(--red); }
.kpi .k-label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.kpi .k-val { font-size: 24px; font-weight: 700; margin: 6px 0 7px; }
.kpi.good .k-val { color: var(--green); }
.kpi.warn .k-val { color: var(--amber); }
.kpi.bad .k-val { color: var(--red); }
.kpi .k-sub { font-size: 12px; color: var(--muted); margin-top: 7px; }
.prog { height: 5px; background: #edf1f7; border-radius: 99px; overflow: hidden; }
.prog-fill { height: 100%; border-radius: 99px; transition: width .4s; }

/* ================= cards & tables ================= */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.admin-grid { grid-template-columns: 380px 1fr; align-items: start; }
@media (max-width: 1050px) { .grid, .admin-grid { grid-template-columns: 1fr; } }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px;
  margin-bottom: 15px; box-shadow: var(--shadow);
}
.card h2 { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 13px; font-weight: 700; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; color: var(--muted); font-weight: 700; padding: 9px 11px;
  border-bottom: 1px solid var(--line); white-space: nowrap; background: #f8fafd; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .4px;
}
td { padding: 9px 11px; border-bottom: 1px solid #eef1f7; white-space: nowrap; vertical-align: middle; }
tbody tr:hover td { background: #f8fafe; }
tr:last-child td { border-bottom: none; }
.empty { color: var(--muted); padding: 14px 0; font-size: 14px; }

.pill { display: inline-block; min-width: 44px; text-align: center; padding: 2px 8px; border-radius: 99px; font-weight: 700; font-size: 12px; }
.pill.good { background: var(--green-soft); color: var(--green); }
.pill.warn { background: var(--amber-soft); color: var(--amber); }
.pill.bad { background: var(--red-soft); color: var(--red); }
.pill.zero { background: #f1f2f5; color: var(--muted); }
.sev { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.sev.critical { background: var(--red-soft); color: var(--red); }
.sev.high { background: var(--amber-soft); color: var(--amber); }
.sev.medium { background: #eef1f7; color: var(--muted); }
.role-pill {
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  padding: 2px 9px; border-radius: 99px; font-weight: 700; font-size: 12px;
}
.scope-text { color: var(--muted); }
.muted-text { color: var(--muted); font-size: 12px; }

/* ================= chat ================= */
.chat-log {
  background: #fbfcfe; border: 1px solid var(--line); border-radius: 10px;
  padding: 15px; min-height: 250px; max-height: 580px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px; font-size: 14px;
}
.msg-row { display: flex; gap: 8px; }
.msg-row.user { justify-content: flex-end; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 12px; line-height: 1.55; }
.msg.user { background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.msg.bot { background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 3px; }
.msg.typing { color: var(--muted); font-style: italic; }
.chat-text { white-space: pre-wrap; }
.chat-text table, .msg.bot .table-wrap table { margin-top: 9px; }
.chat-text table td { color: var(--text); }
.warn-mark { color: var(--amber); }
.ok-mark { color: var(--green); }
.quick-chips { margin: 11px 0; display: flex; flex-wrap: wrap; gap: 7px; }
.chat-form { display: flex; gap: 10px; }
.chat-form input {
  flex: 1; background: #fbfcfe; border: 1px solid var(--line); border-radius: 8px;
  padding: 11px 14px; color: var(--text); font-size: 14px; transition: border .15s, box-shadow .15s;
}
.chat-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chat-form button {
  background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 0 24px; font-weight: 600;
}
.chat-form button:hover { background: var(--accent-dark); }
.chat-form button:disabled { opacity: .6; }
.chat-hint { font-size: 12px; color: var(--muted); margin-top: 9px; }

/* ================= admin form ================= */
.admin-form label { display: block; font-size: 12px; color: var(--muted); margin: 13px 0 5px; font-weight: 600; }
.admin-form input, .admin-form select {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: #fbfcfe; color: var(--text); font-size: 13.5px; transition: border .15s, box-shadow .15s;
}
.admin-form input:focus, .admin-form select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.admin-form input:disabled { background: #f1f3f7; color: var(--muted); }
.req { color: var(--red); }
.role-preview {
  margin-top: 14px; font-size: 13px; background: var(--accent-soft); color: var(--accent-dark);
  border-radius: 8px; padding: 10px 12px; line-height: 1.5;
}
.form-actions { display: flex; gap: 9px; margin-top: 16px; }
.btn {
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 9px 16px; font-size: 13px; font-weight: 600; transition: all .15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); color: var(--red); background: var(--red-soft); }
.btn.confirm { background: var(--red); border-color: var(--red); color: #fff !important; }
.btn.confirm:hover { background: #a11515; }
.actions { display: flex; gap: 6px; }
.form-msg { margin-top: 13px; font-size: 13px; border-radius: 8px; padding: 9px 12px; }
.form-msg.ok { background: var(--green-soft); color: var(--green); }
.form-msg.bad { background: var(--red-soft); color: var(--red); }
