/* Autoemail control panel.
   One stylesheet, no framework, no build step - the deploy is a file copy. */

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #fbfbfa;
  --line: #e6e4df;
  --line-strong: #d6d3cc;
  --text: #1a1a18;
  --muted: #6f6d67;
  --faint: #96938c;
  --accent: #1f6f4a;
  --accent-soft: #e8f1ec;
  --accent-text: #ffffff;
  --warn: #8a5a12;
  --warn-soft: #fbf1de;
  --danger: #a02f22;
  --danger-soft: #fbecea;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(20, 18, 14, .05), 0 4px 14px rgba(20, 18, 14, .04);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131311;
    --surface: #1c1c1a;
    --surface-2: #201f1d;
    --line: #2e2d2a;
    --line-strong: #3c3a36;
    --text: #eceae5;
    --muted: #a29f98;
    --faint: #7d7a73;
    --accent: #4fa87a;
    --accent-soft: #1b2a22;
    --accent-text: #0d1310;
    --warn: #d8a94f;
    --warn-soft: #2a2213;
    --danger: #e08074;
    --danger-soft: #2b1815;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .2);
  }
}

* { box-sizing: border-box; }

/* Any rule below that sets `display` on a class would otherwise out-specify the
   user agent's `[hidden] { display: none }` and leave hidden elements visible. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; letter-spacing: -.015em; font-weight: 650; }
h1 { font-size: 26px; line-height: 1.2; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.error { color: var(--danger); font-size: 14px; }
.mono { font-family: var(--mono); font-size: 13px; }

/* ── gate ─────────────────────────────────────────────────────────────── */
.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
}
.gate-mark svg, .brand-mark svg { width: 100%; height: 100%; }
.gate-mark rect, .brand-mark rect { fill: var(--accent); }
.gate-mark { width: 44px; height: 44px; }
.gate-card h1 { font-size: 21px; }
.gate-card .muted { font-size: 14px; margin-top: -8px; }

/* ── layout ───────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100dvh; }

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--surface-2);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: sticky;
  top: 0;
  height: 100dvh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-mark { width: 26px; height: 26px; flex: none; }
.brand-text { font-weight: 650; letter-spacing: -.02em; }
.brand-text em {
  display: block;
  font: 400 11px/1.4 var(--mono);
  color: var(--faint);
  font-style: normal;
}

.shop-switch { display: grid; gap: 3px; }
.shop-switch button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.shop-switch button:hover { background: var(--surface); color: var(--text); }
.shop-switch button.active {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--text);
  font-weight: 550;
  box-shadow: var(--shadow);
}
.pip { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--faint); }
.pip.ok { background: var(--accent); }
.pip.warn { background: var(--warn); }
.pip.off { background: var(--line-strong); }

.nav { display: grid; gap: 2px; }
.nav button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.nav button:hover { background: var(--surface); color: var(--text); }
.nav button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--warn); }

.sidebar-foot { margin-top: auto; display: grid; gap: 2px; }
.link {
  background: none; border: 0; padding: 7px 10px; text-align: left;
  color: var(--faint); font: inherit; font-size: 13px; cursor: pointer; border-radius: 8px;
}
.link:hover { color: var(--text); background: var(--surface); }

.main { padding: 34px 40px 80px; max-width: 1080px; }
.page-head { margin-bottom: 26px; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.page-head p { color: var(--muted); font-size: 14px; margin-top: 5px; max-width: 62ch; }

/* ── cards ────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
/* Let the text block shrink so a status badge stays on the title's line
   instead of being pushed below a long description. */
.card-head > div:first-child { flex: 1 1 240px; min-width: 0; }
.card-head p { color: var(--muted); font-size: 13.5px; margin-top: 4px; max-width: 62ch; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.grid-2 .card + .card { margin-top: 0; }

/* ── forms ────────────────────────────────────────────────────────────── */
/* align-content:start keeps the input directly under its label. Without it a
   field stretches to the tallest cell in its grid row, so a neighbour with help
   text below pushes this one's input out of line. */
.field { display: grid; gap: 6px; align-content: start; }
.field > span { font-size: 13px; font-weight: 550; color: var(--text); }
.field small { color: var(--faint); font-size: 12.5px; line-height: 1.45; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=time], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
textarea { resize: vertical; min-height: 76px; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
input::placeholder { color: var(--faint); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 15px; }
.form-grid.full { grid-template-columns: 1fr; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row .field { flex: 1 1 200px; }

.switch { display: flex; align-items: center; gap: 11px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  width: 38px; height: 22px; border-radius: 999px; background: var(--line-strong);
  position: relative; transition: background .15s; flex: none;
}
.switch .track::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; transition: transform .15s;
  box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch-text { font-size: 14px; }
.switch-text small { display: block; color: var(--faint); font-size: 12.5px; }

/* ── buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 550; cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--faint); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.actions { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; padding: 0 4px; }

/* ── status bits ──────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; letter-spacing: .01em;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.badge.ok { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

.checklist { display: grid; gap: 9px; }
.checklist li { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; }
.checklist ul, .checklist { list-style: none; margin: 0; padding: 0; }
.tick { width: 18px; height: 18px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 11px; font-weight: 700; margin-top: 1px; }
.tick.on { background: var(--accent); color: var(--accent-text); }
.tick.off { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn); }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 2px 20px; }
.stat { padding: 2px 0; }
.stat b { display: block; font-size: 22px; font-weight: 620; letter-spacing: -.02em; }
.stat span { font-size: 12.5px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; padding: 0 10px 8px 0; }
td { padding: 10px 10px 10px 0; border-top: 1px solid var(--line); vertical-align: middle; }
td.num, th.num { text-align: right; padding-right: 0; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.prod { display: flex; align-items: center; gap: 10px; min-width: 0; }
.prod img { width: 34px; height: 34px; border-radius: 6px; object-fit: cover; background: var(--surface-2); flex: none; }
.prod a { color: inherit; text-decoration: none; font-weight: 520; }
.prod a:hover { text-decoration: underline; }
.strike { text-decoration: line-through; color: var(--faint); }
.down { color: var(--accent); font-weight: 620; }

.empty { padding: 34px 20px; text-align: center; color: var(--muted); font-size: 14px; }
.note { padding: 12px 14px; border-radius: 8px; font-size: 13.5px; line-height: 1.5; }
.note.warn { background: var(--warn-soft); color: var(--warn); }
.note.info { background: var(--accent-soft); color: var(--accent); }
.note.bad { background: var(--danger-soft); color: var(--danger); }
.note + .note { margin-top: 8px; }

.preview-frame { width: 100%; height: 620px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

/* ── drawer ───────────────────────────────────────────────────────────── */
.drawer {
  position: fixed; right: 18px; bottom: 18px; width: min(560px, calc(100vw - 36px));
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.22); z-index: 50; overflow: hidden;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.drawer-head strong { font-size: 14px; }
.drawer-head .muted { font-size: 12px; margin-left: 8px; font-variant-numeric: tabular-nums; }
.drawer-log {
  margin: 0; padding: 12px 14px; max-height: 300px; overflow: auto;
  font-family: var(--mono); font-size: 12px; line-height: 1.55;
  color: var(--muted); white-space: pre-wrap; word-break: break-word;
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 550; z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,.22);
}
.toast.bad { background: var(--danger); color: #fff; }

.spin { display: inline-block; width: 13px; height: 13px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 780px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: column; }
  .nav { grid-auto-flow: column; overflow-x: auto; }
  .main { padding: 24px 18px 70px; }
}

/* ── guided setup ──────────────────────────────────────────────────────── */

.progress-bar {
  height: 4px; border-radius: 99px; background: var(--line);
  overflow: hidden; margin-bottom: 22px;
}
.progress-bar i { display: block; height: 100%; background: var(--accent); transition: width .35s ease; }

.nav-setup { font-weight: 600; }
.step-count { font: 500 11px/1 var(--mono); color: var(--faint); font-style: normal; }

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; counter-reset: step; }

.step {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.step.open { border-color: var(--line-strong); }
.step.blocked { opacity: .55; }

.step-head {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 15px 18px; background: none; border: 0; cursor: pointer;
  font: inherit; text-align: left; color: var(--text);
}
.step-head:hover { background: var(--surface-2); }

.step-num {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 650;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--line-strong);
}
.step.done .step-num { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.step.open .step-num { border-color: var(--accent); color: var(--accent); }

.step-title { flex: 1; min-width: 0; }
.step-title strong { display: block; font-size: 15px; font-weight: 600; }
.step-title small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.step-chevron { color: var(--faint); font-size: 12px; }

.step-body { padding: 4px 18px 20px 58px; border-top: 1px solid var(--line); padding-top: 18px; }
@media (max-width: 620px) { .step-body { padding-left: 18px; } }

.howto { margin: 0; padding-left: 20px; display: grid; gap: 9px; font-size: 14px; line-height: 1.55; }
.howto li { padding-left: 3px; }
.howto b { font-weight: 600; }

.scopes { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.scopes span {
  font: 500 12px/1 var(--mono);
  background: var(--surface-2); border: 1px solid var(--line-strong);
  border-radius: 6px; padding: 5px 8px; color: var(--text);
}

.result { font-size: 13.5px; line-height: 1.45; }
.result.ok { color: var(--accent); }
.result.bad { color: var(--danger); }

.rule-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.rule-card {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px 15px;
}
.rule-card strong { display: block; font-size: 14px; font-weight: 620; margin-bottom: 5px; }
.rule-card p { font-size: 13px; line-height: 1.5; color: var(--muted); margin: 0; }
