:root {
  --bg: #f5f5f1; --panel: #ffffff; --line: #e4e4dd; --line2: #efefe9;
  --ink: #17201d; --ink2: #4b5651; --ink3: #87918c;
  --side: #10241f; --side2: #183530; --side-ink: #cfe0d9; --side-ink2: #7fa094;
  --accent: #127a5a; --accent-ink: #fff; --accent-soft: #e3f3ec;
  --ok: #15924f; --ok-soft: #e4f5ea; --warn: #c27207; --warn-soft: #fdf1dc; --fail: #cf2f2f; --fail-soft: #fde6e4; --unk: #9aa39f; --unk-soft: #eff1ef;
  --r: 10px; --shadow: 0 1px 2px rgba(16,36,31,.05), 0 2px 8px rgba(16,36,31,.04);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 22px; font-weight: 650; } h2 { font-size: 16px; font-weight: 650; } h3 { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--ink3); }
code, .mono { font-family: var(--mono); font-size: 12.5px; }

/* layout */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; font-weight: 700; font-size: 15px; color: #fff; }
.brand i { width: 22px; height: 22px; border-radius: 7px; background: #1d4c41; display: grid; place-items: center; }
.brand i::after { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #37d399; box-shadow: 0 0 0 3px rgba(55,211,153,.2); }
.nav { padding: 4px 10px; display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 7px; color: var(--side-ink); font-weight: 500; }
.nav a:hover { background: var(--side2); text-decoration: none; }
.nav a.on { background: #21463e; color: #fff; }
.nav .count { margin-left: auto; background: var(--fail); color: #fff; font-size: 11px; font-weight: 700; padding: 0 6px; border-radius: 10px; }
.side-sites { flex: 1; overflow: auto; padding: 12px 10px; border-top: 1px solid #1d3a34; margin-top: 10px; }
.side-sites .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--side-ink2); padding: 0 10px 6px; display: flex; justify-content: space-between; }
.side-sites a { display: flex; align-items: center; gap: 9px; padding: 5px 10px; border-radius: 6px; color: var(--side-ink); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-sites a:hover { background: var(--side2); text-decoration: none; }
.side-sites a.on { background: #21463e; color: #fff; }
.side-foot { padding: 12px 18px; border-top: 1px solid #1d3a34; font-size: 12px; color: var(--side-ink2); display: flex; justify-content: space-between; }
.side-foot button { background: none; border: 0; color: var(--side-ink2); cursor: pointer; padding: 0; } .side-foot button:hover { color: #fff; }
main { padding: 26px 32px 60px; min-width: 0; max-width: 1400px; }
.head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.head .grow { flex: 1; min-width: 0; }
.sub { color: var(--ink3); font-size: 13px; margin-top: 3px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grow { flex: 1; } .muted { color: var(--ink3); } .small { font-size: 12px; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.sp { height: 16px; }

/* buttons & inputs */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 550; font-size: 13px; white-space: nowrap; }
.btn:hover { border-color: #cfcfc6; background: #fafaf7; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); } .btn.primary:hover { background: #0f6a4e; }
.btn.danger { color: var(--fail); } .btn.danger.solid { background: var(--fail); color: #fff; border-color: var(--fail); }
.btn.ghost { border-color: transparent; background: transparent; } .btn.ghost:hover { background: var(--line2); }
.btn.sm { height: 26px; padding: 0 9px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn .spin { width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
input[type=text], input[type=password], input[type=url], input[type=number], input[type=email], input[type=search], input[type=datetime-local], select, textarea {
  width: 100%; height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; outline: none; }
textarea { height: auto; padding: 8px 10px; resize: vertical; line-height: 1.5; }
textarea.code { font-family: var(--mono); font-size: 12.5px; min-height: 380px; tab-size: 2; white-space: pre; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.f { display: grid; gap: 5px; font-weight: 550; font-size: 13px; }
label.f .hint { font-weight: 400; color: var(--ink3); font-size: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; } .grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stack { display: grid; gap: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.counter { font-weight: 400; color: var(--ink3); font-size: 11.5px; float: right; } .counter.over { color: var(--fail); }

/* cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.card.pad { padding: 18px; }
.card-h { display: flex; align-items: center; gap: 10px; padding: 13px 18px; border-bottom: 1px solid var(--line2); }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.tile { padding: 14px 16px; } .tile .n { font-size: 26px; font-weight: 700; letter-spacing: -.02em; } .tile .l { color: var(--ink3); font-size: 12.5px; }
.tile.fail .n { color: var(--fail); } .tile.warn .n { color: var(--warn); } .tile.ok .n { color: var(--ok); }
.sites { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; }
.site-card { padding: 15px 16px 13px; cursor: pointer; transition: border-color .12s, transform .12s; position: relative; overflow: hidden; }
.site-card:hover { border-color: #c9cfc9; }
.site-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--unk); }
.site-card.ok::before { background: var(--ok); } .site-card.warn::before { background: var(--warn); } .site-card.fail::before { background: var(--fail); }
.site-card .t { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 14.5px; }
.site-card .t span.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-card .u { color: var(--ink3); font-size: 12.5px; margin: 2px 0 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; padding: 2px 7px; border-radius: 20px; background: var(--unk-soft); color: var(--ink2); white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: #11663a; } .chip.warn { background: var(--warn-soft); color: #8a5106; } .chip.fail { background: var(--fail-soft); color: #a32121; }
.site-card .foot { display: flex; align-items: center; justify-content: space-between; margin-top: 11px; color: var(--ink3); font-size: 11.5px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--unk); flex: none; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.fail { background: var(--fail); box-shadow: 0 0 0 3px rgba(207,47,47,.18); }
.badge { display: inline-flex; align-items: center; font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 5px; text-transform: uppercase; letter-spacing: .04em; flex: none; }
.badge.wordpress { background: #e7eef8; color: #24569a; } .badge.shopify { background: #eaf4df; color: #3d6b16; }
.badge.s-ok, .badge.s-publish, .badge.s-active, .badge.s-paid, .badge.s-fulfilled { background: var(--ok-soft); color: #11663a; }
.badge.s-warn, .badge.s-draft, .badge.s-pending, .badge.s-unfulfilled, .badge.s-processing { background: var(--warn-soft); color: #8a5106; }
.badge.s-fail, .badge.s-archived, .badge.s-refunded, .badge.s-cancelled, .badge.s-failed { background: var(--fail-soft); color: #a32121; }
.badge.s-private, .badge.s-future, .badge.s-unknown, .badge.gray { background: var(--unk-soft); color: var(--ink2); }
.badge.s-main { background: var(--accent-soft); color: var(--accent); }

.filters { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.seg { display: inline-flex; background: #ebebe5; border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 11px; border-radius: 6px; cursor: pointer; font-size: 12.5px; font-weight: 550; color: var(--ink2); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.filters input[type=search] { width: 240px; height: 32px; }

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

/* tables */
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: 11.5px; font-weight: 600; color: var(--ink3); text-transform: uppercase; letter-spacing: .04em; padding: 9px 14px; border-bottom: 1px solid var(--line); background: #fbfbf9; }
table.t td { padding: 9px 14px; border-bottom: 1px solid var(--line2); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tr.click { cursor: pointer; } table.t tr.click:hover td { background: #fafaf6; }
table.t td.title { font-weight: 550; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.t input { height: 30px; }
.thumb { width: 34px; height: 34px; border-radius: 6px; object-fit: cover; background: var(--line2); display: block; }
.empty { padding: 40px 20px; text-align: center; color: var(--ink3); }
.empty b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }
.more { padding: 12px; text-align: center; border-top: 1px solid var(--line2); }

.banner { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: 9px; margin-bottom: 14px; font-size: 13px; background: var(--accent-soft); color: #0b4d38; }
.banner.warn { background: var(--warn-soft); color: #7a4704; } .banner.fail { background: var(--fail-soft); color: #8f1d1d; }
.banner b { display: block; }

.checks-list { display: grid; }
.checks-list .ck { display: grid; grid-template-columns: 22px 150px 1fr auto; gap: 10px; align-items: center; padding: 11px 18px; border-bottom: 1px solid var(--line2); }
.checks-list .ck:last-child { border-bottom: 0; }
.checks-list .ck .lab { font-weight: 600; }
.cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }
.feed { display: grid; }
.feed .it { padding: 10px 18px; border-bottom: 1px solid var(--line2); font-size: 13px; }
.feed .it:last-child { border-bottom: 0; }
.feed .it .m { color: var(--ink3); font-size: 12px; margin-top: 2px; }
.chart { padding: 10px 18px 14px; }
.chart svg { width: 100%; height: 110px; display: block; }

/* drawer + modal */
.overlay { position: fixed; inset: 0; background: rgba(16,30,26,.38); z-index: 50; display: flex; justify-content: flex-end; animation: fade .12s; }
.overlay.center { justify-content: center; align-items: flex-start; padding-top: 8vh; }
@keyframes fade { from { opacity: 0; } }
.drawer { width: min(880px, 96vw); height: 100%; background: var(--bg); display: flex; flex-direction: column; box-shadow: -10px 0 30px rgba(0,0,0,.12); animation: slide .16s ease-out; }
@keyframes slide { from { transform: translateX(30px); opacity: .6; } }
.drawer-h { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.drawer-b { flex: 1; overflow: auto; padding: 20px; }
.drawer-f { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px; border-top: 1px solid var(--line); background: var(--panel); }
.modal { width: min(560px, 94vw); background: var(--panel); border-radius: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.2); max-height: 84vh; display: flex; flex-direction: column; animation: pop .14s ease-out; }
.modal.wide { width: min(760px, 94vw); }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: .5; } }
.modal-h { padding: 16px 20px 0; } .modal-b { padding: 14px 20px; overflow: auto; } .modal-f { padding: 12px 20px 16px; display: flex; gap: 8px; justify-content: flex-end; }
.diff { display: grid; gap: 10px; }
.diff .d { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; font-size: 12.5px; }
.diff .d .k { padding: 6px 10px; background: #fbfbf9; font-weight: 600; border-bottom: 1px solid var(--line2); }
.diff .d .o, .diff .d .n { padding: 6px 10px; white-space: pre-wrap; word-break: break-word; max-height: 140px; overflow: auto; font-family: var(--mono); font-size: 12px; }
.diff .d .o { background: #fff4f3; color: #8f1d1d; } .diff .d .n { background: #f0faf4; color: #0e5a33; }
.preview { border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 16px; max-height: 480px; overflow: auto; }
.preview img { max-width: 100%; }
.pt { display: flex; gap: 6px; margin-bottom: 6px; }

/* toasts */
#toasts { position: fixed; bottom: 18px; right: 18px; display: grid; gap: 8px; z-index: 100; }
.toast { background: #10241f; color: #fff; padding: 10px 14px; border-radius: 9px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 420px; font-size: 13px; animation: pop .15s; }
.toast.err { background: #8f1d1d; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; background: var(--side); }
.auth .card { width: 380px; padding: 28px; }
.auth .brand { color: var(--ink); padding: 0 0 18px; }

.help { background: #fbfbf8; border: 1px dashed var(--line); border-radius: 8px; padding: 10px 12px; font-size: 12.5px; color: var(--ink2); }
.help ol { margin: 4px 0 0; padding-left: 18px; } .help li { margin: 2px 0; }
.kp-row { display: grid; grid-template-columns: 1fr 1fr 32px; gap: 8px; }

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; } .side { position: static; height: auto; } .side-sites { display: none; }
  .nav { grid-auto-flow: column; overflow-x: auto; } main { padding: 18px; }
  .tiles { grid-template-columns: repeat(2, 1fr); } .cols, .grid2, .grid3 { grid-template-columns: 1fr; }
}
.side-sites .lbl a { display: inline; padding: 0; text-transform: none; letter-spacing: 0; font-size: 12px; }
.side-sites .lbl a:hover { background: none; color: #fff !important; }
.modal > form { display: flex; flex-direction: column; min-height: 0; max-height: 84vh; }
.modal-b { flex: 1; min-height: 0; }
.modal-h, .modal-f { flex: none; }
label.f { position: relative; }
label.f > .counter { position: absolute; right: 0; top: 1px; float: none; }

/* ---- SaaS additions ---- */
.ws-switch { padding: 0 14px 10px; }
.ws-switch select { background: #1a3832; color: #fff; border-color: #24453e; height: 32px; font-weight: 600; }
.ws-meta { font-size: 11.5px; color: var(--side-ink2); margin-top: 5px; padding-left: 2px; }
.nav .count.warn { background: var(--warn); }
.side-foot a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.url-box { display: block; flex: 1; padding: 9px 12px; background: #f4f4ef; border: 1px solid var(--line); border-radius: 8px; word-break: break-all; font-family: var(--mono); font-size: 12.5px; }
.cmd { display: block; margin: 4px 0; padding: 6px 8px; background: #f4f4ef; border-radius: 6px; word-break: break-all; }
.site-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 4px 12px; margin: 6px 0; }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
input[type=radio] { accent-color: var(--accent); }
.check span b { font-weight: 600; }

.chat-shell { display: grid; grid-template-columns: 270px 1fr; gap: 14px; height: calc(100vh - 52px); }
.chat-list { display: flex; flex-direction: column; min-height: 0; }
.chat-items { overflow: auto; flex: 1; padding: 4px 6px 10px; }
.chat-items a { display: block; padding: 8px 10px; border-radius: 7px; color: var(--ink); }
.chat-items a:hover { background: #f4f4ef; text-decoration: none; }
.chat-items a.on { background: var(--accent-soft); }
.chat-items .t { display: block; font-weight: 550; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-items .m { display: block; font-size: 11.5px; color: var(--ink3); }
.chat-main { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.chat-h { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line2); }
.chat-log { flex: 1; overflow: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 760px; line-height: 1.55; }
.msg p { margin: 0 0 6px; } .msg p:last-child { margin: 0; } .msg ul, .msg ol { margin: 4px 0 6px; padding-left: 20px; } .msg li { margin: 2px 0; }
.msg .md-h { font-weight: 650; margin: 8px 0 4px; }
.msg code { background: #f0f0ea; padding: 1px 5px; border-radius: 4px; }
.msg .code-block { background: #10241f; color: #d9efe6; padding: 10px 12px; border-radius: 8px; overflow: auto; font-size: 12px; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; padding: 9px 13px; border-radius: 14px 14px 4px 14px; max-width: 70%; }
.msg.user code { background: rgba(255,255,255,.18); }
.msg.bot { align-self: flex-start; }
.msg.hint { color: var(--ink3); }
.msg.err { color: var(--fail); }
.tool-row { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; color: var(--ink2); background: #f7f7f3; border: 1px solid var(--line2); border-radius: 8px; padding: 6px 10px; max-width: 760px; }
.tool-row.ok > span:first-child { color: var(--ok); font-weight: 700; } .tool-row.err > span:first-child { color: var(--fail); font-weight: 700; }
.tool-row .spin { margin-top: 3px; color: var(--accent); }
.proposal-card { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid #f0d9a8; background: var(--warn-soft); border-radius: 9px; max-width: 760px; }
.proposal-card > div { flex: 1; }
.chat-input { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line2); align-items: flex-end; }
.chat-input textarea { resize: none; min-height: 44px; max-height: 160px; }
.chat-input .btn { height: 44px; }
@media (max-width: 980px) { .chat-shell { grid-template-columns: 1fr; height: auto; } .chat-main { min-height: 70vh; } }
