/* ==========================================================================
   POP Telecom BSS — application shell
   Sidebar navigation + content area, light/dark themes, mobile drawer.
   Framework-free. Credit: jon.com
   ========================================================================== */

/* ---- Tokens -------------------------------------------------------------- */
:root {
  --accent:      #111111;      /* single accent: black */
  --accent-deep: #000000;
  --side:        #111111;      /* sidebar */
  --side-2:      #1F1F1F;      /* sidebar hover */
  --side-3:      #0A0A0A;      /* sidebar submenu band */
  --canvas:      #F4F4F4;
  --surface:     #FFFFFF;
  --surface-2:   #FAFAFA;      /* table header, subtle fills */
  --line:        #E3E3E3;
  --line-soft:   #EEEEEE;
  --text:        #111111;
  --text-muted:  #6B6B6B;
  --text-faint:  #A3A3A3;
  --nav-text:    #C4C4C4;
  --nav-bright:  #FFFFFF;
  --nav-faint:   #7A7A7A;
  --green:       #1E8E4E; --green-bg: #E6F4EC;
  --amber:       #B36B00; --amber-bg: #FBF0DC;
  --red:         #C62828; --red-bg: #FBE5E5;

  --sidebar-w:   260px;
  --gutter:      24px;
  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 1px 2px rgba(0,0,0,.05), 0 6px 18px rgba(0,0,0,.04);
  --font:        "Helvetica Neue", Helvetica, Arial, sans-serif;
  --speed:       .18s;
}

[data-theme="dark"] {
  --accent:      #FFFFFF;
  --accent-deep: #E6E6E6;
  --side:        #000000;
  --side-2:      #1A1A1A;
  --side-3:      #000000;
  --canvas:      #121212;
  --surface:     #1C1C1C;
  --surface-2:   #232323;
  --line:        #333333;
  --line-soft:   #2A2A2A;
  --text:        #F2F2F2;
  --text-muted:  #A0A0A0;
  --text-faint:  #666666;
  --nav-text:    #BDBDBD;
  --nav-bright:  #FFFFFF;
  --nav-faint:   #767676;
  --green-bg:    #173A27; --amber-bg: #3D2E12; --red-bg: #45201F;
  --green:       #4CC07A; --amber: #E0A030; --red: #EF6B6B;
  --shadow:      0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.3);
  color-scheme: dark;
}

/* ---- Base ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--canvas);
  min-height: 100vh;
  display: flex;
}
a { color: var(--text); }
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---- Sidebar ------------------------------------------------------------- */
.pop-sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  height: 100dvh;
  position: sticky;
  top: 0;
  background: var(--side);
  color: var(--nav-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  z-index: 40;
}

.pop-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  color: var(--nav-bright);
  text-decoration: none;
  flex-shrink: 0;
}
.pop-brand-mark {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -.02em;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.pop-brand-mark.pop-brand-logo { background: transparent; border-radius: 50%; overflow: hidden; }
.pop-brand-mark.pop-brand-logo img { width: 100%; height: 100%; display: block; object-fit: contain; }
.pop-brand-name  { font-size: 15px; font-weight: 700; line-height: 1.15; }
.pop-brand-sub   { font-size: 11px; color: var(--nav-faint); letter-spacing: .04em; }

.pop-nav {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--side-2) transparent;
}
.pop-nav::-webkit-scrollbar { width: 4px; }
.pop-nav::-webkit-scrollbar-thumb { background: var(--side-2); border-radius: 2px; }

.pop-nav ul { list-style: none; margin: 0; padding: 0; }

.pop-nav-section {
  padding: 16px 20px 4px;
  font-size: 11px;
  color: var(--nav-faint);
  letter-spacing: .04em;
}

.pop-nav a, .pop-nav button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px 9px 17px;      /* 17 + 3px edge = 20 */
  border: 0;
  border-left: 3px solid transparent;
  background: none;
  color: var(--nav-text);
  font-size: 14px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--speed), color var(--speed);
}
.pop-nav a:hover, .pop-nav button:hover,
.pop-nav button[aria-expanded="true"] {
  background: var(--side-2);
  color: var(--nav-bright);
}
.pop-nav a.is-active {
  color: var(--nav-bright);
  border-left-color: var(--accent);
  background: rgba(255,255,255,.10);
  font-weight: 600;
}
.pop-nav svg {
  width: 18px; height: 18px;
  flex-shrink: 0;
  stroke: currentColor; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
  opacity: .9;
}
.pop-nav .pop-chev { margin-left: auto; width: 14px; height: 14px; opacity: .6; transition: transform .22s ease; }
.pop-nav button[aria-expanded="true"] .pop-chev { transform: rotate(180deg); }

/* Submenu band */
.pop-sub {
  display: none;
  background: var(--side-3);
  padding: 4px 0;
}
.pop-sub.is-open { display: block; }
.pop-sub a {
  padding: 7px 20px 7px 44px;
  font-size: 13px;
  color: var(--nav-faint);
  border-left: 0;
}
.pop-sub a:hover { color: var(--nav-bright); background: rgba(255,255,255,.05); }
.pop-sub a.is-active { color: var(--nav-bright); background: rgba(255,255,255,.10); font-weight: 600; }
.pop-sub svg { width: 15px; height: 15px; }

/* Sidebar footer: user card, theme toggle, sign out */
.pop-side-foot {
  flex-shrink: 0;
  padding: 12px 12px;
  border-top: 1px solid rgba(255,255,255,.07);
}
.pop-user {
  display: flex; align-items: center; gap: 10px;
  padding: 8px;
  border-radius: 8px;
  color: inherit; text-decoration: none;
  margin-bottom: 6px;
  transition: background var(--speed);
}
.pop-user:hover { background: rgba(255,255,255,.06); }
.pop-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0;
}
.pop-user-name  { font-size: 13px; font-weight: 600; color: var(--nav-bright); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pop-user-email { font-size: 11px; color: var(--nav-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pop-user-gear  { margin-left: auto; width: 14px; height: 14px; stroke: var(--nav-faint); fill: none; stroke-width: 1.8; flex-shrink: 0; }

.pop-side-foot .pop-foot-link {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 8px 8px;
  border: 0; border-radius: 8px;
  background: none;
  color: var(--nav-text);
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--speed);
}
.pop-side-foot .pop-foot-link:hover { background: rgba(255,255,255,.06); color: var(--nav-bright); }
.pop-side-foot .pop-foot-link svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.pop-side-foot form { margin: 0; }
.pop-side-foot .pop-signout { color: #FFFFFF; }
.pop-side-foot .pop-signout:hover { color: #FFFFFF; }
[data-theme="dark"] .pop-theme-sun  { display: inline; }
[data-theme="dark"] .pop-theme-moon { display: none; }
.pop-theme-sun { display: none; }

/* ---- Content ------------------------------------------------------------- */
.pop-main {
  flex: 1;
  min-width: 0;
  padding: var(--gutter);
}
.pop-page-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px;
  margin-bottom: 20px;
}
.pop-page-head h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.pop-page-head .pop-page-sub { margin: 2px 0 0; color: var(--text-muted); font-size: 13px; }
.pop-page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Topbar — only visible on small screens */
.pop-topbar { display: none; }

/* ---- Cards --------------------------------------------------------------- */
.pop-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.pop-card + .pop-card { margin-top: 16px; }
.pop-card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}
.pop-card-body { padding: 18px; }
.pop-card-body.is-flush { padding: 0; }
.pop-card-note { padding: 12px 18px; color: var(--text-muted); font-size: 12px; border-top: 1px solid var(--line-soft); }

/* ---- Filter row ---------------------------------------------------------- */
.pop-filters { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 12px 16px; margin-bottom: 14px; }
.pop-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-muted); }
.pop-field input, .pop-field select {
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 7px 10px; min-width: 160px;
}
.pop-field select { padding-right: 28px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B6B6B' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
.pop-filter-summary { color: var(--text-muted); font-size: 13px; padding-bottom: 8px; }
.pop-filter-summary strong { color: var(--text); }

/* Browser autofill forces its own light background that normal `background`
   CSS can't override, so any field the browser matches to a saved credential
   (e.g. the row for whoever's signed in) goes white-on-white in dark mode
   otherwise, however the rest of the page is themed. Needed site-wide, not
   just on the legacy pages — this is the same family of bug that hit the
   Giacom API password field via an autofilled site password. */
[data-theme="dark"] input:-webkit-autofill,
[data-theme="dark"] input:-webkit-autofill:hover,
[data-theme="dark"] input:-webkit-autofill:focus,
[data-theme="dark"] input:-webkit-autofill:active {
  -webkit-box-shadow: 0 0 0 1000px var(--surface) inset !important;
  box-shadow: 0 0 0 1000px var(--surface) inset !important;
  -webkit-text-fill-color: var(--text) !important;
  caret-color: var(--text);
  transition: background-color 9999s ease-in-out 0s;
}

/* ---- Tables -------------------------------------------------------------- */
.pop-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.pop-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.pop-table th {
  text-align: left; white-space: nowrap;
  padding: 10px 16px;
  font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface-2);
  border-bottom: 2px solid var(--line);
}
.pop-table td { padding: 12px 16px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; white-space: nowrap; }
.pop-table td.is-wrap { white-space: normal; }
.pop-table tbody tr:last-child td { border-bottom: 0; }
.pop-table tbody tr:hover td { background: var(--surface-2); }
.pop-table .is-num { text-align: right; font-variant-numeric: tabular-nums; }
.pop-table .is-empty td { color: var(--text-muted); padding: 22px 16px; }

/* ---- Small bits ---------------------------------------------------------- */
.pop-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
  cursor: pointer; text-decoration: none;
  transition: background var(--speed), border-color var(--speed);
}
.pop-btn-primary { background: var(--accent); color: var(--surface); }
.pop-btn-primary:hover { background: var(--accent-deep); }
.pop-btn-quiet { background: var(--surface); color: var(--text); border-color: var(--line); }
.pop-btn-quiet:hover { border-color: var(--text-faint); }
.pop-btn-sm { padding: 5px 10px; font-size: 12px; }
.pop-btn svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.pop-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pop-badge-ok    { background: var(--green-bg); color: var(--green); }
.pop-badge-warn  { background: var(--amber-bg); color: var(--amber); }
.pop-badge-bad   { background: var(--red-bg);   color: var(--red); }
.pop-badge-muted { background: var(--line-soft); color: var(--text-muted); }

.pop-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 16px; }
.pop-stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.pop-stat-label { font-size: 13px; color: var(--text-muted); }
.pop-stat-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.pop-stat-delta { font-size: 12px; margin-top: 4px; color: var(--text-muted); }
.pop-stat-delta.is-up { color: var(--green); }
.pop-stat-delta.is-down { color: var(--red); }

/* ---- Responsive: drawer under 1024px ------------------------------------- */
@media (max-width: 1023px) {
  body { display: block; }

  .pop-topbar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 30;
    height: 56px; padding: 0 12px;
    background: var(--side); color: #fff;
  }
  .pop-topbar .pop-brand-mark { width: 30px; height: 30px; font-size: 13px; }
  .pop-topbar-title { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .pop-menu-btn {
    width: 40px; height: 40px;
    border: 0; border-radius: 8px;
    background: none; color: #fff; cursor: pointer;
    display: grid; place-items: center;
  }
  .pop-menu-btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }
  .pop-menu-btn:hover { background: rgba(255,255,255,.08); }

  .pop-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: min(300px, 86vw); min-width: 0;
    transform: translateX(-100%);
    transition: transform .24s ease;
    box-shadow: none;
  }
  body.nav-open .pop-sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.5), 8px 0 30px rgba(0,0,0,.3); }
  body.nav-open { overflow: hidden; }

  .pop-main { padding: 16px; }
  .pop-page-head h1 { font-size: 20px; }
  .pop-card-body { padding: 14px; }
  .pop-table th, .pop-table td { padding-left: 12px; padding-right: 12px; }
  .pop-field input, .pop-field select { min-width: 0; width: 100%; }
  .pop-field { flex: 1 1 140px; }
}

@media (max-width: 480px) {
  .pop-stat-value { font-size: 22px; }
}

/* ---- Auth pages (sign in / 2FA) — no sidebar, centred card ---------------- */
body.pop-auth { display: grid; place-items: center; padding: 24px; }
.pop-auth-box { width: 100%; max-width: 420px; }
.pop-auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 18px; color: var(--text); font-weight: 700; font-size: 16px; }
.pop-auth-brand .pop-brand-mark { background: var(--accent); color: var(--surface); }
.pop-auth-box .card, .pop-auth-box main { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.pop-auth-box h1 { font-size: 22px; margin: 0 0 6px; font-weight: 700; letter-spacing: -.02em; }
.pop-auth-box .lead { color: var(--text-muted); margin: 0 0 16px; }
.pop-auth-box .field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.pop-auth-box .field label { font-size: 13px; font-weight: 600; }
.pop-auth-box input { font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); }
.pop-auth-box input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.pop-auth-box .actions { display: flex; align-items: center; gap: 10px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line-soft); }
.pop-auth-box .spacer { flex: 1; }
.pop-auth-box .btn { display: inline-flex; align-items: center; padding: 10px 16px; border-radius: var(--radius-sm); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; border: 1px solid transparent; }
.pop-auth-box .btn-primary { background: var(--accent); color: var(--surface); }
.pop-auth-box .btn-ghost { background: none; color: var(--text-muted); border-color: var(--line); }
.pop-auth-box .btn-ghost:hover { color: var(--text); }
.pop-auth-box .notice { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 14px; background: var(--surface-2); border: 1px solid var(--line); }
.pop-auth-box .notice.bad { background: var(--red-bg); color: var(--red); border-color: transparent; }
.pop-auth-box .notice.ok { background: var(--green-bg); color: var(--green); border-color: transparent; }
.pop-auth-box .hint { font-size: 12px; color: var(--text-muted); margin: 12px 0 0; }
.pop-auth-box .brand { display: none; }   /* legacy brand row inside the body — replaced by .pop-auth-brand */
