:root {
  --bg: #f6f3f7; --panel: #ffffff; --text: #241b2a; --muted: #6f6577; --line: #e4dde8;
  --accent: #8e3b8a; --accent-text: #fff; --ok: #1b8a4b; --warn: #b26a00; --bad: #c62828;
  color-scheme: light dark;
  font-family: -apple-system, "Rubik", "Segoe UI", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #17131a; --panel: #231d27; --text: #f1eaf4; --muted: #a99db0; --line: #3a3140; --accent: #c77dc2; --accent-text: #1a1020; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 16px; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 12px; }
h2 { font-size: 20px; } h3 { font-size: 17px; }
.muted { color: var(--muted); } .small { font-size: 13px; }

button { font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 10px 16px; min-height: 44px; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 700; }
button.ghost { background: transparent; }
button.small { padding: 6px 10px; min-height: 34px; font-size: 14px; }
button.wide { width: 100%; margin-top: 12px; }
button.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; min-height: 44px; }
input[type=color] { padding: 2px; height: 44px; }
input[type=checkbox], input[type=radio] { width: 22px; min-height: 22px; height: 22px; accent-color: var(--accent); }
input[type=range] { padding: 0; accent-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-size: 16px; }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login .panel { width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px; text-align: center; }
.error { color: var(--bad); font-weight: 700; margin: 0; }

.topbar { display: flex; align-items: center; gap: 6px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; overflow-x: auto; }
.topbar .app-name { margin-inline-end: 12px; white-space: nowrap; }
.tab { border: 0; background: transparent; white-space: nowrap; }
.tab.on { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); font-weight: 700; }
.spacer { flex: 1; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); }

.view { padding: 16px; max-width: 1400px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.span2 { grid-column: span 2; }
@media (max-width: 700px) { .span2 { grid-column: auto; } }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.row-between h2, .row-between h3 { margin: 0; }
.sticky { position: sticky; top: 64px; background: var(--bg); z-index: 5; padding: 8px 0; }

.alert { background: color-mix(in srgb, var(--bad) 12%, var(--panel)); border: 1px solid var(--bad); color: var(--text); border-radius: 12px; padding: 12px 16px; margin-bottom: 16px; font-weight: 600; }
.alert.warn { background: color-mix(in srgb, var(--warn) 12%, var(--panel)); border-color: var(--warn); }
.status-list { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0; }
.status-list dt { color: var(--muted); }
.status-list dd { margin: 0; font-weight: 600; }
.ok { color: var(--ok); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #fff3cd; color: #6b4e00; font-weight: 700; }
.big-number { font-size: 56px; font-weight: 800; line-height: 1; }
.qr-small { width: 180px; height: 180px; background: #fff; border-radius: 12px; display: block; margin: 8px 0; }
.last-final img { width: 100%; max-width: 320px; border-radius: 10px; display: block; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: start; padding: 8px 6px; border-bottom: 1px solid var(--line); }

.smtp-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.smtp-grid > .inline, .smtp-grid > .row { grid-column: 1 / -1; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.card { display: flex; flex-direction: column; gap: 8px; }
.card .swatch { height: 70px; border-radius: 10px; background-size: cover; background-position: center; display: flex; align-items: center; justify-content: center; font-weight: 700; padding: 8px; text-align: center; }
.card .actions { display: flex; flex-wrap: wrap; gap: 6px; }

.editor-grid { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(320px, 440px); gap: 16px; align-items: start; }
@media (max-width: 900px) { .editor-grid { grid-template-columns: 1fr; } }
.editor-form fieldset { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); padding: 16px; margin: 0 0 16px; display: flex; flex-direction: column; gap: 12px; }
.editor-form legend { font-weight: 700; font-size: 17px; padding: 0 6px; color: var(--text); }
.colors { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.upload { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; font-size: 14px; color: var(--muted); }
.upload img { grid-row: span 2; width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: repeating-conic-gradient(#ddd 0 25%, #fff 0 50%) 0 0/12px 12px; }
.upload img:not([src]), .upload img[src=""] { visibility: hidden; }
.previews { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 130px; }
.phone { width: 100%; max-width: 340px; margin: 0 auto; aspect-ratio: 9 / 18; border: 10px solid #222; border-radius: 34px; overflow: hidden; background: #000; }
.phone iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.stamp-preview { width: 100%; border-radius: 10px; display: block; background: var(--line); aspect-ratio: 4 / 5; object-fit: contain; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; min-height: 36px; padding: 6px 12px; }
.seg button.on { background: var(--accent); color: var(--accent-text); }

.overlay { position: fixed; inset: 0; background: #fff; z-index: 50; display: grid; place-items: center; color: #222; }
.qr-big { text-align: center; padding: 20px; }
.qr-big img { width: min(70vh, 80vw); height: min(70vh, 80vw); }
.qr-big h1 { font-size: 40px; }
.qr-big p { font-size: 28px; margin: 6px; }
.toast { position: fixed; bottom: 20px; inset-inline: 0; margin: auto; width: fit-content; max-width: 90vw; background: #222; color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 60; }
