/* =========================================================================
   Kelvin's M365 Foundation — base stylesheet
   Light + dark theming via CSS variables. Sidebar layout, cards, panels.
   ========================================================================= */

/* ---- Design tokens (light) ---------------------------------------------- */
:root {
  --accent: #0f6cbd;
  --accent-ink: #ffffff;
  --accent-soft: #e8f1fb;
  --accent-ring: rgba(15, 108, 189, .35);

  --bg: #eef1f7;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --sidebar-bg: #ffffff;
  --text: #1b1f26;
  --text-muted: #5b6573;
  --text-faint: #8a93a3;
  --border: #e3e8f0;
  --border-strong: #d4dae4;

  --ok: #107c41;
  --ok-soft: #e4f3ea;
  --warn: #9a6700;
  --warn-soft: #fbf3dd;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .05);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, .08), 0 2px 4px rgba(16, 24, 40, .04);
  --shadow-lg: 0 18px 40px rgba(16, 24, 40, .14);

  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --sidebar-w: 268px;
  --topbar-h: 64px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Code", Consolas, monospace;
}

/* ---- Dark tokens -------------------------------------------------------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #4aa3ec;
    --accent-ink: #06243b;
    --accent-soft: #15314a;
    --accent-ring: rgba(74, 163, 236, .4);

    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1b212b;
    --sidebar-bg: #11161d;
    --text: #e8edf4;
    --text-muted: #9aa5b5;
    --text-faint: #6e7889;
    --border: #272e3a;
    --border-strong: #333c4a;

    --ok: #3fb950;
    --ok-soft: #122d1c;
    --warn: #d6a425;
    --warn-soft: #2e2611;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, .45);
    --shadow-lg: 0 20px 44px rgba(0, 0, 0, .55);
  }
}
:root[data-theme="dark"] {
  --accent: #4aa3ec;
  --accent-ink: #06243b;
  --accent-soft: #15314a;
  --accent-ring: rgba(74, 163, 236, .4);

  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1b212b;
  --sidebar-bg: #11161d;
  --text: #e8edf4;
  --text-muted: #9aa5b5;
  --text-faint: #6e7889;
  --border: #272e3a;
  --border-strong: #333c4a;

  --ok: #3fb950;
  --ok-soft: #122d1c;
  --warn: #d6a425;
  --warn-soft: #2e2611;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, .45);
  --shadow-lg: 0 20px 44px rgba(0, 0, 0, .55);
}

/* ---- Reset / base ------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
code {
  font-family: var(--mono);
  font-size: .88em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .1em .4em;
}
svg { width: 100%; height: 100%; display: block; }

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

.shell {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  margin-left: var(--sidebar-w);
}

/* ---- Sidebar ------------------------------------------------------------ */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 40;
  transition: transform .25s ease;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
}
.brand__mark {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--accent), #1a84dd);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.brand__mark svg { width: 22px; height: 22px; }
.brand__text { display: flex; flex-direction: column; line-height: 1.15; }
.brand__title { font-weight: 700; font-size: 15px; }
.brand__sub { font-size: 12px; color: var(--text-muted); }

.nav { flex: 1; overflow-y: auto; padding: 14px 12px; }
.nav__group { margin-bottom: 14px; }
.nav__heading {
  font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-faint);
  padding: 6px 12px;
  margin: 0;
}
.nav__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.nav__link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 550;
  font-size: 14px;
  position: relative;
  transition: background .15s, color .15s;
}
.nav__link:hover { background: var(--surface-2); color: var(--text); }
.nav__icon { width: 20px; height: 20px; flex: none; opacity: .85; }
.nav__label { flex: 1; min-width: 0; }
.nav__link.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.nav__link.is-active .nav__icon { opacity: 1; }
.nav__link.is-active::before {
  content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.nav__badge {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--warn); background: var(--warn-soft);
  padding: 2px 7px; border-radius: 999px;
}

.sidebar__footer {
  border-top: 1px solid var(--border);
  padding: 12px 18px;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; color: var(--text-muted);
}
.env { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; }
.env .dot { width: 8px; height: 8px; border-radius: 50%; }
.env--prod .dot { background: var(--ok); }
.env--dev .dot { background: var(--warn); }
.sidebar__version { color: var(--text-faint); font-variant-numeric: tabular-nums; }

/* ---- Topbar ------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__title h1 { font-size: 18px; font-weight: 650; }
.topbar__actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.iconbtn {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.iconbtn:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-2); }
.iconbtn svg { width: 20px; height: 20px; }
.topbar__toggle { display: none; }

.icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; }

.avatar {
  width: 38px; height: 38px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--accent), #1a84dd);
  color: #fff; font-weight: 700; font-size: 15px;
}

/* ---- Content ------------------------------------------------------------ */
.content { padding: 28px; max-width: 1180px; width: 100%; margin: 0 auto; }
.section { margin-top: 30px; }
.section__head { margin-bottom: 16px; }
.section__head h3 { font-size: 17px; }
.section__head p { color: var(--text-muted); font-size: 14px; margin-top: 3px; }

/* ---- Hero --------------------------------------------------------------- */
.hero {
  display: flex; align-items: center; gap: 24px;
  background:
    radial-gradient(120% 140% at 100% 0%, var(--accent-soft) 0%, transparent 55%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 30px 32px;
  box-shadow: var(--shadow-sm);
}
.hero__content { flex: 1; min-width: 0; }
.hero__eyebrow {
  display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--accent);
  background: var(--accent-soft); padding: 4px 11px; border-radius: 999px; margin-bottom: 14px;
}
.hero__title { font-size: 28px; letter-spacing: -.02em; }
.hero__title strong { color: var(--accent); font-weight: 750; }
.hero__lead { margin-top: 10px; color: var(--text-muted); max-width: 60ch; font-size: 15px; }
.hero__actions { margin-top: 20px; display: flex; gap: 10px; flex-wrap: wrap; }
.hero__badge {
  width: 120px; height: 120px; flex: none;
  display: grid; place-items: center; color: var(--accent); opacity: .55;
}
.hero__badge svg { width: 96px; height: 96px; }

/* ---- Buttons ------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px;
  font-weight: 600; font-size: 14px; cursor: pointer;
  border: 1px solid transparent; transition: transform .05s, box-shadow .15s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-sm); }
.btn--primary:hover { box-shadow: 0 4px 14px var(--accent-ring); }
.btn--ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn--ghost:hover { background: var(--surface-2); }

/* ---- Stats -------------------------------------------------------------- */
.stats {
  margin-top: 20px;
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
.stat {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm);
}
.stat__icon {
  width: 42px; height: 42px; flex: none; border-radius: 11px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.stat__icon svg { width: 22px; height: 22px; }
.stat__icon--ok { background: var(--ok-soft); color: var(--ok); }
.stat__icon--muted { background: var(--surface-2); color: var(--text-muted); }
.stat__value { display: block; font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.stat__label { display: block; font-size: 13px; color: var(--text-muted); }

/* ---- Card grid ---------------------------------------------------------- */
.cardgrid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  transition: transform .12s, box-shadow .15s, border-color .15s;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.card__icon {
  width: 44px; height: 44px; flex: none; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.card__icon svg { width: 23px; height: 23px; }
.card--soon .card__icon { background: var(--surface-2); color: var(--text-muted); }
.card__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.card__title { font-weight: 650; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.card__group { font-size: 12.5px; color: var(--text-muted); }
.card__arrow { width: 18px; height: 18px; color: var(--text-faint); flex: none; transition: transform .12s, color .12s; }
.card:hover .card__arrow { transform: translateX(3px); color: var(--accent); }

.tag {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--warn); background: var(--warn-soft); padding: 2px 7px; border-radius: 999px;
}
.tag--soon { vertical-align: middle; margin-left: 8px; }

/* ---- Panels ------------------------------------------------------------- */
.panel {
  display: flex; gap: 16px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow-sm);
}
.panel--accent { background: linear-gradient(120% 140% at 0 0, var(--accent-soft), var(--surface) 60%); }
.panel__icon {
  width: 44px; height: 44px; flex: none; border-radius: 12px;
  display: grid; place-items: center; background: var(--surface); color: var(--accent);
  border: 1px solid var(--border);
}
.panel__icon svg { width: 23px; height: 23px; }
.panel h4 { font-size: 15.5px; margin-bottom: 4px; }
.panel p { color: var(--text-muted); font-size: 14px; }

/* ---- Page head (tool pages) --------------------------------------------- */
.pagehead { display: flex; gap: 18px; align-items: flex-start; }
.pagehead__icon {
  width: 56px; height: 56px; flex: none; border-radius: 15px;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.pagehead__icon svg { width: 30px; height: 30px; }
.pagehead__eyebrow {
  font-size: 12.5px; color: var(--text-muted); font-weight: 600;
  display: flex; align-items: center;
}
.pagehead h2 { font-size: 24px; margin-top: 4px; }
.pagehead__lead { color: var(--text-muted); margin-top: 6px; max-width: 64ch; }

/* ---- Feature list ------------------------------------------------------- */
.featurelist {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.featurelist li {
  display: flex; gap: 11px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 13px 15px; box-shadow: var(--shadow-sm);
  font-size: 14px;
}
.featurelist__check {
  width: 22px; height: 22px; flex: none; border-radius: 7px;
  display: grid; place-items: center; background: var(--ok-soft); color: var(--ok);
}
.featurelist__check svg { width: 15px; height: 15px; }

/* ---- Empty / error state ------------------------------------------------ */
.emptystate { text-align: center; padding: 60px 20px; }
.emptystate__code { font-size: 64px; font-weight: 800; color: var(--accent); letter-spacing: -.03em; }
.emptystate h2 { font-size: 22px; margin: 8px 0; }
.emptystate p { color: var(--text-muted); margin-bottom: 20px; }

/* ---- Scrim (mobile nav) ------------------------------------------------- */
.scrim {
  position: fixed; inset: 0; z-index: 35;
  background: rgba(10, 15, 25, .45); backdrop-filter: blur(2px);
  opacity: 0; transition: opacity .2s; display: none;
}
.scrim.is-open { display: block; opacity: 1; }

/* ---- Responsive --------------------------------------------------------- */
@media (max-width: 900px) {
  .shell { margin-left: 0; }
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.is-open { transform: translateX(0); }
  .topbar__toggle { display: grid; }
  .content { padding: 20px 16px; }
  .hero { flex-direction: column; align-items: flex-start; padding: 24px; }
  .hero__badge { display: none; }
  .hero__title { font-size: 23px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* =========================================================================
   Forms, tables, auth & tool components (v0.2)
   ========================================================================= */

:root { --danger: #c0392b; --danger-soft: #fdecea; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --danger: #f87171; --danger-soft: #3a1d1d; }
}
:root[data-theme="dark"] { --danger: #f87171; --danger-soft: #3a1d1d; }

.muted { color: var(--text-muted); }

/* ---- Forms -------------------------------------------------------------- */
.panel--form { flex-direction: column; align-items: stretch; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 15px; }
.field:last-child { margin-bottom: 0; }
.field label { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], select, textarea {
  font: inherit; width: 100%; padding: 10px 12px;
  border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring);
}
input:disabled, select:disabled { background: var(--surface-2); color: var(--text-faint); cursor: not-allowed; }
.field__hint { font-size: 12px; color: var(--text-faint); }
.field__picked { font-size: 13px; color: var(--ok); font-weight: 600; }
.form__actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 4px; }

.vac-grid { display: flex; flex-direction: column; gap: 2px; max-width: 580px; }
.field--submit { margin-top: 8px; }

/* ---- Buttons (extra) ---------------------------------------------------- */
.btn--sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn--danger { background: var(--surface); color: var(--danger); border: 1px solid var(--border-strong); }
.btn--danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---- Tables ------------------------------------------------------------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-faint); padding: 8px 10px; border-bottom: 1px solid var(--border); font-weight: 700;
}
.table td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: none; }
.table__actions { text-align: right; white-space: nowrap; width: 1%; }
.rowbtns { display: flex; gap: 8px; justify-content: flex-end; }
.inline-form { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.inline-form input { max-width: 320px; }

/* ---- Pills / tags ------------------------------------------------------- */
.status-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; }
.status-pill--ok { background: var(--ok-soft); color: var(--ok); }
.status-pill--warn { background: var(--warn-soft); color: var(--warn); }
.tag--ok { color: var(--ok); background: var(--ok-soft); }

.kv { display: flex; gap: 12px; align-items: center; padding: 7px 0; }
.kv__k { width: 84px; flex: none; font-weight: 600; font-size: 13px; color: var(--text-muted); }
.kv__v { font-size: 13px; word-break: break-all; }

/* ---- Flash (topbar) & form messages ------------------------------------ */
.flash { font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 999px; }
.flash--ok { background: var(--ok-soft); color: var(--ok); }
.flash--err { background: var(--danger-soft); color: var(--danger); }
.formmsg { margin-top: 14px; padding: 11px 14px; border-radius: 10px; font-size: 14px; font-weight: 500; }
.formmsg--ok { background: var(--ok-soft); color: var(--ok); }
.formmsg--err { background: var(--danger-soft); color: var(--danger); }

/* ---- Combo (user search) ----------------------------------------------- */
.field--search { position: relative; }
.combo {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 20; margin-top: 4px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px;
  box-shadow: var(--shadow-lg); max-height: 300px; overflow: auto;
}
.combo__item {
  display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left;
  padding: 10px 14px; background: none; border: none; border-bottom: 1px solid var(--border);
  cursor: pointer; color: var(--text); font: inherit;
}
.combo__item:last-child { border-bottom: none; }
.combo__item:hover { background: var(--surface-2); }
.combo__name { font-weight: 600; font-size: 14px; }
.combo__sub { font-size: 12.5px; color: var(--text-muted); }

/* ---- User menu (topbar) ------------------------------------------------- */
.usermenu { display: flex; align-items: center; gap: 10px; }
.usermenu__info { display: flex; flex-direction: column; line-height: 1.2; }
.usermenu__name { font-size: 13px; font-weight: 600; }
.usermenu__upn { font-size: 11.5px; color: var(--text-muted); }
@media (max-width: 760px) { .usermenu__info { display: none; } }

/* ---- Centered standalone pages (login, consent) ------------------------ */
.centerbox { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.centerbox__card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: var(--shadow-lg); padding: 38px 36px; max-width: 420px; width: 100%; text-align: center;
}
.centerbox__brand { display: flex; gap: 12px; align-items: center; justify-content: center; margin-bottom: 20px; }
.centerbox__brand .brand__mark { width: 40px; height: 40px; }
.centerbox__brand .brand__mark svg { width: 24px; height: 24px; }
.centerbox__brand div { text-align: left; }
.centerbox__brand strong { display: block; font-size: 15px; }
.centerbox__brand span { font-size: 12px; color: var(--text-muted); }
.centerbox h1 { font-size: 21px; margin-bottom: 8px; }
.centerbox p { color: var(--text-muted); margin-bottom: 20px; }
.centerbox__icon { width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 16px; }
.centerbox__icon.is-ok { background: var(--ok-soft); color: var(--ok); }
.centerbox__icon.is-err { background: var(--danger-soft); color: var(--danger); }
.centerbox__icon svg { width: 30px; height: 30px; }
