/* Velvetap app (admin). Design plan:
   - Color: plum ink on a lilac-tinted paper; one velvet accent for primary actions and the live state.
   - Type: Instrument Sans for everything; Instrument Serif italic only for the wordmark.
   - Layout: rows, not card grids. Left-aligned forms. In the editor the phone preview is the hero.
   - One loud element per screen (the primary action); everything else stays quiet. */
@font-face { font-family: "Instrument Sans"; font-weight: 400 700; font-display: swap; src: url(/fonts/instrument-sans.woff2) format("woff2"); }
@font-face { font-family: "Instrument Serif"; font-style: italic; font-weight: 400; font-display: swap; src: url(/fonts/instrument-serif-italic.woff2) format("woff2"); }

:root {
  --bg: #f6f4f8;
  --surface: #ffffff;
  --sunk: #eeeaf2;
  --ink: #1d1426;
  --muted: #6b6276;
  --line: #e2dce8;
  --velvet: #7b2463;
  --velvet-ink: #ffffff;
  --velvet-soft: #f4e4ef;
  --chart: #a3368a;          /* validated: lightness band + 3:1 on surface */
  --ok: #1f7a4d;
  --ok-soft: #e2f3ea;
  --warn: #8a5300;
  --warn-soft: #fbefd9;
  --bad: #b3261e;
  --bad-soft: #fbe5e3;
  --shadow: 0 1px 2px rgba(29, 20, 38, .06), 0 8px 24px rgba(29, 20, 38, .06);
  --sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mark: "Instrument Serif", Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151019; --surface: #1d1723; --sunk: #110c15; --ink: #f0eaf4; --muted: #a69cb0; --line: #2e2636;
    --velvet: #e58bc9; --velvet-ink: #1d0f19; --velvet-soft: #3a2234; --chart: #c95fae;
    --ok: #63c996; --ok-soft: #173326; --warn: #f0b45a; --warn-soft: #3a2a12; --bad: #ff8a80; --bad-soft: #3d1a18;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151019; --surface: #1d1723; --sunk: #110c15; --ink: #f0eaf4; --muted: #a69cb0; --line: #2e2636;
  --velvet: #e58bc9; --velvet-ink: #1d0f19; --velvet-soft: #3a2234; --chart: #c95fae;
  --ok: #63c996; --ok-soft: #173326; --warn: #f0b45a; --warn-soft: #3a2a12; --bad: #ff8a80; --bad-soft: #3d1a18;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 400 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; }
h1 { font-size: 26px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 17px; font-weight: 650; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* Top bar */
.bar {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right));
}
.bar-in { max-width: 1180px; margin: 0 auto; height: 60px; display: flex; align-items: center; gap: 12px; }
.mark { font: italic 400 26px/1 var(--mark); letter-spacing: -.01em; text-decoration: none; color: var(--ink); }
.bar .grow { flex: 1; }

.wrap {
  max-width: 880px; margin: 0 auto; padding-block: 32px 64px;
  padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right));
  display: grid; gap: 24px;
}

/* Buttons and fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: 600 14px/1.2 var(--sans); cursor: pointer; text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--velvet); border-color: var(--velvet); color: var(--velvet-ink); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--velvet); }
.btn-quiet { background: transparent; border-color: transparent; }
.btn-quiet:hover { background: var(--sunk); border-color: transparent; }
.btn-danger { color: var(--bad); }
.btn-tg { background: #229ed9; border-color: #229ed9; color: #fff; min-height: 48px; padding: 12px 20px; font-size: 15px; }
.btn svg { width: 18px; height: 18px; flex: none; }
.icon-btn { width: 40px; padding: 0; }
:focus-visible { outline: 2px solid var(--velvet); outline-offset: 2px; }

.field { display: grid; gap: 6px; justify-items: start; }
.field > input, .field > select, .field > textarea, .field > .prefix, .field > .stack, .field > .colors, .field > .photo { justify-self: stretch; }
.field > span { font-weight: 600; font-size: 14px; }
.field .hint { font-size: 13px; color: var(--muted); }
input[type="text"], input[type="email"], input[type="url"], input:not([type]), select, textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: 400 15px/1.4 var(--sans);
}
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--velvet); outline-offset: 0; border-color: transparent; }
.prefix { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); overflow: hidden; }
.prefix span { display: flex; align-items: center; padding: 0 2px 0 12px; color: var(--muted); white-space: nowrap; }
.prefix input { border: 0; border-radius: 0; padding-left: 2px; }
.prefix:focus-within { outline: 2px solid var(--velvet); }
.prefix input:focus { outline: none; }

.check { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--velvet); margin: 0; }

.seg { display: inline-flex; flex-wrap: wrap; background: var(--sunk); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; color: var(--muted); font: 600 13px/1 var(--sans); padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.msg { padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.msg-bad { background: var(--bad-soft); color: var(--bad); }
.msg-warn { background: var(--warn-soft); color: var(--warn); }
.msg-ok { background: var(--ok-soft); color: var(--ok); }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-live { background: var(--ok-soft); color: var(--ok); }
.pill-draft { background: var(--sunk); color: var(--muted); }
.pill-changes { background: var(--warn-soft); color: var(--warn); }
.pill-off { background: var(--bad-soft); color: var(--bad); }

/* Home and sign in (/ and /login). The one loud element is the velvet panel: a deep plum pile with a
   directional sheen, the same in light and dark, carrying the wordmark. The sign-in side stays plain. */
.home { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr); }
.pile {
  --pile-ink: #f7e8f2; --pile-muted: #dcbfd2;
  position: relative; overflow: hidden; color: var(--pile-ink);
  background:
    radial-gradient(120% 70% at 18% 8%, rgba(214, 120, 186, .38), transparent 60%),
    radial-gradient(90% 60% at 95% 100%, rgba(150, 52, 120, .45), transparent 65%),
    linear-gradient(160deg, #4b1a41 0%, #2e0d28 55%, #1f081b 100%);
  padding: max(28px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 32px max(20px, env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 28px;
}
/* Fine pile: a faint diagonal grain, like nap on velvet. */
.pile::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .5; mix-blend-mode: soft-light;
  background: repeating-linear-gradient(115deg, rgba(255, 255, 255, .07) 0 1px, transparent 1px 3px);
}
.pile > * { position: relative; z-index: 1; }
.pile-mark { color: var(--pile-ink); font-size: clamp(56px, 16vw, 132px); line-height: .9; letter-spacing: -.03em; }
.pile-mark:focus-visible { outline-color: var(--pile-ink); }
.pile-copy { display: grid; gap: 20px; max-width: 34ch; }
.pile h1 { font-size: clamp(21px, 2.4vw, 28px); font-weight: 600; line-height: 1.3; letter-spacing: -.01em; color: var(--pile-ink); }
.pile-points { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; color: var(--pile-muted); font-size: 15px; }
.pile-points li { padding-left: 18px; position: relative; }
.pile-points li::before { content: ""; position: absolute; left: 0; top: .62em; width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid var(--pile-muted); }
.signin-col {
  width: 100%; max-width: 440px; padding: 36px 20px 48px; margin: 0 auto;
  display: flex; flex-direction: column; justify-content: center; gap: 24px;
}
.signin-col h2 { font-size: 24px; letter-spacing: -.01em; }
.tg-widget { min-height: 40px; }
@media (min-width: 900px) {
  .home { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
  .pile { padding: 56px clamp(40px, 6vw, 96px); justify-content: center; gap: 40px; min-height: 100vh; min-height: 100dvh; }
  .pile-copy { gap: 24px; }
  .pile-mark { font-size: clamp(96px, 10vw, 152px); }
  .signin-col { padding: 48px 32px; }
}
@media (max-width: 899px) {
  /* The panel keeps its own height; the sign-in takes the rest, from the top. */
  .home { grid-template-rows: auto 1fr; }
  .signin-col { justify-content: flex-start; }
  .pile-points { display: none; }
}
.signin-or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.signin-or::before, .signin-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.code-input { font-size: 22px !important; letter-spacing: 8px; font-variant-numeric: tabular-nums; }

/* Page list */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.item { display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 14px 16px; }
.item + .item { border-top: 1px solid var(--line); }
.thumb { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; background: var(--sunk); display: block; }
.item-main { min-width: 0; display: grid; gap: 2px; }
.item-title { font-weight: 650; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; }
.item-title:hover { text-decoration: underline; }
.item-url { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 4px; font-size: 13px; color: var(--muted); }
.item-actions { display: flex; gap: 4px; align-items: center; }
.empty { padding: 40px 24px; display: grid; gap: 16px; justify-items: start; }

.menu { position: relative; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 190px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px;
  display: grid;
}
.menu-pop button, .menu-pop a { text-align: left; border: 0; background: transparent; color: var(--ink); font: 500 14px/1.3 var(--sans); padding: 9px 10px; border-radius: 8px; cursor: pointer; text-decoration: none; }
.menu-pop button:hover, .menu-pop a:hover { background: var(--sunk); }

/* Dialog */
dialog { border: 0; border-radius: 16px; padding: 0; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(17, 10, 22, .45); }
.dlg { padding: 24px; display: grid; gap: 16px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow); }

/* Editor */
.ed { max-width: 1180px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 32px; align-items: start;
  padding-block: 24px 80px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
.ed-form { display: grid; gap: 16px; min-width: 0; }
.sec { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.sec > summary { list-style: none; cursor: pointer; padding: 16px 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary::after { content: ""; width: 9px; height: 9px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .15s; flex: none; }
.sec[open] > summary::after { transform: rotate(-135deg); }
.sec > summary .muted { font-weight: 400; font-size: 13px; }
.sec-body { padding: 0 18px 18px; display: grid; gap: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.colors { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.color { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px 6px 6px; }
.color input[type="color"] { width: 32px; height: 32px; border: 0; padding: 0; background: none; border-radius: 6px; cursor: pointer; flex: none; }
.color span { font-size: 13px; }
.presets { display: flex; gap: 8px; flex-wrap: wrap; }
.preset { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; padding: 0; overflow: hidden; display: grid; grid-template-columns: 1fr 1fr; }
.preset i { display: block; }
.photo { display: flex; gap: 14px; align-items: center; }
.photo img, .photo-empty { width: 72px; height: 90px; object-fit: cover; border-radius: 10px; background: var(--sunk); flex: none; }

.btn-card { border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.btn-card-head { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 4px; }
.drag { cursor: grab; touch-action: none; color: var(--muted); padding: 8px 6px; border: 0; background: none; display: grid; place-items: center; }
.drag svg { width: 16px; height: 16px; }
.btn-card-title { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-card-body { padding: 4px 14px 14px; display: grid; gap: 14px; }
.btn-card.dragging { opacity: .6; }
.btn-card.drop-before { box-shadow: 0 -3px 0 var(--velvet); }
.btn-card.drop-after { box-shadow: 0 3px 0 var(--velvet); }
.tag { font-size: 12px; color: var(--muted); }

.phone-col { position: sticky; top: 84px; display: grid; gap: 12px; justify-items: center; }
.phone { width: 360px; height: 720px; border-radius: 44px; padding: 12px; background: #0c090f; border: 1px solid var(--line); box-shadow: var(--shadow); }
.phone iframe { width: 100%; height: 100%; border: 0; border-radius: 34px; background: var(--surface); display: block; }
.phone-tools { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.save-state { font-size: 13px; color: var(--muted); }

.ed-bar-title { min-width: 0; display: flex; align-items: center; gap: 10px; }
.ed-bar-title select { width: auto; max-width: 220px; min-height: 36px; padding: 6px 10px; font-weight: 600; }
.tabs { display: none; }

@media (max-width: 960px) {
  .ed { grid-template-columns: minmax(0, 1fr); }
  .tabs { display: flex; position: sticky; top: 60px; z-index: 15; background: var(--bg); padding: 8px 0; }
  .tabs .seg { width: 100%; }
  .tabs .seg button { flex: 1; }
  .ed[data-tab="edit"] .phone-col { display: none; }
  .ed[data-tab="preview"] .ed-form { display: none; }
  .phone-col { position: static; }
  .phone { width: min(360px, 100%); height: 680px; }
}
@media (max-width: 560px) {
  .item { grid-template-columns: 40px minmax(0, 1fr); }
  .thumb { width: 40px; height: 40px; }
  .item-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  .bar .hide-sm { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Stats */
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; display: grid; gap: 4px; }
.tile b { font-size: 30px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.tile span { color: var(--muted); font-size: 13px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px; display: grid; gap: 14px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.panels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--chart); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--chart); opacity: .12; }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.chart .dot { fill: var(--chart); stroke: var(--surface); stroke-width: 2; }
.tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--bg); padding: 6px 10px; border-radius: 8px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -110%); }
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.bar-value { font-variant-numeric: tabular-nums; font-size: 14px; color: var(--muted); }
.bar-track { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--sunk); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 0 4px 4px 0; background: var(--chart); min-width: 2px; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.data td { padding: 8px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
table.data td.n, table.data th.n { text-align: right; }
.table-wrap { overflow-x: auto; }
@media (max-width: 720px) { .panels { grid-template-columns: minmax(0, 1fr); } .tiles { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .tile b { font-size: 24px; } }

/* Legal pages (/privacy, /terms): one readable column, list spacing, a highlighted short version. */
.doc { max-width: 680px; gap: 14px; }
.doc .mark { margin-bottom: 8px; }
.doc h2 { margin-top: 18px; }
.doc ul { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.doc p, .doc li { max-width: 68ch; }
.doc code { font-size: 13px; background: var(--sunk); padding: 1px 5px; border-radius: 5px; }
.doc-short { background: var(--velvet-soft); border-radius: 14px; padding: 16px 18px; display: grid; gap: 8px; }
.doc-short h2 { margin-top: 0; }
