/* ── Design Tokens ─────────────────────────────────────────────────────────── */
:root {
  --bg-base:      #0b0e14;
  --bg-panel:     #121620;
  --bg-card:      #1a1f2e;
  --bg-input:     #141925;
  --border-light: rgba(255, 255, 255, 0.06);
  --border-strong:rgba(255, 255, 255, 0.12);
  --accent:       #6366f1; /* Indigo */
  --accent-glow:  rgba(99, 102, 241, 0.35);
  --accent-dim:   rgba(99, 102, 241, 0.1);
  --ok:           #10b981;
  --warn:         #f59e0b;
  --err:          #ef4444;
  --info:         #3b82f6;
  --text-main:    #f3f4f6;
  --text-dim:     #9ca3af;
  --text-muted:   #6b7280;
  --radius-sm:    8px;
  --radius-md:    12px;
  --radius-lg:    20px;
  --shadow-sm:    0 2px 8px rgba(0,0,0,0.4);
  --shadow-md:    0 8px 32px rgba(0,0,0,0.6);
  --shadow-glow:  0 0 24px var(--accent-glow);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  background: var(--bg-base);
  color: var(--text-main);
  min-height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Glassmorphism Panel Helper */
.glass-panel {
  background: rgba(26, 31, 46, 0.6);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md);
}

/* ── Auth Gate ─────────────────────────────────────────────────────────────── */
#auth-gate {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(circle at top right, #1a1b3c, #0b0e14 60%);
  overflow: hidden;
}

.auth-bg-glow {
  position: absolute;
  top: 10%;
  left: 20%;
  width: 400px;
  height: 400px;
  background: var(--accent);
  filter: blur(140px);
  opacity: 0.15;
  border-radius: 50%;
  z-index: 0;
}
.auth-bg-glow.glow-2 {
  top: 60%;
  left: 70%;
  background: var(--info);
}

.auth-card {
  position: relative;
  z-index: 10;
  background: rgba(18, 22, 32, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 56px 48px;
  width: 420px;
  box-shadow: var(--shadow-md), 0 0 0 1px rgba(255,255,255,0.03) inset;
}

.auth-logo { text-align: center; margin-bottom: 40px; }
.logo-icon { font-size: 48px; display: block; margin-bottom: 16px; filter: drop-shadow(0 4px 12px var(--accent-glow)); }
.logo-title { display: block; font-size: 24px; font-weight: 700; color: #fff; letter-spacing: -0.5px; }
.logo-sub   { display: block; font-size: 13px; color: var(--text-dim); margin-top: 6px; }

.auth-form label { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
.auth-form input  { width: 100%; margin-bottom: 20px; padding: 12px 16px; font-size: 15px; border-radius: var(--radius-sm); }
.auth-form .btn   { width: 100%; padding: 12px; font-size: 15px; justify-content: center; }
.auth-err { color: var(--err); font-size: 13px; margin-top: 12px; text-align: center; font-weight: 500; }

/* ── App Layout (Sidebar + Main) ───────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  width: 100vw;
  background: var(--bg-base);
}

/* Sidebar */
.app-sidebar {
  width: 260px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 100;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  border-bottom: 1px solid var(--border-light);
}

.sidebar-logo-circle {
  width: 40px;
  height: 40px;
  background: var(--accent-dim);
  border: 1px solid rgba(99, 102, 241, 0.2);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.sidebar-titles { display: flex; flex-direction: column; }
.sidebar-title { font-size: 15px; font-weight: 700; color: #fff; letter-spacing: -0.2px; }
.sidebar-subtitle { font-size: 11px; color: var(--text-dim); }

.sidebar-nav {
  flex: 1;
  padding: 20px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin: 16px 0 6px 8px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  width: 100%;
  text-align: left;
}

.nav-icon { width: 18px; height: 18px; opacity: 0.7; }
.nav-btn .icon { font-size: 16px; opacity: 0.8; }

.nav-btn:hover { background: rgba(255,255,255,0.03); color: var(--text-main); }
.nav-btn:hover .nav-icon { opacity: 1; }
.nav-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}
.nav-btn.active .nav-icon { opacity: 1; stroke: var(--accent); }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-light);
}
.sidebar-lock-btn { width: 100%; justify-content: center; }

/* Main Content Area */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

#main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Sub-tab bar (Segmented Control style) ─────────────────────────────────── */
.subtab-bar {
  display: flex;
  gap: 8px;
  padding: 16px 24px;
  background: var(--bg-base);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
  align-items: center;
  overflow-x: auto;
}

.subtab-btn {
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  color: var(--text-dim);
  padding: 8px 16px;
  border-radius: 999px; /* Pill shape */
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.subtab-btn:hover {
  background: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-strong);
}

.subtab-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 4px 12px var(--accent-glow);
  font-weight: 600;
}

/* ── Tab body & Layouts ────────────────────────────────────────────────────── */
.tab-body { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg-panel); }

.split-pane { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.split-top { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }

/* ── Toolbar Row ───────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  flex-shrink: 0;
  flex-wrap: wrap;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-light);
}

.toolbar .spacer { flex: 1; }

.search-input {
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  color: var(--text-main);
  padding: 8px 16px 8px 36px; /* Space for icon */
  border-radius: var(--radius-lg);
  font-size: 13px;
  width: 320px;
  transition: all 0.2s ease;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%239ca3af'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
  background-size: 16px;
}

.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); background-color: var(--bg-card); }

/* ── Tabulator Overrides for Dark SaaS Theme ───────────────────────────────── */
.tabulator { 
  background-color: var(--bg-panel) !important; 
  border: none !important; 
  font-family: inherit !important;
  font-size: 13px;
}
.tabulator-tableholder { overflow: auto !important; }

.tabulator .tabulator-header { 
  background: var(--bg-panel) !important; 
  border-bottom: 1px solid var(--border-strong) !important; 
  color: var(--text-dim) !important;
}
.tabulator .tabulator-col { 
  background: transparent !important; 
  border-right: none !important; 
}
.tabulator .tabulator-col-title { 
  font-weight: 600; 
  font-size: 12px; 
  text-transform: uppercase; 
  letter-spacing: 0.5px; 
  padding: 12px 16px !important;
}

.tabulator .tabulator-row { 
  background: var(--bg-panel) !important; 
  border-bottom: 1px solid var(--border-light) !important; 
  transition: background 0.15s ease;
}
.tabulator .tabulator-row:hover { background: var(--bg-card) !important; }
.tabulator .tabulator-row.tabulator-selected { background: var(--accent-dim) !important; }
.tabulator .tabulator-cell { 
  color: var(--text-main) !important; 
  border-right: none !important; 
  padding: 12px 16px !important;
}
.tabulator .tabulator-row.row-active { 
  background: var(--bg-card) !important; 
  position: relative;
}
.tabulator .tabulator-row.row-active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

.tabulator .tabulator-footer { 
  background: var(--bg-base) !important; 
  border-top: 1px solid var(--border-light) !important; 
  color: var(--text-dim) !important; 
}

/* ── Detail Panel & Forms ──────────────────────────────────────────────────── */
.detail-panel { padding: 24px; }
.detail-title { font-size: 18px; font-weight: 600; color: #fff; margin-bottom: 20px; letter-spacing: -0.3px; }

.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 20px; }
.detail-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.detail-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

.form-group { display: flex; flex-direction: column; gap: 8px; }
.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}

input, select, textarea {
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  width: 100%;
  transition: all 0.2s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
  background: var(--bg-card);
}
input:disabled, select:disabled, textarea:disabled { opacity: 0.6; cursor: not-allowed; }
input::placeholder, textarea::placeholder { color: var(--text-muted); }
textarea { resize: vertical; min-height: 80px; }
select option { background: var(--bg-card); color: var(--text-main); }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
}

.btn:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.15); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; filter: grayscale(50%); }

.btn-primary { 
  background: var(--accent); 
  color: #fff; 
  box-shadow: 0 4px 12px var(--accent-glow);
}
.btn-success { 
  background: rgba(16, 185, 129, 0.15); 
  color: var(--ok); 
  border-color: rgba(16, 185, 129, 0.3);
}
.btn-success:hover:not(:disabled) { background: rgba(16, 185, 129, 0.25); }

.btn-danger { 
  background: rgba(239, 68, 68, 0.15); 
  color: var(--err); 
  border-color: rgba(239, 68, 68, 0.3);
}
.btn-danger:hover:not(:disabled) { background: rgba(239, 68, 68, 0.25); }

.btn-warning { 
  background: rgba(245, 158, 11, 0.15); 
  color: var(--warn); 
  border-color: rgba(245, 158, 11, 0.3);
}

.btn-info {
  background: var(--info);
  color: #fff;
  border-color: var(--info);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
}
.btn-info:hover:not(:disabled) {
  background: #2563eb;
  border-color: #2563eb;
}

.btn-ghost { 
  background: transparent; 
  color: var(--text-dim); 
  border-color: var(--border-strong); 
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-card); color: var(--text-main); }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-icon { padding: 6px; border-radius: var(--radius-sm); width: 32px; height: 32px; }

/* ── Cards / Sections ──────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.card-header { font-size: 15px; font-weight: 600; color: #fff; margin-bottom: 16px; }
.divider { border: none; border-top: 1px solid var(--border-light); margin: 24px 0; }

/* Add-form Specifics */
.add-form-container {
  padding: 24px 32px;
  max-width: 1200px;
  margin: 0 auto;
}
.form-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  margin: 24px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}

/* ── Admin Prompt Overlay ──────────────────────────────────────────────────── */
#admin-prompt-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 14, 20, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fade-in 0.2s ease;
}
.admin-prompt-card {
  padding: 32px;
  width: 440px;
  border-radius: var(--radius-lg);
}
.admin-prompt-header {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  align-items: center;
}
.admin-prompt-icon-wrap {
  width: 48px;
  height: 48px;
  background: rgba(239, 68, 68, 0.15);
  color: var(--err);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.admin-prompt-icon-wrap svg { width: 24px; height: 24px; }
.admin-prompt-title { font-size: 18px; font-weight: 600; color: #fff; margin-bottom: 4px; }
.admin-prompt-sub   { font-size: 13px; color: var(--text-dim); }
.admin-prompt-row   { display: flex; gap: 12px; }
.admin-prompt-row input { flex: 1; }

/* ── Detail Modal ──────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 14, 20, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  animation: fade-in 0.2s ease;
}
.modal-card {
  width: 85vw;
  max-width: 1200px;
  height: 85vh;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  overflow: hidden;
  animation: slide-up 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-light);
  background: rgba(26, 31, 46, 0.9);
}
.modal-title {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
}
.modal-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
}

/* Modal sticky subtab bar */
.modal-body > div:first-child {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(18, 22, 32, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

@keyframes fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { 
  from { transform: translateY(40px) scale(0.98); opacity: 0; } 
  to   { transform: translateY(0) scale(1); opacity: 1; } 
}

/* ── Toasts ────────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 32px;
  right: 32px;
  display: flex;
  flex-direction: column-reverse;
  gap: 12px;
  z-index: 2000;
}
.toast {
  padding: 14px 20px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md);
  animation: slide-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 400px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.toast-success { border-left: 4px solid var(--ok); }
.toast-error   { border-left: 4px solid var(--err); }
.toast-warning { border-left: 4px solid var(--warn); }
.toast-info    { border-left: 4px solid var(--info); }

@keyframes slide-in {
  from { transform: translateX(60px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Inner Panels & Tables ─────────────────────────────────────────────────── */
.panel-table { 
  width: 100%; 
  border-collapse: collapse; 
  font-size: 13px; 
  margin-top: 12px; 
  background: var(--bg-card);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.panel-table th {
  background: rgba(255,255,255,0.03);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
}
.panel-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-main);
}
.panel-table tr:last-child td { border-bottom: none; }
.panel-table tr:hover td { background: rgba(255,255,255,0.02); }

/* ── Badges ────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-ok   { background: rgba(16, 185, 129, 0.15); color: var(--ok); border: 1px solid rgba(16, 185, 129, 0.3); }
.badge-warn { background: rgba(245, 158, 11, 0.15); color: var(--warn); border: 1px solid rgba(245, 158, 11, 0.3); }
.badge-err  { background: rgba(239, 68, 68, 0.15); color: var(--err); border: 1px solid rgba(239, 68, 68, 0.3); }

/* ── Utilities ─────────────────────────────────────────────────────────────── */
.text-dim   { color: var(--text-dim); }
.text-muted { color: var(--text-muted); }
.text-accent{ color: var(--accent); }
.text-sm    { font-size: 12px; }
.mt-8       { margin-top: 8px; }
.mb-8       { margin-bottom: 8px; }
.flex       { display: flex; }
.flex-gap   { gap: 12px; }
.align-center { align-items: center; }

/* Custom Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); }

@media print {
  body * {
    visibility: hidden !important;
  }
  #ra-modal, #ra-modal * {
    visibility: visible !important;
  }
  #ra-modal {
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: auto !important;
    background: white !important;
    color: black !important;
  }
  #ra-modal-body, #ra-modal-body * {
    visibility: visible !important;
  }
  #ra-modal-body {
    padding: 0 !important;
    margin: 0 !important;
    background: white !important;
    color: black !important;
  }
  #ra-modal .modal-header {
    display: none !important;
  }
  .print-btn {
    display: none !important;
  }
}
