/* BitSync admin panel. No inline styles anywhere (strict CSP); everything is class based. */
:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #16181d;
  --muted: #5b6270;
  --border: #d7dbe1;
  --accent: #2153c9;
  --accent-hover: #1a44a8;
  --accent-text: #ffffff;
  --accent-soft: #e5ecfb;
  --danger: #b42318;
  --danger-hover: #931c13;
  --danger-soft: #fdecea;
  --ok: #17703a;
  --ok-soft: #e3f3e8;
  --warn: #8a5a00;
  --warn-soft: #fff3d6;
  --focus: #2153c9;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Tahoma, "Noto Sans Arabic", "Geeza Pro", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #1a1d24;
    --surface-2: #232731;
    --text: #e8eaf0;
    --muted: #a0a7b5;
    --border: #343a46;
    --accent: #7aa2ff;
    --accent-hover: #9bb9ff;
    --accent-text: #0d1220;
    --accent-soft: #1f2a44;
    --danger: #ff7b72;
    --danger-hover: #ff9a92;
    --danger-soft: #3a1d1c;
    --ok: #5fd08a;
    --ok-soft: #173326;
    --warn: #f2c35b;
    --warn-soft: #3a2f14;
    --focus: #9bb9ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .6em; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
code, .mono { font-family: var(--mono); font-size: .92em; direction: ltr; unicode-bidi: isolate; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.nowrap { white-space: nowrap; }

.skip { position: absolute; inset-inline-start: 8px; top: -60px; background: var(--surface); padding: 8px 12px; border-radius: 6px; z-index: 50; }
.skip:focus { top: 8px; }
.boot, .noscript { padding: 32px 16px; text-align: center; color: var(--muted); }

/* ---------- buttons and inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 6px 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
@media (prefers-color-scheme: dark) { .btn-danger { color: #1a0d0c; } }
.btn-danger-outline { border-color: var(--danger); color: var(--danger); }
.btn-danger-outline:hover { background: var(--danger-soft); }
.btn-small { min-height: 32px; padding: 3px 10px; font-size: .88rem; }
.btn-link { background: none; border: none; color: var(--accent); padding: 0; min-height: 0; font-weight: 600; cursor: pointer; font: inherit; text-decoration: underline; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

label { display: block; font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 12px; min-width: 0; }
.field .hint { font-weight: 400; color: var(--muted); font-size: .86rem; margin: 4px 0 0; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; min-height: 40px; padding: 7px 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 70px; resize: vertical; }
input[readonly] { background: var(--surface-2); }
input.ltr, input[type=email], input.code-input { direction: ltr; text-align: left; }
.code-input { font-family: var(--mono); letter-spacing: .2em; font-size: 1.15rem; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.check input { width: 18px; height: 18px; margin: 0; }

/* Switch: a styled checkbox */
.switch { appearance: none; -webkit-appearance: none; width: 42px; height: 24px; border-radius: 999px; background: var(--border); position: relative; cursor: pointer; margin: 0; flex: none; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: inset-inline-start .15s; }
.switch:checked { background: var(--ok); }
.switch:checked::after { inset-inline-start: 21px; }
.switch.switch-danger:checked { background: var(--danger); }
.switch:disabled { opacity: .5; cursor: not-allowed; }
.switch-label { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; margin: 0; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 0 12px; align-items: end; }
.form-error { color: var(--danger); background: var(--danger-soft); border-radius: 8px; padding: 8px 12px; font-weight: 600; }
.form-ok { color: var(--ok); background: var(--ok-soft); border-radius: 8px; padding: 8px 12px; font-weight: 600; }
.note { background: var(--warn-soft); color: var(--text); border-inline-start: 4px solid var(--warn); border-radius: 6px; padding: 8px 12px; margin: 0 0 12px; }
.note-info { background: var(--accent-soft); border-inline-start-color: var(--accent); }
.note-danger { background: var(--danger-soft); border-inline-start-color: var(--danger); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; }
.auth-card { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px 20px; box-shadow: var(--shadow); }
.auth-card .brand { font-size: 1.2rem; font-weight: 800; margin: 0; }
.auth-card .product { color: var(--muted); margin: 0 0 16px; }
.auth-links { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.copy-row { display: flex; gap: 8px; align-items: stretch; }
.copy-row input { flex: 1; min-width: 0; font-family: var(--mono); font-size: .85rem; }
.steps { padding-inline-start: 20px; margin: 0 0 12px; }

/* ---------- app shell ---------- */
.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.top .brand { font-weight: 800; color: var(--text); text-decoration: none; font-size: 1.05rem; }
.top .product { color: var(--muted); font-size: .9rem; }
.top .spacer { flex: 1; }
.who { color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.app-body { display: block; }
.nav {
  display: flex; gap: 4px; overflow-x: auto; padding: 8px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  scrollbar-width: thin;
}
.nav a {
  flex: none; padding: 7px 12px; border-radius: 8px; color: var(--text); text-decoration: none; white-space: nowrap; font-weight: 600; font-size: .93rem;
}
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current=page] { background: var(--accent); color: var(--accent-text); }
.nav .owner-tag { font-size: .7rem; font-weight: 600; opacity: .75; margin-inline-start: 4px; }
.main { padding: 16px; min-width: 0; outline: none; }
@media (min-width: 960px) {
  .app-body { display: grid; grid-template-columns: 230px minmax(0, 1fr); align-items: start; }
  .nav { flex-direction: column; overflow: visible; border-bottom: none; border-inline-end: 1px solid var(--border); min-height: calc(100vh - 56px); position: sticky; top: 56px; padding: 12px; }
  .main { padding: 24px; }
}

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 12px; }
.page-head h1 { margin: 0; }
.crumb { margin: 0 0 6px; font-size: .9rem; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); min-width: 0; }
.card > h2 { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 170px), 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: var(--text); box-shadow: var(--shadow); display: block; }
.stat:hover { border-color: var(--accent); }
.stat .num { display: block; font-size: 1.8rem; font-weight: 800; line-height: 1.2; }
.stat .lbl { color: var(--muted); font-weight: 600; font-size: .92rem; }
.stat.attention .num { color: var(--danger); }

dl.kv { display: grid; grid-template-columns: minmax(110px, max-content) minmax(0, 1fr); gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); font-weight: 600; }
dl.kv dd { margin: 0; overflow-wrap: anywhere; min-width: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; padding: 0; list-style: none; }
.chips li { background: var(--surface-2); border-radius: 999px; padding: 3px 12px; font-size: .9rem; }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .82rem; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--accent-soft); color: var(--accent); }

/* ---------- tables ---------- */
.table-wrap { width: 100%; max-width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td { padding: 8px 10px; text-align: start; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
table.data td.wrap { white-space: normal; min-width: 180px; max-width: 360px; overflow-wrap: anywhere; }
table.data th { background: var(--surface-2); font-weight: 700; color: var(--muted); font-size: .85rem; position: sticky; top: 0; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: var(--surface-2); }
table.data td.empty { text-align: center; color: var(--muted); padding: 18px; }
table.data .actions { display: flex; gap: 6px; flex-wrap: nowrap; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 12px; }
.toolbar .field { margin: 0; flex: 1 1 200px; }
.toolbar .field.narrow { flex: 0 1 180px; }
pre.detail { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--mono); font-size: .8rem; direction: ltr; text-align: left; max-width: 420px; }
details summary { cursor: pointer; color: var(--accent); font-weight: 600; }

/* ---------- profiles ---------- */
.profile-list { display: grid; gap: 8px; }
.profile-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.profile-row .pid { flex: 1 1 200px; font-family: var(--mono); font-weight: 600; direction: ltr; text-align: left; overflow-wrap: anywhere; }
.profile-row.off { background: var(--danger-soft); }

/* ---------- plans ---------- */
.plan-form { border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 12px; }
.plan-form h3 { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sar { color: var(--muted); font-weight: 600; }

/* ---------- dialogs ---------- */
dialog.dlg {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto;
  border: 1px solid var(--border); border-radius: 14px; padding: 20px;
  background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}
dialog.dlg::backdrop { background: rgba(10, 12, 16, .55); }
dialog.dlg-danger { border-top: 5px solid var(--danger); }
.dlg-intro { margin-bottom: 12px; }
.dlg-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.secret-value { font-family: var(--mono); font-size: 1.2rem; font-weight: 700; letter-spacing: .05em; }

/* ---------- toasts ---------- */
.toasts { position: fixed; bottom: 16px; inset-inline: 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 100; pointer-events: none; }
.toast { pointer-events: auto; max-width: 520px; width: 100%; background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-weight: 600; box-shadow: var(--shadow); }
.toast-error { background: var(--danger); color: #fff; }
@media (prefers-color-scheme: dark) { .toast-error { color: #1a0d0c; } }

.loading { color: var(--muted); padding: 24px 0; }
.error-box { color: var(--danger); background: var(--danger-soft); border-radius: 8px; padding: 12px 16px; }
