/* ============================================================
   RegiFortis — shared brand & design system
   Modern SaaS / tech: dark, indigo→violet gradient, glass, glow.
   Loaded by every public and admin page for one cohesive look.
   ============================================================ */

:root {
  color-scheme: dark;

  /* surfaces */
  --bg-0: #08081a;
  --bg-1: #0b0b1e;
  --card: rgba(255, 255, 255, 0.045);
  --card-brd: rgba(255, 255, 255, 0.09);
  --card-brd-hi: rgba(129, 140, 248, 0.38);
  --surface: #12122a;               /* used by chart JS for dot strokes */

  /* brand */
  --brand-1: #6366f1;
  --brand-2: #a855f7;
  --brand-3: #22d3ee;
  --grad: linear-gradient(120deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);
  --glow: 0 0 22px rgba(99, 102, 241, 0.45);

  /* text */
  --ink: #ffffff;
  --ink-2: #c7cadd;
  --muted: #8b8fb0;

  /* chart plumbing (consumed by monitor JS via getComputedStyle) */
  --grid: #26264a;
  --s1: #6366f1;  --s2: #22c55e;  --s3: #ec4899;  --s4: #f59e0b;
  --s-cpu: #6366f1;  --s-mem: #22c55e;  --s-disk: #ec4899;  --s-load: #f59e0b;

  /* status */
  --ok: #34d399;
  --bad: #fb7185;

  --radius: 16px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  background:
    radial-gradient(1200px 620px at 12% -12%, rgba(99, 102, 241, 0.20), transparent 60%),
    radial-gradient(1000px 680px at 105% -5%, rgba(168, 85, 247, 0.18), transparent 55%),
    radial-gradient(900px 700px at 90% 110%, rgba(34, 211, 238, 0.08), transparent 55%),
    linear-gradient(160deg, #08081a 0%, #0b0b1e 55%, #0a0a18 100%);
  background-attachment: fixed;
}

/* layout modes ------------------------------------------------ */
body.app { padding: 2rem 1.5rem; }
body.center {
  display: flex; align-items: center; justify-content: center;
  padding: 2rem; min-height: 100vh;
}

.wrap { max-width: 1080px; margin: 0 auto; }
.wrap.narrow { max-width: 880px; }

/* header / nav ------------------------------------------------ */
header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1.85rem; flex-wrap: wrap; gap: 1rem;
}
h1 { font-size: 1.55rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.05rem; margin-bottom: 1rem; color: var(--ink-2); font-weight: 600; }

nav a {
  color: var(--ink-2); text-decoration: none; margin-left: 1.4rem;
  font-size: 0.92rem; font-weight: 500; transition: color 0.15s;
}
nav a:hover { color: var(--ink); }

/* brand mark -------------------------------------------------- */
.brand {
  display: inline-flex; align-items: center; gap: 0.6rem;
  font-weight: 700; font-size: 1.18rem; letter-spacing: -0.02em;
  color: var(--ink); text-decoration: none;
}
.brand .logo {
  width: 30px; height: 30px; border-radius: 9px; background: var(--grad);
  display: grid; place-items: center; box-shadow: var(--glow);
  font-size: 0.95rem; flex: 0 0 auto;
}
.grad-text {
  background: var(--grad);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* cards ------------------------------------------------------- */
.card {
  background: var(--card); border: 1px solid var(--card-brd);
  border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.5rem;
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.newlink { border-color: var(--card-brd-hi); box-shadow: var(--glow); }

/* buttons ----------------------------------------------------- */
button,
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.7rem 1.3rem; border: none; border-radius: 10px;
  font: inherit; font-weight: 600; font-size: 0.94rem; cursor: pointer;
  text-decoration: none; color: #fff; background: var(--grad);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.30); transition: transform 0.16s, box-shadow 0.16s, background 0.16s;
}
button:hover,
.btn:hover { box-shadow: 0 9px 28px rgba(139, 92, 246, 0.5); transform: translateY(-1px); }

.btn-ghost, button.mini, .btnlike {
  background: rgba(255, 255, 255, 0.08); color: var(--ink);
  border: 1px solid var(--card-brd); box-shadow: none;
}
.btn-ghost:hover, button.mini:hover, .btnlike:hover {
  background: rgba(255, 255, 255, 0.16); box-shadow: none; transform: translateY(-1px);
}
button.mini { padding: 0.4rem 0.7rem; font-size: 0.85rem; }
.btnlike { padding: 0.5rem 1rem; }

button.danger, .btn-danger {
  background: rgba(251, 113, 133, 0.16); color: var(--bad);
  border: 1px solid rgba(251, 113, 133, 0.4); box-shadow: none;
}
button.danger:hover, .btn-danger:hover {
  background: rgba(251, 113, 133, 0.28); box-shadow: none;
}

/* forms ------------------------------------------------------- */
label { display: block; margin-bottom: 0.4rem; color: var(--ink-2); font-size: 0.88rem; }
input[type=text], input[type=email], input[type=password], input:not([type]),
select, textarea {
  width: 100%;
  padding: 0.7rem 1rem; background: rgba(8, 8, 22, 0.6);
  border: 1px solid var(--card-brd); border-radius: 10px;
  color: var(--ink); font: inherit; font-size: 0.95rem; transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder { color: var(--muted); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand-1);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}
select option { background: #12122a; }

form.create, form.inline { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; }
form.create input, form.inline input, form.inline select { flex: 1; min-width: 150px; }
form.create button, form.inline button { flex: 0 0 auto; }

form.auth input { margin-bottom: 1rem; }
form.auth button { width: 100%; margin-top: 0.25rem; }

/* auth / centered cards -------------------------------------- */
.auth-card { width: 100%; max-width: 400px; }
.sub { text-align: center; color: var(--muted); font-size: 0.9rem; margin-bottom: 1.5rem; }
.welcome {
  margin-top: 1.25rem; padding: 1rem 1.25rem; border-radius: 12px;
  background: rgba(99, 102, 241, 0.1); border: 1px solid rgba(99, 102, 241, 0.3);
}
.welcome strong { color: #a5b4fc; }
.meta { font-size: 0.85rem; color: var(--muted); margin-top: 0.5rem; }
.back { display: block; text-align: center; margin-top: 1.25rem; color: var(--brand-1); text-decoration: none; font-size: 0.9rem; }
.back:hover { text-decoration: underline; }

/* flashes ----------------------------------------------------- */
.flash { padding: 0.7rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-size: 0.92rem; border: 1px solid transparent; }
.flash.ok  { background: rgba(52, 211, 153, 0.14); color: var(--ok); border-color: rgba(52, 211, 153, 0.3); }
.flash.bad, .error { background: rgba(251, 113, 133, 0.14); color: var(--bad); border-color: rgba(251, 113, 133, 0.3); }
.error { padding: 0.6rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-size: 0.9rem; }

/* tables ------------------------------------------------------ */
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; vertical-align: middle; padding: 0.6rem 0.6rem; border-bottom: 1px solid rgba(255, 255, 255, 0.07); font-size: 0.9rem; }
th { color: var(--muted); font-weight: 600; }
td.name { font-weight: 600; }
tr.total td { border-top: 2px solid rgba(255, 255, 255, 0.2); font-weight: 700; }
.tbl-num { white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbl-num th, .tbl-num td { text-align: right; }
.tbl-num th:first-child, .tbl-num td:first-child { text-align: left; }
tr.edit-row td { background: rgba(255, 255, 255, 0.03); }
tr.edit-row form.inline { align-items: center; }

/* usage / limit indicator ------------------------------------ */
.use { min-width: 92px; }
.use-top { font-size: 0.82rem; white-space: nowrap; }
.use-val { color: var(--ink); font-weight: 600; }
.use-lim { color: var(--muted); }
.use-track { height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.09); margin-top: 4px; overflow: hidden; }
.use-fill { height: 100%; border-radius: 3px; background: var(--brand-1); transition: width 0.3s; }
.use-fill.warn { background: #f5b301; }
.use-fill.over { background: var(--bad); }

/* tiles ------------------------------------------------------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.tile {
  position: relative; overflow: hidden;
  background: var(--card); border: 1px solid var(--card-brd);
  border-radius: var(--radius); padding: 1.15rem 1.35rem 1.15rem 1.5rem;
}
.tile::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--grad); }
.tile .label { color: var(--muted); font-size: 0.76rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.tile .value { font-size: 1.9rem; font-weight: 700; margin-top: 0.25rem; color: var(--ink); letter-spacing: -0.01em; }
.tile .sub { color: var(--ink-2); font-size: 0.82rem; margin-top: 0.15rem; }

/* filters (time-range switchers, tenant picker) --------------- */
.filters { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; align-items: center; }
.filters a {
  padding: 0.45rem 1rem; border-radius: 9px; font-size: 0.88rem; font-weight: 600;
  color: var(--ink-2); text-decoration: none; background: rgba(255, 255, 255, 0.05);
  border: 1px solid transparent; transition: background 0.15s;
}
.filters a:hover { background: rgba(255, 255, 255, 0.1); }
.filters a.active { background: var(--grad); color: #fff; box-shadow: var(--glow); }
.filters select { width: auto; padding: 0.45rem 0.9rem; }

/* charts ------------------------------------------------------ */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 1rem; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; }
.card h2 .key, .legend .lk {
  display: inline-block; width: 14px; height: 3px; border-radius: 2px;
  vertical-align: middle; margin-right: 0.45rem;
}
.legend { display: flex; gap: 1rem; margin-bottom: 0.6rem; }
.legend span { font-size: 0.8rem; color: var(--ink-2); }

.tooltip {
  position: absolute; pointer-events: none; display: none;
  background: #0a0a1c; border: 1px solid var(--card-brd); border-radius: 9px;
  padding: 0.45rem 0.7rem; font-size: 0.82rem; white-space: nowrap; z-index: 5;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.55);
}
.tooltip .tv { font-weight: 700; color: var(--ink); }
.tooltip .tl { color: var(--ink-2); }
.tooltip .trow { display: flex; align-items: center; gap: 0.45rem; }
.tooltip .tk { display: inline-block; width: 12px; height: 3px; border-radius: 2px; }
.tooltip .tt { color: var(--muted); margin-top: 0.2rem; }

/* misc -------------------------------------------------------- */
code { background: rgba(0, 0, 0, 0.35); padding: 0.15rem 0.45rem; border-radius: 5px; font-size: 0.85rem; font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; }
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 1rem 0; }
.note, .hint { color: var(--muted); font-size: 0.85rem; margin-top: 0.6rem; }
details { margin-top: 1.5rem; }
summary { cursor: pointer; color: var(--brand-1); font-size: 0.9rem; margin-bottom: 0.75rem; }
.actions { white-space: nowrap; text-align: right; }
.actions > * { vertical-align: middle; }
.actions > * + * { margin-left: 0.4rem; }
.actions form { display: inline; }
.linkrow, .linkcell { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.tenant-url {
  color: #a5b4fc; word-break: break-all; text-decoration: none;
  background: rgba(0, 0, 0, 0.3); padding: 0.4rem 0.7rem; border-radius: 7px; font-size: 0.9rem;
}
.tenant-url:hover { text-decoration: underline; }

/* admin sidebar layout --------------------------------------- */
body.admin { padding: 0; display: flex; min-height: 100vh; }

.sidebar {
  flex: 0 0 240px; width: 240px;
  position: sticky; top: 0; align-self: flex-start; height: 100vh;
  display: flex; flex-direction: column; gap: 0.4rem;
  padding: 1.5rem 1rem;
  background: rgba(10, 10, 25, 0.5); border-right: 1px solid var(--card-brd);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.sidebar .brand { margin: 0.25rem 0.5rem 1.5rem; }

.side-nav { display: flex; flex-direction: column; gap: 0.25rem; }
.side-nav a {
  display: flex; align-items: center; gap: 0.75rem; margin: 0;
  padding: 0.65rem 0.8rem; border-radius: 10px;
  color: var(--ink-2); text-decoration: none; font-size: 0.94rem; font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.side-nav a .ic { width: 1.15rem; text-align: center; font-size: 1rem; flex: 0 0 auto; }
.side-nav a:hover { background: rgba(255, 255, 255, 0.06); color: var(--ink); }
.side-nav a.active { background: var(--grad); color: #fff; box-shadow: var(--glow); }

/* draggable reordering */
nav.side-nav a { cursor: grab; }
nav.side-nav a:active { cursor: grabbing; }
nav.side-nav a.dragging { opacity: 0.4; }
.side-nav a .ic { pointer-events: none; }

.side-foot { margin-top: auto; }
.side-foot a { color: var(--muted); cursor: pointer; }
.side-foot a:hover { color: var(--bad); background: rgba(251, 113, 133, 0.1); }

.main { flex: 1 1 auto; min-width: 0; padding: 2rem 2.5rem; }
.main .wrap { max-width: 1000px; }

@media (max-width: 820px) {
  body.admin { flex-direction: column; }
  .sidebar {
    flex: none; width: auto; height: auto; position: static;
    flex-direction: row; align-items: center; gap: 0.25rem; overflow-x: auto;
    padding: 0.7rem 1rem; border-right: none; border-bottom: 1px solid var(--card-brd);
  }
  .sidebar .brand { margin: 0 1rem 0 0.25rem; flex: 0 0 auto; }
  .side-nav { flex-direction: row; }
  .side-nav a { white-space: nowrap; }
  .side-foot { margin-top: 0; margin-left: auto; }
  .main { padding: 1.5rem 1.25rem; }
}

/* row action menu (kebab dropdown) --------------------------- */
.rowmenu { position: relative; display: inline-block; }
.kebab {
  background: rgba(255, 255, 255, 0.08); color: var(--ink);
  border: 1px solid var(--card-brd); box-shadow: none;
  padding: 0.3rem 0.7rem; font-size: 1.15rem; line-height: 1; border-radius: 9px;
}
.kebab:hover { background: rgba(255, 255, 255, 0.16); box-shadow: none; transform: none; }
.kebab.on { background: var(--grad); box-shadow: var(--glow); }

.menu {
  position: fixed; z-index: 60; min-width: 214px; display: none;
  flex-direction: column; gap: 2px; padding: 0.4rem;
  background: #14142c; border: 1px solid var(--card-brd); border-radius: 12px;
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.menu.open { display: flex; }
.menu .menu-head {
  padding: 0.4rem 0.7rem 0.5rem; font-size: 0.74rem; font-weight: 700;
  letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px;
}
.menu a, .menu button {
  display: flex; align-items: center; gap: 0.65rem; width: 100%;
  justify-content: flex-start; text-align: left;
  padding: 0.55rem 0.7rem; border-radius: 8px; font-size: 0.9rem; font-weight: 500;
  background: transparent; color: var(--ink-2); border: none; box-shadow: none; cursor: pointer;
}
.menu a:hover, .menu button:hover { background: rgba(255, 255, 255, 0.07); color: var(--ink); box-shadow: none; transform: none; }
.menu .mi { width: 1.15rem; text-align: center; flex: 0 0 auto; }
.menu .sep { height: 1px; background: var(--card-brd); margin: 0.35rem 0.2rem; }
.menu .danger-item { color: var(--bad); }
.menu .danger-item:hover { background: rgba(251, 113, 133, 0.12); color: var(--bad); }

/* side drawer (right-half panel) ----------------------------- */
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  border-radius: 9px; background: rgba(255, 255, 255, 0.08); border: 1px solid var(--card-brd);
  color: var(--ink); text-decoration: none; cursor: pointer; font-size: 0.95rem; box-shadow: none;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.16); box-shadow: none; transform: none; }

.drawer { position: fixed; inset: 0; z-index: 80; display: none; }
.drawer.open { display: block; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(4, 4, 12, 0.55); opacity: 0; transition: opacity 0.25s; }
.drawer.open .drawer-backdrop { opacity: 1; }
.drawer-panel {
  position: absolute; top: 0; right: 0; height: 100%; width: 50%;
  display: flex; flex-direction: column;
  background: #0b0b1e; border-left: 1px solid var(--card-brd-hi);
  box-shadow: -24px 0 70px rgba(0, 0, 0, 0.55);
  transform: translateX(100%); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.drawer.open .drawer-panel { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.85rem 1.1rem; border-bottom: 1px solid var(--card-brd); background: rgba(255, 255, 255, 0.03);
}
.drawer-title { font-weight: 700; font-size: 1.02rem; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-head-actions { display: flex; gap: 0.5rem; align-items: center; flex: 0 0 auto; }
.drawer-frame { flex: 1 1 auto; width: 100%; border: 0; background: #0b0b1e; }
@media (max-width: 820px) { .drawer-panel { width: 100%; } }

/* table toolbar (search + export) ---------------------------- */
.tablehead { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.tabletools { display: flex; gap: 0.6rem; align-items: center; }
.tabletools input[type=search] { width: 220px; max-width: 46vw; }
.linklike { background: transparent; border: none; box-shadow: none; color: #a5b4fc; padding: 0; font: inherit; cursor: pointer; }
.linklike:hover { box-shadow: none; transform: none; text-decoration: underline; }

/* centered modal dialog -------------------------------------- */
.modal { position: fixed; inset: 0; z-index: 90; display: none; }
.modal.open { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(4, 4, 12, 0.6); }
.modal-box {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(520px, calc(100% - 2rem)); max-height: calc(100% - 2rem); overflow: auto;
  background: #0c0c1e; border: 1px solid var(--card-brd-hi); border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--card-brd); }
.modal-title { font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; }
.modal-body { padding: 1.25rem; }
.modal-body .stack { display: flex; flex-direction: column; gap: 0.5rem; }

/* large centered modal that hosts an iframe (e.g. Manage users) */
.modal-box.modal-lg {
  width: min(960px, calc(100% - 2rem)); height: min(82vh, 780px);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-lg .modal-head { flex: 0 0 auto; }
.pm-frame { flex: 1 1 auto; width: 100%; border: 0; background: #0b0b1e; }
.kv { display: grid; gap: 0.55rem; }
.kv > div { display: flex; justify-content: space-between; gap: 1rem; align-items: center; font-size: 0.9rem; }
.kv > div > span:first-child { color: var(--muted); }
