/* TheEdge — Main Stylesheet */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-card: #151d2e;
  --bg-input: #1a2332;
  --border: #1e293b;
  --border-focus: #3b82f6;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-glow: rgba(59, 130, 246, 0.15);
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.1);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.1);
  --yellow: #eab308;
  --yellow-bg: rgba(234, 179, 8, 0.1);
  --orange: #f97316;
  --purple: #a78bfa;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --transition: 150ms ease;
}

/* Light theme */
[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f1f5f9;
  --border: #e2e8f0;
  --border-focus: #3b82f6;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-glow: rgba(37, 99, 235, 0.1);
  --green: #16a34a;
  --green-bg: rgba(22, 163, 74, 0.08);
  --red: #dc2626;
  --red-bg: rgba(220, 38, 38, 0.08);
  --yellow: #ca8a04;
  --yellow-bg: rgba(202, 138, 4, 0.08);
  --orange: #ea580c;
  --purple: #7c3aed;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); }

/* ---- LAYOUT ---- */
.app-wrapper { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px; background: var(--bg-secondary); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 100; transition: transform 0.3s ease;
}
.sidebar-brand {
  padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border);
  font-size: 1.25rem; font-weight: 700; letter-spacing: -0.5px;
}
.sidebar-brand span { color: var(--accent); }
.sidebar-nav { flex: 1; padding: 0.75rem 0; overflow-y: auto; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.6rem 1.5rem; color: var(--text-secondary); font-size: 0.875rem;
  transition: all var(--transition); border-left: 3px solid transparent;
}
.sidebar-nav a:hover { color: var(--text-primary); background: var(--accent-glow); }
.sidebar-nav a.active {
  color: var(--accent); background: var(--accent-glow);
  border-left-color: var(--accent); font-weight: 600;
}
.sidebar-nav .nav-section {
  padding: 1rem 1.5rem 0.4rem; font-size: 0.7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted);
}
.sidebar-footer {
  padding: 1rem 1.5rem; border-top: 1px solid var(--border); font-size: 0.8rem;
  color: var(--text-muted);
}

/* min-width:0 is the load-bearing piece — without it, flex items default
   to `min-width: auto` (= intrinsic content width) and a wide table inside
   .page-body pushes the whole page wider than the viewport, defeating the
   horizontal scroll inside child widgets. v4.86.2 fix.  */
.main-content {
  flex: 1; min-width: 0; margin-left: 240px; min-height: 100vh;
  /* Cap the content column to the remaining viewport so wide children
     scroll horizontally inside their own boxes instead of pushing the
     page past the viewport edge. v4.86.4 fix — both spellings for
     cross-engine support (WebKit/Blink → -webkit-fill-available,
     spec name → stretch). */
  max-width: -webkit-fill-available;
  max-width: stretch;
}
.page-header {
  padding: 1.5rem 2rem; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg-secondary);
}
.page-header h1 { font-size: 1.4rem; font-weight: 700; }
.page-header .breadcrumb { font-size: 0.8rem; color: var(--text-muted); }

.page-body { padding: 1.5rem 2rem; }

/* ---- CARDS ---- */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.25rem; margin-bottom: 1rem;
}
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--border);
}
.card-header h3 { font-size: 1rem; font-weight: 600; }
.card-grid { display: grid; gap: 1rem; }
.card-grid-2 { grid-template-columns: repeat(2, 1fr); }
.card-grid-3 { grid-template-columns: repeat(3, 1fr); }
.card-grid-4 { grid-template-columns: repeat(4, 1fr); }

.stat-card { text-align: center; padding: 1.25rem; }
.stat-value { font-size: 1.75rem; font-weight: 700; }
.stat-label { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.25rem; }
.stat-delta { font-size: 0.8rem; margin-top: 0.25rem; }
.stat-delta.up { color: var(--green); }
.stat-delta.down { color: var(--red); }

/* ---- TABLES ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th {
  background: var(--bg-secondary); color: var(--text-secondary); font-weight: 600;
  padding: 0.6rem 0.75rem; text-align: left; border-bottom: 2px solid var(--border);
  position: sticky; top: 0; z-index: 3; font-size: 0.8rem; text-transform: uppercase;
  letter-spacing: 0.5px; white-space: nowrap;
}
thead th.sort-asc::after { content: ' ▲'; font-size: 0.65rem; color: var(--accent); }
thead th.sort-desc::after { content: ' ▼'; font-size: 0.65rem; color: var(--accent); }
tbody td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); }
tbody tr:hover td { background: rgba(59, 130, 246, 0.03); }
tbody tr:last-child td { border-bottom: none; }

.text-right { text-align: right; }
.text-center { text-align: center; }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-yellow { color: var(--yellow); }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }

.font-mono { font-family: 'JetBrains Mono', monospace; font-size: 0.82em; }
.font-bold { font-weight: 700; }

/* ---- BADGES ---- */
.badge {
  display: inline-block; font-size: 0.7rem; font-weight: 600; padding: 0.15rem 0.5rem;
  border-radius: 4px; text-transform: uppercase; letter-spacing: 0.3px;
}
.badge-green, .badge-approved { background: var(--green-bg); color: var(--green); }
.badge-red, .badge-rejected { background: var(--red-bg); color: var(--red); }
.badge-yellow, .badge-pending { background: var(--yellow-bg); color: var(--yellow); }
.badge-blue { background: var(--accent-glow); color: var(--accent); }
.badge-small { background: rgba(167,139,250,.12); color: var(--purple); }
.badge-mid { background: rgba(59,130,246,.12); color: var(--accent); }

.action-badge { font-size: 0.75rem; padding: 0.2rem 0.5rem; border-radius: 4px; }
.badge-new { background: rgba(234,179,8,.12); color: var(--yellow); }
.badge-exit { background: var(--red-bg); color: var(--red); }
.badge-up { background: var(--green-bg); color: var(--green); }
.badge-down { background: var(--red-bg); color: var(--red); }
.badge-hold { background: rgba(148,163,184,.1); color: var(--text-muted); }

.rank-up { color: var(--green); font-weight: 600; font-size: 0.8rem; }
.rank-down { color: var(--red); font-weight: 600; font-size: 0.8rem; }
.rank-same { color: var(--text-muted); font-size: 0.8rem; }

/* ---- FORMS ---- */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 0.35rem;
  color: var(--text-secondary);
}
.form-control {
  width: 100%; padding: 0.6rem 0.75rem; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text-primary); font-size: 0.9rem; font-family: inherit;
  transition: border-color var(--transition);
}
.form-control:focus { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--accent-glow); }
textarea.form-control { min-height: 80px; resize: vertical; }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.55rem 1.1rem; font-size: 0.875rem; font-weight: 600;
  border-radius: var(--radius); border: 1px solid transparent; cursor: pointer;
  transition: all var(--transition); font-family: inherit; text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { opacity: 0.9; color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: 0.9; color: #fff; }
.btn-outline {
  background: transparent; color: var(--text-secondary);
  border-color: var(--border);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.78rem; }
.btn-block { display: flex; width: 100%; justify-content: center; }

/* ---- ALERTS ---- */
.alert {
  padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem;
  font-size: 0.875rem; border: 1px solid;
}
.alert-success { background: var(--green-bg); border-color: rgba(34,197,94,.2); color: var(--green); }
.alert-error { background: var(--red-bg); border-color: rgba(239,68,68,.2); color: var(--red); }
.alert-warning { background: var(--yellow-bg); border-color: rgba(234,179,8,.2); color: var(--yellow); }
.alert-info { background: var(--accent-glow); border-color: rgba(59,130,246,.2); color: var(--accent); }

/* ---- AUTH PAGES (centered card) ---- */
.auth-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 2rem;
}
.auth-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 2rem; width: 100%; max-width: 420px;
}
.auth-card h1 {
  font-size: 1.5rem; margin-bottom: 0.25rem; text-align: center;
}
.auth-card .auth-subtitle {
  color: var(--text-muted); font-size: 0.875rem; text-align: center;
  margin-bottom: 1.5rem;
}
.auth-card .auth-footer {
  text-align: center; margin-top: 1.25rem; font-size: 0.85rem; color: var(--text-muted);
}

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .card-grid-2, .card-grid-3, .card-grid-4 { grid-template-columns: 1fr; }
  .page-header { padding: 1rem; flex-direction: column; align-items: flex-start; gap: .5rem; }
  .page-body { padding: .75rem; }
  .page-header h1 { font-size: 1.1rem; }
  .table-wrap { margin: 0 -.75rem; }
  table { font-size: .78rem; }
  .stat-card { padding: .75rem; }
  .stat-value { font-size: 1.3rem; }
  .qs-dialog { width: 95%; }
  #quickSearchModal { padding-top: 8vh; }
  .nav-fav-star { display: none !important; }
}

@media (max-width: 480px) {
  .page-body { padding: .5rem; }
  .card { padding: .75rem; }
  .card-header { padding: .5rem .75rem; }
  .stat-value { font-size: 1.1rem; }
  .btn { padding: .4rem .8rem; font-size: .8rem; }
}

/* ---- PENDING PAGE ---- */
.pending-container {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 2rem;
}
.pending-icon { font-size: 3rem; margin-bottom: 1rem; }
.pending-container h2 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.pending-container p { color: var(--text-secondary); max-width: 400px; }
.pending-actions { margin-top: 1.5rem; display: flex; gap: 0.75rem; }

/* TheEdge v3.3 — Extended Styles */
.badge-suspended { background: rgba(249, 115, 22, 0.12); color: #f97316; }
.badge-delete_requested { background: rgba(239, 68, 68, 0.18); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.4); }

/* Smooth page transitions */
.page-body { animation: fadeIn 0.2s ease-in; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* Better table row interactions */
tbody tr { transition: background var(--transition); }
tbody tr:hover td { background: rgba(59, 130, 246, 0.06); }

/* Scrollbar styling (WebKit) */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Focus visible for accessibility */
.btn:focus-visible, .form-control:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Print styles */
@media print {
  .sidebar, .page-header .btn, form { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .card { break-inside: avoid; border: 1px solid #ccc; }
  body { background: #fff; color: #000; }
}

/* Tooltip for action badges */
.action-badge[title] { position: relative; cursor: help; }

/* Stat card improvements */
.stat-card { transition: transform var(--transition), box-shadow var(--transition); }
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.2); }

/* Loading skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-input) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: var(--radius);
}
@keyframes skeleton-loading { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Empty state */
.empty-state {
  text-align: center; padding: 3rem 1.5rem; color: var(--text-muted);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.5; }
.empty-state-text { font-size: 0.9rem; max-width: 400px; margin: 0 auto; }

/* Sort indicators */
thead th.sort-asc::after { content: ' ▲'; font-size: .6rem; color: var(--accent); }
thead th.sort-desc::after { content: ' ▼'; font-size: .6rem; color: var(--accent); }
thead th[style*="cursor: pointer"]:hover { color: var(--accent); }

/* Row highlight on click */
tbody tr.row-highlighted td { background: rgba(59, 130, 246, 0.08) !important; }

/* Keyboard shortcut hints */
.kbd {
  display: inline-block; padding: 0.1rem 0.4rem; font-size: .7rem;
  font-family: 'JetBrains Mono', monospace; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: 3px; color: var(--text-muted);
}

/* Double-click copy feedback */
.font-mono { cursor: default; }
.font-mono[title] { cursor: help; }

/* Quick Search Modal */
#quickSearchModal {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  z-index: 9999; display: flex; align-items: flex-start; justify-content: center;
  padding-top: 15vh;
}
.qs-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
}
.qs-dialog {
  position: relative; width: 90%; max-width: 520px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  overflow: hidden;
}
.qs-dialog input {
  width: 100%; padding: 1rem 1.25rem; font-size: 1rem;
  background: transparent; border: none; border-bottom: 1px solid var(--border);
  color: var(--text-primary); outline: none;
  font-family: 'Inter', sans-serif;
}
.qs-dialog input::placeholder { color: var(--text-muted); }
.qs-results { max-height: 300px; overflow-y: auto; }
.qs-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: .6rem 1.25rem; color: var(--text-primary);
  text-decoration: none; font-size: .88rem; transition: background var(--transition);
}
.qs-item:hover, .qs-item.qs-selected {
  background: var(--accent-glow); color: var(--accent);
}
.qs-type { font-size: .7rem; color: var(--text-muted); }
.qs-footer {
  display: flex; gap: 1rem; padding: .5rem 1.25rem;
  border-top: 1px solid var(--border); font-size: .7rem; color: var(--text-muted);
}
.qs-footer kbd {
  display: inline-block; padding: 0 .3rem; font-size: .65rem;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 3px; font-family: 'JetBrains Mono', monospace;
}

/* ─── PRINT STYLES ────────────────────────────────────── */
@media print {
  .sidebar, .page-header, .qs-footer, #quickSearchModal,
  .btn, button, form, .breadcrumb { display: none !important; }
  .main-content { margin-left: 0 !important; padding: 0 !important; }
  .app-wrapper { display: block !important; }
  .card { box-shadow: none !important; border: 1px solid #ddd !important; break-inside: avoid; }
  body { background: #fff !important; color: #000 !important; font-size: 10pt; }
  table { font-size: 8pt; }
  a { color: #000 !important; text-decoration: none !important; }
  .text-green { color: #16a34a !important; }
  .text-red { color: #dc2626 !important; }
  .badge { border: 1px solid #999; }
}
