/* StitchViewer — shared styles (user app + admin portal) */
:root {
  --navy: #2a43c4;
  --navy-2: #2238a8;
  --thread: #e85d3f;
  --thread-dark: #c8442a;
  --linen: #eef0f4;
  --bg: #eef0f4;
  --surface: #ffffff;
  --surface-2: #f6f7fa;
  --ink: #1b1d26;
  --muted: #6a6c78;
  --line: #d9dce5;
  --ok: #1f8a5b;
  --ok-bg: #e5f4ec;
  --warn: #a8640a;
  --warn-bg: #fdf1dd;
  --bad: #b3261e;
  --bad-bg: #fbe7e5;
  --info-bg: #e8eefb;
  --wa: #1fa855;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 33, 61, .06), 0 8px 24px rgba(20, 33, 61, .08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1424;
    --surface: #171e33;
    --surface-2: #1c2440;
    --ink: #ecebf2;
    --muted: #a3a6b8;
    --line: #2b3554;
    --ok-bg: #12352a;
    --warn-bg: #3a2c12;
    --bad-bg: #3d1a1a;
    --info-bg: #1d2a4d;
    --ok: #5fd39b;
    --warn: #f0b356;
    --bad: #ff8a80;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
a { color: var(--thread-dark); }
code { font-size: .9em; background: var(--surface-2); padding: .1em .35em; border-radius: 5px; }
.muted { color: var(--muted); }
.inline { display: inline; margin: 0; }
.center { text-align: center; }
[hidden] { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  min-height: 44px; padding: .6em 1.1em;
  font: inherit; font-weight: 600; text-decoration: none; white-space: nowrap;
  border: 1px solid transparent; border-radius: 10px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--thread) 45%, transparent); outline-offset: 2px;
}
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-2); }
.btn-accent { background: var(--thread); color: #fff; }
.btn-accent:hover { background: var(--thread-dark); }
.btn-whatsapp { background: var(--wa); color: #fff; }
.btn-whatsapp:hover { filter: brightness(.95); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.btn-danger:hover { background: var(--bad-bg); }
.btn-ok { background: var(--ok); color: #fff; }
.btn-ok:hover { filter: brightness(.95); }
.btn-sm { min-height: 34px; padding: .35em .75em; font-size: .875rem; border-radius: 8px; }
.btn-block { width: 100%; }
@media (prefers-color-scheme: dark) {
  .btn-primary { background: #8d9cff; color: #10132a; }
  .btn-primary:hover { background: #a3b0ff; }
}

/* ---------- Forms ---------- */
.form { display: grid; gap: 1rem; }
.field { display: grid; gap: .35rem; }
.field > span:first-child { font-size: .875rem; font-weight: 600; }
.field small { color: var(--muted); font-size: .8rem; }
input[type=text], input[type=password], input[type=number], input[type=search],
input[type=datetime-local], select, textarea {
  width: 100%; min-height: 46px; padding: .6em .8em;
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px;
}
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 4.5rem; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; color: var(--muted); font: inherit; font-size: .85rem; font-weight: 600;
  padding: .4em .6em; cursor: pointer; border-radius: 6px;
}
.input-row { display: flex; gap: .5rem; }
.input-row input { flex: 1; }

/* ---------- Alerts ---------- */
.alert { padding: .8rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-size: .95rem; border: 1px solid transparent; }
.alert-error, .alert-locked { background: var(--bad-bg); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }
.alert-warning, .alert-expired { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.alert-info { background: var(--info-bg); color: var(--ink); }
.alert-ok { background: var(--ok-bg); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.alert-link { display: block; margin-top: .4rem; font-weight: 700; color: inherit; }

/* ---------- Auth page ---------- */
.auth-page {
  min-height: 100vh; min-height: 100dvh;
  background:
    radial-gradient(1200px 500px at 50% -10%, color-mix(in srgb, var(--navy) 14%, transparent), transparent 70%),
    var(--bg);
}
.auth-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); padding: 28px 24px;
}
.brand { display: flex; align-items: center; gap: .8rem; margin-bottom: 1.5rem; color: inherit; text-decoration: none; }
.brand h1 { margin: 0; font-size: 1.4rem; }
.brand p { margin: 0; font-size: .9rem; }
.brand-mark { flex: none; display: block; }
.brand-sm { margin: 0; gap: .55rem; }
.divider { display: flex; align-items: center; gap: .75rem; margin: 1.4rem 0 1rem; color: var(--muted); font-size: .85rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.fine { margin: .75rem 0 0; font-size: .8rem; color: var(--muted); text-align: center; }

/* ---------- User app ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--navy); color: #fff;
  padding-top: env(safe-area-inset-top);
}
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.topbar .brand { color: #fff; }
.topbar .btn-ghost { color: #fff; border-color: rgba(255, 255, 255, .25); }
.topbar .btn-ghost:hover { background: rgba(255, 255, 255, .08); }
.topbar-actions { display: flex; align-items: center; gap: .6rem; }
.chip { display: inline-block; padding: .25em .7em; border-radius: 99px; font-size: .8rem; font-weight: 700; background: rgba(255, 255, 255, .12); white-space: nowrap; }
.chip-warn { background: var(--thread); }
.app-main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 48px; }
.welcome { margin: 8px 0 20px; }
.install-card {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  background: var(--surface); border: 1px dashed var(--thread); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 20px;
}
.install-card p { margin: 0; font-size: .9rem; }
.placeholder-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.tile-thumb {
  aspect-ratio: 4 / 3; border-radius: 10px; margin-bottom: 12px;
  background: repeating-linear-gradient(45deg, var(--surface-2) 0 10px, color-mix(in srgb, var(--line) 60%, transparent) 10px 12px);
}
.tile p { margin: 0; font-size: .9rem; }

dialog.sheet {
  width: min(440px, calc(100vw - 32px)); border: 0; border-radius: 18px; padding: 22px;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
dialog.sheet::backdrop { background: rgba(10, 14, 28, .55); }
dialog.sheet ol { padding-left: 1.2rem; }
dialog.sheet li { margin-bottom: .4rem; }
.note { background: var(--warn-bg); color: var(--warn); padding: .7rem .8rem; border-radius: 10px; font-size: .9rem; }
.sheet-actions { display: flex; justify-content: flex-end; gap: .5rem; flex-wrap: wrap; }

/* ---------- Admin ---------- */
.admin-page { background: var(--bg); }
.admin-top { background: var(--navy); color: #fff; }
.admin-top-inner { max-width: 1280px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.admin-top .brand { color: #fff; }
.admin-top nav { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.admin-top nav a, .admin-top nav button { color: #fff; }
.admin-top .btn-ghost { color: #fff; border-color: rgba(255, 255, 255, .25); }
.admin-top .btn-ghost:hover { background: rgba(255, 255, 255, .08); }
.admin-main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 60px; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }

.folders { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }
.folder {
  display: flex; align-items: center; gap: .8rem; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; color: inherit; transition: border-color .15s, box-shadow .15s;
}
.folder:hover { border-color: var(--muted); }
.folder.is-current { border-color: var(--navy); box-shadow: inset 0 -3px 0 var(--thread); }
.folder-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.folder-icon svg { width: 22px; height: 22px; }
.folder-active .folder-icon { background: var(--ok-bg); color: var(--ok); }
.folder-expired .folder-icon { background: var(--warn-bg); color: var(--warn); }
.folder-locked .folder-icon { background: var(--bad-bg); color: var(--bad); }
.folder strong { display: block; font-size: .95rem; }
.folder .count { font-size: 1.5rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.folder-text { flex: 1; min-width: 0; }
@media (prefers-color-scheme: dark) { .folder.is-current { border-color: var(--thread); } }

.toolbar { display: flex; gap: .5rem; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1; min-width: 200px; }

.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.num { font-variant-numeric: tabular-nums; }
.uname { font-weight: 700; }
.unote { display: block; font-size: .8rem; color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pw-cell { display: flex; align-items: center; gap: .3rem; }
.pw-value { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; min-width: 7ch; }
.icon-btn {
  width: 32px; height: 32px; display: inline-grid; place-items: center; flex: none;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 8px; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 16px; height: 16px; }
.actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; gap: .35em; padding: .2em .6em; border-radius: 99px; font-size: .75rem; font-weight: 700; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.b-ok { background: var(--ok-bg); color: var(--ok); }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-bad { background: var(--bad-bg); color: var(--bad); }
.b-mute { background: var(--surface-2); color: var(--muted); }
.days { font-weight: 800; }
.days.low { color: var(--thread-dark); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.pager { display: flex; gap: .4rem; justify-content: center; margin-top: 14px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.two-col { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1rem; font-size: .9rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.log { list-style: none; padding: 0; margin: 0; font-size: .85rem; }
.log li { padding: .45rem 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: .2rem .6rem; }
.log li:last-child { border-bottom: 0; }
.log time { color: var(--muted); font-size: .8rem; }
.log small { grid-column: 1 / -1; color: var(--muted); }
.danger-zone { border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: .6rem 1rem; border-radius: 10px; font-size: .9rem;
  box-shadow: var(--shadow); z-index: 50;
}

/* Admin table → cards on phones */
@media (max-width: 860px) {
  .folders { grid-template-columns: 1fr; gap: 8px; }
  .folder { padding: 10px 14px; }
  .two-col { grid-template-columns: 1fr; }
  table.data thead { display: none; }
  table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  table.data tr { padding: 10px 12px; border-bottom: 1px solid var(--line); }
  table.data tr:last-child { border-bottom: 0; }
  table.data td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
  table.data td::before { content: attr(data-label); font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
  table.data td.cell-user::before { content: none; }
  table.data td.cell-actions { padding-top: 8px; }
  table.data td.cell-actions::before { content: none; }
  .actions { width: 100%; }
  .actions .btn, .actions form { flex: 1; }
  .actions form .btn { width: 100%; }
}
