/* Docvio Ad Control — mobile-first, light & dark */
:root {
  --blue: #1e4fd8;
  --blue-dark: #1740b0;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #151a24;
  --muted: #586071;
  --line: #dfe4ec;
  --field: #f0f3f8;
  --on: #0f8a4f;
  --on-bg: #def7ea;
  --off: #8a5a00;
  --off-bg: #fff1d6;
  --danger: #c62828;
  --danger-bg: #fdecec;
  --radius: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --blue: #7ea2ff;
    --blue-dark: #a9c0ff;
    --bg: #0e1116;
    --card: #181c23;
    --text: #e3e6ec;
    --muted: #a3aab8;
    --line: #2b3039;
    --field: #1f242c;
    --on: #5ed69a;
    --on-bg: #133325;
    --off: #f2c56b;
    --off-bg: #3a2c10;
    --danger: #ff8a80;
    --danger-bg: #3a1717;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
h1 { font-size: 1.5rem; margin: 0 0 4px; line-height: 1.25; }
h2 { font-size: 1.05rem; margin: 0 0 8px; }
p { margin: 0 0 12px; }
code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .85em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.grow { flex: 1; min-width: 0; }
.inline { display: inline; margin: 0; }
[hidden] { display: none !important; }

/* App bar */
.appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--blue); color: #fff;
}
@media (prefers-color-scheme: dark) { .appbar { background: #142c73; } }
.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { display: block; font-size: 1.05rem; line-height: 1.2; }
.brand span { font-size: .78rem; opacity: .8; }
.logo { width: 30px; height: 30px; flex: none; }
.topnav { display: flex; align-items: center; gap: 4px; }
.navlink {
  color: #fff; text-decoration: none; font: inherit; font-size: .9rem;
  padding: 8px 10px; border-radius: 10px; background: none; border: 0; cursor: pointer;
}
.navlink:hover, .navlink:focus-visible { background: rgba(255, 255, 255, .16); outline: none; }

.container { width: 100%; max-width: 760px; margin: 0 auto; padding: 16px; }

/* Cards */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 14px;
}
.narrow { max-width: 420px; margin: 8vh auto 0; }
.narrow-left { max-width: 460px; }
.center { text-align: center; }
.empty { text-align: center; padding: 32px 20px; }

.lock {
  width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 18px;
  display: grid; place-items: center; background: var(--blue); color: #fff;
}
.lock .logo { width: 38px; height: 38px; }

.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 4px 0 14px; }
.back { display: inline-block; color: var(--blue); text-decoration: none; font-size: .9rem; margin-bottom: 4px; }

/* Forms */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .875rem; font-weight: 600; margin-bottom: 6px; }
.field em { font-weight: 400; font-style: normal; color: var(--muted); }
.field small { display: block; margin-top: 6px; font-size: .8rem; }
input[type=text], input[type=password], input[type=number], input[type=search], textarea {
  width: 100%; font: inherit; color: var(--text);
  background: var(--field); border: 1.5px solid transparent; border-radius: 12px;
  padding: 12px 14px; min-height: 48px;
}
textarea { resize: vertical; }
input:focus, textarea:focus { outline: none; border-color: var(--blue); background: var(--card); }
input[aria-invalid=true] { border-color: var(--danger); }
input.pin { letter-spacing: .35em; font-size: 1.2rem; text-align: center; }
input.pin.big { font-size: 1.6rem; margin: 8px 0 16px; }
.search { margin-bottom: 14px; }

.switch { display: flex; align-items: center; gap: 12px; margin: 4px 0 18px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  position: relative; width: 50px; height: 30px; flex: none; border-radius: 30px;
  background: var(--line); transition: background .2s;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s;
}
.switch input:checked + .track { background: var(--blue); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 3px solid var(--blue); outline-offset: 2px; }

.form h2 { margin-top: 6px; padding-top: 6px; }
.form h2 + .field, .form h2 + p { margin-top: 4px; }
.formactions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px;
  font: inherit; font-weight: 600; font-size: .92rem; text-decoration: none; cursor: pointer;
  color: var(--text); background: var(--field); border: 1px solid var(--line);
}
.btn:hover { filter: brightness(.97); }
.btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0b1a45; } }
.btn.ghost { background: transparent; color: var(--blue); }
.btn.block { width: 100%; }
.btn.dangerbtn { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* App cards */
.list { display: grid; gap: 14px; }
.apphead { display: flex; align-items: center; gap: 12px; }
.apphead h2 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appicon {
  width: 44px; height: 44px; border-radius: 12px; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 1.2rem;
  background: var(--blue); color: #fff;
}
.pkg { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { flex: none; font-size: .78rem; font-weight: 700; padding: 4px 10px; border-radius: 20px; }
.pill.on { color: var(--on); background: var(--on-bg); }
.pill.off { color: var(--off); background: var(--off-bg); }
.units { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 8px; }
.unit {
  font-size: .78rem; padding: 4px 10px; border-radius: 20px;
  border: 1px dashed var(--line); color: var(--muted);
}
.unit.set { border: 1px solid transparent; background: var(--field); color: var(--text); }
.unit.set::before { content: "✓ "; color: var(--on); }
.meta { font-size: .8rem; margin-bottom: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
code.block {
  display: block; padding: 12px; margin-bottom: 10px; border-radius: 12px;
  background: var(--field); word-break: break-all;
}
.danger { border-color: var(--danger-bg); }

/* Messages */
.error { color: var(--danger); background: var(--danger-bg); padding: 10px 12px; border-radius: 10px; font-size: .9rem; }
small.error { padding: 6px 10px; }
.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px; z-index: 20;
  background: #151a24; color: #fff; font-size: .92rem; box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
  transition: opacity .4s;
}
.toast.hide { opacity: 0; pointer-events: none; }

/* Small phones */
@media (max-width: 420px) {
  .container { padding: 12px; }
  .card { padding: 16px; }
  .pagehead { flex-direction: column; align-items: stretch; }
  .pagehead .btn { width: 100%; }
  .actions .btn, .actions form, .actions form .btn { flex: 1 1 auto; }
  .formactions { flex-direction: column-reverse; }
  .formactions .btn { width: 100%; }
  .brand span { display: none; }
}
