:root {
  --bg: #f4f6f9; --panel: #ffffff; --text: #1d2330; --muted: #6b7385; --line: #e3e7ee;
  --accent: #2563eb; --accent-2: #1d4ed8; --good: #15803d; --good-bg: #dcfce7; --bad: #b91c1c; --bad-bg: #fee2e2;
  --side: #111827; --side-text: #cbd2de; --side-on: #1f2a40; --warn-bg: #fff7d6; --code: #eef1f6;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f131a; --panel: #171c25; --text: #e6e9ef; --muted: #8d96a8; --line: #273040;
    --accent: #4f8cff; --accent-2: #3b7af0; --good: #4ade80; --good-bg: #14321f; --bad: #f87171; --bad-bg: #3a1717;
    --side: #0b0e13; --side-text: #aeb7c7; --side-on: #1a2333; --warn-bg: #3a3214; --code: #222a37;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 16px; margin: 0 0 10px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
code { background: var(--code); padding: 1px 5px; border-radius: 4px; }
.wrap { word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.good { color: var(--good); } .bad { color: var(--bad); }
.right { text-align: right; } .nowrap { white-space: nowrap; } .hidden { display: none !important; }
.inline { display: inline; }

.layout { display: flex; min-height: 100vh; }
.side { width: 230px; flex: none; background: var(--side); color: var(--side-text); padding: 14px 10px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side a { color: var(--side-text); display: block; padding: 6px 10px; border-radius: 7px; }
.side a:hover { background: var(--side-on); text-decoration: none; color: #fff; }
.side a.on { background: var(--side-on); color: #fff; font-weight: 600; }
.side .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #6b7588; margin: 14px 10px 4px; }
.side .foot { margin-top: auto; padding: 14px 10px 0; font-size: 12.5px; }
.side .foot a.inline { display: inline; padding: 0; color: #fff; }
.brand { font-weight: 700; font-size: 16px; padding: 4px 10px 10px; color: #fff; }
.brand.big { font-size: 20px; color: var(--text); padding: 0 0 12px; }
.logo { color: var(--accent); }
main { flex: 1; min-width: 0; padding: 22px 28px 40px; max-width: 1300px; }
.menu-btn { display: none; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card.note { background: var(--warn-bg); }
.card.narrow { max-width: 460px; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.head h1 { margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 { margin-bottom: 16px; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row label { margin: 0; }
.scroll { overflow-x: auto; }
.btnrow { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); gap: 12px; }
form > .btn, form > button { margin-top: 4px; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; color: var(--text); }
.stat b { display: block; font-size: 26px; }
.stat span { color: var(--muted); font-size: 12.5px; }
a.stat:hover { border-color: var(--accent); text-decoration: none; }

.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--bg); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl.kv th { width: 170px; background: none; }
.tbl td.empty { padding: 26px; text-align: center; }
.tbl audio { height: 32px; max-width: 260px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: var(--code); }
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.warn { background: var(--warn-bg); color: #b45309; }
.regstat { min-width: 150px; }

label { display: block; margin: 0 0 12px; font-weight: 500; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 7px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { display: inline; width: auto; margin: 0 6px 0 0; }
input[type=file] { padding: 6px; }
textarea { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
label.check { font-weight: 400; display: flex; align-items: center; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 20px; }
.field { margin-bottom: 10px; }
.field.full { grid-column: 1 / -1; }
.field label { margin-bottom: 0; }
.help { font-size: 12px; color: var(--muted); margin-top: 3px; }
.req { color: var(--bad); }
.checks { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 6px; }
.pw { display: flex; gap: 6px; align-items: center; }
.pw input { margin: 0; }
.keymap { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 6px; }
.keymap .key { display: flex; align-items: center; gap: 8px; }
.keymap .key b { width: 26px; height: 26px; flex: none; display: grid; place-items: center; background: var(--code); border-radius: 50%; }
.keymap select { margin: 0; }
.actions { display: flex; gap: 10px; margin-top: 10px; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; font: inherit; font-weight: 500; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 7px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.small { padding: 3px 9px; font-size: 12.5px; }
.btn.wide { width: 100%; justify-content: center; }
.btn.big { padding: 12px 22px; font-size: 16px; }
.btn:disabled { opacity: .6; cursor: wait; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: var(--good-bg); color: var(--good); white-space: pre-wrap; }
.flash.error { background: var(--bad-bg); color: var(--bad); }
.applybar { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--warn-bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 8px 8px 14px; margin-bottom: 14px; }
pre.out { background: var(--code); padding: 10px 12px; border-radius: 7px; overflow-x: auto; white-space: pre-wrap; word-break: break-word; font-size: 12.5px; max-height: 420px; margin: 6px 0; }

.center { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }
.card.login { width: 100%; max-width: 380px; }

/* AI chat */
.chat { display: flex; flex-direction: column; height: calc(100vh - 230px); min-height: 420px; }
.chat-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; }
.msg.me { justify-content: flex-end; }
.bubble { max-width: 80%; padding: 10px 14px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); overflow-wrap: anywhere; }
.msg.me .bubble { background: var(--accent); color: #fff; border-color: var(--accent); white-space: pre-wrap; }
.bubble ul { margin: 6px 0 0; padding-left: 20px; }
.msg.tool { font-size: 12.5px; color: var(--muted); }
.msg.tool details { max-width: 90%; }
.msg.tool summary { cursor: pointer; }
.msg.tool.err code { color: var(--bad); }
.chat-input { display: flex; gap: 10px; padding: 12px; border-top: 1px solid var(--line); }
.chat-input textarea { margin: 0; resize: vertical; font-family: inherit; font-size: 14px; }
details > summary { cursor: pointer; }

/* web phone */
.phone { max-width: 340px; text-align: center; }
.phone-status { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.good { background: var(--good); } .dot.bad { background: var(--bad); }
.phone-display { min-height: 24px; margin: 12px 0 6px; font-weight: 600; }
.phone-number { font-size: 22px; text-align: center; }
.dialpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.dialpad .key { font-size: 20px; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); cursor: pointer; }
.dialpad .key:active { background: var(--line); }
.phone-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 10px; }
.qr { width: 220px; margin: 8px 0; background: #fff; padding: 6px; border-radius: 8px; }

@media (max-width: 860px) {
  .layout { display: block; }
  .side { position: fixed; z-index: 10; left: -260px; transition: left .2s; height: 100vh; }
  .side.open { left: 0; }
  main { padding: 56px 16px 30px; }
  .menu-btn { display: block; position: fixed; top: 10px; left: 10px; z-index: 11; font-size: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 4px 10px; color: var(--text); }
  .grid2, .fields { grid-template-columns: 1fr; }
  .keymap { grid-template-columns: 1fr 1fr; }
}
