:root {
  --bg: #f4f5fb;
  --panel: #ffffff;
  --panel-2: #f8f9fd;
  --text: #141726;
  --muted: #646a85;
  --line: #e3e5f0;
  --accent: #4f46e5;
  --accent-2: #eef0ff;
  --ok: #0f9d6b;
  --ok-bg: #e5f7ef;
  --warn: #b26a00;
  --warn-bg: #fff4dd;
  --bad: #d23b3b;
  --bad-bg: #fde9e9;
  --owner: #4f46e5;
  --shadow: 0 1px 2px rgba(20, 23, 38, 0.06), 0 4px 16px rgba(20, 23, 38, 0.05);
  --radius: 14px;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f1a;
    --panel: #151829;
    --panel-2: #1b1f33;
    --text: #e9ebf7;
    --muted: #9298b5;
    --line: #272c45;
    --accent: #8b85ff;
    --accent-2: #24254a;
    --ok: #3ccf95;
    --ok-bg: #12301f;
    --warn: #f0b44c;
    --warn-bg: #33270f;
    --bad: #ff7a7a;
    --bad-bg: #3a1717;
    --owner: #6c64ff;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pre { white-space: pre-wrap; word-break: break-word; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; }

/* Layout */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; letter-spacing: 0.04em; padding: 4px 10px 18px; }
.brand img { width: 30px; height: 30px; }
.nav a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 12px; border-radius: 10px; color: var(--text); text-decoration: none; margin-bottom: 2px; }
.nav a:hover { background: var(--panel-2); }
.nav a.active { background: var(--accent-2); color: var(--accent); font-weight: 600; }
.badge { min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--bad); color: #fff; font-size: 12px; text-align: center; font-weight: 700; }
.side-foot { margin-top: 18px; padding: 0 12px; }
.main { padding: 24px 28px 48px; max-width: 1180px; width: 100%; }
.topbar { display: none; }

/* Cards & grid */
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.pill.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.pill.info { background: var(--accent-2); color: var(--accent); border-color: transparent; }
.agent { display: flex; flex-direction: column; gap: 6px; }
.agent .name { font-weight: 800; font-size: 16px; }
.agent.soon { opacity: 0.6; }

/* Forms */
input, select, textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 44px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
button { border: 0; border-radius: 10px; padding: 9px 16px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; white-space: nowrap; }
button:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.55; cursor: progress; }
button.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
button.danger { background: var(--bad); }
button.ok { background: var(--ok); }
button.sm { padding: 5px 11px; font-size: 13px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Chat */
.chat { display: flex; flex-direction: column; height: calc(100vh - 140px); min-height: 420px; }
.messages { flex: 1; overflow-y: auto; padding: 4px 2px 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 78%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; word-break: break-word; }
.msg.owner { align-self: flex-end; background: var(--owner); color: #fff; border-bottom-right-radius: 5px; }
.msg.saydu { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.msg .meta { display: block; font-size: 11.5px; opacity: 0.7; margin-top: 4px; }
.composer { display: flex; gap: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.composer textarea { min-height: 48px; max-height: 160px; }
.typing { color: var(--muted); font-style: italic; }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 400px; padding: 26px; }
.qr { display: block; margin: 8px auto; border-radius: 10px; background: #fff; padding: 6px; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; font-family: ui-monospace, Consolas, monospace; background: var(--panel-2); padding: 12px; border-radius: 10px; }

/* Modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(8, 10, 20, 0.5); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--panel); border-radius: var(--radius); padding: 22px; width: 100%; max-width: 380px; border: 1px solid var(--line); }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity 0.2s; max-width: calc(100vw - 32px); z-index: 60; }
#toast.show { opacity: 1; }
video { width: 100%; max-width: 260px; border-radius: 12px; background: #000; display: block; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumbs img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.empty { color: var(--muted); padding: 18px 0; text-align: center; }
.list-item { padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }

@media (max-width: 960px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 40; transform: translateX(-105%); transition: transform 0.2s; box-shadow: 0 0 40px rgba(0, 0, 0, 0.3); }
  .side.open { transform: none; }
  .topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
  .main { padding: 16px 16px 40px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .msg { max-width: 90%; }
  .chat { height: calc(100vh - 150px); }
}
.row select, .row input[type="file"] { width: auto; }
