/* KADILI BOT CLOUD — interface styles. Light theme by default; dark via [data-theme="dark"] or system preference. */
:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f1f3f6; --border: #e3e6eb; --text: #17202b; --muted: #5f6b7a;
  --accent: #0b7a5a; --accent-strong: #08654a; --accent-soft: #e3f3ed; --on-accent: #ffffff;
  --ok: #157f4b; --ok-soft: #e4f4ea; --warn: #9a6200; --warn-soft: #fbf0d9; --bad: #b42318; --bad-soft: #fdecea; --info-soft: #e8f0fb;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --radius: 10px; --sidebar: 248px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0f141a; --surface: #161d25; --surface-2: #1d2630; --border: #2a3541; --text: #e6ebf1; --muted: #98a4b3;
  --accent: #2fbf8f; --accent-strong: #4fd3a6; --accent-soft: #143a2f; --on-accent: #062a1e;
  --ok: #4fd18b; --ok-soft: #133524; --warn: #f0b44c; --warn-soft: #3a2c10; --bad: #ff7a6e; --bad-soft: #3d1a17; --info-soft: #182a40;
  --shadow: none; color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    --bg: #0f141a; --surface: #161d25; --surface-2: #1d2630; --border: #2a3541; --text: #e6ebf1; --muted: #98a4b3;
    --accent: #2fbf8f; --accent-strong: #4fd3a6; --accent-soft: #143a2f; --on-accent: #062a1e;
    --ok: #4fd18b; --ok-soft: #133524; --warn: #f0b44c; --warn-soft: #3a2c10; --bad: #ff7a6e; --bad-soft: #3d1a17; --info-soft: #182a40;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 var(--font); background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
small, .muted { color: var(--muted); }
code, .mono { font-family: var(--mono); font-size: .9em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; padding: .25rem .5rem 1rem; letter-spacing: .02em; color: var(--text); }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; font-weight: 800; }
.brand small { display: block; font-weight: 500; font-size: .72rem; color: var(--muted); letter-spacing: 0; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: .65rem; padding: .5rem .65rem; border-radius: 8px; color: var(--text); font-size: .92rem; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.nav .section { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: .9rem .65rem .3rem; }
.nav .count { margin-left: auto; background: var(--accent); color: var(--on-accent); border-radius: 999px; font-size: .72rem; padding: 0 .45rem; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: .75rem; padding: .75rem 1.5rem; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: .88rem; color: var(--muted); }
.menu-toggle { display: none; }
.content { padding: 1.5rem; max-width: 1280px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head p { margin: 0; color: var(--muted); }

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .75rem; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow); }
.stat .label { font-size: .8rem; color: var(--muted); }
.stat .value { font-size: 1.35rem; font-weight: 650; letter-spacing: -.01em; margin-top: .15rem; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: .8rem; color: var(--muted); margin-top: .1rem; }
.badge { display: inline-block; padding: .08rem .55rem; border-radius: 999px; font-size: .76rem; font-weight: 600; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-neutral { background: var(--surface-2); color: var(--muted); }
.alert { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid transparent; }
.alert-success { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.alert-error { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }
.alert-info { background: var(--info-soft); color: var(--text); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .6rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

form.stack > * + * { margin-top: .85rem; }
label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .3rem; }
.hint { font-size: .8rem; color: var(--muted); font-weight: 400; margin-top: .25rem; }
input:not([type]), input[type=text], input[type=email], input[type=password], input[type=number], input[type=tel], input[type=date], input[type=datetime-local], input[type=time], input[type=search], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.check { display: flex; align-items: flex-start; gap: .5rem; font-weight: 500; }
.check input { margin-top: .25rem; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 160px; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn-sm { padding: .3rem .65rem; font-size: .82rem; }
.btn-link { background: none; border: 0; color: var(--accent); padding: 0; font-weight: 600; cursor: pointer; font: inherit; }
.inline { display: inline; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters input, .filters select { width: auto; min-width: 180px; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .5rem .8rem; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; font-size: .9rem; }
.tabs a.active { border-color: var(--accent); color: var(--text); }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .86rem; }
dl.kv dd { margin: 0; }
.steps { display: flex; gap: .5rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.steps span { padding: .3rem .7rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .82rem; font-weight: 600; }
.steps span.done { background: var(--ok-soft); color: var(--ok); }
.steps span.now { background: var(--accent); color: var(--on-accent); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.auth-card { width: 100%; max-width: 440px; }
.auth-card.wide { max-width: 640px; }
.auth .brand { justify-content: center; padding-bottom: 1.25rem; }

/* ---------- inbox ---------- */
.inbox { display: grid; grid-template-columns: 320px 1fr 280px; gap: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); min-height: 70vh; overflow: hidden; }
.inbox-list { border-right: 1px solid var(--border); overflow-y: auto; max-height: 78vh; }
.inbox-list a { display: block; padding: .7rem .9rem; border-bottom: 1px solid var(--border); color: var(--text); }
.inbox-list a:hover, .inbox-list a.active { background: var(--surface-2); text-decoration: none; }
.inbox-list .top { display: flex; justify-content: space-between; gap: .5rem; font-weight: 600; font-size: .9rem; }
.inbox-list .prev { font-size: .82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread { display: flex; flex-direction: column; min-width: 0; }
.thread-head { padding: .75rem 1rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: .5rem; align-items: center; flex-wrap: wrap; }
.messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .5rem; max-height: 60vh; background: var(--bg); }
.msg { max-width: 75%; padding: .5rem .75rem; border-radius: 10px; white-space: pre-wrap; word-wrap: break-word; font-size: .9rem; }
.msg.in { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); }
.msg.out { align-self: flex-end; background: var(--accent-soft); }
.msg .meta { display: block; font-size: .72rem; color: var(--muted); margin-top: .2rem; }
.composer { border-top: 1px solid var(--border); padding: .75rem; display: flex; gap: .5rem; }
.composer textarea { min-height: 44px; height: 44px; }
.side { border-left: 1px solid var(--border); padding: 1rem; overflow-y: auto; max-height: 78vh; font-size: .88rem; }

/* ---------- bot builder & simulator ---------- */
.menu-card { border: 1px solid var(--border); border-radius: 8px; padding: .75rem; margin-bottom: .75rem; background: var(--surface-2); }
.menu-card .item { display: grid; grid-template-columns: 28px 1.3fr 1fr 1.3fr auto; gap: .4rem; align-items: center; margin-top: .4rem; }
.menu-card .pos { font-weight: 700; color: var(--muted); text-align: center; }
.phone { max-width: 420px; border: 1px solid var(--border); border-radius: 18px; overflow: hidden; background: var(--surface); }
.phone .messages { max-height: 55vh; min-height: 55vh; }
.qr-box { width: 280px; height: 280px; border: 1px solid var(--border); border-radius: 12px; display: grid; place-items: center; background: #fff; }
.qr-box img { width: 260px; height: 260px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .inbox { grid-template-columns: 280px 1fr; }
  .side { display: none; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 82vw; max-width: 300px; z-index: 20; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-flex; }
  .content { padding: 1rem; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .inbox { grid-template-columns: 1fr; }
  .inbox.has-active .inbox-list { display: none; }
  .inbox:not(.has-active) .thread { display: none; }
  .menu-card .item { grid-template-columns: 24px 1fr; }
  th, td { padding: .5rem .4rem; }
  .hide-sm { display: none; }
}
@media (max-width: 480px) { .grid-4 { grid-template-columns: 1fr 1fr; } .stat .value { font-size: 1.1rem; } }
@media print { .sidebar, .topbar, .actions, .btn { display: none !important; } .shell { display: block; } }
.w-auto { width: auto !important; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mb-0 { margin-bottom: 0; }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.big { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: var(--accent); border-radius: 4px; min-width: 2px; }
.bar-track { background: var(--surface-2); border-radius: 4px; }
.pre { white-space: pre-wrap; }

.filters .check { flex: none; display: inline-flex; align-items: center; gap: .35rem; margin: 0; white-space: nowrap; }
.filters .check input { margin: 0; }
.filters input[type=checkbox] { min-width: 0; width: auto; }
