/* rPBX admin interface
 *
 * Design rules:
 * - full-viewport application shell, never a centred marketing page;
 * - compact vertical rhythm so a 1080p screen shows a working set of rows;
 * - one accent colour, restrained status colours, mono for numbers/IDs;
 * - master-detail and data grids instead of nested panels;
 * - one primary action per page, secondary actions in an overflow menu.
 */

:root {
  color-scheme: light;
  --font-sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --surface-3: #e4eaf1;
  --hover: #f6f8fb;
  --border: #d5dde7;
  --border-strong: #b9c4d3;
  --text: #16202c;
  --muted: #5b6b7c;
  --faint: #8494a6;
  --accent: #0f766e;
  --accent-strong: #0b5c56;
  --accent-soft: #e4f3f0;
  --accent-text: #ffffff;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --warning: #a15c07;
  --warning-soft: #fdf3e3;
  --success: #067647;
  --success-soft: #e7f6ee;
  --info: #175cd3;
  --info-soft: #eaf1fd;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.16);
  --radius: 10px;
  --radius-sm: 7px;
  --rail: 232px;
  --topbar: 52px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a111c;
  --surface: #101a28;
  --surface-2: #15202f;
  --surface-3: #1b2839;
  --hover: #182434;
  --border: #253246;
  --border-strong: #35465f;
  --text: #e7eef8;
  --muted: #9fb0c5;
  --faint: #72849a;
  --accent: #2dd4bf;
  --accent-strong: #5eead4;
  --accent-soft: #0d2f2c;
  --accent-text: #05221f;
  --danger: #f97066;
  --danger-soft: #361816;
  --warning: #fdb022;
  --warning-soft: #33260c;
  --success: #47cd89;
  --success-soft: #0d2a1e;
  --info: #84adff;
  --info-soft: #11233f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

code,
.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 8px;
  z-index: 100;
  background: var(--surface);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
}

.skip-link:focus {
  left: 8px;
}

/* ------------------------------------------------------------------ shell */

.app {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar);
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-text);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: -0.02em;
}

.brand-name {
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-name span {
  color: var(--muted);
  font-weight: 500;
}

.nav {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 10px 8px 16px;
}

.nav-group {
  margin: 12px 0 4px;
  padding: 0 10px;
  color: var(--faint);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
}

.nav-link:hover {
  background: var(--surface-2);
  text-decoration: none;
}

.nav-link[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 650;
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  color: var(--muted);
}

.nav-link[aria-current="page"] .nav-icon {
  color: var(--accent);
}

.nav-footer {
  border-top: 1px solid var(--border);
  padding: 10px;
  flex: 0 0 auto;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.topbar {
  height: var(--topbar);
  flex: 0 0 var(--topbar);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-spacer {
  flex: 1 1 auto;
}

.tenant-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  background: var(--surface-2);
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
}

.content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 16px 20px 28px;
}

.content-flush {
  padding: 0;
  overflow: hidden;
}

/* --------------------------------------------------------------- headings */

.page-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  margin-bottom: 12px;
}

.page-head h1 {
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: -0.015em;
  font-weight: 700;
}

.page-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.page-head .spacer {
  flex: 1 1 auto;
}

.head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.metric-strip {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--muted);
  font-size: 12px;
  flex-wrap: wrap;
}

.metric-strip strong {
  color: var(--text);
  font-family: var(--font-mono);
  font-weight: 650;
}

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-2);
  text-decoration: none;
}

.btn:focus-visible,
.nav-link:focus-visible,
summary:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.btn-primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
}

.btn-ghost:hover {
  background: var(--surface-2);
}

.btn-sm {
  height: 28px;
  padding: 0 9px;
  font-size: 12px;
}

.btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-icon {
  width: 32px;
  padding: 0;
}

/* -------------------------------------------------------------- more menu */

.menu {
  position: relative;
}

.menu > summary {
  list-style: none;
}

.menu > summary::-webkit-details-marker {
  display: none;
}

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 190px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 30;
}

.menu-panel a,
.menu-panel button {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 13px;
  cursor: pointer;
}

.menu-panel a:hover,
.menu-panel button:hover {
  background: var(--surface-2);
  text-decoration: none;
}

.menu-panel .danger {
  color: var(--danger);
}

.menu-sep {
  height: 1px;
  background: var(--border);
  margin: 5px 4px;
}

/* ------------------------------------------------------------------ cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
}

.card-head h2 {
  font-size: 13px;
  font-weight: 700;
}

.card-body {
  padding: 14px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.stat {
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.stat-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.stat-note {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

/* ------------------------------------------------------------------ split */

.split {
  display: grid;
  grid-template-columns: minmax(300px, 34%) minmax(0, 1fr);
  height: 100%;
  min-height: 0;
}

.split-list {
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.split-detail {
  overflow: auto;
  min-width: 0;
  padding: 18px 20px 26px;
  background: var(--bg);
}

.list-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.search {
  flex: 1 1 auto;
  position: relative;
}

.search input {
  width: 100%;
  height: 32px;
  padding: 0 10px 0 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.search::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 9px;
  width: 12px;
  height: 12px;
  border: 1.6px solid var(--muted);
  border-radius: 50%;
  box-shadow: 7px 7px 0 -5px var(--muted);
  opacity: 0.8;
}

.list-scroll {
  overflow: auto;
  min-height: 0;
  flex: 1 1 auto;
}

.list-row {
  display: block;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  border-left: 3px solid transparent;
}

.list-row:hover {
  background: var(--hover);
  text-decoration: none;
}

.list-row[aria-current="true"] {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.list-row-main {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.list-row-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-row .spacer {
  flex: 1 1 auto;
}

/* ------------------------------------------------------------------ grid */

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

.grid th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: left;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.grid td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.grid tr:last-child td {
  border-bottom: 0;
}

.grid tbody tr:hover td {
  background: var(--hover);
}

.grid tr[aria-current="true"] td {
  background: var(--accent-soft);
}

.grid .num,
.grid .id {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.grid .right {
  text-align: right;
}

.grid .nowrap {
  white-space: nowrap;
}

.grid-compact td {
  padding-top: 5px;
  padding-bottom: 5px;
}

/* ------------------------------------------------------------------ pills */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
  background: var(--surface-3);
  color: var(--muted);
}

.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.85;
}

.pill-success {
  background: var(--success-soft);
  color: var(--success);
}

.pill-warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.pill-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.pill-info {
  background: var(--info-soft);
  color: var(--info);
}

.pill-accent {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.pill-plain::before {
  display: none;
}

/* ------------------------------------------------------------------- tabs */

.tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.tab {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 11px;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab:hover {
  color: var(--text);
  text-decoration: none;
}

.tab[aria-current="page"] {
  color: var(--accent-strong);
  border-bottom-color: var(--accent);
}

/* ------------------------------------------------------------------ forms */

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 14px;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
}

.field input,
.field select,
.field textarea {
  height: 32px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  min-width: 0;
}

.field textarea {
  height: auto;
  min-height: 72px;
  padding: 8px 9px;
  resize: vertical;
}

.field .hint {
  color: var(--faint);
  font-size: 11px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
}

.check input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.inline-form {
  display: inline;
}

/* ----------------------------------------------------------------- banner */

.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-size: 13px;
  border: 1px solid transparent;
}

.banner-success {
  background: var(--success-soft);
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 25%, transparent);
}

.banner-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 25%, transparent);
}

.banner-info {
  background: var(--info-soft);
  color: var(--info);
  border-color: color-mix(in srgb, var(--info) 25%, transparent);
}

.banner .spacer {
  flex: 1 1 auto;
}

/* ------------------------------------------------------------------- misc */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  padding: 36px 18px;
  color: var(--muted);
}

.empty h3 {
  color: var(--text);
  font-size: 14px;
}

.empty p {
  max-width: 46ch;
  font-size: 13px;
}

.kv {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 7px 14px;
  font-size: 13px;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 18px 0 8px;
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.section-title:first-child {
  margin-top: 0;
}

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

.faint {
  color: var(--faint);
}

.small {
  font-size: 12px;
}

.tiny {
  font-size: 11px;
}

.right {
  text-align: right;
}

.nowrap {
  white-space: nowrap;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 14px 0;
}

.code-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 280px;
  overflow: auto;
}

.copy-field {
  display: flex;
  gap: 6px;
}

.copy-field input {
  flex: 1 1 auto;
  font-family: var(--font-mono);
  font-size: 12px;
}

/* ---------------------------------------------------------------- login */

.auth {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  background: var(--bg);
}

.auth-brand {
  background:
    radial-gradient(900px 400px at 15% 10%, rgba(45, 212, 191, 0.18), transparent 60%),
    linear-gradient(160deg, #0b2a2a 0%, #081420 60%, #060d16 100%);
  color: #e6f4f1;
  padding: 48px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.auth-brand h1 {
  font-size: 30px;
  letter-spacing: -0.03em;
  max-width: 18ch;
}

.auth-brand p {
  color: #a8c4c0;
  max-width: 44ch;
  margin-top: 12px;
}

.auth-points {
  display: grid;
  gap: 10px;
  margin-top: 26px;
  max-width: 44ch;
}

.auth-point {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  color: #cfe6e2;
  font-size: 13px;
}

.auth-point::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #2dd4bf;
  margin-top: 6px;
  flex: 0 0 auto;
}

.auth-panel {
  display: grid;
  place-items: center;
  padding: 28px;
}

.auth-card {
  width: min(380px, 100%);
}

.auth-card h2 {
  font-size: 20px;
  letter-spacing: -0.02em;
}

.auth-card .sub {
  color: var(--muted);
  margin: 4px 0 18px;
  font-size: 13px;
}

.auth-card form {
  display: grid;
  gap: 12px;
}

.auth-card .btn {
  width: 100%;
  height: 36px;
}

.auth-foot {
  margin-top: 18px;
  color: var(--faint);
  font-size: 11px;
}

/* --------------------------------------------------------------- responsive */

@media (max-width: 1120px) {
  :root {
    --rail: 64px;
  }

  .brand-name,
  .nav-link span,
  .nav-group {
    display: none;
  }

  .brand {
    justify-content: center;
    padding: 0;
  }

  .nav-link {
    justify-content: center;
    padding: 0;
  }

  .split {
    grid-template-columns: minmax(250px, 40%) minmax(0, 1fr);
  }
}

@media (max-width: 820px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar) minmax(0, 1fr);
  }

  .sidebar {
    flex-direction: row;
    align-items: center;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }

  .brand {
    border-bottom: 0;
    border-right: 1px solid var(--border);
    width: 56px;
    flex: 0 0 56px;
  }

  .nav {
    display: flex;
    align-items: center;
    padding: 0 8px;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .nav-footer {
    display: none;
  }

  .content {
    padding: 12px;
  }

  .split {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(180px, 40%) minmax(0, 1fr);
  }

  .split-list {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .auth {
    grid-template-columns: 1fr;
  }

  .auth-brand {
    display: none;
  }
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* A single secondary action is rendered as a button, not an overflow menu. */
.menu-single {
  display: inline-flex;
  align-items: center;
}

.menu-single form {
  display: inline;
}

.menu-single a,
.menu-single button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.menu-single a:hover,
.menu-single button:hover {
  background: var(--surface-2);
  text-decoration: none;
}

.menu-single .danger {
  color: var(--danger);
}
