:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --sidebar: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-text: #94a3b8;
  --sidebar-active: #ffffff;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --warning: #d97706;
  --muted: #64748b;
  --border: #e2e8f0;
  --text: #0f172a;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 16px rgba(15, 23, 42, 0.04);
  --font: "Inter", system-ui, -apple-system, sans-serif;
}

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

.hidden { display: none !important; }

/* Auth */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #2563eb 100%);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 16px;
  padding: 40px 36px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.2);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.auth-logo h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
}

.auth-subtitle {
  color: var(--muted);
  margin: 0 0 28px;
}

.auth-card label {
  display: block;
  font-weight: 500;
  margin-bottom: 6px;
}

.auth-card input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  margin-bottom: 8px;
}

.auth-card input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 0;
  border-color: var(--primary);
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 20px;
}

.hint code {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
}

.error-text {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
}

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

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 12px 20px;
  color: var(--sidebar-active);
  font-weight: 700;
  font-size: 16px;
}

.sidebar-section {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 12px;
  margin: 8px 0 8px;
  color: #475569;
}

.module-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.module-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--sidebar-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.module-btn:hover:not(:disabled) {
  background: var(--sidebar-hover);
  color: var(--sidebar-active);
}

.module-btn.active {
  background: var(--primary);
  color: #fff;
}

.module-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.module-btn .badge-soon {
  margin-left: auto;
  font-size: 10px;
  background: #334155;
  padding: 2px 6px;
  border-radius: 4px;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid #1e293b;
  margin-top: 12px;
}

.user-badge {
  font-size: 12px;
  color: #94a3b8;
  margin: 0 0 8px;
  word-break: break-word;
}

.platform-nav {
  margin-top: 4px;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 28px 32px 40px;
  overflow-y: auto;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.page-header h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

.page-description {
  margin: 4px 0 0;
  color: var(--muted);
}

.sub-nav {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.sub-nav-btn {
  padding: 10px 16px;
  border: none;
  background: none;
  font: inherit;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s;
}

.sub-nav-btn:hover:not(:disabled) { color: var(--text); }

.sub-nav-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.sub-nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Cards & table */
.card {
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: #f8fafc;
}

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

tr:hover td { background: #f8fafc; }

.mono {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 13px;
}

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.badge-active { background: #dcfce7; color: #166534; }
.badge-active::before { background: var(--success); }

.badge-expired { background: #fef3c7; color: #92400e; }
.badge-expired::before { background: var(--warning); }

.badge-revoked { background: #fee2e2; color: #991b1b; }
.badge-revoked::before { background: var(--danger); }

.badge-sub-monthly { background: #e0e7ff; color: #3730a3; }
.badge-sub-yearly { background: #f3e8ff; color: #6b21a8; }

.badge-online { background: #dcfce7; color: #166534; }
.badge-online::before { background: #16a34a; }
.badge-offline { background: #f1f5f9; color: #475569; }
.badge-offline::before { background: #94a3b8; }

.presence-summary {
  margin-bottom: 16px;
}
.presence-summary .mono {
  font-size: 13px;
  word-break: break-all;
  margin: 0 0 8px;
}
.presence-summary .hint {
  color: #64748b;
  font-size: 13px;
  margin: 8px 0 0;
}
.muted { color: #94a3b8; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border: none;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #15803d; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: #f1f5f9;
  color: var(--text);
}

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }

.btn-icon {
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0 4px;
}

.btn-icon:hover { color: var(--text); }

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Forms */
.form-grid {
  display: grid;
  gap: 16px;
}

.form-field label {
  display: block;
  font-weight: 500;
  margin-bottom: 6px;
}

.form-field input,
.form-field textarea,
.form-field select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  background: #fff;
}

.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 0;
  border-color: var(--primary);
}

.form-field .field-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
}

/* Placeholder */
.coming-soon {
  padding: 48px 32px;
  text-align: center;
}

.coming-soon-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.3;
}

.coming-soon h3 {
  margin: 0 0 8px;
  font-size: 18px;
}

.coming-soon p {
  color: var(--muted);
  max-width: 420px;
  margin: 0 auto;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
  animation: overlayIn 0.18s ease;
}

.modal-overlay.closing {
  animation: overlayOut 0.16s ease forwards;
}

.modal {
  position: relative;
  background: var(--surface);
  border-radius: 18px;
  width: 100%;
  max-width: 480px;
  max-height: min(90vh, 720px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow:
    0 0 0 1px rgba(15, 23, 42, 0.06),
    0 24px 64px rgba(15, 23, 42, 0.28);
  animation: modalIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal.modal-wide { max-width: 640px; }

.modal-overlay.closing .modal {
  animation: modalOut 0.16s ease forwards;
}

.modal-accent {
  height: 4px;
  background: linear-gradient(90deg, #2563eb, #60a5fa);
  flex-shrink: 0;
}

.modal.variant-danger .modal-accent {
  background: linear-gradient(90deg, #dc2626, #f87171);
}

.modal.variant-success .modal-accent {
  background: linear-gradient(90deg, #16a34a, #4ade80);
}

.modal.variant-warning .modal-accent {
  background: linear-gradient(90deg, #d97706, #fbbf24);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 22px 24px 0;
}

.modal-heading {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  min-width: 0;
}

.modal-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: #eff6ff;
  color: #2563eb;
}

.modal.variant-danger .modal-icon {
  background: #fef2f2;
  color: #dc2626;
}

.modal.variant-success .modal-icon {
  background: #f0fdf4;
  color: #16a34a;
}

.modal.variant-warning .modal-icon {
  background: #fffbeb;
  color: #d97706;
}

.modal-heading-text {
  min-width: 0;
  padding-top: 2px;
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.modal-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}

.modal-subtitle:empty { display: none; }

.modal-close-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.modal-close-btn:hover {
  background: #f1f5f9;
  color: var(--text);
}

.modal-body {
  padding: 18px 24px 24px;
  overflow-y: auto;
}

.modal-meta {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 4px;
}

.modal-meta-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: baseline;
}

.modal-meta-row .label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.modal-meta-row .value {
  font-weight: 600;
  text-align: right;
  word-break: break-all;
}

.modal-message {
  margin: 0;
  color: #334155;
  font-size: 14px;
  line-height: 1.55;
}

.modal-message strong {
  color: var(--text);
}

.confirm-card {
  display: grid;
  gap: 16px;
}

@keyframes overlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes overlayOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes modalOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(8px) scale(0.98); }
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.toast {
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--sidebar);
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: slideIn 0.25s ease;
}

.toast-error { background: var(--danger); }
.toast-success { background: var(--success); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Stats row */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

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

.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
}

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

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.filter-bar input[type="search"],
.filter-bar select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font: inherit;
  background: #fff;
}

.filter-bar input[type="search"] {
  flex: 1 1 220px;
  min-width: 180px;
}

.filter-bar select {
  flex: 0 0 auto;
}

.filter-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.filter-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
}

tr.row-archived {
  opacity: 0.72;
}

@media (max-width: 768px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; }
  .main { padding: 20px 16px; }
}
