/* ==========================================================================
   Sibyl - Design System CSS
   Dark Theme SaaS Admin Panel
   ========================================================================== */

/* ==========================================================================
   1. CSS Variables
   ========================================================================== */

:root {
  /* Backgrounds */
  --bg-primary: #0f1419;
  --bg-secondary: #1a2332;
  --bg-tertiary: #243447;
  --bg-card: #1e2d3d;
  --bg-hover: #2a3f54;
  --bg-input: #1a2332;

  /* Text */
  --text-primary: #ffffff;
  --text-secondary: #8899a6;
  --text-muted: #5c6d7e;
  --text-placeholder: #4a5568;

  /* Accents */
  --accent-primary: #1da1f2;
  --accent-secondary: #17bf63;
  --accent-warning: #ffad1f;
  --accent-danger: #e0245e;
  --accent-purple: #794bc4;

  /* Borders */
  --border-color: #2f3e50;
  --border-light: #38444d;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);

  /* Layout */
  --sidebar-width: 240px;
  --header-height: 60px;

  /* Border Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 50%;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

/* ==========================================================================
   2. Reset / Base
   ========================================================================== */

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: var(--accent-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: #4db5f5;
}

img {
  max-width: 100%;
  display: block;
}

ul, ol {
  list-style: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
}

h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
h4 { font-size: 16px; }

/* Scrollbar - Webkit */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) var(--bg-primary);
}

/* ==========================================================================
   3. Layout
   ========================================================================== */

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.header {
  height: var(--header-height);
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.main-container {
  display: flex;
  height: calc(100vh - var(--header-height));
  flex: 1;
}

.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}

.content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6);
}

/* ==========================================================================
   4. Header
   ========================================================================== */

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.header-left .logo img {
  width: 32px;
  height: 32px;
}

.header-left .logo-text {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

.header-center {
  display: flex;
  align-items: center;
  flex: 1;
  justify-content: center;
  padding: 0 var(--space-6);
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.header-right .user-menu {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  transition: background-color var(--transition-fast);
}

.header-right .user-menu:hover {
  background-color: var(--bg-hover);
}

.header-right .user-menu .user-name {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ==========================================================================
   5. Sidebar Navigation
   ========================================================================== */

.sidebar-nav {
  padding: var(--space-3) 0;
  flex: 1;
}

.sidebar-section {
  padding: var(--space-4) var(--space-4) var(--space-2);
}

.sidebar-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  margin: 1px var(--space-2);
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition-fast);
  cursor: pointer;
  text-decoration: none;
}

.sidebar-nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.sidebar-nav-item:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-nav-item.active {
  background-color: rgba(29, 161, 242, 0.15);
  color: var(--accent-primary);
}

.sidebar-nav-item.active svg {
  color: var(--accent-primary);
}

.sidebar-bottom {
  padding: var(--space-4);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.sidebar-bottom .sidebar-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background-color: var(--bg-tertiary);
  flex-shrink: 0;
}

.sidebar-bottom .sidebar-user-info {
  flex: 1;
  min-width: 0;
}

.sidebar-bottom .sidebar-user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-bottom .sidebar-user-email {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-bottom .sign-out-link {
  font-size: 12px;
  color: var(--text-muted);
  transition: color var(--transition-fast);
}

.sidebar-bottom .sign-out-link:hover {
  color: var(--accent-danger);
}

/* ==========================================================================
   6. Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
  height: 38px;
}

.btn:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

.btn-primary {
  background-color: var(--accent-primary);
  color: #ffffff;
}

.btn-primary:hover {
  background-color: #1a91da;
}

.btn-primary:active {
  background-color: #1681bf;
}

.btn-secondary {
  background-color: transparent;
  color: var(--text-secondary);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-light);
}

.btn-danger {
  background-color: var(--accent-danger);
  color: #ffffff;
}

.btn-danger:hover {
  background-color: #c91f52;
}

.btn-ghost {
  background-color: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: transparent;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.btn-icon-sm {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: transparent;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.btn-icon-sm:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.btn-sm {
  height: 30px;
  padding: var(--space-1) var(--space-3);
  font-size: 12px;
}

.btn:disabled,
.btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn.loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

.btn.loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: var(--radius-full);
  animation: spin 0.6s linear infinite;
}

/* ==========================================================================
   7. Forms
   ========================================================================== */

.form-group {
  margin-bottom: var(--space-4);
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.form-control {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  height: 40px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-control::placeholder {
  color: var(--text-placeholder);
}

.form-control:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(29, 161, 242, 0.15);
}

.form-control:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

textarea.form-control {
  height: auto;
  min-height: 100px;
  resize: vertical;
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%238899a6' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-helper {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: var(--space-1);
}

.form-error {
  font-size: 12px;
  color: var(--accent-danger);
  margin-top: var(--space-1);
}

.form-control.is-error {
  border-color: var(--accent-danger);
}

.form-control.is-error:focus {
  box-shadow: 0 0 0 3px rgba(224, 36, 94, 0.15);
}

/* ==========================================================================
   8. Cards
   ========================================================================== */

.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  transition: all var(--transition-normal);
}

.card:hover {
  border-color: var(--border-light);
}

.card-clickable {
  cursor: pointer;
}

.card-clickable:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.card-header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h3,
.card-header h4 {
  font-size: 15px;
  font-weight: 600;
}

.card-body {
  padding: var(--space-5);
}

.card-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
}

/* ==========================================================================
   9. Tables
   ========================================================================== */

.table-container {
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
}

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

.table th {
  background-color: var(--bg-secondary);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-color);
  font-size: 14px;
  color: var(--text-secondary);
  vertical-align: middle;
}

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

.table tr:hover td {
  background-color: var(--bg-hover);
}

.table .col-actions {
  text-align: right;
  white-space: nowrap;
}

/* ==========================================================================
   10. Badges
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 20px;
  background-color: rgba(255, 173, 31, 0.15);
  color: var(--accent-warning);
  line-height: 1.6;
}

.badge-primary {
  background-color: rgba(29, 161, 242, 0.15);
  color: var(--accent-primary);
}

.badge-success {
  background-color: rgba(23, 191, 99, 0.15);
  color: var(--accent-secondary);
}

.badge-danger {
  background-color: rgba(224, 36, 94, 0.15);
  color: var(--accent-danger);
}

.badge-muted {
  background-color: rgba(92, 109, 126, 0.15);
  color: var(--text-muted);
}

/* ==========================================================================
   11. Tags
   ========================================================================== */

.tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.tag-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: var(--radius-full);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  transition: all var(--transition-fast);
  padding: 0;
}

.tag-remove:hover {
  background-color: var(--accent-danger);
  color: #ffffff;
}

/* ==========================================================================
   12. Modal
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: scale(0.95);
  transition: transform var(--transition-normal);
}

.modal-overlay.open .modal {
  transform: scale(1);
}

/* When a <form> wraps body+footer it must propagate the flex column
   so .modal-body can actually scroll within max-height: 90vh. */
.modal > form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.modal-sm {
  max-width: 400px;
}

.modal-lg {
  max-width: 720px;
}

.modal-xl {
  max-width: 960px;
}

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

.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 20px;
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.modal-body {
  padding: var(--space-5);
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

/* ==========================================================================
   13. Toast
   ========================================================================== */

.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--accent-primary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 300px;
  max-width: 480px;
  font-size: 14px;
  color: var(--text-primary);
  pointer-events: auto;
  animation: slideInRight 0.3s ease forwards;
}

.toast-success {
  border-left-color: var(--accent-secondary);
}

.toast-error {
  border-left-color: var(--accent-danger);
}

.toast-warning {
  border-left-color: var(--accent-warning);
}

.toast-info {
  border-left-color: var(--accent-primary);
}

.toast-message {
  flex: 1;
}

.toast-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: var(--space-1);
  transition: color var(--transition-fast);
}

.toast-close:hover {
  color: var(--text-primary);
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ==========================================================================
   14. Avatar
   ========================================================================== */

.avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background-color: var(--bg-tertiary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  flex-shrink: 0;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-xs {
  width: 24px;
  height: 24px;
  font-size: 10px;
}

.avatar-sm {
  width: 28px;
  height: 28px;
  font-size: 12px;
}

.avatar-lg {
  width: 48px;
  height: 48px;
  font-size: 18px;
}

.avatar-xl {
  width: 64px;
  height: 64px;
  font-size: 24px;
}

/* ==========================================================================
   15. Dropdown
   ========================================================================== */

.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 500;
  min-width: 180px;
  padding: var(--space-2) 0;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: all var(--transition-fast);
}

.dropdown.open .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.dropdown-item:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.dropdown-item.danger {
  color: var(--accent-danger);
}

.dropdown-item.danger:hover {
  background-color: rgba(224, 36, 94, 0.1);
}

.dropdown-divider {
  height: 1px;
  background-color: var(--border-color);
  margin: var(--space-2) 0;
}

/* ==========================================================================
   16. Empty State
   ========================================================================== */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-10) var(--space-6);
  text-align: center;
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  margin-bottom: var(--space-5);
  color: var(--text-muted);
  opacity: 0.5;
}

.empty-state-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.empty-state-description {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 360px;
  margin-bottom: var(--space-5);
}

/* ==========================================================================
   17. KPI Cards
   ========================================================================== */

.kpi-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.kpi-card-content {
  flex: 1;
}

.kpi-card-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
  margin-bottom: var(--space-1);
}

.kpi-card-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

.kpi-card-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(29, 161, 242, 0.1);
  color: var(--accent-primary);
  flex-shrink: 0;
}

.kpi-card-delta {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: 12px;
  font-weight: 600;
}

.kpi-card-delta.positive {
  color: var(--accent-secondary);
}

.kpi-card-delta.negative {
  color: var(--accent-danger);
}

/* ==========================================================================
   18. Page Headers
   ========================================================================== */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-6);
  gap: var(--space-4);
}

.page-header-info {
  flex: 1;
}

.page-header-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.page-header-subtitle {
  font-size: 14px;
  color: var(--text-muted);
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

/* ==========================================================================
   19. Utilities
   ========================================================================== */

.text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-center { text-align: center; }
.text-right { text-align: right; }

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent-primary); }
.text-success { color: var(--accent-secondary); }
.text-danger { color: var(--accent-danger); }
.text-warning { color: var(--accent-warning); }

.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-normal { font-weight: 400; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }

.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-5 { gap: var(--space-5); }
.gap-6 { gap: var(--space-6); }

.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }

.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-5 { margin-bottom: var(--space-5); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }

.p-1 { padding: var(--space-1); }
.p-2 { padding: var(--space-2); }
.p-3 { padding: var(--space-3); }
.p-4 { padding: var(--space-4); }
.p-5 { padding: var(--space-5); }
.p-6 { padding: var(--space-6); }

.d-none { display: none; }
.d-block { display: block; }
.d-flex { display: flex; }
.d-inline-flex { display: inline-flex; }
.d-grid { display: grid; }

.w-100 { width: 100%; }
.h-100 { height: 100%; }

.overflow-hidden { overflow: hidden; }
.overflow-auto { overflow: auto; }

.relative { position: relative; }
.absolute { position: absolute; }

.cursor-pointer { cursor: pointer; }

/* ==========================================================================
   20. Login Page
   ========================================================================== */

.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--space-6);
  background-color: var(--bg-primary);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}

.login-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-purple), var(--accent-danger));
}

.login-card .login-header {
  text-align: center;
  margin-bottom: var(--space-8);
}

.login-card .login-logo {
  text-align: center;
  margin: 0 auto var(--space-4);
}

.login-card .login-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.login-card .login-subtitle {
  font-size: 14px;
  color: var(--text-muted);
}

.login-card .login-footer {
  text-align: center;
  margin-top: var(--space-6);
  font-size: 13px;
  color: var(--text-muted);
}

.login-card .login-footer a {
  color: var(--accent-primary);
  font-weight: 600;
}

/* ==========================================================================
   21. Spinner / Loading
   ========================================================================== */

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color);
  border-top-color: var(--accent-primary);
  border-radius: var(--radius-full);
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

.spinner-sm {
  width: 14px;
  height: 14px;
  border-width: 2px;
}

.spinner-lg {
  width: 32px;
  height: 32px;
  border-width: 3px;
}

.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-10);
}

/* ==========================================================================
   22. Grid Helpers
   ========================================================================== */

.grid {
  display: grid;
  gap: var(--space-5);
}

.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 1024px) {
  .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-cols-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .grid-cols-4,
  .grid-cols-3,
  .grid-cols-2 { grid-template-columns: 1fr; }

  .sidebar {
    display: none;
  }

  .content {
    padding: var(--space-4);
  }

  .page-header {
    flex-direction: column;
  }
}

/* ==========================================================================
   Guida (in-app help) + Inline tooltips
   ========================================================================== */

.guida-toc-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  transition: var(--transition-fast);
  margin-bottom: 2px;
}

.guida-toc-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.guida-toc-item.active {
  background: rgba(29, 161, 242, 0.12);
  color: var(--accent-primary);
  font-weight: 500;
}

.guida-content h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 var(--space-4) 0;
}

.guida-content h3 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  margin: var(--space-6) 0 var(--space-3) 0;
  padding-top: var(--space-3);
  border-top: 1px solid var(--border-color);
}

.guida-content h3:first-of-type {
  border-top: none;
  padding-top: 0;
}

.guida-content p {
  font-size: 14px;
  color: var(--text-primary);
  margin: 0 0 var(--space-3) 0;
}

.guida-content ul,
.guida-content ol {
  font-size: 14px;
  color: var(--text-primary);
  padding-left: var(--space-5);
  margin: 0 0 var(--space-3) 0;
}

.guida-content li {
  margin-bottom: var(--space-2);
}

.guida-content code {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  color: var(--accent-primary);
}

.guida-content a {
  color: var(--accent-primary);
  text-decoration: none;
}

.guida-content a:hover {
  text-decoration: underline;
}

.guida-content table {
  font-size: 13px;
}

.guida-content pre {
  margin: var(--space-3) 0;
}

.guida-content em {
  color: var(--text-secondary);
  font-style: italic;
}

/* Inline tooltip helper */
.info-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: help;
  position: relative;
  vertical-align: middle;
  border: 1px solid var(--border-color);
  transition: var(--transition-fast);
}

.info-tip:hover {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
}

/* The actual tooltip body is a fixed-position element rendered to <body>
   by JS (see _floatingTipInit in app.js). This way it can never be clipped
   by overflow:hidden / overflow:auto parents (e.g. .modal-body). */
.floating-tip {
  position: fixed;
  background: #0a0e14;
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #ffffff;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.55;
  white-space: pre-line;
  max-width: 320px;
  text-align: left;
  z-index: 10000;
  pointer-events: none;
  box-shadow:
    0 12px 32px rgba(0, 0, 0, 0.6),
    0 4px 12px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.12s ease, transform 0.12s ease;
  transform: translateY(4px);
}

.floating-tip.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Hide default <details> marker (we use custom chevron) */
details > summary::-webkit-details-marker { display: none; }
details > summary { list-style: none; }
details[open] .kb-quota-chevron { transform: rotate(180deg); }
.kb-quota-chevron { transition: transform 0.2s ease; display: inline-block; }

@media (max-width: 768px) {
  .guida-content {
    padding: var(--space-4) !important;
  }
}
