/* Access Controller — 2plus1 design system, matching Backup Manager.
   Light professional theme: white surfaces on slate, blue CTA, teal/amber
   accents, Lexend display + Source Sans 3 body + JetBrains Mono data. */

@font-face {
  font-family: "Lexend";
  font-weight: 600;
  font-display: swap;
  src: url("/static/fonts/Lexend-600.woff2") format("woff2");
}
@font-face {
  font-family: "Lexend";
  font-weight: 700;
  font-display: swap;
  src: url("/static/fonts/Lexend-700.woff2") format("woff2");
}
@font-face {
  font-family: "Source Sans 3";
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/Source_Sans_3-400.woff2") format("woff2");
}
@font-face {
  font-family: "Source Sans 3";
  font-weight: 600;
  font-display: swap;
  src: url("/static/fonts/Source_Sans_3-600.woff2") format("woff2");
}
@font-face {
  font-family: "JetBrains Mono";
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/JetBrains_Mono-400.woff2") format("woff2");
}

:root {
  color-scheme: light;

  /* 2plus1 brand tokens (shared with Backup Manager) */
  --ink:         #020617;
  --navy:        #0F172A;
  --slate:       #334155;
  --muted:       #475569;
  --faint:       #94A3B8;
  --bg:          #F8FAFC;
  --bg-soft:     #F1F5F9;
  --surface:     #FFFFFF;
  --line:        #E2E8F0;
  --line-strong: #CBD5E1;

  --cta:           #0369A1;
  --cta-dark:      #075985;
  --accent:        #0F766E;
  --accent-bright: #14B8A6;
  --cyan:          #5BC0D8;
  --cyan-deep:     #1C8AA6;
  --amber:         #F0A800;
  --amber-deep:    #B07A00;

  --radius:    14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .05);
  --shadow:    0 10px 30px -12px rgba(15, 23, 42, .18);
  --shadow-lg: 0 24px 60px -20px rgba(15, 23, 42, .28);
  --ring:      0 0 0 3px rgba(3, 105, 161, .30);

  --up:        #15803D;
  --up-bg:     #E7F6EC;
  --up-line:   #BBE6C9;
  --down:      #DC2626;
  --down-bg:   #FDECEB;
  --down-line: #F6C9C6;
  --warn-ink:  #8A6100;
  --warn-bg:   #FDF4DC;
  --warn-line: #F0DFAC;

  --font-display: "Lexend", system-ui, sans-serif;
  --font-body:    "Source Sans 3", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono:         "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
}

/* ---- Dark theme: same 2plus1 system, slate-dark surfaces ---- */
html[data-theme="dark"] {
  color-scheme: dark;

  --ink:         #E8EDF4;
  --navy:        #F1F5F9;
  --slate:       #C2CEDD;
  --muted:       #93A1B5;
  --faint:       #6B7A90;
  --bg:          #0B1120;
  --bg-soft:     #141D2E;
  --surface:     #161F30;
  --line:        #273347;
  --line-strong: #3A4860;

  --cta:           #2E90D4;
  --cta-dark:      #5CA8E0;   /* hover goes brighter on dark */
  --accent:        #2DD4BF;
  --accent-bright: #2DD4BF;
  --cyan:          #5BC0D8;
  --cyan-deep:     #67C7DD;
  --amber:         #F0B429;
  --amber-deep:    #FBBF24;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .40), 0 1px 3px rgba(0, 0, 0, .30);
  --shadow:    0 10px 30px -12px rgba(0, 0, 0, .60);
  --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, .70);
  --ring:      0 0 0 3px rgba(46, 144, 212, .38);

  --up:        #4ADE80;
  --up-bg:     #12301F;
  --up-line:   #1F5236;
  --down:      #F87171;
  --down-bg:   #3A1A1C;
  --down-line: #5E2B2D;
  --warn-ink:  #FBBF24;
  --warn-bg:   #332810;
  --warn-line: #58451A;
}

/* Dark overrides for the few components carrying literal colours. */
html[data-theme="dark"] .flash { background: #122436; color: #9FD0F0; border-color: #1F4661; }
html[data-theme="dark"] .side-nav a.on { background: rgba(46, 144, 212, .16); color: #8FC6EC; }
html[data-theme="dark"] .termlog { background: #060B16; }
html[data-theme="dark"] .chip.c-blue   { background: rgba(46, 144, 212, .16); color: #6FB6E6; }
html[data-theme="dark"] .chip.c-violet { background: rgba(45, 212, 191, .14); color: #4FD6C2; }
html[data-theme="dark"] .chip.c-brass  { background: rgba(240, 180, 41, .15); color: #F4C95B; }
html[data-theme="dark"] .chip.c-green  { background: rgba(74, 222, 128, .15); color: #5FE08F; }
html[data-theme="dark"] .chip.c-teal   { background: rgba(103, 199, 221, .15); color: #74CEE0; }
html[data-theme="dark"] .chip.c-red    { background: rgba(248, 113, 113, .15); color: #F58A8A; }
html[data-theme="dark"] ::selection { background: rgba(46, 144, 212, .32); }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--cta); text-decoration: none; }
a:hover { color: var(--cta-dark); text-decoration: underline; }
::selection { background: rgba(3, 105, 161, .16); }
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }

/* ---- app shell ---- */
body.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 238px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 14px 14px;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  color: var(--navy) !important;
  white-space: nowrap;
  text-decoration: none !important;
  padding: 2px 10px 14px;
}
.brand .logo { display: block; flex-shrink: 0; color: var(--navy); }
.brand .b1 { font-weight: 700; }
.brand .b2 { font-weight: 600; color: var(--muted); }
.brand.big { font-size: 19px; }

.side-nav { flex: 1; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.side-nav a {
  display: flex; align-items: center; gap: 10px;
  color: var(--slate);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none !important;
  transition: background .12s, color .12s;
}
.side-nav a svg {
  width: 17px; height: 17px; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
  opacity: .85;
}
.side-nav a:hover { background: var(--bg-soft); color: var(--navy); }
.side-nav a.on { background: rgba(3, 105, 161, .09); color: var(--cta-dark); font-weight: 600; }
.side-foot { margin: 0; padding: 12px 10px 0; border-top: 1px solid var(--line); }

.side-nav .seg {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em;
  color: var(--faint); padding: 14px 12px 5px;
}
.side-nav .seg:first-child { padding-top: 4px; }

.content { flex: 1; min-width: 0; }
main { max-width: 1080px; margin: 0 auto; padding: 28px 32px 64px; }

/* ---- page header: title + optional subtitle, actions on the right ---- */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin: 2px 0 20px;
}
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); font-size: 14px; margin: 4px 0 0; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs + .page-head { margin-top: 0; }

/* ---- toolbar: a light bar for inline "add" / filter forms ---- */
.toolbar {
  display: flex; gap: 9px; flex-wrap: wrap; align-items: center;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; margin: 0 0 16px;
  box-shadow: var(--shadow-sm);
}
.toolbar input, .toolbar select { width: auto; }
.grow { flex: 1 1 220px; }
.toolbar .tb-label { font-size: 12px; font-weight: 600; color: var(--muted); margin-right: 2px; white-space: nowrap; }

/* ---- table wrapper: rounded container + horizontal scroll on small screens ---- */
.table-wrap {
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow-x: auto; box-shadow: var(--shadow-sm); margin: 0 0 16px;
}
.table-wrap > table { border: 0; border-radius: 0; box-shadow: none; }
@media (max-width: 760px) { .table-wrap > table { min-width: 560px; } }

/* ---- empty state ---- */
.empty {
  text-align: center; color: var(--muted); font-size: 14px;
  padding: 30px 20px; border: 1px dashed var(--line-strong);
  border-radius: var(--radius); background: var(--bg-soft);
}
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }

/* ---- section header: h2 + a trailing action/link ---- */
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 26px 0 10px; }
.sec-head h2 { margin: 0; }
.sec-head a { font-size: 13px; font-weight: 600; }

@media (max-width: 880px) {
  body.app { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: static;
    flex-direction: row; align-items: center;
    padding: 8px 10px; border-right: none; border-bottom: 1px solid var(--line);
  }
  .brand { padding: 4px 8px; }
  .side-nav { flex-direction: row; overflow-x: auto; }
  .side-nav a { padding: 7px 10px; white-space: nowrap; }
  .side-foot { border-top: none; padding: 0 8px; }
  main { padding: 22px 18px 60px; }
}

/* ---- typography & bits ---- */
h1 {
  font-family: var(--font-display);
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--navy);
  margin: 0 0 6px;
}
h1 + p.muted { margin-top: 0; margin-bottom: 22px; font-size: 14px; }
h2 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  color: var(--navy);
  margin: 24px 0 10px;
}
.panel h2:first-child { margin-top: 2px; }

code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  padding: 1px 6px;
  border-radius: 5px;
  color: var(--slate);
}
.muted { color: var(--muted); }
.dim { color: var(--faint); font-size: .6em; font-family: var(--font-body); font-weight: 400; }
.crumbs { margin: 0 0 6px; font-size: 13px; }

/* ---- flash banners ---- */
.flash {
  max-width: 1036px;
  margin: 18px 32px 0;
  padding: 11px 15px;
  background: #E8F3FB;
  color: var(--cta-dark);
  border: 1px solid #BFE0F3;
  border-radius: var(--radius-sm);
  font-size: 14px;
  animation: rise .3s both;
}
.flash.error { background: var(--down-bg); color: #991B1B; border-color: var(--down-line); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---- panels ---- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin: 14px 0;
  box-shadow: var(--shadow-sm);
  animation: rise .35s both;
}
.panel.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-ink); }
.panel.grant { background: var(--up-bg); border-color: var(--up-line); }
.panel.deny { background: var(--down-bg); border-color: var(--down-line); }
.panel.grant h2, .panel.deny h2 { margin-top: 0; }
.panel.danger-zone { border-style: dashed; box-shadow: none; background: transparent; }
.panel.scanbox { border-left: 4px solid var(--amber); }

.scan-input {
  font-family: var(--mono);
  font-size: 15px;
  min-width: 280px;
}

.termlog {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--navy);
  color: #DBE7F3;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-top: 12px;
  max-height: 240px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* ---- stat cards ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(186px, 1fr)); gap: 14px; margin: 18px 0 26px; }
.card {
  position: relative;
  overflow: hidden;
  display: flex; align-items: center; gap: 13px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  color: var(--ink) !important;
  text-decoration: none !important;
  animation: rise .4s both;
  transition: box-shadow .12s, transform .12s;
}
.card::before {
  content: ""; position: absolute; top: 0; left: 0; bottom: 0; width: 4px;
  background: linear-gradient(180deg, var(--cta), var(--accent-bright));
}
.cards .card:nth-child(2) { animation-delay: .05s; }
.cards .card:nth-child(3) { animation-delay: .1s; }
.cards .card:nth-child(4) { animation-delay: .15s; }
.cards .card:nth-child(5) { animation-delay: .2s; }
.cards .card:nth-child(6) { animation-delay: .25s; }
a.card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.card .num {
  display: block;
  font-family: var(--font-display);
  font-size: 27px; font-weight: 700;
  letter-spacing: -.02em; line-height: 1.1;
  color: var(--navy);
}
.card .lbl {
  display: block;
  color: var(--muted);
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em;
}
.card .chip {
  width: 38px; height: 38px; flex-shrink: 0;
  border-radius: 10px;
  display: grid; place-items: center;
}
.card .chip svg {
  width: 19px; height: 19px;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.chip.c-blue   { background: #E8F3FB; color: var(--cta); }
.chip.c-violet { background: #E6F4F2; color: var(--accent); }
.chip.c-brass  { background: #FDF4DC; color: var(--amber-deep); }
.chip.c-green  { background: var(--up-bg); color: var(--up); }
.chip.c-teal   { background: #E9F6FA; color: var(--cyan-deep); }
.chip.c-red    { background: var(--down-bg); color: var(--down); }
.card.alert { border-color: var(--down-line); }
.card.alert .num { color: var(--down); }

.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 860px) { .cols { grid-template-columns: 1fr; } }

/* ---- tables ---- */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
th, td { text-align: left; padding: 11px 16px; font-size: 14px; vertical-align: middle; }
th {
  color: var(--muted);
  font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: .07em;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
}
td { border-bottom: 1px solid var(--line); color: var(--slate); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-soft); }
td a { font-weight: 600; }
table.sched input, table.sched select { width: auto; }
table.sched tr:hover td { background: transparent; }
.actions { display: flex; flex-wrap: wrap; gap: 5px; }
.actions form { display: inline-block; margin: 0; }

/* re-point disclosure: a small popover form so it doesn't reflow the table row */
.repoint { position: relative; display: inline-block; margin: 0; }
.repoint > summary { list-style: none; cursor: pointer; }
.repoint > summary::-webkit-details-marker { display: none; }
.repoint[open] > form {
  position: absolute; z-index: 30; right: 0; top: calc(100% + 4px);
  width: 250px; text-align: left; display: grid; gap: 7px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px;
  box-shadow: 0 14px 32px -14px rgba(15, 23, 42, .3);
}
.repoint[open] > form label { font-size: 12px; font-weight: 600; display: block; }
.repoint[open] > form input { width: 100%; box-sizing: border-box; margin-top: 3px; }
.repoint[open] > form .hint { margin: 0; }

/* ---- status pills ---- */
.badge {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--bg-soft);
  color: var(--muted);
  border: 1px solid var(--line);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.badge.ok { background: var(--up-bg); color: var(--up); border-color: var(--up-line); }
.badge.ok::before { background: var(--up); }
.badge.bad { background: var(--down-bg); color: var(--down); border-color: var(--down-line); }
.badge.bad::before { background: var(--down); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn-line); }
.badge.warn::before { background: var(--amber); }

/* ---- forms ---- */
label { display: block; margin: 12px 0; font-size: 13px; font-weight: 600; color: var(--slate); }
label input, label select, label textarea { display: block; width: 100%; margin-top: 6px; font-weight: 400; }
label.check { font-weight: 400; margin: 7px 0; color: var(--slate); }
label.check input { display: inline; width: auto; margin-right: 6px; accent-color: var(--cta); }

input, select, textarea {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 14.5px;
  font-family: var(--font-body);
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--cta); box-shadow: var(--ring); }
input::placeholder, textarea::placeholder { color: var(--faint); }
input.sm { padding: 5px 9px; font-size: 13px; margin-top: 4px; }
input[name="fob"], input[name="uid"] { font-family: var(--mono); }

.inline-form { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; margin: 0; }
.inline-form input, .inline-form select { width: auto; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface);
  color: var(--slate);
  border: 1px solid var(--line-strong);
  cursor: pointer;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600;
  font-family: var(--font-body);
  transition: background .12s, color .12s, border-color .12s, box-shadow .12s, transform .08s;
}
.btn:hover { background: var(--bg-soft); color: var(--navy); border-color: var(--cta); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--cta);
  color: #fff;
  border-color: transparent;
  box-shadow: var(--shadow-sm);
}
.btn.primary:hover { background: var(--cta-dark); color: #fff; box-shadow: var(--shadow); }
.btn.danger { background: var(--surface); color: var(--down); border-color: var(--down-line); }
.btn.danger:hover { background: var(--down-bg); color: #B91C1C; border-color: var(--down); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn.ghost:hover { background: var(--bg-soft); color: var(--navy); }
.btn.sm { padding: 5px 11px; font-size: 13px; }
.btn.wide { width: 100%; justify-content: center; margin-top: 14px; }

/* ---- login ---- */
.login-body {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: 20px;
  background:
    radial-gradient(900px 540px at 50% -10%, rgba(3, 105, 161, .07), transparent 60%),
    radial-gradient(700px 480px at 50% 110%, rgba(15, 118, 110, .05), transparent 60%),
    var(--bg);
}
.login-card {
  width: 384px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 32px 28px;
  box-shadow: var(--shadow-lg);
  position: relative; overflow: hidden;
  text-align: center;
  animation: rise .45s both;
}
.login-card::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--cta), var(--accent-bright), var(--amber));
}
.login-card .brand { color: var(--navy) !important; justify-content: center; margin-top: 12px; padding: 0; }
.login-card .tagline {
  color: var(--muted);
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .18em;
  margin: 6px 0 20px;
}
.login-card form { text-align: left; }
.login-card .flash { margin: 12px 0; max-width: none; }

/* ---- flasher widget ---- */
esp-web-install-button {
  --esp-tools-button-color: #0369A1;
  --esp-tools-button-border-radius: 9px;
}

/* ---- dark-mode toggle ---- */
.side-foot {
  display: flex; align-items: center; gap: 8px;
}
.side-foot form { flex: 1; margin: 0; }
.side-foot form .btn { width: 100%; justify-content: center; }

.theme-toggle {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; flex-shrink: 0;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--muted); cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.theme-toggle:hover { background: var(--bg-soft); color: var(--navy); border-color: var(--cta); }
.theme-toggle svg {
  width: 17px; height: 17px;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.theme-toggle .i-sun { display: none; }
html[data-theme="dark"] .theme-toggle .i-moon { display: none; }
html[data-theme="dark"] .theme-toggle .i-sun  { display: block; }

.theme-toggle.fixed { position: fixed; top: 18px; right: 18px; z-index: 5; box-shadow: var(--shadow-sm); }

/* Smooth the flip without animating layout. */
body, .sidebar, .panel, .card, table, th, td, code, .badge,
.btn, input, select, textarea, .theme-toggle, .flash {
  transition: background-color .2s ease, border-color .2s ease, color .2s ease;
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
