/* ============================================================
   CircleISP — Application Stylesheet
   Utilitarian, blue-toned, no gradients, no emojis
   Dark / Light via [data-theme] on <html>
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@300;400;500;600&display=swap');

/* ── CSS Variables ─────────────────────────────────────────── */

:root,
[data-theme="light"] {
  /* Blues */
  --blue-950: #0a1628;
  --blue-900: #0f2040;
  --blue-800: #163460;
  --blue-700: #1d4a8a;
  --blue-600: #2563b0;
  --blue-500: #3b7dd8;
  --blue-400: #6ba3e8;
  --blue-300: #a0c4f4;
  --blue-200: #cce0fa;
  --blue-100: #e8f2fd;
  --blue-50:  #f4f9ff;

  /* Backgrounds */
  --bg-base:    #f8fafd;
  --bg-surface: #ffffff;
  --bg-raised:  #f0f6ff;
  --bg-sunken:  #e8f0fb;

  /* Borders */
  --border:       #d0ddf0;
  --border-focus: #2563b0;
  --border-strong: #9ab4d8;

  /* Text */
  --text-primary:   #0f1e38;
  --text-secondary: #3a5070;
  --text-muted:     #6a8aaa;
  --text-on-blue:   #ffffff;

  /* Accent / interactive */
  --accent:       #2563b0;
  --accent-hover: #163460;
  --accent-light: #e8f2fd;

  /* Status */
  --status-online:  #1a6b3a;
  --status-offline: #9b1c1c;
  --status-pending: #7c5200;
  --status-online-bg:  #d4f0e0;
  --status-offline-bg: #fce8e8;
  --status-pending-bg: #fff3cd;

  /* Nav */
  --nav-bg:     #0f2040;
  --nav-text:   #c8d8f0;
  --nav-active: #ffffff;
  --nav-border: #163460;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(15, 32, 64, 0.08);
  --shadow-md: 0 3px 8px rgba(15, 32, 64, 0.12);
}

[data-theme="dark"] {
  --blue-50:  #0a1628;
  --blue-100: #0f2040;
  --blue-200: #163460;

  --bg-base:    #070e1c;
  --bg-surface: #0d1b35;
  --bg-raised:  #122040;
  --bg-sunken:  #091428;

  --border:       #1d3560;
  --border-focus: #3b7dd8;
  --border-strong: #2a4a80;

  --text-primary:   #d8e8f8;
  --text-secondary: #8aaed4;
  --text-muted:     #506888;
  --text-on-blue:   #ffffff;

  --accent:       #3b7dd8;
  --accent-hover: #6ba3e8;
  --accent-light: #122040;

  --status-online:  #4ade80;
  --status-offline: #f87171;
  --status-pending: #fbbf24;
  --status-online-bg:  #0d2e1a;
  --status-offline-bg: #2e0d0d;
  --status-pending-bg: #2e1e00;

  --nav-bg:     #050c1a;
  --nav-text:   #6a8aaa;
  --nav-active: #d8e8f8;
  --nav-border: #0f2040;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 3px 8px rgba(0, 0, 0, 0.4);
}

/* ── Reset & Base ──────────────────────────────────────────── */

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

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: 'IBM Plex Sans', sans-serif;
  font-weight: 400;
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Navigation ────────────────────────────────────────────── */

.nav {
  background: var(--nav-bg);
  border-bottom: 1px solid var(--nav-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 0;
  height: 52px;
}

.nav-brand {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--nav-active);
  text-decoration: none;
  letter-spacing: 0.04em;
  margin-right: 2rem;
  flex-shrink: 0;
}

.nav-brand span {
  color: var(--blue-400);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0;
  flex: 1;
  list-style: none;
}

.nav-links a {
  display: block;
  padding: 0 0.875rem;
  height: 52px;
  line-height: 52px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--nav-text);
  text-decoration: none;
  letter-spacing: 0.02em;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--nav-active);
  border-bottom-color: var(--blue-500);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

.nav-user {
  font-size: 0.75rem;
  color: var(--nav-text);
  letter-spacing: 0.02em;
}

.btn-theme {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.25rem 0.625rem;
  background: transparent;
  color: var(--nav-text);
  border: 1px solid var(--nav-border);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  line-height: 1.4;
}

.btn-theme:hover {
  color: var(--nav-active);
  border-color: var(--blue-500);
}

/* ── Page Layout ───────────────────────────────────────────── */

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 1.75rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
  flex-wrap: wrap;
}

.page-header h1 {
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 1.375rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.page-header-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ── Breadcrumb ────────────────────────────────────────────── */

.breadcrumb {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

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

.breadcrumb a:hover { text-decoration: underline; }

.breadcrumb-sep {
  color: var(--border-strong);
}

/* ── Alerts / Flash ────────────────────────────────────────── */

.flash {
  padding: 0.625rem 1rem;
  font-size: 0.8125rem;
  border-left: 3px solid;
  margin-bottom: 1.25rem;
  background: var(--bg-surface);
}

.flash.notice {
  border-color: var(--blue-600);
  color: var(--text-secondary);
  background: var(--accent-light);
}

.flash.alert {
  border-color: var(--status-offline);
  color: var(--status-offline);
  background: var(--status-offline-bg);
}

/* ── Buttons ───────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.4375rem 0.875rem;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  line-height: 1.4;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

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

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

.btn-secondary {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-danger {
  background: transparent;
  color: var(--status-offline);
  border-color: var(--border);
}

.btn-danger:hover {
  background: var(--status-offline-bg);
  border-color: var(--status-offline);
}

.btn-sm {
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
}

/* ── Cards ─────────────────────────────────────────────────── */

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1rem;
}

.card-header {
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h2,
.card-header h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}

.card-body {
  padding: 1.25rem;
}

/* ── Tables ────────────────────────────────────────────────── */

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

thead tr {
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
}

thead th {
  padding: 0.625rem 1rem;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

tbody tr:last-child {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--bg-raised);
}

td {
  padding: 0.625rem 1rem;
  color: var(--text-primary);
  vertical-align: middle;
}

td.mono {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.775rem;
  color: var(--text-secondary);
}

td.actions {
  white-space: nowrap;
  text-align: right;
}

/* ── Status Badges ─────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 0.1875rem 0.5rem;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge-online {
  background: var(--status-online-bg);
  color: var(--status-online);
}

.badge-offline {
  background: var(--status-offline-bg);
  color: var(--status-offline);
}

.badge-pending, .badge-suspended {
  background: var(--status-pending-bg);
  color: var(--status-pending);
}

.badge-active {
  background: var(--status-online-bg);
  color: var(--status-online);
}

.badge-cancelled {
  background: var(--bg-sunken);
  color: var(--text-muted);
}

.badge-managed {
  background: var(--accent-light);
  color: var(--accent);
}

.badge-overlimit {
  background: var(--status-offline-bg);
  color: var(--status-offline);
}

/* ── Forms ─────────────────────────────────────────────────── */

.form-group {
  margin-bottom: 1.125rem;
}

label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.375rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--border-focus);
}

input[type="checkbox"] {
  accent-color: var(--accent);
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}

textarea {
  resize: vertical;
  min-height: 6rem;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.form-error {
  font-size: 0.75rem;
  color: var(--status-offline);
  margin-top: 0.25rem;
}

.field-errors {
  background: var(--status-offline-bg);
  border-left: 3px solid var(--status-offline);
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
}

.field-errors h2 {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--status-offline);
  margin-bottom: 0.5rem;
}

.field-errors ul {
  padding-left: 1.25rem;
  font-size: 0.8rem;
  color: var(--status-offline);
}

details summary {
  cursor: pointer;
  font-size: 0.8125rem;
  color: var(--accent);
  margin-bottom: 0.75rem;
  user-select: none;
}

/* ── Stat Blocks ───────────────────────────────────────────── */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.stat {
  background: var(--bg-surface);
  padding: 1.25rem 1.5rem;
}

.stat-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.375rem;
}

.stat-value {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1.5rem;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.2;
}

.stat-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* ── Definition lists ─────────────────────────────────────── */

.dl-grid {
  display: grid;
  grid-template-columns: 10rem 1fr;
  gap: 0;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  font-size: 0.8125rem;
}

.dl-grid dt {
  padding: 0.625rem 1rem;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: flex;
  align-items: center;
}

.dl-grid dd {
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  display: flex;
  align-items: center;
}

.dl-grid dt:last-of-type,
.dl-grid dd:last-of-type {
  border-bottom: none;
}

/* ── Usage bar ─────────────────────────────────────────────── */

.usage-bar-wrap {
  height: 6px;
  background: var(--bg-sunken);
  width: 100%;
  max-width: 300px;
  overflow: hidden;
}

.usage-bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s;
}

.usage-bar-fill.warn { background: var(--status-pending); }
.usage-bar-fill.danger { background: var(--status-offline); }

/* ── Portal layout ─────────────────────────────────────────── */

.portal-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: calc(100vh - 52px);
}

.portal-sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  padding: 1.5rem 0;
}

.portal-sidebar-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 1.25rem;
  margin-bottom: 0.5rem;
}

.portal-sidebar a {
  display: block;
  padding: 0.5rem 1.25rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.portal-sidebar a:hover,
.portal-sidebar a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-light);
}

.portal-main {
  padding: 2rem;
}

/* ── Inline actions / link groups ──────────────────────────── */

.action-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

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

a:hover {
  text-decoration: underline;
}

/* ── Two-col form layout ───────────────────────────────────── */

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

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
}

/* ── Operator badge ────────────────────────────────────────── */

.operator-notice {
  font-size: 0.75rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 0.375rem 0.75rem;
  background: var(--bg-raised);
  display: inline-block;
  margin-bottom: 1.25rem;
  font-family: 'IBM Plex Mono', monospace;
  letter-spacing: 0.02em;
}

/* ── Dividers / section titles ─────────────────────────────── */

.section-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.875rem;
  margin-top: 1.75rem;
  padding-bottom: 0.375rem;
  border-bottom: 1px solid var(--border);
}

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

/* ── Empty state ───────────────────────────────────────────── */

.empty-state {
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  border: 1px dashed var(--border);
  background: var(--bg-surface);
}

.empty-state p { margin-bottom: 1rem; }

/* ── Code / mono ───────────────────────────────────────────── */

code {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.825em;
  background: var(--bg-sunken);
  color: var(--text-secondary);
  padding: 0.1em 0.35em;
}

pre {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  background: var(--bg-sunken);
  color: var(--text-secondary);
  padding: 1rem 1.25rem;
  overflow-x: auto;
  border: 1px solid var(--border);
  line-height: 1.7;
}

/* ── Responsive nav ────────────────────────────────────────── */

@media (max-width: 768px) {
  .nav-links { display: none; }
  .portal-layout {
    grid-template-columns: 1fr;
  }
  .portal-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 0;
  }
  .portal-sidebar a { display: inline-block; padding: 0.375rem 1rem; }
}

/* ── Turbo progress bar ────────────────────────────────────── */

.turbo-progress-bar {
  height: 2px;
  background: var(--blue-500);
}

/* ── Page transitions ──────────────────────────────────────── */

@media (prefers-reduced-motion: no-preference) {
  .page {
    animation: fadeUp 0.18s ease both;
  }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
