/* ============================================================
   EDU LABS — GLOBAL DESIGN SYSTEM
   Light, clean, simple.
   ============================================================ */

/* ----------------------------------------------------------
   SIDEBAR + APP SHELL LAYOUT
   ---------------------------------------------------------- */

/* Sidebar width tokens */
:root {
  --sidebar-w:          260px;
  --sidebar-w-collapsed: 64px;
  --topbar-h:           56px;
}

/* When sidebar is visible the body gets .sidebar-open */
body.sidebar-open {
  overflow-x: hidden;
}

/* ── App layout wrapper ── */
.app-layout {
  transition: margin-left var(--transition-md);
}
body.sidebar-open .app-layout {
  margin-left: var(--sidebar-w);
}
body.sidebar-open.sidebar-collapsed .app-layout {
  margin-left: var(--sidebar-w-collapsed);
}

/* ── Sidebar ── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  z-index: 800;
  transition: width var(--transition-md), transform var(--transition-md);
  overflow: hidden;
}

/* Collapsed state */
body.sidebar-collapsed .sidebar {
  width: var(--sidebar-w-collapsed);
}
body.sidebar-collapsed .sidebar-logo-text,
body.sidebar-collapsed .sidebar-section-label,
body.sidebar-collapsed .sidebar-item-text,
body.sidebar-collapsed .sidebar-item-badge,
body.sidebar-collapsed .sidebar-item-ext,
body.sidebar-collapsed .sidebar-user-info {
  opacity: 0;
  width: 0;
  overflow: hidden;
  pointer-events: none;
}
body.sidebar-collapsed .sidebar-collapse-btn svg {
  transform: rotate(180deg);
}
body.sidebar-collapsed .sidebar-item {
  justify-content: center;
  padding: 0.65rem 0;
}
body.sidebar-collapsed .sidebar-user {
  justify-content: center;
  padding: 0.75rem 0;
}
body.sidebar-collapsed .sidebar-logout-btn {
  margin-left: 0;
}

/* ── Sidebar Header ── */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.75rem 0 1rem;
  height: 60px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  overflow: hidden;
  min-width: 0;
}
.sidebar-logo-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius);
}
.sidebar-logo-text {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  transition: opacity var(--transition-md), width var(--transition-md);
}

.sidebar-collapse-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.sidebar-collapse-btn:hover {
  background: var(--gray-100);
  color: var(--text);
  border-color: var(--gray-300);
}
.sidebar-collapse-btn svg {
  transition: transform var(--transition-md);
}

/* ── Sidebar Nav ── */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.75rem 0;
  scrollbar-width: thin;
  scrollbar-color: var(--gray-200) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 99px; }

.sidebar-section {
  padding: 0 0.625rem;
  margin-bottom: 0.5rem;
}

.sidebar-section-label {
  display: block;
  padding: 0.5rem 0.5rem 0.35rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--gray-400);
  white-space: nowrap;
  transition: opacity var(--transition-md), width var(--transition-md);
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.575rem 0.625rem;
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), padding var(--transition-md);
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}
.sidebar-item:hover {
  background: var(--gray-100);
  color: var(--text);
  text-decoration: none;
}
.sidebar-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
  border-color: rgba(79,110,247,.15);
}
.sidebar-item:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.sidebar-item-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

.sidebar-item-text {
  flex: 1;
  transition: opacity var(--transition-md), width var(--transition-md);
}

.sidebar-item-badge {
  flex-shrink: 0;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: var(--radius-full);
  padding: 0.1rem 0.45rem;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.5;
  transition: opacity var(--transition-md);
}
.sidebar-item.active .sidebar-item-badge {
  background: rgba(79,110,247,.2);
}

.sidebar-item-ext {
  flex-shrink: 0;
  color: var(--gray-400);
  display: flex;
  align-items: center;
  transition: opacity var(--transition-md);
}

/* ── Sidebar Footer ── */
.sidebar-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 0.625rem;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.625rem 0.5rem;
  border-radius: var(--radius);
  overflow: hidden;
  transition: padding var(--transition-md);
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  flex-shrink: 0;
}

.sidebar-user-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  transition: opacity var(--transition-md), width var(--transition-md);
}
.sidebar-user-name {
  display: block;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-email {
  display: block;
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-logout-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  margin-left: auto;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), margin-left var(--transition-md);
}
.sidebar-logout-btn:hover {
  background: var(--danger-light);
  border-color: var(--danger-border);
  color: var(--danger);
}

/* Mobile overlay */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.4);
  backdrop-filter: blur(2px);
  z-index: 799;
  animation: backdropIn 0.18s ease;
}

/* ── Topbar (mobile) ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: var(--topbar-h);
  padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}
.topbar-menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}
.topbar-menu-btn:hover { background: var(--gray-100); color: var(--text); }
.topbar-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}
.topbar-avatar {
  width: 30px; height: 30px;
  font-size: 0.72rem;
}
.topbar-right { display: flex; align-items: center; gap: 0.5rem; }

/* ── Page content ── */
.page-content {
  min-height: 100vh;
}

/* ── Login shell (centered) ── */
.login-shell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  min-height: 100vh;
  padding: 3rem max(2rem, calc((100% - 440px) / 2));
}
.login-brand { margin-bottom: 1rem; }
.login-shell h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  letter-spacing: -0.04em;
  color: var(--text);
  margin-bottom: 0.75rem;
}
.login-shell > p {
  max-width: 48ch;
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 1.25rem;
}
.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  padding: 1.75rem;
  margin-top: 2rem;
}

/* ── Dashboard page header ── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.page-header h2 { margin: 0; }

/* Authenticated content padding */
.home {
  padding: 1.5rem;
}

.page-panels {
  display: grid;
  gap: 0.9rem;
}

.page-panel {
  display: none;
  animation: panelFade 180ms ease;
}
.page-panel.active {
  display: grid;
  gap: 0.9rem;
}

.rag-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  background:
    radial-gradient(circle at top right, rgba(59,130,246,.12), transparent 30%),
    linear-gradient(135deg, #ffffff 0%, #f8fbff 100%);
}
.rag-hero h3 {
  margin-bottom: 0.35rem;
  font-size: 1.3rem;
}

.rag-form {
  display: grid;
  gap: 1rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.field {
  display: grid;
  gap: 0.4rem;
  color: var(--text);
  font-weight: 600;
  font-size: 0.88rem;
}
.field-wide {
  grid-column: 1 / -1;
}
.field span {
  color: var(--text);
}
.field input,
.field select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0.65rem 0.85rem;
  font: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(79,110,247,.12);
}
.field input:disabled,
.field select:disabled {
  background: var(--gray-50);
  color: var(--text-disabled);
  cursor: not-allowed;
}

.rag-form-actions {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.rag-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  gap: 0.75rem;
  margin: 0.9rem 0;
}

.field-inline {
  gap: 0.35rem;
}

.field-inline span {
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.field-inline input,
.field-inline select {
  min-height: 40px;
}

.table-wrap {
  overflow: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.rag-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}
.rag-table th,
.rag-table td {
  padding: 0.85rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.rag-table th {
  font-size: 0.77rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  background: var(--gray-50);
}
.rag-table tr:last-child td {
  border-bottom: none;
}
.table-empty {
  text-align: center !important;
  color: var(--text-secondary);
  padding: 1.25rem 0.9rem;
}

.rag-doc-name {
  font-weight: 600;
  color: var(--text);
}
.rag-doc-meta {
  display: block;
  color: var(--text-secondary);
  font-size: 0.8rem;
  margin-top: 0.2rem;
}

.rag-row-actions {
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
}

.rag-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.9rem;
  flex-wrap: wrap;
}

.rag-pagination-summary {
  color: var(--text-secondary);
  font-size: 0.86rem;
  font-weight: 500;
}

.rag-pagination-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.rag-page-indicator {
  color: var(--text-secondary);
  font-size: 0.86rem;
}

.reader-toolbar {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.9rem;
}

.reader-toolbar .btn-secondary {
  margin-top: 1.35rem;
}

.reader-document-field {
  min-width: min(100%, 520px);
  flex: 1;
}

.reader-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 0.9rem 0 1rem;
}

.reader-summary-card {
  background: var(--gray-50);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 0.95rem;
  color: var(--text-secondary);
  font-size: 0.88rem;
}
.reader-summary-card strong {
  display: block;
  color: var(--text);
  margin-bottom: 0.2rem;
}

.reader-table-section {
  margin: 0.9rem 0 1rem;
  padding: 0.95rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, #fff, #fbfcff);
}

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

.reader-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
  font-size: 0.86rem;
}

.reader-table thead th {
  text-align: left;
  padding: 0.75rem 0.7rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.reader-table tbody td {
  vertical-align: top;
  padding: 0.8rem 0.7rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.reader-table tbody tr:last-child td {
  border-bottom: 0;
}

.reader-table .table-empty {
  color: var(--text-secondary);
  text-align: center;
  padding: 1rem;
}

.reader-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.reader-section {
  background: linear-gradient(180deg, #fff, #fbfcff);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.95rem;
}
.reader-section-full {
  grid-column: 1 / -1;
}

.reader-list,
.reader-tags {
  display: grid;
  gap: 0.6rem;
}

.reader-tag {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  flex-wrap: wrap;
  background: var(--primary-light);
  color: var(--primary-hover);
  border: 1px solid rgba(79,110,247,.15);
  border-radius: var(--radius-full);
  padding: 0.42rem 0.75rem;
  font-size: 0.86rem;
  font-weight: 600;
}
.reader-tag small {
  color: var(--text-secondary);
  font-size: 0.72rem;
}

.reader-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0.8rem 0.85rem;
}
.reader-card-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: baseline;
  margin-bottom: 0.35rem;
}
.reader-card-head h5 {
  font-size: 0.95rem;
  margin: 0;
}
.reader-card-head span {
  color: var(--text-secondary);
  font-size: 0.78rem;
}
.reader-card p {
  font-size: 0.88rem;
}

.reader-empty {
  color: var(--text-secondary);
  font-size: 0.88rem;
  padding: 0.35rem 0;
}

.reader-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.reader-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(10px);
}

.reader-modal-card {
  position: relative;
  width: min(720px, 100%);
  background: var(--surface);
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 28px;
  box-shadow: 0 28px 70px rgba(15, 23, 42, 0.25);
  padding: 1.25rem;
  animation: panelFade 180ms ease-out;
}

.reader-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.reader-modal-head h3 {
  margin: 0.25rem 0 0;
  font-size: 1.6rem;
}

.reader-modal-body {
  margin-top: 1rem;
}

.reader-modal-message {
  color: var(--text-secondary);
  font-size: 0.98rem;
  margin: 0 0 1rem;
}

.reader-modal-stage {
  display: grid;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.reader-modal-stage-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.reader-modal-stage-value {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}

.reader-modal-steps {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.5rem;
}

.reader-modal-step {
  padding: 0.7rem 0.75rem;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--gray-50);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
}

.reader-modal-step.active {
  background: var(--primary-light);
  color: var(--primary);
  border-color: rgba(79,110,247,.18);
}

.reader-modal-step.done {
  background: rgba(16, 185, 129, 0.12);
  color: #0f766e;
  border-color: rgba(16,185,129,.2);
}

.reader-modal-step.error {
  background: rgba(248, 113, 113, 0.12);
  color: #b91c1c;
  border-color: rgba(248,113,113,.2);
}

.reader-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.reader-modal-actions .btn {
  min-width: 140px;
}

@media (max-width: 640px) {
  .rag-toolbar {
    grid-template-columns: 1fr;
  }
  .reader-summary,
  .reader-grid {
    grid-template-columns: 1fr;
  }
  .rag-pagination {
    align-items: flex-start;
  }
  .reader-card-head {
    flex-direction: column;
    align-items: flex-start;
  }
  .reader-modal-card {
    border-radius: 22px;
    padding: 1rem;
  }
  .reader-modal-steps {
    grid-template-columns: 1fr;
  }
  .reader-modal-actions {
    flex-direction: column-reverse;
  }
  .reader-modal-actions .btn {
    min-width: 0;
    width: 100%;
  }
}

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

/* ── Responsive ── */

/* Tablet: collapse sidebar by default */
@media (max-width: 1024px) {
  body.sidebar-open:not(.sidebar-mobile-open) .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-w);
  }
  body.sidebar-open:not(.sidebar-mobile-open) .app-layout {
    margin-left: 0;
  }
  body.sidebar-open.sidebar-mobile-open .sidebar {
    transform: translateX(0);
    width: var(--sidebar-w);
  }
  body.sidebar-open.sidebar-mobile-open .app-layout {
    margin-left: 0;
  }
  .topbar { display: flex !important; }
}

@media (max-width: 640px) {
  .login-shell {
    padding: 2rem 1.25rem;
    min-height: 100vh;
  }
  .login-card { border-radius: var(--radius-lg); padding: 1.35rem; }
  .home { padding: 1rem; }
  .page-header { flex-direction: column; }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .rag-hero {
    flex-direction: column;
  }
}

/* ----------------------------------------------------------
   TOKENS
   ---------------------------------------------------------- */
:root {
  /* Brand */
  --primary:        #4f6ef7;
  --primary-hover:  #3b5be0;
  --primary-light:  #eef1fe;
  --primary-text:   #ffffff;

  /* Surface */
  --bg:             #f4f6fa;
  --surface:        #ffffff;
  --surface-raised: #ffffff;
  --border:         #e2e8f0;
  --border-focus:   #4f6ef7;

  /* Text */
  --text:           #1a202c;
  --text-secondary: #64748b;
  --text-disabled:  #a0aec0;

  /* State colors */
  --success:        #22c55e;
  --success-light:  #f0fdf4;
  --success-border: #bbf7d0;
  --danger:         #ef4444;
  --danger-hover:   #dc2626;
  --danger-light:   #fef2f2;
  --danger-border:  #fecaca;
  --warning:        #f59e0b;
  --warning-light:  #fffbeb;
  --warning-border: #fde68a;
  --info:           #3b82f6;
  --info-light:     #eff6ff;
  --info-border:    #bfdbfe;

  /* Neutral scale */
  --gray-50:  #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;

  /* Shape */
  --radius-sm:   6px;
  --radius:      10px;
  --radius-lg:   16px;
  --radius-xl:   24px;
  --radius-full: 999px;

  /* Shadow */
  --shadow-xs: 0 1px 2px rgba(0,0,0,.05);
  --shadow-sm: 0 1px 4px rgba(0,0,0,.07), 0 0 0 1px rgba(0,0,0,.03);
  --shadow:    0 4px 16px rgba(0,0,0,.08), 0 0 0 1px rgba(0,0,0,.03);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.12), 0 0 0 1px rgba(0,0,0,.04);
  --shadow-xl: 0 24px 64px rgba(0,0,0,.16);

  /* Motion */
  --transition:    150ms ease;
  --transition-md: 220ms ease;
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  font-size: 0.9375rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ----------------------------------------------------------
   TYPOGRAPHY
   ---------------------------------------------------------- */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: var(--text);
}
h1 { font-size: clamp(2rem, 5vw, 3.5rem); letter-spacing: -0.04em; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; }
h5 { font-size: 0.9rem; }
h6 { font-size: 0.8rem; }

p { color: var(--text-secondary); line-height: 1.65; }
p + p { margin-top: 0.75rem; }

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover { color: var(--primary-hover); text-decoration: underline; }

small  { font-size: 0.8125rem; color: var(--text-secondary); }
strong { font-weight: 600; color: var(--text); }

code, pre {
  font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 0.875em;
}
code {
  background: var(--gray-100);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.1em 0.4em;
  color: var(--primary-hover);
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

/* ----------------------------------------------------------
   LAYOUT HELPERS
   ---------------------------------------------------------- */
.container {
  width: min(1200px, calc(100% - 2rem));
  margin-inline: auto;
}
.shell {
  width: min(1120px, calc(100% - 2rem));
  margin-inline: auto;
  padding: 3rem 0 4rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
}
.card + .card { margin-top: 1rem; }

.flex          { display: flex; }
.flex-col      { flex-direction: column; }
.items-center  { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.hidden { display: none !important; }

/* ----------------------------------------------------------
   BADGE / TAG
   ---------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1;
  white-space: nowrap;
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid rgba(79,110,247,.2);
}
.badge-success { background: var(--success-light); color: #16a34a;            border-color: var(--success-border); }
.badge-danger  { background: var(--danger-light);  color: var(--danger-hover); border-color: var(--danger-border);  }
.badge-warning { background: var(--warning-light); color: #b45309;            border-color: var(--warning-border); }
.badge-info    { background: var(--info-light);    color: #1d4ed8;            border-color: var(--info-border);    }
.badge-neutral { background: var(--gray-100);      color: var(--gray-600);    border-color: var(--gray-200);       }
.badge-lg { padding: 0.35rem 0.85rem; font-size: 0.8125rem; }

/* ----------------------------------------------------------
   BUTTONS
   ---------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.5625rem 1.125rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: 600 0.9rem/1 "Inter", system-ui, sans-serif;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), box-shadow var(--transition),
              transform var(--transition);
  -webkit-user-select: none;
  user-select: none;
  -webkit-appearance: none;
  appearance: none;
}
.btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* Sizes */
.btn-xs   { padding: 0.3rem 0.65rem; font-size: 0.78rem; border-radius: var(--radius-sm); }
.btn-sm   { padding: 0.45rem 0.875rem; font-size: 0.84rem; }
.btn-lg   { padding: 0.75rem 1.5rem; font-size: 1rem; border-radius: var(--radius-lg); }
.btn-xl   { padding: 0.9rem 2rem; font-size: 1.05rem; border-radius: var(--radius-lg); }
.btn-full { width: 100%; }
.btn-icon { padding: 0.55rem; border-radius: var(--radius); min-width: 2.25rem; }
.btn-icon.btn-sm { padding: 0.4rem; min-width: 1.875rem; }
.btn-icon.btn-lg { padding: 0.7rem; min-width: 2.75rem; }

/* Primary */
.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 1px 3px rgba(79,110,247,.35);
}
.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(79,110,247,.35);
  transform: translateY(-1px);
  text-decoration: none;
  color: #fff;
}

/* Secondary */
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover {
  background: var(--gray-50);
  border-color: var(--gray-300);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
  text-decoration: none;
}

/* Danger */
.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
  box-shadow: 0 1px 3px rgba(239,68,68,.3);
}
.btn-danger:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
  box-shadow: 0 4px 12px rgba(239,68,68,.3);
  transform: translateY(-1px);
  color: #fff;
  text-decoration: none;
}

/* Success */
.btn-success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
  box-shadow: 0 1px 3px rgba(34,197,94,.3);
}
.btn-success:hover {
  background: #16a34a;
  border-color: #16a34a;
  box-shadow: 0 4px 12px rgba(34,197,94,.3);
  transform: translateY(-1px);
  color: #fff;
  text-decoration: none;
}

/* Ghost */
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--gray-100);
  color: var(--text);
  text-decoration: none;
}

/* Link-style */
.btn-link {
  background: transparent;
  color: var(--primary);
  border-color: transparent;
  padding-inline: 0.25rem;
  font-weight: 500;
}
.btn-link:hover { color: var(--primary-hover); text-decoration: underline; }

/* Outline variants */
.btn-outline-primary {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary);
}
.btn-outline-primary:hover { background: var(--primary-light); text-decoration: none; }

.btn-outline-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-outline-danger:hover { background: var(--danger-light); text-decoration: none; }

/* Loading */
.btn.loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.loading::after {
  content: "";
  position: absolute;
  width: 1em; height: 1em;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------
   FORMS — INPUTS, TEXTAREA, SELECT
   ---------------------------------------------------------- */
.form-group { display: grid; gap: 0.4rem; }
.form-group + .form-group { margin-top: 1rem; }

label, .label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
}
.label-optional { font-weight: 400; color: var(--text-secondary); font-size: 0.8rem; }

.form-error { font-size: 0.8rem; color: var(--danger); margin-top: 0.25rem; display: flex; align-items: center; gap: 0.3rem; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="search"],
input[type="date"],
input[type="time"],
textarea,
select {
  display: block;
  width: 100%;
  padding: 0.5625rem 0.875rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.5;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
input::placeholder, textarea::placeholder { color: var(--gray-400); }
input:hover:not(:disabled),
textarea:hover:not(:disabled),
select:hover:not(:disabled) { border-color: var(--gray-300); }

input:focus, textarea:focus, select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(79,110,247,.15);
}
input:disabled, textarea:disabled, select:disabled {
  background: var(--gray-50);
  color: var(--text-disabled);
  cursor: not-allowed;
}
input.is-invalid, textarea.is-invalid, select.is-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(239,68,68,.12);
}
input.is-valid, textarea.is-valid, select.is-valid {
  border-color: var(--success);
  box-shadow: 0 0 0 3px rgba(34,197,94,.12);
}

textarea { resize: vertical; min-height: 6rem; }

.input-sm { padding: 0.375rem 0.7rem; font-size: 0.84rem; border-radius: var(--radius-sm); }
.input-lg { padding: 0.75rem 1.1rem; font-size: 1rem; border-radius: var(--radius-lg); }

.input-group { position: relative; }
.input-group .input-icon-left  { position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%); color: var(--gray-400); pointer-events: none; }
.input-group .input-icon-right { position: absolute; right: 0.75rem; top: 50%; transform: translateY(-50%); color: var(--gray-400); }
.input-group input.has-left-icon  { padding-left: 2.5rem; }
.input-group input.has-right-icon { padding-right: 2.5rem; }

/* ----------------------------------------------------------
   CHECKBOX
   ---------------------------------------------------------- */
.check {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  user-select: none;
  font-size: 0.9rem;
  color: var(--text);
}
.check input { display: none; }
.check__box {
  width: 1.125rem;
  height: 1.125rem;
  min-width: 1.125rem;
  border: 1.5px solid var(--gray-300);
  border-radius: 5px;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}
.check__box::after {
  content: "";
  width: 5px; height: 9px;
  border: 2px solid #fff;
  border-top: none; border-left: none;
  transform: rotate(45deg) translate(-1px,-1px);
  opacity: 0;
  transition: opacity var(--transition);
}
.check input:checked ~ .check__box {
  background: var(--primary);
  border-color: var(--primary);
}
.check input:checked ~ .check__box::after { opacity: 1; }
.check:hover .check__box { border-color: var(--primary); }
.check input:focus-visible ~ .check__box { box-shadow: 0 0 0 3px rgba(79,110,247,.2); }
.check input:disabled ~ .check__box,
.check input:disabled ~ span { opacity: 0.5; cursor: not-allowed; }

/* ----------------------------------------------------------
   RADIO (CIRCLE)
   ---------------------------------------------------------- */
.radio {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  user-select: none;
  font-size: 0.9rem;
  color: var(--text);
}
.radio input { display: none; }
.radio__circle {
  width: 1.125rem;
  height: 1.125rem;
  min-width: 1.125rem;
  border: 1.5px solid var(--gray-300);
  border-radius: 50%;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--transition);
}
.radio__circle::after {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--primary);
  transform: scale(0);
  transition: transform var(--transition);
}
.radio input:checked ~ .radio__circle { border-color: var(--primary); }
.radio input:checked ~ .radio__circle::after { transform: scale(1); }
.radio:hover .radio__circle { border-color: var(--primary); }
.radio input:focus-visible ~ .radio__circle { box-shadow: 0 0 0 3px rgba(79,110,247,.2); }
.radio input:disabled ~ .radio__circle,
.radio input:disabled ~ span { opacity: 0.5; cursor: not-allowed; }

/* Segmented radio group */
.radio-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--gray-50);
}
.radio-group label {
  padding: 0.45rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  border-right: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.radio-group label:last-child { border-right: none; }
.radio-group input[type="radio"] { display: none; }
.radio-group label:has(input:checked) {
  background: var(--primary);
  color: #fff;
}
.radio-group label:hover:not(:has(input:checked)) { background: var(--gray-100); color: var(--text); }

/* ----------------------------------------------------------
   TOGGLE / SWITCH
   ---------------------------------------------------------- */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  cursor: pointer;
  user-select: none;
  font-size: 0.9rem;
  color: var(--text);
}
.toggle input { display: none; }
.toggle__track {
  position: relative;
  width: 2.5rem;
  height: 1.375rem;
  background: var(--gray-300);
  border-radius: var(--radius-full);
  transition: background var(--transition-md);
  flex-shrink: 0;
}
.toggle__track::after {
  content: "";
  position: absolute;
  top: 0.1875rem; left: 0.1875rem;
  width: 1rem; height: 1rem;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
  transition: transform var(--transition-md);
}
.toggle input:checked ~ .toggle__track { background: var(--primary); }
.toggle input:checked ~ .toggle__track::after { transform: translateX(1.125rem); }
.toggle input:focus-visible ~ .toggle__track { box-shadow: 0 0 0 3px rgba(79,110,247,.25); }
.toggle input:disabled ~ .toggle__track,
.toggle input:disabled ~ span { opacity: 0.45; cursor: not-allowed; }

.toggle-sm .toggle__track { width: 2rem; height: 1.125rem; }
.toggle-sm .toggle__track::after { width: 0.75rem; height: 0.75rem; }
.toggle-sm input:checked ~ .toggle__track::after { transform: translateX(0.875rem); }

.toggle-lg .toggle__track { width: 3.25rem; height: 1.75rem; }
.toggle-lg .toggle__track::after { width: 1.375rem; height: 1.375rem; }
.toggle-lg input:checked ~ .toggle__track::after { transform: translateX(1.5rem); }

.toggle-success input:checked ~ .toggle__track { background: var(--success); }
.toggle-danger  input:checked ~ .toggle__track { background: var(--danger); }

/* ----------------------------------------------------------
   SELECT / DROPDOWN
   ---------------------------------------------------------- */
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.25rem;
  cursor: pointer;
}

.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 11rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 0.35rem;
  z-index: 200;
  animation: fadeDown 0.12s ease;
}
.dropdown-menu.right { left: auto; right: 0; }
@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  font: 500 0.875rem/1.4 inherit;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
}
.dropdown-item:hover { background: var(--gray-100); text-decoration: none; }
.dropdown-item.active { background: var(--primary-light); color: var(--primary); }
.dropdown-item.danger  { color: var(--danger); }
.dropdown-item.danger:hover { background: var(--danger-light); }
.dropdown-item:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

.dropdown-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.35rem 0;
}
.dropdown-header {
  padding: 0.3rem 0.75rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

/* ----------------------------------------------------------
   TABS
   ---------------------------------------------------------- */
.tabs {
  display: flex;
  gap: 0.15rem;
  border-bottom: 2px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  padding: 0.65rem 1.1rem;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  background: none;
  font: 500 0.9rem/1 inherit;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
}
.tab:hover { color: var(--text); background: var(--gray-50); text-decoration: none; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; border-radius: var(--radius-sm); }
.tab .tab-badge {
  background: var(--gray-200); color: var(--gray-600);
  border-radius: var(--radius-full);
  padding: 0.1rem 0.45rem;
  font-size: 0.72rem; font-weight: 600; line-height: 1.4;
}
.tab.active .tab-badge { background: var(--primary-light); color: var(--primary); }

.tab-content { padding-top: 1.25rem; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Pill tabs */
.tabs-pills {
  border-bottom: none;
  background: var(--gray-100);
  border-radius: var(--radius-lg);
  padding: 0.3rem;
  gap: 0.35rem;
}
.tabs-pills .tab {
  border-bottom: none; margin-bottom: 0;
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
}
.tabs-pills .tab:hover { background: rgba(0,0,0,.04); }
.tabs-pills .tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  border-bottom-color: transparent;
}

/* ----------------------------------------------------------
   TABLE
   ---------------------------------------------------------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
table, .table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  background: var(--surface);
}
thead { background: var(--gray-50); border-bottom: 1px solid var(--border); }
th {
  padding: 0.7rem 1rem;
  text-align: left;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-secondary);
  white-space: nowrap;
}
td {
  padding: 0.75rem 1rem;
  color: var(--text);
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--gray-50); }
tbody tr.selected td { background: var(--primary-light); }

th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--text); background: var(--gray-100); }
th.sort-asc::after  { content: " ↑"; opacity: 0.7; }
th.sort-desc::after { content: " ↓"; opacity: 0.7; }

.table-striped tbody tr:nth-child(even) td { background: var(--gray-50); }
.table-striped tbody tr:nth-child(even):hover td { background: var(--gray-100); }
.table-sm th, .table-sm td { padding: 0.45rem 0.75rem; }

/* ----------------------------------------------------------
   PAGINATION
   ---------------------------------------------------------- */
.pagination {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
}
.page-item { display: inline-flex; }
.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.125rem;
  height: 2.125rem;
  padding: 0 0.625rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-secondary);
  font: 500 0.875rem/1 inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), box-shadow var(--transition);
  box-shadow: var(--shadow-xs);
}
.page-link:hover {
  background: var(--gray-100);
  color: var(--text);
  border-color: var(--gray-300);
  text-decoration: none;
}
.page-item.active .page-link {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(79,110,247,.3);
}
.page-item.disabled .page-link {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}
.pagination-sm .page-link {
  min-width: 1.75rem;
  height: 1.75rem;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

/* ----------------------------------------------------------
   MODAL
   ---------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.4);
  backdrop-filter: blur(4px);
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: backdropIn 0.18s ease;
}
@keyframes backdropIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 30rem;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  animation: modalIn 0.2s cubic-bezier(.34,1.2,.64,1);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-sm { max-width: 22rem; }
.modal-lg { max-width: 42rem; }
.modal-xl { max-width: 58rem; }

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.35rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3, .modal-header h4 { margin: 0; font-size: 1.05rem; font-weight: 700; }
.modal-close {
  background: none;
  border: none;
  width: 2rem; height: 2rem;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--gray-400);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
  font-size: 1.1rem; line-height: 1;
}
.modal-close:hover { background: var(--gray-100); color: var(--text); }
.modal-body { padding: 1.25rem 1.5rem; }
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
  padding: 1rem 1.5rem 1.35rem;
  border-top: 1px solid var(--border);
}

/* ----------------------------------------------------------
   SWEETALERT2 OVERRIDES
   ---------------------------------------------------------- */
.swal2-popup {
  font-family: "Inter", system-ui, sans-serif !important;
  border-radius: var(--radius-xl) !important;
  border: 1px solid var(--border) !important;
  box-shadow: var(--shadow-xl) !important;
  padding: 2rem 2rem 1.5rem !important;
  background: var(--surface) !important;
  color: var(--text) !important;
  max-width: 26rem !important;
}
.swal2-title {
  font-size: 1.15rem !important;
  font-weight: 700 !important;
  letter-spacing: -0.02em !important;
  color: var(--text) !important;
  padding: 0 !important;
  margin-bottom: 0.5rem !important;
}
.swal2-html-container {
  font-size: 0.9rem !important;
  color: var(--text-secondary) !important;
  line-height: 1.6 !important;
  margin: 0 !important;
  padding: 0 !important;
}
.swal2-icon { border-width: 2px !important; margin: 0 auto 1.25rem !important; }
.swal2-icon.swal2-success { border-color: var(--success) !important; color: var(--success) !important; }
.swal2-icon.swal2-error   { border-color: var(--danger) !important;  color: var(--danger) !important;  }
.swal2-icon.swal2-warning { border-color: var(--warning) !important; color: var(--warning) !important; }
.swal2-icon.swal2-info    { border-color: var(--info) !important;    color: var(--info) !important;    }
.swal2-icon.swal2-question{ border-color: var(--primary) !important; color: var(--primary) !important; }
.swal2-icon.swal2-success .swal2-success-ring { border-color: rgba(34,197,94,.3) !important; }
.swal2-success-circular-line-left,
.swal2-success-circular-line-right,
.swal2-success-fix { background: var(--surface) !important; }
.swal2-icon.swal2-success [class^="swal2-success-line"] { background: var(--success) !important; }

.swal2-actions { margin-top: 1.5rem !important; gap: 0.5rem !important; flex-wrap: wrap !important; }
.swal2-confirm {
  border-radius: var(--radius) !important;
  padding: 0.5625rem 1.25rem !important;
  font: 600 0.9rem/1 "Inter", sans-serif !important;
  box-shadow: none !important;
  background: var(--primary) !important;
  color: #fff !important;
  border: 1px solid var(--primary) !important;
  transition: background var(--transition), box-shadow var(--transition) !important;
}
.swal2-confirm:hover {
  background: var(--primary-hover) !important;
  box-shadow: 0 4px 12px rgba(79,110,247,.35) !important;
}
.swal2-deny {
  border-radius: var(--radius) !important;
  padding: 0.5625rem 1.25rem !important;
  font: 600 0.9rem/1 "Inter", sans-serif !important;
  box-shadow: none !important;
  background: var(--danger) !important;
  color: #fff !important;
  border: 1px solid var(--danger) !important;
}
.swal2-deny:hover { background: var(--danger-hover) !important; }
.swal2-cancel {
  border-radius: var(--radius) !important;
  padding: 0.5625rem 1.25rem !important;
  font: 600 0.9rem/1 "Inter", sans-serif !important;
  box-shadow: none !important;
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
}
.swal2-cancel:hover { background: var(--gray-100) !important; }

.swal2-input, .swal2-textarea, .swal2-select {
  font-family: "Inter", sans-serif !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  font-size: 0.9rem !important;
  color: var(--text) !important;
  box-shadow: none !important;
}
.swal2-input:focus, .swal2-textarea:focus {
  border-color: var(--border-focus) !important;
  box-shadow: 0 0 0 3px rgba(79,110,247,.15) !important;
  outline: none !important;
}
.swal2-validation-message {
  background: var(--danger-light) !important;
  color: var(--danger) !important;
  border-radius: var(--radius-sm) !important;
  font-size: 0.85rem !important;
  border: 1px solid var(--danger-border) !important;
}
.swal2-close {
  color: var(--gray-400) !important;
  font-size: 1.5rem !important;
  border-radius: var(--radius) !important;
}
.swal2-close:hover { color: var(--text) !important; background: var(--gray-100) !important; }

.swal2-toast {
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-lg) !important;
  padding: 0.75rem 1.25rem !important;
}
.swal2-toast .swal2-title { font-size: 0.9rem !important; }

/* ----------------------------------------------------------
   ALERTS (inline)
   ---------------------------------------------------------- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 0.9rem;
  line-height: 1.5;
}
.alert-icon  { font-size: 1.1rem; flex-shrink: 0; margin-top: 0.05rem; }
.alert-title { font-weight: 600; margin-bottom: 0.15rem; }
.alert-info    { background: var(--info-light);    border-color: var(--info-border);    color: #1e40af; }
.alert-success { background: var(--success-light); border-color: var(--success-border); color: #15803d; }
.alert-warning { background: var(--warning-light); border-color: var(--warning-border); color: #92400e; }
.alert-danger  { background: var(--danger-light);  border-color: var(--danger-border);  color: #b91c1c; }

/* ----------------------------------------------------------
   STATUS (inline form feedback)
   ---------------------------------------------------------- */
.status { min-height: 1.4em; font-size: 0.9rem; color: var(--text-secondary); }
.status.ok      { color: #16a34a; }
.status.error   { color: var(--danger); }
.status.warning { color: #b45309; }

/* ----------------------------------------------------------
   SPINNER / SKELETON
   ---------------------------------------------------------- */
.spinner {
  display: inline-block;
  width: 1.5rem; height: 1.5rem;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}
.spinner-sm { width: 1rem; height: 1rem; border-width: 2px; }
.spinner-lg { width: 2.5rem; height: 2.5rem; border-width: 3px; }

.skeleton {
  background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 37%, var(--gray-100) 63%);
  background-size: 400% 100%;
  border-radius: var(--radius);
  animation: shimmer 1.4s ease infinite;
}
@keyframes shimmer { from { background-position: 100% 50%; } to { background-position: 0 50%; } }

/* ----------------------------------------------------------
   AVATAR
   ---------------------------------------------------------- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary);
  overflow: hidden;
  flex-shrink: 0;
  font-size: 0.875rem;
  width: 2.25rem; height: 2.25rem;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 1.75rem; height: 1.75rem; font-size: 0.75rem; }
.avatar-lg { width: 3rem;    height: 3rem;    font-size: 1.1rem; }
.avatar-xl { width: 4rem;    height: 4rem;    font-size: 1.4rem; }

/* ----------------------------------------------------------
   DIVIDER
   ---------------------------------------------------------- */
.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
}
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* ----------------------------------------------------------
   TOOLTIP
   ---------------------------------------------------------- */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--gray-900);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 500;
}
[data-tooltip]:hover::after { opacity: 1; }

/* ----------------------------------------------------------
   APP-SPECIFIC: PANEL / LAYOUT
   ---------------------------------------------------------- */
.panel-grid {
  display: grid;
  grid-template-columns: minmax(0, 520px);
  gap: 1.125rem;
}
.panel, .home-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}
.panel { padding: 1.5rem; }
.panel-login { width: 100%; }

.panel-head, .output-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.125rem;
}
.panel-head h2, .output-head h2 { margin: 0; font-size: 1.15rem; }
.panel-head span { color: var(--text-secondary); font-size: 0.85rem; }

.form { display: grid; gap: 1rem; }
.login-google-wrap {
  gap: 0.85rem;
}
.google-signin-button {
  width: 100%;
  max-width: 320px;
  min-height: 44px;
}
.form label {
  display: grid;
  gap: 0.4rem;
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 500;
}
.form input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0.5625rem 0.875rem;
  font: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  -webkit-appearance: none;
  appearance: none;
}
.form input::placeholder { color: var(--gray-400); }
.form input:hover:not(:disabled) { border-color: var(--gray-300); }
.form input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(79,110,247,.15);
}
.form button {
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius);
  padding: 0.5625rem 1.125rem;
  font: 600 0.9rem/1 inherit;
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition), transform var(--transition);
  box-shadow: 0 1px 3px rgba(79,110,247,.3);
}
.form button:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(79,110,247,.3);
  transform: translateY(-1px);
}
.form button:active { transform: translateY(0); }

/* ----------------------------------------------------------
   APP-SPECIFIC: HERO
   ---------------------------------------------------------- */
.hero { max-width: 640px; margin-bottom: 2rem; }
.hero h1 {
  margin: 0;
  font-size: clamp(2rem, 5.5vw, 3.8rem);
  line-height: 1.05;
  letter-spacing: -0.04em;
  color: var(--text);
}
.hero p {
  margin: 1rem 0 0;
  max-width: 54ch;
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1.65;
}
.hero-links {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}
.hero-links a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  padding: 0.5625rem 1.125rem;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}
.hero-links a:first-child {
  background: var(--primary);
  color: #fff;
  border: 1px solid var(--primary);
  box-shadow: 0 1px 3px rgba(79,110,247,.35);
}
.hero-links a:first-child:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(79,110,247,.35);
  transform: translateY(-1px);
  text-decoration: none;
}
.hero-links a:not(:first-child) {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}
.hero-links a:not(:first-child):hover {
  background: var(--gray-50);
  border-color: var(--gray-300);
  transform: translateY(-1px);
  text-decoration: none;
}

/* ----------------------------------------------------------
   APP-SPECIFIC: HOME
   ---------------------------------------------------------- */
.home { display: grid; gap: 1.125rem; }
.home-card { padding: 1.5rem; }
.home-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
}
.home-kicker {
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.72rem;
  font-weight: 700;
  margin-bottom: 0.6rem;
}
.home h2, .home h3 { margin: 0; }
.home p { margin: 0.75rem 0 0; color: var(--text-secondary); line-height: 1.6; }

.home-actions, .home-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.625rem;
}
.home-actions a, .home-links a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  font: 600 0.875rem/1 inherit;
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}
.home-actions a:hover, .home-links a:hover {
  background: var(--gray-50);
  border-color: var(--gray-300);
  transform: translateY(-1px);
  text-decoration: none;
}
.home-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  font: 600 0.875rem/1 inherit;
  border: 1px solid var(--danger);
  background: var(--danger);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(239,68,68,.25);
  transition: background var(--transition), box-shadow var(--transition), transform var(--transition);
}
.home-actions button:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
  box-shadow: 0 4px 12px rgba(239,68,68,.25);
  transform: translateY(-1px);
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.125rem;
}
.home-text { font-size: 0.9rem; color: var(--text-secondary); }

/* ----------------------------------------------------------
   RESPONSIVE
   ---------------------------------------------------------- */
@media (max-width: 880px) {
  .panel-grid { grid-template-columns: 1fr; }
  .home-hero  { flex-direction: column; align-items: flex-start; }
  .home-grid  { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .shell { width: calc(100% - 1.5rem); padding-top: 1.5rem; }
  .panel, .home-card { border-radius: var(--radius-lg); }
  .modal { border-radius: var(--radius-lg); }
  .tabs  { gap: 0; }
  .tab   { padding: 0.55rem 0.75rem; font-size: 0.85rem; }
  th, td { padding: 0.6rem 0.75rem; }
}
