@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ─────────────────────────────────────
   DESIGN TOKENS
───────────────────────────────────── */
:root {
  /* Brand */
  --primary:        #0099cc;
  --primary-dark:   #007aa3;
  --primary-darker: #005f80;
  --primary-light:  #e6f6fc;
  --primary-muted:  #b3dff0;

  /* Backgrounds */
  --bg:             #f0f2f5;
  --bg-panel:       #ffffff;
  --bg-surface:     #f7fafc;
  --bg-hover:       #f0f4f8;
  --bg-input:       #ffffff;

  /* Sidebar */
  --sidebar-bg:     #1a1d21;
  --sidebar-text:   #9ca3af;
  --sidebar-hover:  #252830;
  --sidebar-active-bg: rgba(0,153,204,0.12);

  /* Text */
  --text:           #1a202c;
  --text-mid:       #4a5568;
  --text-dim:       #718096;
  --text-muted:     #a0aec0;

  /* Borders */
  --border:         #e2e8f0;
  --border-mid:     #e2e8f0;
  --border-bright:  #cbd5e0;

  /* Status — kept as aliases so existing views work unchanged */
  --green:          #38a169;
  --green-mid:      #276749;
  --green-dim:      #48bb78;
  --green-dark:     #f0fff4;
  --red:            #e53e3e;
  --red-dim:        #c53030;
  --amber:          #d69e2e;
  --amber-dim:      #b7791f;
  --blue:           #3182ce;
  --blue-dim:       #2b6cb0;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:  0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.05);
  --shadow-lg:  0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);

  /* Deprecated glow aliases (used in inline styles) — map to shadows */
  --glow-sm:    var(--shadow-sm);
  --glow-md:    var(--shadow-md);
  --glow-lg:    var(--shadow-lg);

  /* Layout */
  --sidebar-w:  240px;
  --topbar-h:   60px;
  --radius:     8px;
  --radius-sm:  4px;
  --radius-lg:  12px;
  --radius-full:9999px;

  /* Typography */
  --font:       'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, sans-serif;
  --font-mono:  'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

/* ─────────────────────────────────────
   RESET & BASE
───────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─────────────────────────────────────
   LOGIN PAGE
───────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #0f1724 0%, #1a2b40 50%, #0d1e2e 100%);
}

.login-box {
  width: 420px;
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,0.4), 0 8px 20px rgba(0,0,0,0.2);
  overflow: hidden;
}

.login-header {
  padding: 32px 32px 24px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.login-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background: var(--primary);
  border-radius: 12px;
  margin-bottom: 16px;
}

.login-logo svg { color: #fff; }

.login-header .sys-title {
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.login-header .sys-sub {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 4px;
}

/* Deprecated status bar — hidden in new design */
.login-status-bar { display: none; }

.login-body { padding: 28px 32px; }

.login-body .field-label {
  display: block;
  color: var(--text-mid);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
}

.login-body input[type="text"],
.login-body input[type="password"] {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  caret-color: var(--primary);
  margin-bottom: 16px;
}

.login-body input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,153,204,0.15);
}

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

.login-error {
  background: #fff5f5;
  border: 1px solid #fed7d7;
  border-radius: var(--radius-sm);
  color: var(--red);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}

.login-error::before { content: ''; }

.btn-login {
  width: 100%;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-sm);
  color: #ffffff;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  padding: 11px;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
}

.btn-login:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 12px rgba(0,153,204,0.3);
}

.login-footer {
  border-top: 1px solid var(--border);
  padding: 14px 32px;
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-surface);
}

/* ─────────────────────────────────────
   APP LAYOUT
───────────────────────────────────── */
.app-wrap {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--primary);
  border-radius: 8px;
  flex-shrink: 0;
}

.sidebar-brand-icon svg { color: #fff; }

.sidebar-brand .brand-name {
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.sidebar-brand .brand-sub {
  color: var(--sidebar-text);
  font-size: 11px;
  margin-top: 1px;
}

/* Deprecated */
.sidebar-brand .brand-version { display: none; }

.sidebar-section {
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.sidebar-section-title {
  padding: 8px 16px 4px;
  color: rgba(255,255,255,0.3);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 400;
  transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent;
  border-radius: 0;
  margin: 1px 8px 1px 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.sidebar-nav a:hover {
  background: var(--sidebar-hover);
  color: #e2e8f0;
}

.sidebar-nav a.active {
  background: var(--sidebar-active-bg);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 500;
}

.sidebar-nav a .nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: inherit;
  opacity: 0.7;
}

.sidebar-nav a.active .nav-icon { opacity: 1; }

.sidebar-footer {
  margin-top: auto;
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
  background: rgba(0,0,0,0.2);
}

.sidebar-footer .user-line {
  color: var(--sidebar-text);
  font-size: 12px;
}

.sidebar-footer .user-line strong { color: #e2e8f0; font-weight: 500; }

.sidebar-footer a.logout-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
  color: rgba(255,100,100,0.7);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.15s;
}
.sidebar-footer a.logout-btn:hover { color: #fc8181; }

/* ── Main content ── */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.topbar {
  height: var(--topbar-h);
  padding: 0 24px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 10;
}

.topbar-title {
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--text-dim);
  font-size: 13px;
}

.topbar-right .status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 2px rgba(56,161,105,0.2);
}

.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ─────────────────────────────────────
   PAGE HEADING
───────────────────────────────────── */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-head h1 {
  color: var(--text);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.4px;
  text-transform: none;
}

.page-head .page-sub {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 3px;
  font-weight: 400;
}

/* ─────────────────────────────────────
   PANELS & CARDS
───────────────────────────────────── */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
  overflow: hidden;
}

.panel-head {
  padding: 14px 20px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-head .panel-title {
  color: var(--text-mid);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

.panel-body { padding: 20px; }

/* ── Stat cards ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 3px;
  background: var(--primary);
  border-radius: var(--radius) var(--radius) 0 0;
}

.stat-card.red::before   { background: var(--red); }
.stat-card.amber::before { background: var(--amber); }
.stat-card.blue::before  { background: var(--blue); }

.stat-card .stat-label {
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.stat-card .stat-value {
  color: var(--text);
  font-size: 32px;
  font-weight: 700;
  line-height: 1.1;
  margin: 8px 0 4px;
  letter-spacing: -1px;
}

.stat-card.red   .stat-value { color: var(--red); }
.stat-card.amber .stat-value { color: var(--amber); }
.stat-card.blue  .stat-value { color: var(--blue); }

.stat-card .stat-sub {
  color: var(--text-muted);
  font-size: 12px;
}

/* ─────────────────────────────────────
   TABLE
───────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table th {
  text-align: left;
  padding: 11px 16px;
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  white-space: nowrap;
}

table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-mid);
  vertical-align: middle;
}

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

table tbody tr:hover td {
  background: #f8fafc;
}

table .key-cell {
  color: var(--primary-dark);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
}

table .id-cell {
  color: var(--text-dim);
  font-size: 12px;
}

table .empty-row td {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 16px;
  font-size: 13px;
}

/* ─────────────────────────────────────
   FORMS
───────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

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

.field.span-2 { grid-column: span 2; }

label {
  color: var(--text-mid);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}

input[type="text"],
input[type="email"],
input[type="date"],
input[type="number"],
select,
textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 13.5px;
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  caret-color: var(--primary);
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,153,204,0.12);
}

input::placeholder, textarea::placeholder { color: var(--text-muted); }

select { cursor: pointer; }

textarea { resize: vertical; min-height: 80px; }

/* ─────────────────────────────────────
   BUTTONS
───────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, box-shadow 0.15s, border-color 0.15s;
  white-space: nowrap;
  line-height: 1;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}
.btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  box-shadow: 0 4px 12px rgba(0,153,204,0.25);
}

.btn-danger {
  background: #fff5f5;
  border-color: #fed7d7;
  color: var(--red);
}
.btn-danger:hover {
  background: #fed7d7;
  border-color: #fc8181;
}

.btn-warning {
  background: #fffaf0;
  border-color: #fbd38d;
  color: var(--amber);
}
.btn-warning:hover {
  background: #fbd38d;
  border-color: #f6ad55;
}

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

.btn-sm {
  padding: 5px 11px;
  font-size: 12px;
}

/* ─────────────────────────────────────
   BADGES
───────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  font-size: 11.5px;
  font-weight: 500;
  border-radius: var(--radius-full);
  border: 1px solid transparent;
  white-space: nowrap;
  letter-spacing: 0;
}

.badge-green  { background: #f0fff4; color: #276749; border-color: #c6f6d5; }
.badge-red    { background: #fff5f5; color: #c53030; border-color: #fed7d7; }
.badge-amber  { background: #fffaf0; color: #975a16; border-color: #fbd38d; }
.badge-blue   { background: #ebf8ff; color: #2b6cb0; border-color: #bee3f8; }
.badge-dim    { background: var(--bg-surface); color: var(--text-dim); border-color: var(--border); }

/* ─────────────────────────────────────
   ALERTS / FLASH
───────────────────────────────────── */
.alert {
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13.5px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.alert::before { font-weight: 700; flex-shrink: 0; margin-top: 0; }

.alert-success {
  background: #f0fff4;
  border-color: #c6f6d5;
  color: #276749;
}
.alert-success::before { content: '✓'; }

.alert-error {
  background: #fff5f5;
  border-color: #fed7d7;
  color: #c53030;
}
.alert-error::before { content: '✕'; }

.alert-warning {
  background: #fffaf0;
  border-color: #fbd38d;
  color: #975a16;
}
.alert-warning::before { content: '!'; }

/* ─────────────────────────────────────
   MODAL
───────────────────────────────────── */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(2px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-backdrop.open { display: flex; }

.modal {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 540px;
  max-width: 95vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-head {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.modal-head .modal-title {
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 2px 6px;
  transition: color 0.15s;
  border-radius: var(--radius-sm);
}
.modal-close:hover {
  color: var(--text);
  background: var(--bg-hover);
}

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

.modal-foot {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ─────────────────────────────────────
   LOG ENTRIES
───────────────────────────────────── */
.log-line {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 12px;
  font-size: 12.5px;
}

.log-time { color: var(--text-muted); white-space: nowrap; flex-shrink: 0; font-size: 12px; }
.log-type { width: 100px; flex-shrink: 0; }
.log-msg  { color: var(--text-mid); }

/* ─────────────────────────────────────
   GRID LAYOUTS
───────────────────────────────────── */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

/* ─────────────────────────────────────
   MISC UTILITIES
───────────────────────────────────── */
.mono { font-family: var(--font-mono); }

.text-green  { color: var(--green); }
.text-red    { color: var(--red); }
.text-amber  { color: var(--amber); }
.text-dim    { color: var(--text-dim); }
.text-right  { text-align: right; }
.mb-0  { margin-bottom: 0; }
.mt-16 { margin-top: 16px; }
.mt-8  { margin-top: 8px; }

hr.sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

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

/* Info row */
.info-row {
  font-size: 12.5px;
  color: var(--text-dim);
  padding: 10px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  letter-spacing: 0;
}

/* License key display */
.key-display {
  background: var(--bg-surface);
  border: 1px solid var(--primary-muted);
  border-radius: var(--radius-sm);
  color: var(--primary-dark);
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 2px;
  text-align: center;
  padding: 20px;
  margin: 16px 0;
}

/* Copy button */
.copy-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font);
  font-size: 11.5px;
  padding: 1px 5px;
  transition: color 0.15s;
  border-radius: 3px;
}
.copy-btn:hover {
  color: var(--primary);
  background: var(--primary-light);
}

/* Cursor — stripped of retro blink */
.cursor::after { content: ''; }

/* Deprecated login clock */
#login-clock { display: none; }

/* ─────────────────────────────────────
   RESPONSIVE
───────────────────────────────────── */
@media (max-width: 900px) {
  :root { --sidebar-w: 0px; }
  .sidebar { display: none; }
}

@media (max-width: 768px) {
  .form-grid,
  .form-grid.cols-3 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .content { padding: 16px; }
}
