:root {
  --navy: #002366;
  --navy-2: #0b3380;
  --lilac: #b5b8d5;
  --lilac-soft: #dcdeec;
  --taupe: #988475;
  --ink: #252525;
  --bg: #edeceb;
  --card: #f6f5f4;
  --line: #d9d6d3;
  --muted: #6f655d;
  --ok: #2f7d4f;
  --warn: #a8641a;
  --err: #b23a3a;
  --radius: 12px;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 14px; line-height: 1.45; }
a { color: var(--navy); }
h1 { font-size: 22px; margin: 0 0 4px; color: var(--navy); }
h2 { font-size: 16px; margin: 0 0 12px; color: var(--navy); }
h3 { font-size: 14px; margin: 0 0 8px; }
p.lead { color: var(--muted); margin: 0 0 20px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--navy); color: #edeceb; padding: 20px 14px; display: flex; flex-direction: column; gap: 4px; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: .3px; padding: 0 10px 18px; }
.brand span { color: var(--lilac); }
.side a { color: #dfe1ee; text-decoration: none; padding: 9px 12px; border-radius: 8px; display: flex; align-items: center; gap: 10px; }
.side a:hover { background: rgba(255,255,255,.08); }
.side a.on { background: var(--lilac); color: var(--navy); font-weight: 600; }
.side .spacer { flex: 1; }
.side form button { width: 100%; background: transparent; color: #dfe1ee; border: 1px solid rgba(255,255,255,.25); }
.conn-pill { margin: 6px 10px 12px; font-size: 12px; padding: 6px 10px; border-radius: 99px; background: rgba(255,255,255,.1); }
.conn-pill.ok::before { content: '●'; color: #7fd1a0; margin-right: 6px; }
.conn-pill.off::before { content: '●'; color: #f0a0a0; margin-right: 6px; }
main { padding: 28px 32px 60px; max-width: 1180px; width: 100%; }

/* Cards & grid */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 18px; }
.kpi .v { font-size: 28px; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.two { grid-template-columns: 1fr 1fr; }
.meter { height: 8px; background: var(--lilac-soft); border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.meter > div { height: 100%; background: var(--navy); }

/* Buttons & inputs */
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { border-color: var(--taupe); }
.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.primary:hover { background: var(--navy-2); }
.danger { color: var(--err); }
.ghost { background: transparent; border-color: transparent; }
.ghost:hover { background: var(--lilac-soft); }
button:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=url], input[type=search], input[type=password], input[type=email], select, textarea {
  font: inherit; width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fbfaf9; color: var(--ink);
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--lilac); border-color: var(--navy); }
label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; font-weight: 600; margin-bottom: 5px; }
label.f > small { display: block; color: var(--muted); margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; margin: 8px 0; cursor: pointer; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 160px; }
.toolbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; }
.seg button.on { background: var(--navy); color: #fff; }

/* Tables */
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: .4px; color: var(--muted); font-weight: 600; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--lilac-soft); }
.tag { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--lilac-soft); color: var(--navy); margin: 1px 2px 1px 0; }
.tag.ok { background: #dcefe3; color: var(--ok); }
.tag.warn { background: #f6e6d2; color: var(--warn); }
.tag.err { background: #f4dada; color: var(--err); }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }

/* Automations list */
.auto-list { display: grid; gap: 12px; }
.auto { display: grid; grid-template-columns: 56px 1fr auto; gap: 14px; align-items: center; }
.thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: var(--lilac-soft); display: grid; place-items: center; color: var(--navy); font-size: 20px; }
.auto .stats { display: flex; gap: 14px; color: var(--muted); font-size: 12px; margin-top: 4px; flex-wrap: wrap; }
.auto .stats b { color: var(--ink); }
.switch { position: relative; width: 38px; height: 22px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; transition: .15s; cursor: pointer; }
.switch span::before { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--navy); }
.switch input:checked + span::before { transform: translateX(16px); }

/* Editor */
.editor { display: grid; grid-template-columns: 1fr; gap: 16px; }
.section-title { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.section-title .n { width: 24px; height: 24px; border-radius: 50%; background: var(--navy); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; max-height: 300px; overflow: auto; padding: 2px; }
.media-grid .m { border: 2px solid transparent; border-radius: 8px; overflow: hidden; cursor: pointer; background: var(--lilac-soft); aspect-ratio: 1; position: relative; padding: 0; }
.media-grid .m img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-grid .m.on { border-color: var(--navy); box-shadow: 0 0 0 2px var(--lilac); }
.media-grid .m .any { display: grid; place-items: center; height: 100%; font-weight: 600; color: var(--navy); font-size: 12px; text-align: center; padding: 6px; }
.step { border: 1px solid var(--line); border-left: 4px solid var(--navy); border-radius: 10px; padding: 14px; background: #fbfaf9; margin-bottom: 12px; }
.step-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.btn-row { display: grid; grid-template-columns: 1fr 130px 1.4fr auto; gap: 8px; margin-bottom: 8px; }
.counter { text-align: right; font-size: 11px; color: var(--muted); }
.opt { background: var(--card); border-radius: 8px; padding: 8px 12px; margin-top: 8px; }
.savebar { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; display: flex; gap: 10px; justify-content: flex-end; border-top: 1px solid var(--line); }

/* Simulator */
.sim { display: grid; grid-template-columns: 320px 1fr; gap: 16px; align-items: start; }
.phone { background: #fbfaf9; border: 1px solid var(--line); border-radius: 22px; padding: 14px; min-height: 480px; display: flex; flex-direction: column; }
.phone .top { font-weight: 600; padding-bottom: 10px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.msgs { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 8px; max-height: 520px; padding: 4px; }
.bubble { max-width: 78%; padding: 9px 12px; border-radius: 16px; white-space: pre-wrap; word-break: break-word; }
.bubble.in { align-self: flex-end; background: var(--navy); color: #fff; border-bottom-right-radius: 4px; }
.bubble.out { align-self: flex-start; background: var(--lilac-soft); border-bottom-left-radius: 4px; }
.bubble.note { align-self: center; background: transparent; color: var(--muted); font-size: 12px; text-align: center; max-width: 100%; }
.bubble .bt { display: block; width: 100%; margin-top: 6px; justify-content: center; background: var(--card); color: var(--navy); font-weight: 600; }
.bubble .meta { display: block; font-size: 10px; opacity: .7; margin-top: 4px; }

/* Drawer */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100%); background: var(--card); border-left: 1px solid var(--line); padding: 20px; overflow: auto; box-shadow: -10px 0 30px rgba(0,0,0,.08); z-index: 10; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.copy { display: flex; gap: 6px; }
.copy input { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.steps-list { padding-left: 20px; }
.steps-list li { margin-bottom: 8px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 20; }
.toast.err { background: var(--err); }
.alert { background: #f6e6d2; color: #6b4210; border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { flex-direction: row; flex-wrap: wrap; padding: 10px 16px; gap: 2px; }
  .brand { padding: 6px 10px; width: 100%; }
  .side .spacer, .conn-pill { display: none; }
  main { padding: 20px 16px 60px; }
  .two, .sim { grid-template-columns: 1fr; }
  .btn-row { grid-template-columns: 1fr 1fr; }
  .table-wrap { overflow-x: auto; }
}
