/* ============================================================
   THEME TOKENS — Aleph Graphics brand.
   Brand cyan is #00aeef (sampled from the logo). On light surfaces a
   darker cyan drives text/buttons/links so they pass WCAG AA on white,
   while --accent carries the vivid cyan for highlights on dark surfaces.
   ============================================================ */
:root {
  --brand:        #0079ab;   /* accessible cyan: buttons, links (AA on white) */
  --brand-ink:    #005f87;   /* darker brand shade for hovers */
  --accent:       #00aeef;   /* vivid brand cyan: highlights on dark surfaces */
  --bg:           #f5f7f8;   /* page background */
  --surface:      #ffffff;   /* cards / panels */
  --ink:          #16202b;   /* primary text */
  --muted:        #5d6b78;   /* secondary text */
  --line:         #e2e8ec;   /* hairline borders */
  --ok:           #1d7a44;   /* valid / success */
  --warn:         #b4541a;   /* expired / warning */
  --danger:       #b42318;   /* destructive */
  --code-bg:      #0f1722;   /* dark chip behind generated keys */
  --code-fg:      #e7f1f5;
  --field-bg:     #ffffff;   /* inputs / selects */
  --btn-fg:       #ffffff;   /* text on the primary button */
  --ghost-bg:     #e7f3f9;   /* ghost button (cyan tint) */
  --ghost-bg-h:   #d6ecf6;
  --warn-bg:      #fbeae5;   /* warning / destructive button */
  --warn-bg-h:    #f6d8cf;
  --badge-ok-bg:  #e4f3ea;
  --badge-exp-bg: #f8e7df;
  --badge-role-bg:#eef1f4;
  --badge-admin-bg:#e7eefc;
  --badge-admin-fg:#2349a8;
  --flash-ok-bg:  #e4f3ea;
  --flash-err-bg: #fbeae5;
  --sheet:        rgba(16, 24, 32, .55);  /* dimmed modal backdrop */
  --radius:       10px;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", "Menlo", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---- dark theme: overrides the tokens above ---- */
:root[data-theme="dark"] {
  --brand:        #00aeef;   /* vivid brand cyan reads well on dark */
  --brand-ink:    #5ec8f5;
  --accent:       #38bdf8;   /* vivid brand cyan: highlights on dark surfaces */
  --bg:           #0e1620;
  --surface:      #16212c;
  --ink:          #e7eef4;
  --muted:        #93a3b2;
  --line:         #28333f;
  --ok:           #4ade80;
  --warn:         #f0a868;
  --danger:       #f87171;
  --code-bg:      #0a121b;
  --code-fg:      #d7e6ee;
  --field-bg:     #0f1a24;
  --btn-fg:       #06231f;
  --ghost-bg:     #1d2b39;
  --ghost-bg-h:   #243343;
  --warn-bg:      #3a1f1d;
  --warn-bg-h:    #4a2724;
  --badge-ok-bg:  rgba(74, 222, 128, .14);
  --badge-exp-bg: rgba(240, 168, 104, .16);
  --badge-role-bg:rgba(147, 163, 178, .16);
  --badge-admin-bg:rgba(96, 138, 232, .18);
  --badge-admin-fg:#9db4f5;
  --flash-ok-bg:  rgba(74, 222, 128, .14);
  --flash-err-bg: rgba(248, 113, 113, .16);
  --sheet:        rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* Sticky footer: fill the viewport and let <main> absorb the slack so the
     footer sits at the bottom even on short pages. */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
main.wrap { flex: 1 0 auto; }
.site-footer { flex-shrink: 0; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 0.85rem 1.4rem;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; letter-spacing: -0.01em; display: flex; align-items: baseline; gap: .5rem; color: inherit; text-decoration: none; }
.brand-mark { height: 1.5em; width: auto; display: block; align-self: center; }
.brand-sub { color: var(--muted); font-weight: 500; font-size: .85rem; }
.nav { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; }
.nav a { color: var(--ink); font-size: .92rem; }
.nav a:hover { color: var(--brand); text-decoration: none; }
.who { color: var(--muted); font-size: .85rem; padding-left: .4rem; border-left: 1px solid var(--line); }
.inline { display: inline; margin: 0; }
.nowrap { white-space: nowrap; }
.linkbtn { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; font-size: .92rem; padding: 0; }
.linkbtn:hover { color: var(--danger); }
.langswitch { display: inline-flex; gap: .5rem; align-items: center; }
.langswitch a { color: var(--muted); font-size: .8rem; }
.langswitch a:hover { color: var(--brand); }
.langswitch a.active { color: var(--ink); font-weight: 600; cursor: default; }
.login-lang { margin-top: 1.1rem; justify-content: center; flex-wrap: wrap; }

/* ---- layout ---- */
.wrap { max-width: 1200px; margin: 0 auto; padding: 1.8rem 1.4rem 4rem; }
h1 { font-size: 1.35rem; letter-spacing: -0.01em; margin: 0 0 .3rem; }
h2 { font-size: 1rem; letter-spacing: .02em; text-transform: uppercase; color: var(--muted); margin: 2rem 0 .8rem; }
.lead { color: var(--muted); margin-top: 0; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.3rem; margin-bottom: 1.2rem;
}

/* ---- forms ---- */
label { display: block; font-size: .82rem; color: var(--muted); margin: 0 0 .3rem; }
input, select {
  width: 100%; padding: .6rem .7rem; font: inherit;
  border: 1px solid var(--line); border-radius: 8px; background: var(--field-bg); color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
.field { margin-bottom: .9rem; }
.row { display: flex; gap: .8rem; flex-wrap: wrap; }
.row > * { flex: 1 1 160px; }

.btn {
  display: inline-block; background: var(--brand); color: var(--btn-fg); border: 0;
  padding: .62rem 1.1rem; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { background: var(--brand-ink); }
.btn.small { padding: .35rem .7rem; font-size: .82rem; font-weight: 500; }
.btn.ghost { background: var(--ghost-bg); color: var(--brand); }
.btn.ghost:hover { background: var(--ghost-bg-h); }
.btn.warn { background: var(--warn-bg); color: var(--danger); }
.btn.warn:hover { background: var(--warn-bg-h); }
.btn:disabled, .btn:disabled:hover { opacity: .5; cursor: not-allowed; background: var(--ghost-bg); color: var(--muted); }

/* ---- generated key chip ---- */
.keyout {
  background: var(--code-bg); color: var(--code-fg); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; margin-bottom: 1.2rem;
  border-left: 3px solid var(--accent);   /* vivid brand cyan highlights the fresh key */
}
.keyout .label { color: #9fb3ae; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; }
.keyout .value { font-family: var(--mono); font-size: 1.5rem; letter-spacing: .04em; margin: .3rem 0; word-break: break-all; }
.keyout .meta { color: #9fb3ae; font-size: .82rem; }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--line); }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
td.code, .code { font-family: var(--mono); }
tr:last-child td { border-bottom: 0; }

/* ---- stats ---- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .9rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; }
.stat .n { font-size: 1.8rem; font-weight: 700; letter-spacing: -.02em; }
.stat .k { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
@media (max-width: 720px) { .stats { grid-template-columns: repeat(2, 1fr); } }

/* ---- badges / flashes ---- */
.badge { display: inline-block; padding: .12rem .5rem; border-radius: 999px; font-size: .76rem; font-weight: 600; }
.badge.ok { background: var(--badge-ok-bg); color: var(--ok); }
.badge.exp { background: var(--badge-exp-bg); color: var(--warn); }
.badge.role { background: var(--badge-role-bg); color: var(--muted); }
.badge.admin { background: var(--badge-admin-bg); color: var(--badge-admin-fg); }
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: .9rem; }
.flash.ok { background: var(--flash-ok-bg); color: var(--ok); }
.flash.err { background: var(--flash-err-bg); color: var(--danger); }
.muted { color: var(--muted); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
@media (max-width: 720px) { .cols { grid-template-columns: 1fr; } }

/* ---- login ---- */
.login-wrap { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.2rem; padding: 1.4rem; }
.login-card { width: 100%; max-width: 360px; }
.login-wrap .brand { flex-direction: column; align-items: center; text-align: center; gap: .25rem; font-size: 1.2rem; }
.login-wrap .brand-name { display: inline-flex; align-items: center; gap: .5rem; }
.login-settings { margin-top: 1.1rem; text-align: center; }

/* ---- icon button (gear / close) ---- */
.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; padding: 0; border-radius: 8px;
  background: none; border: 1px solid transparent; color: var(--muted);
  font-size: 1.05rem; line-height: 1; cursor: pointer;
}
.iconbtn:hover { color: var(--brand); border-color: var(--line); background: var(--surface); }
.iconbtn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

/* ---- settings modal ---- */
.modal[hidden] { display: none; }
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 1.4rem;
}
.modal-sheet { position: absolute; inset: 0; background: var(--sheet); backdrop-filter: blur(1px); }
.modal-card {
  position: relative; z-index: 1; width: 100%; max-width: 340px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.2rem 1.3rem 1.4rem;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .28);
  animation: modal-drop .16s ease-out;
}
@keyframes modal-drop {
  from { opacity: 0; transform: translateY(-10px) scale(.98); }
  to   { opacity: 1; transform: none; }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.modal-head h2 { margin: 0; font-size: 1rem; text-transform: none; letter-spacing: 0; color: var(--ink); }
.modal-section { margin-bottom: 1.1rem; }
.modal-section:last-child { margin-bottom: 0; }
.modal-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: .5rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.3rem; }
.modal-head h2 .muted { font-weight: 400; }
body.modal-on { overflow: hidden; }

/* page header with a primary action on the right (e.g. Engineers › New account) */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.page-head h1 { margin-bottom: .2rem; }
.page-head .lead { margin-top: 0; }

/* row-action menu (Engineers table): a single trigger opens a popover that
   stacks every action, so the cell stays compact regardless of row count. */
.menu { position: relative; display: inline-block; }
.menu > summary { list-style: none; cursor: pointer; white-space: nowrap; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + .3rem); z-index: 20;
  min-width: 11rem; padding: .35rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 9px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
  display: grid; gap: .2rem;
}
.menu-panel > form { display: contents; }
.menu-panel .btn { width: 100%; text-align: left; }
.menu-panel select { width: 100%; }

/* horizontal group of row actions (e.g. Offices: Add overseer / Delete group) */
.row-actions { display: flex; flex-wrap: wrap; gap: .4rem; }
/* staged selections inside a modal, shown as removable chips */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .8rem 0 0; }
.chips:empty { margin: 0; }
/* staged overseer chip: solid fill (white on brand cyan) for clear contrast
   against the modal surface, distinct from the ghost dropdown buttons. */
.btn.chip { background: var(--brand); color: var(--btn-fg); }
.btn.chip:hover { background: var(--brand-ink); }

/* ---- segmented control (theme switch) ---- */
.seg { display: inline-flex; gap: .25rem; padding: .25rem; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; width: 100%; }
.seg-btn {
  flex: 1; padding: .4rem .6rem; border: 0; border-radius: 6px;
  background: none; color: var(--muted); font: inherit; font-size: .85rem; cursor: pointer;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.seg-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

/* language dropdown inside the settings modal */
.lang-select { width: 100%; }

/* ---- site footer (Alephgraphics colophon) ---- */
.site-footer { border-top: 1px solid var(--line); background: var(--surface); margin-top: 3rem; }
.foot-inner {
  max-width: 1200px; margin: 0 auto; padding: 2rem 1.4rem;
  display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 2rem;
}
.foot-brand { text-align: center; }
.foot-brand img { height: 56px; width: auto; display: block; margin: 0 auto .7rem; }
.foot-brand p { margin: 0 auto; max-width: 40ch; color: var(--muted); font-size: .85rem; line-height: 1.6; }
.site-footer h3 {
  font-size: .72rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 .8rem; font-weight: 600;
}
.foot-col address { font-style: normal; font-size: .85rem; line-height: 1.8; }
.foot-col a { color: var(--ink); }
.foot-col a:hover { color: var(--brand); }
.foot-social { display: flex; gap: .9rem; }
.foot-social a { color: var(--muted); display: inline-flex; }
.foot-social a:hover { color: var(--brand); text-decoration: none; }
.foot-social svg { width: 20px; height: 20px; display: block; fill: currentColor; }
.foot-bar { border-top: 1px solid var(--line); }
.foot-bar-inner {
  max-width: 1200px; margin: 0 auto; padding: .9rem 1.4rem;
  display: flex; flex-wrap: wrap; gap: .5rem 1.2rem; justify-content: space-between;
  font-size: .78rem; color: var(--muted);
}
.foot-bar a { color: var(--muted); }
.foot-bar a:hover { color: var(--brand); }
@media (max-width: 720px) { .foot-inner { grid-template-columns: 1fr; text-align: center; } }
