:root {
  --bg: #f4f6f5;
  --panel: #ffffff;
  --ink: #17211d;
  --muted: #5d6b65;
  --line: #dde3e0;
  --brand: #0f7a52;
  --brand-2: #0b5e3f;
  --brand-soft: #e3f3ec;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #9a6700;
  --warn-soft: #fff6dd;
  --chat-in: #ffffff;
  --chat-out: #d9fdd3;
  --chat-bg: #efeae2;
  --side: #10241c;
  --side-ink: #cfe0d8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 36, 28, .06), 0 2px 8px rgba(16, 36, 28, .05);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Noto Sans", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.side { width: 232px; flex: none; background: var(--side); color: var(--side-ink); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 15px; padding: 4px 8px 16px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: #25d366; display: grid; place-items: center; color: #073b25; font-weight: 800; }
.side a { color: var(--side-ink); padding: 9px 10px; border-radius: 8px; display: flex; gap: 10px; align-items: center; }
.side a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.side a.on { background: rgba(37, 211, 102, .16); color: #fff; }
.side .spacer { flex: 1; }
.side .who { font-size: 12px; padding: 8px 10px; opacity: .8; }
.main { flex: 1; min-width: 0; }
.topbar { display: none; }

/* Mobile first: 16px gutter; wide screens use the available width (global rule). */
.page { padding: 20px 16px 48px; width: 100%; margin: 0 auto; }
@media (min-width: 1280px) {
  .page { max-width: min(100%, 1680px); padding-left: clamp(1.5rem, 2.5vw, 3rem); padding-right: clamp(1.5rem, 2.5vw, 3rem); }
}
@media (min-width: 1920px) {
  .page { max-width: 1840px; }
}
@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .side { width: auto; flex-direction: row; flex-wrap: wrap; padding: 10px 12px; gap: 2px; }
  .brand { padding: 4px 8px; width: 100%; }
  .side .spacer, .side .who { display: none; }
  .side a { padding: 7px 9px; font-size: 13px; }
}

.head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.head .sub { color: var(--muted); }

/* ---------- panels and grids ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
td .row { flex-wrap: nowrap; }
.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.two { grid-template-columns: 1fr; }
@media (min-width: 1100px) { .two { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); } }
.stat .n { font-size: 26px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12.5px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td .clip { max-width: 520px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- forms ---------- */
label { display: block; font-weight: 600; font-size: 13px; margin: 0 0 4px; }
.field { margin-bottom: 14px; }
.hint { color: var(--muted); font-size: 12.5px; font-weight: 400; margin-top: 3px; }
input[type=text], input[type=password], input[type=number], input[type=time], input[type=url], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #c9d2ce; border-radius: 8px; font: inherit; background: #fff; color: var(--ink);
}
textarea { min-height: 84px; resize: vertical; }
textarea.code { font-family: var(--mono); font-size: 12.5px; min-height: 140px; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15,122,82,.25); border-color: var(--brand); }
.form-grid { display: grid; gap: 0 18px; grid-template-columns: 1fr; }
@media (min-width: 800px) { .form-grid { grid-template-columns: 1fr 1fr; } .form-grid .full { grid-column: 1 / -1; } }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.checks label { font-weight: 400; display: flex; align-items: center; gap: 6px; margin: 0; }
.narrow { max-width: 440px; margin: 0 auto; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--brand); background: var(--brand); color: #fff; padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--brand-2); text-decoration: none; }
.btn.ghost { background: #fff; color: var(--brand); }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.danger { background: #fff; color: var(--danger); border-color: #e9b7b2; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .6; cursor: wait; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eef1f0; color: var(--muted); }
.pill.ok { background: var(--brand-soft); color: var(--brand-2); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

.note { padding: 10px 12px; border-radius: 8px; background: var(--brand-soft); color: #0b4a33; margin-bottom: 14px; }
.note.warn { background: var(--warn-soft); color: #6b4800; }
.note.bad { background: var(--danger-soft); color: var(--danger); }
.copy { display: flex; gap: 6px; }
.copy input { font-family: var(--mono); font-size: 12.5px; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 600; }
.tabs a.on { color: var(--brand); border-color: var(--brand); }
.tabs a:hover { text-decoration: none; color: var(--ink); }

/* ---------- connectors ---------- */
.conn { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; margin-bottom: 16px; }
.conn-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.conn-body { padding: 4px 6px; }
.tool-name { font-family: var(--mono); font-weight: 600; }

/* ---------- WhatsApp-style chat ---------- */
.chat { background: var(--chat-bg); border-radius: var(--radius); border: 1px solid var(--line); display: flex; flex-direction: column; height: 560px; }
.chat-head { background: #075e54; color: #fff; padding: 10px 14px; border-radius: var(--radius) var(--radius) 0 0; display: flex; gap: 10px; align-items: center; }
.chat-head .av { width: 32px; height: 32px; border-radius: 50%; background: #25d366; display: grid; place-items: center; font-weight: 700; color: #073b25; }
.chat-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 78%; padding: 7px 10px 18px; border-radius: 8px; white-space: pre-wrap; overflow-wrap: anywhere; position: relative; box-shadow: 0 1px .5px rgba(0,0,0,.13); }
.bubble.in { align-self: flex-end; background: var(--chat-out); }
.bubble.out { align-self: flex-start; background: var(--chat-in); }
.bubble .meta { position: absolute; right: 8px; bottom: 2px; font-size: 10.5px; color: #667781; }
.bubble.err { background: var(--danger-soft); }
.chat-form { display: flex; gap: 8px; padding: 10px; background: #f0f2f5; border-radius: 0 0 var(--radius) var(--radius); }
.chat-form input { border-radius: 20px; flex: 1; min-width: 0; width: auto; }
.chat-form .btn { flex: none; }
@media (max-width: 600px) { .chat { height: 520px; } .bubble { max-width: 90%; } }
.typing { align-self: flex-start; color: #667781; font-style: italic; font-size: 12.5px; padding: 4px 8px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #10241c, #0f7a52); }
.login { width: 100%; max-width: 400px; }
.login .brand { color: var(--ink); padding: 0 0 16px; }

/* ---------- dialogs ---------- */
dialog { border: 0; border-radius: 12px; padding: 0; width: min(760px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(16, 36, 28, .45); }
dialog .dlg-head { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
dialog .dlg-body { padding: 18px; max-height: 70vh; overflow-y: auto; }
dialog .dlg-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
pre.result { background: #0f1a16; color: #cfe8dc; padding: 12px; border-radius: 8px; max-height: 320px; overflow: auto; font-size: 12px; }

.toast { position: fixed; right: 16px; bottom: 16px; background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); z-index: 50; max-width: 420px; }
.toast.bad { background: var(--danger); }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding-top: 8px; }
.bars div { flex: 1; background: #9fd8bd; border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.bars div:hover { background: var(--brand); }
.empty { padding: 26px; text-align: center; color: var(--muted); }
