/* ── Design Tokens ────────────────────────────────────────────────────────── */
:root {
  --bg:         #0d0f14;
  --bg2:        #13161d;
  --bg3:        #1a1e28;
  --border:     #252a37;
  --border2:    #2f3547;
  --text:       #e8eaf0;
  --text2:      #8b91a8;
  --text3:      #555e7a;
  --accent:     #3d7fff;
  --accent-dim: #1a3a70;
  --accent-glow:#3d7fff22;
  --green:      #22c98a;
  --green-dim:  #0f3d2a;
  --red:        #ff4d6a;
  --red-dim:    #3d1020;
  --yellow:     #f5b83a;
  --radius:     10px;
  --radius-sm:  6px;
  --shadow:     0 4px 24px rgba(0,0,0,0.4);
  --font:       'DM Sans', system-ui, sans-serif;
  --font-mono:  'DM Mono', 'Fira Code', monospace;
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: var(--font); }

/* ── Utilities ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.screen { height: 100vh; }

/* ── Login Screen ──────────────────────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.login-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 80%, #0d2855 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 20%, #1a1040 0%, transparent 50%),
    var(--bg);
}

.login-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 48px 48px;
  opacity: 0.4;
  mask-image: radial-gradient(ellipse 70% 70% at 50% 50%, black 30%, transparent 100%);
}

.login-card {
  position: relative;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 16px;
  padding: 48px 40px;
  width: 380px;
  box-shadow: var(--shadow), 0 0 80px rgba(61,127,255,0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  animation: fadeUp 0.5s ease both;
}

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

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

.logo-mark {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--accent), #6fa3ff);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 600;
  color: white;
  flex-shrink: 0;
}

.login-brand { line-height: 1.2; }
.brand-name { display: block; font-size: 18px; font-weight: 600; color: var(--text); }
.brand-sub  { display: block; font-size: 11px; color: var(--text3); letter-spacing: 0.5px; text-transform: uppercase; }

.login-tagline {
  color: var(--text2);
  font-size: 13px;
  text-align: center;
  margin-bottom: 28px;
}

.btn-ms-login {
  display: flex;
  align-items: center;
  gap: 10px;
  background: white;
  color: #333;
  font-size: 14px;
  font-weight: 500;
  padding: 12px 24px;
  border-radius: var(--radius);
  width: 100%;
  justify-content: center;
  transition: box-shadow 0.2s, transform 0.15s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.btn-ms-login:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  transform: translateY(-1px);
}

.login-note {
  margin-top: 16px;
  font-size: 11px;
  color: var(--text3);
}

/* ── App Shell Layout ──────────────────────────────────────────────────────── */
#app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-mark-sm {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent), #6fa3ff);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  color: white;
  flex-shrink: 0;
}

.sidebar-brand { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.2; }
.sidebar-sub   { font-size: 10px; color: var(--text3); letter-spacing: 0.5px; }

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text3);
  padding: 8px 8px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-size: 13px;
  font-weight: 400;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
  margin-bottom: 1px;
}

.nav-item:hover {
  background: var(--bg3);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 500;
}

.sidebar-footer {
  padding: 12px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-chip {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.user-info { min-width: 0; }
.user-name { font-size: 12px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 10px; color: var(--text3); text-transform: capitalize; }

.logout-btn {
  color: var(--text3);
  padding: 5px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
  display: flex;
}
.logout-btn:hover { color: var(--red); background: var(--red-dim); }

/* ── Main Content ──────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
  padding: 32px 36px;
}

.page { display: none; }
.page.active { display: block; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── Page Header ───────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
}

.page-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.3px;
}

.page-desc {
  color: var(--text2);
  font-size: 13px;
  margin-top: 3px;
}

.page-actions { display: flex; gap: 10px; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn-outline {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text2);
  font-size: 13px;
  font-weight: 500;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-glow); }

.btn-download {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
  white-space: nowrap;
}
.btn-download:hover { background: #5490ff; transform: translateY(-1px); }
.btn-download:active { transform: translateY(0); }
.btn-download:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text2);
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.btn-ghost:hover { border-color: var(--text2); color: var(--text); }

/* ── Stats Bar ──────────────────────────────────────────────────────────────── */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.stat-value {
  font-size: 26px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
  font-family: var(--font-mono);
}
.stat-value.accent { color: var(--accent); }

.stat-label {
  font-size: 11px;
  color: var(--text3);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Filter Bar ─────────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  align-items: center;
}

.search-wrap {
  position: relative;
  flex: 1;
}

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text3);
  pointer-events: none;
}

.filter-input {
  width: 100%;
  padding: 8px 12px 8px 32px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
.filter-input:focus { border-color: var(--accent); }
.filter-input::placeholder { color: var(--text3); }

.filter-select {
  padding: 8px 12px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}
.filter-select:focus { border-color: var(--accent); }

/* ── Table ──────────────────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

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

.data-table thead tr {
  border-bottom: 1px solid var(--border);
}

.data-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text3);
  white-space: nowrap;
}

.data-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg3); }

.data-table td {
  padding: 13px 16px;
  font-size: 13px;
  color: var(--text2);
  vertical-align: middle;
}

.data-table td:first-child {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
}

.data-table td:nth-child(4) {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.actions-cell { display: flex; gap: 6px; align-items: center; }

/* ── Badges ─────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.badge-green  { background: var(--green-dim); color: var(--green); }
.badge-red    { background: var(--red-dim); color: var(--red); }
.badge-accent { background: var(--accent-dim); color: var(--accent); }
.badge-gray   { background: var(--bg3); color: var(--text3); border: 1px solid var(--border2); }

.dl-count {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-family: var(--font-mono);
}
.dl-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.dl-dot.none { background: var(--border2); }

/* ── States ──────────────────────────────────────────────────────────────────── */
.loading-state, .empty-state, .error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 64px 24px;
  color: var(--text3);
  font-size: 13px;
}

.error-state { color: var(--red); }

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.15s ease;
}

.modal {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 14px;
  width: 520px;
  max-width: calc(100vw - 32px);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  animation: slideUp 0.2s ease;
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 15px; font-weight: 600; color: var(--text); }
.modal-close {
  background: none;
  border: none;
  color: var(--text3);
  font-size: 20px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.modal-close:hover { color: var(--text); background: var(--bg3); }

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  font-size: 13px;
  color: var(--text2);
}

.dl-history-empty { color: var(--text3); text-align: center; padding: 20px; }

.dl-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.dl-history-item:last-child { border-bottom: none; }

.dl-history-date { color: var(--text); font-size: 12px; font-family: var(--font-mono); }
.dl-history-format { }

/* ── Toast ───────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--shadow);
  z-index: 200;
  animation: slideIn 0.2s ease;
  max-width: 320px;
}

.toast.success { border-color: var(--green); color: var(--green); }
.toast.error   { border-color: var(--red); color: var(--red); }

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

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .stats-bar { grid-template-columns: repeat(2, 1fr); }
  .sidebar { width: 60px; }
  .sidebar-brand, .sidebar-sub, .nav-item span, .nav-section-label,
  .user-info, .sidebar-logo > div:last-child { display: none; }
  .main-content { padding: 20px 16px; }
}
