:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --line: #e5e7eb;
  --soft: #f1f2f6;
  --accent: #d62976;
  --accent-2: #962fbf;
  --grad: linear-gradient(135deg, #fa7e1e 0%, #d62976 50%, #962fbf 100%);
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #181b21;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --line: #2a2e37;
    --soft: #20242c;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
}
.hidden { display: none !important; }
a { color: var(--accent); }
h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--err); min-height: 1em; margin: 8px 0 0; }

.logo { font-weight: 800; font-size: 20px; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* layout */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--card); border-right: 1px solid var(--line); padding: 22px 14px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; }
.side nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.side nav a { padding: 10px 12px; border-radius: 10px; color: var(--text); text-decoration: none; cursor: pointer; }
.side nav a:hover { background: var(--soft); }
.side nav a.active { background: var(--soft); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
main { padding: 28px clamp(16px, 4vw, 40px); max-width: 1100px; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: sticky; height: auto; flex-direction: row; align-items: center; padding: 10px 12px; gap: 10px; z-index: 5; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .side .logo { display: none; }
  .side nav { flex-direction: row; gap: 2px; }
  .side nav a { white-space: nowrap; padding: 8px 10px; }
  .side nav a span { display: none; }
  .side nav a.active { box-shadow: inset 0 -3px 0 var(--accent); }
  main { padding: 18px 16px; }
}

/* cards & grid */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 14px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 18px; }
.stat .num { font-size: 28px; font-weight: 750; }
.stat .lbl { color: var(--muted); font-size: 13px; }
.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .two { grid-template-columns: 1fr; } }
.stack > * + * { margin-top: 14px; }

/* checklist */
.check { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.check:last-child { border-bottom: 0; }
.check .dot { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; background: var(--soft); }
.check.ok .dot { background: #dcfce7; color: var(--ok); }
@media (prefers-color-scheme: dark) { .check.ok .dot { background: #14532d; color: #86efac; } }

/* buttons */
.btn { border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 9px 14px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--grad); color: #fff; border: 0; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--err); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* forms */
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 12px; }
label .hint { font-weight: 400; color: var(--muted); }
input[type=text], input[type=password], input[type=url], input[type=number], textarea, select {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-weight: 400;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }
.section { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.section-title { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.section-title h3 { margin: 0; }
.step { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--grad); color: #fff; font-size: 12px; margin-right: 6px; }
.copy { display: flex; gap: 6px; }
.copy input { margin-top: 0; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }

/* automations */
.auto { display: flex; gap: 14px; justify-content: space-between; align-items: flex-start; }
.auto .meta { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; background: var(--soft); font-size: 12px; color: var(--muted); }
.tag.on { background: #dcfce7; color: var(--ok); }
.tag.gate { background: #fce7f3; color: var(--accent); }
@media (prefers-color-scheme: dark) { .tag.on { background: #14532d; color: #86efac; } .tag.gate { background: #500724; color: #f9a8d4; } }
.auto .nums { display: flex; gap: 16px; color: var(--muted); font-size: 13px; }
.auto .nums b { color: var(--text); }
.tag { white-space: nowrap; }
@media (max-width: 760px) {
  .auto { flex-direction: column; }
  .auto .nums { flex-wrap: wrap; gap: 4px 14px; }
}
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.presets { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.preset { cursor: pointer; text-align: left; color: var(--text); font: inherit; width: 100%; }
.preset:hover { border-color: var(--accent); }

/* media picker */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; max-height: 300px; overflow: auto; margin-top: 8px; }
.media-item { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 2px solid transparent; cursor: pointer; background: var(--soft); }
.media-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-item.sel { border-color: var(--accent); }
.media-item.sel::after { content: "✓"; position: absolute; top: 4px; right: 4px; background: var(--accent); color: #fff; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; }
.media-item .cap { position: absolute; inset: auto 0 0 0; font-size: 10px; padding: 2px 4px; background: rgba(0,0,0,.55); color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* tables / logs */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.log { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.log:last-child { border-bottom: 0; }
.log time { color: var(--muted); font-size: 12px; flex: none; width: 92px; padding-top: 2px; }
.log .ico { flex: none; }
.log.error .msg { color: var(--err); }
.log .msg { word-break: break-word; }

/* modal & toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; justify-content: center; align-items: flex-start; padding: 30px 16px; overflow-y: auto; z-index: 20; }
.modal-box { background: var(--card); border-radius: 18px; width: 100%; max-width: 680px; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; position: sticky; bottom: -22px; background: var(--card); padding: 12px 0 0; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 30; max-width: calc(100vw - 32px); }
.toast.err { background: var(--err); color: #fff; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card .btn { width: 100%; justify-content: center; }

.notice { border-radius: 12px; padding: 12px 14px; background: #fef3c7; color: #78350f; margin-bottom: 14px; font-size: 14px; }
@media (prefers-color-scheme: dark) { .notice { background: #422006; color: #fde68a; } }
code { background: var(--soft); padding: 1px 6px; border-radius: 6px; font-size: 13px; }
