/* ── CSS Custom Properties ───────────────────────────────────────────────── */
:root {
  --bg:           #0f1117;
  --bg-2:         #13161f;
  --surface:      #1a1d2e;
  --surface-2:    #1f2235;
  --border:       #2d3148;
  --border-light: #363a54;
  --accent:       #6366f1;
  --accent-hover: #5558e3;
  --accent2:      #22d3ee;
  --success:      #22c55e;
  --warning:      #f59e0b;
  --error:        #ef4444;
  --text:         #e2e8f0;
  --text-dim:     #94a3b8;
  --text-muted:   #64748b;
  --sidebar-w:    240px;
  --header-h:     56px;
  --radius:       8px;
  --radius-sm:    6px;
  --radius-lg:    12px;
  --shadow:       0 4px 24px rgba(0,0,0,0.4);
  --transition:   0.15s ease;
  --font-mono:    'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
}
a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { display: block; max-width: 100%; }

/* ── Auth Layout ─────────────────────────────────────────────────────────── */
.auth-layout {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: radial-gradient(ellipse at 50% 0%, #1a1d2e 0%, var(--bg) 70%);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.auth-brand {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-logo {
  font-size: 3rem;
  color: var(--accent2);
  margin-bottom: 0.75rem;
  line-height: 1;
}

.auth-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.auth-subtitle {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

.auth-form { display: flex; flex-direction: column; gap: 1.25rem; }

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

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-brand {
  padding: 1.25rem 1.25rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.brand-icon {
  font-size: 1.75rem;
  color: var(--accent2);
  line-height: 1;
}

.brand-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

.brand-version {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0;
  overflow-y: auto;
}

.nav-section {
  padding: 0.75rem 1.25rem 0.3rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1.25rem;
  color: var(--text-dim);
  font-size: 0.875rem;
  border-left: 2px solid transparent;
  transition: all var(--transition);
  cursor: pointer;
  min-height: 44px;
}

.nav-item:hover {
  color: var(--text);
  background: rgba(255,255,255,0.04);
  text-decoration: none;
}

.nav-item.active {
  color: var(--accent2);
  background: rgba(34,211,238,0.08);
  border-left-color: var(--accent2);
}

.nav-icon {
  font-size: 1rem;
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}

.user-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
}

.user-role, .user-info .user-role {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}

.btn-logout {
  width: 100%;
  padding: 0.45rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--transition);
  min-height: 36px;
}

.btn-logout:hover {
  border-color: var(--error);
  color: var(--error);
}

/* ── Mobile Header ───────────────────────────────────────────────────────── */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 200;
  align-items: center;
  padding: 0 1rem;
  gap: 1rem;
}

.hamburger {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 22px;
  height: 16px;
  background: none;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  transition: var(--transition);
}

.mobile-logo {
  flex: 1;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent2);
}

.mobile-user {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
}

/* ── Main Content ────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem 2rem 0;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.page-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

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

.page-body {
  padding: 1.25rem 2rem 2rem;
  flex: 1;
}

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert {
  border-radius: var(--radius-sm);
  padding: 0.875rem 1.25rem;
  margin: 0 2rem 0;
  font-size: 0.875rem;
  border-left: 3px solid;
}

.alert-success {
  background: rgba(34,197,94,0.1);
  border-color: var(--success);
  color: var(--success);
}

.alert-error {
  background: rgba(239,68,68,0.1);
  border-color: var(--error);
  color: var(--error);
}

.alert-warning {
  background: rgba(245,158,11,0.1);
  border-color: var(--warning);
  color: var(--warning);
}

.alert-info {
  background: rgba(99,102,241,0.1);
  border-color: var(--accent);
  color: var(--accent2);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 1.125rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  min-height: 44px;
  white-space: nowrap;
  line-height: 1;
}

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

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

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

.btn-secondary:hover {
  border-color: var(--accent2);
  color: var(--accent2);
  text-decoration: none;
}

.btn-danger {
  background: rgba(239,68,68,0.1);
  color: var(--error);
  border-color: rgba(239,68,68,0.3);
}

.btn-danger:hover {
  background: rgba(239,68,68,0.2);
  text-decoration: none;
  color: var(--error);
}

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

.btn-ghost:hover {
  color: var(--text);
  background: rgba(255,255,255,0.04);
  text-decoration: none;
}

.btn-full { width: 100%; }

.btn-sm {
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
  min-height: 36px;
}

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 0.4rem; }
.form-group + .form-group { margin-top: 0; }

.form-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.form-label-link {
  font-size: 0.78rem;
  color: var(--accent2);
}

.form-input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0.6rem 0.875rem;
  font-size: 0.9rem;
  width: 100%;
  transition: border-color var(--transition);
  min-height: 44px;
  appearance: none;
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}

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

.form-input-otp {
  text-align: center;
  font-size: 1.75rem;
  letter-spacing: 0.3em;
  font-family: var(--font-mono);
}

select.form-input {
  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='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.875rem center;
  padding-right: 2.5rem;
}

.input-group {
  position: relative;
  display: flex;
}

.input-group .form-input {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  border-right: none;
}

.input-suffix {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-muted);
  padding: 0 0.875rem;
  cursor: pointer;
  font-size: 0.875rem;
  min-width: 44px;
}

.form-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

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

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.card-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

/* ── Tenant Grid ─────────────────────────────────────────────────────────── */
.tenant-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.tenant-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
}

.tenant-card:hover {
  border-color: var(--accent2);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  text-decoration: none;
}

.tenant-card--inactive { opacity: 0.5; }

.tenant-card-header {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 1.25rem;
}

.tenant-avatar {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  flex-shrink: 0;
}

.tenant-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.tenant-host {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: 0.1rem;
}

.tenant-card-body {
  display: flex;
  gap: 1.5rem;
  padding: 0 1.25rem 1rem;
  border-top: 1px solid var(--border);
  padding-top: 0.875rem;
  margin-top: 0.25rem;
}

.tenant-stat-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.15rem;
}

.tenant-stat-value {
  font-size: 0.85rem;
  font-weight: 500;
}

.tenant-card-footer {
  padding: 0.65rem 1.25rem;
  border-top: 1px solid var(--border);
  color: var(--accent2);
  font-size: 0.8rem;
  font-weight: 500;
  margin-top: auto;
}

/* ── Status dots ─────────────────────────────────────────────────────────── */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-left: auto;
}

.status-dot--green {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}

.status-dot--yellow { background: var(--warning); }
.status-dot--red    { background: var(--error); }
.status-dot--grey   { background: var(--text-muted); }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success { background: rgba(34,197,94,0.15);  color: var(--success); }
.badge-error   { background: rgba(239,68,68,0.15);  color: var(--error); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-info    { background: rgba(99,102,241,0.15); color: var(--accent2); }
.badge-grey    { background: rgba(100,116,139,0.2); color: var(--text-muted); }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }

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

th {
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.75rem 1rem;
  text-align: left;
  white-space: nowrap;
  font-weight: 600;
}

td {
  padding: 0.875rem 1rem;
  border-top: 1px solid var(--border);
  vertical-align: middle;
}

tr:hover td { background: rgba(255,255,255,0.02); }

.td-mono { font-family: var(--font-mono); font-size: 0.82rem; color: var(--text-dim); }

/* ── Stats Grid ──────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

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

.stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  margin-bottom: 0.25rem;
}

.stat-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ── Content Grid ────────────────────────────────────────────────────────── */
.content-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.content-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

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

.content-card-header h3 {
  font-size: 0.9rem;
  font-weight: 600;
}

/* ── Health rows ─────────────────────────────────────────────────────────── */
.health-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.health-row:last-child { border-bottom: none; }
.health-name { font-size: 0.875rem; }

/* ── Empty states ────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
}

.empty-icon {
  font-size: 3rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.empty-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
}

.empty-body {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.empty-state-sm {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ── Loading ─────────────────────────────────────────────────────────────── */
.loading-state {
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.loading-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent2);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ── Utility ─────────────────────────────────────────────────────────────── */
.text-success { color: var(--success); }
.text-error   { color: var(--error); }
.text-warning { color: var(--warning); }
.text-muted   { color: var(--text-muted); }
.text-mono    { font-family: var(--font-mono); }

/* ── Checkboxes (permissions) ────────────────────────────────────────────── */
.permission-group { margin-bottom: 1.25rem; }
.permission-group-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}

.permission-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.permission-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.65rem;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-dim);
  transition: all var(--transition);
  min-height: 36px;
}

.permission-item:hover {
  border-color: var(--accent);
  color: var(--text);
}

.permission-item input[type=checkbox] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.permission-item:has(input:checked) {
  border-color: var(--accent);
  background: rgba(99,102,241,0.1);
  color: var(--accent2);
}

/* ── Responsive: Tablet ──────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .content-grid { grid-template-columns: 1fr; }
  .form-grid    { grid-template-columns: 1fr; }
}

/* ── Responsive: Mobile ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Show mobile header */
  .mobile-header { display: flex; }

  /* Sidebar becomes overlay */
  .sidebar {
    transform: translateX(-100%);
    top: var(--header-h);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow);
  }

  /* Main content takes full width */
  .main-content {
    margin-left: 0;
    padding-top: var(--header-h);
  }

  /* Stack page header */
  .page-header {
    padding: 1rem 1rem 0;
    flex-direction: column;
    align-items: flex-start;
  }

  .page-body { padding: 1rem; }

  .alert { margin: 0 1rem 0; }

  /* Full-width buttons on mobile */
  .page-actions .btn { width: 100%; }

  /* Tenant grid single column */
  .tenant-grid { grid-template-columns: 1fr; }

  /* Stats grid 2 columns on mobile */
  .stats-grid { grid-template-columns: 1fr 1fr; }

  /* Table: horizontal scroll */
  .table-wrap { margin: 0 -1rem; border-radius: 0; border-left: none; border-right: none; }

  /* Auth card full width */
  .auth-card { padding: 1.75rem 1.25rem; }

  /* Form grid single column */
  .form-grid { grid-template-columns: 1fr; }
}

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

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }
