/* Admin portal. Hand-written, no build step: the live host has no Node. Colours follow the mobile app. */
:root {
  --navy: #16235a; --primary: #2447c9; --primary-soft: #eaf0fd; --text: #111827; --muted: #5b6472; --faint: #9ca3af;
  --border: #e3e6ec; --soft: #f4f6fa; --page: #f1f3f8; --ok: #1e7b34; --ok-bg: #e6f4ea; --warn: #b45d09; --warn-bg: #fdf1e3;
  --danger: #c53030; --danger-bg: #fdecec; --premium: #b7791f; --premium-bg: #fef6e4; --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--text); background: var(--page); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0; letter-spacing: -0.2px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* shell */
.shell { display: flex; min-height: 100vh; }
.side { width: 250px; background: var(--navy); color: #fff; flex-shrink: 0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { padding: 20px 20px 14px; font-weight: 800; font-size: 16px; line-height: 1.25; }
.brand small { display: block; font-weight: 400; opacity: .65; font-size: 12px; margin-top: 2px; }
.nav-group { padding: 14px 20px 6px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; opacity: .5; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 20px; color: #dfe4f5; font-size: 14.5px; border-left: 3px solid transparent; }
.nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.nav a.on { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; border-left-color: #8fa8ff; }
.nav .ico { width: 20px; text-align: center; }
.nav .count { margin-left: auto; background: #f5a524; color: #1c1300; border-radius: 99px; font-size: 11.5px; font-weight: 700; padding: 1px 8px; }
.side-foot { margin-top: auto; padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.12); font-size: 13px; }
.side-foot b { display: block; }
.side-foot button { background: none; border: 0; color: #aebbf0; padding: 0; margin-top: 6px; cursor: pointer; font: inherit; }
.main { flex: 1; min-width: 0; padding: 28px 32px 60px; }
.btn.menu-btn { display: none; }

/* page header */
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.head p { margin: 6px 0 0; color: var(--muted); max-width: 720px; }
.crumb { font-size: 13px; color: var(--muted); margin-bottom: 6px; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--border); background: #fff; color: var(--text); border-radius: 8px; padding: 9px 15px; font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--soft); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #1d3bab; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--danger); border-color: #f0c4c4; }
.btn.sm { padding: 5px 10px; font-size: 13px; font-weight: 500; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--primary); }
.btn[disabled] { opacity: .5; cursor: default; }

/* cards & tables */
.card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); }
.card.pad { padding: 20px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.toolbar input[type=search], .toolbar select { height: 38px; }
.toolbar input[type=search] { flex: 1; min-width: 220px; }
.tabs { display: flex; gap: 4px; padding: 0 12px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 12px 12px 10px; font: inherit; font-size: 14px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button.on { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tabs .n { background: var(--soft); border-radius: 99px; padding: 1px 8px; font-size: 12px; margin-left: 4px; color: var(--muted); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 11px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfd; }
td.first a { font-weight: 600; color: var(--text); }
td.actions { text-align: right; white-space: nowrap; }
.empty { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }
.pager { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 14px; }

/* badges */
.badge { display: inline-block; border-radius: 99px; padding: 2px 10px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.badge.draft { background: #eef0f4; color: #4b5563; }
.badge.review { background: var(--warn-bg); color: var(--warn); }
.badge.published { background: var(--ok-bg); color: var(--ok); }
.badge.retired { background: var(--danger-bg); color: var(--danger); }
.pill { border: 1px solid var(--border); background: #fff; border-radius: 99px; padding: 2px 10px; font-size: 12.5px; font-weight: 600; cursor: pointer; font-family: inherit; }
.pill.premium { background: var(--premium-bg); border-color: #f0dcae; color: var(--premium); }
.pill.free { color: var(--muted); }

/* forms */
input[type=text], input[type=search], input[type=email], input[type=password], input[type=number], input[type=date], input[type=url], select, textarea {
  width: 100%; border: 1px solid #cfd5df; border-radius: 8px; padding: 9px 12px; font: inherit; color: var(--text); background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #b9c8f7; border-color: var(--primary); }
textarea { min-height: 96px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.form-grid.single { grid-template-columns: minmax(0, 820px); }
.section { margin-bottom: 18px; }
.section > h2 { padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.field { margin-bottom: 18px; }
.field > label, .field > .label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 5px; }
.field .req { color: var(--danger); }
.field .help { font-size: 13px; color: var(--muted); margin-top: 5px; }
.field .error { font-size: 13px; color: var(--danger); margin-top: 5px; font-weight: 600; }
.field.bad input, .field.bad textarea, .field.bad select { border-color: var(--danger); }
.checks { display: flex; gap: 8px; flex-wrap: wrap; }
.checks label { border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px; cursor: pointer; font-size: 14px; display: inline-flex; gap: 7px; align-items: center; background: #fff; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; font-size: 14px; }
.switch input { appearance: none; width: 42px; height: 24px; border-radius: 99px; background: #cfd5df; position: relative; cursor: pointer; transition: background .15s; margin: 0; flex-shrink: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { left: 21px; }
.rows .row { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; }
.rows .row .cells { flex: 1; display: grid; gap: 8px; }
.rows .row .n { width: 22px; padding-top: 9px; color: var(--faint); font-size: 13px; text-align: right; }
.rows .icon-btn { border: 1px solid var(--border); background: #fff; border-radius: 6px; width: 32px; height: 38px; cursor: pointer; color: var(--muted); font-size: 14px; }
.rows .icon-btn:hover { background: var(--soft); color: var(--text); }
.range { display: flex; align-items: center; gap: 12px; }
.range input[type=range] { flex: 1; accent-color: var(--primary); }
.range output { font-weight: 700; width: 48px; }

/* record picker */
.picker { position: relative; }
.chosen { display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid #cfd5df; border-radius: 8px; padding: 8px 12px; background: var(--soft); margin-bottom: 6px; }
.chosen small { display: block; color: var(--muted); }
.chosen button { border: 0; background: none; color: var(--primary); cursor: pointer; font: inherit; font-size: 13px; font-weight: 600; }
.results { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; margin-top: 4px; background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 30px rgba(15,23,42,.12); max-height: 300px; overflow-y: auto; }
.results button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--border); background: #fff; padding: 9px 12px; cursor: pointer; font: inherit; }
.results button:last-child { border-bottom: 0; }
.results button:hover { background: var(--primary-soft); }
.results small { display: block; color: var(--muted); }
.results .none { padding: 12px; color: var(--muted); font-size: 14px; }

/* sticky save bar */
.savebar { position: sticky; bottom: 0; background: #fff; border-top: 1px solid var(--border); margin: 24px -32px -60px; padding: 14px 32px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; z-index: 10; }
.savebar .spacer { flex: 1; }

/* phone preview */
.phone-wrap { position: sticky; top: 20px; }
.phone { width: 320px; border: 10px solid #1b1f2a; border-radius: 34px; background: #fff; overflow: hidden; margin: 0 auto; }
.phone .p-head { text-align: center; font-weight: 700; font-size: 14px; padding: 14px 12px 10px; }
.phone .p-tabs { display: flex; border-bottom: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.phone .p-tabs span { flex: 1; text-align: center; padding: 7px 0; }
.phone .p-tabs span.on { color: var(--primary); font-weight: 600; border-bottom: 2px solid var(--primary); }
.phone .p-body { padding: 14px; font-size: 12.5px; line-height: 1.55; height: 430px; overflow-y: auto; }
.phone .p-body h4 { font-size: 13.5px; margin: 12px 0 5px; }
.phone .p-body h4:first-child { margin-top: 0; }
.phone .p-body ul { margin: 4px 0; padding-left: 18px; }
.phone-cap { text-align: center; font-size: 13px; color: var(--muted); margin-bottom: 10px; }

/* dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { padding: 16px 18px; display: block; color: inherit; }
.stat:hover { text-decoration: none; border-color: #b9c8f7; }
.stat .n { font-size: 28px; font-weight: 800; color: var(--navy); line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 13.5px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px; }
.list-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.list-row:last-child { border-bottom: 0; }
.steps { counter-reset: s; list-style: none; margin: 0; padding: 0; }
.steps li { counter-increment: s; padding: 8px 0 8px 38px; position: relative; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 7px; width: 26px; height: 26px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-weight: 700; text-align: center; line-height: 26px; font-size: 13px; }

/* tree */
.tree details { border: 1px solid var(--border); border-radius: var(--radius); background: #fff; margin-bottom: 10px; }
.tree summary { padding: 12px 16px; cursor: pointer; display: flex; align-items: center; gap: 10px; font-weight: 700; list-style: none; }
.tree summary::-webkit-details-marker { display: none; }
.tree summary::before { content: "▸"; color: var(--muted); }
.tree details[open] > summary::before { content: "▾"; }
.tree .kids { padding: 0 16px 12px 36px; }
.tree details details { border-color: var(--border); background: var(--soft); }
.tree details details summary { font-weight: 600; font-size: 14.5px; }
.tree .leaf { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--border); font-size: 14px; }
.tree .leaf:last-child { border-bottom: 0; }
.tree .leaf .code { width: 96px; font-weight: 600; flex-shrink: 0; }
.tree .grow { flex: 1; min-width: 0; }
.tree .mini { border: 1px solid var(--border); background: #fff; border-radius: 5px; width: 26px; height: 26px; cursor: pointer; color: var(--muted); padding: 0; }

/* toast, modal, login */
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; background: #111827; color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.25); max-width: 420px; font-size: 14.5px; }
.toast.error { background: var(--danger); }
.confirm { background: var(--danger-bg); border: 1px solid #f0c4c4; border-radius: 8px; padding: 8px 10px; display: inline-flex; gap: 8px; align-items: center; font-size: 13px; white-space: normal; text-align: left; }
.alert { border-radius: 8px; padding: 12px 14px; margin-bottom: 16px; font-size: 14px; }
.alert.info { background: var(--primary-soft); color: #1b3288; }
.alert.error { background: var(--danger-bg); color: var(--danger); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 400px; padding: 32px; }
.login .logo { width: 60px; height: 60px; border-radius: 16px; background: var(--navy); color: #fff; display: grid; place-items: center; font-size: 28px; margin: 0 auto 14px; }
.diff { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; background: var(--soft); border-radius: 6px; padding: 8px 10px; white-space: pre-wrap; word-break: break-word; margin: 0; }

@media (max-width: 1100px) { .form-grid { grid-template-columns: minmax(0, 1fr); } .phone-wrap { position: static; } }
@media (max-width: 820px) {
  .side { position: fixed; left: -260px; z-index: 40; transition: left .2s; }
  .side.open { left: 0; }
  .main { padding: 18px 16px 60px; }
  .savebar { margin: 24px -16px -60px; padding: 12px 16px; }
  .btn.menu-btn { display: inline-flex; margin-bottom: 12px; }
}
