/* ═══════════════════════════════════════════════════════════════════════════
   EONTRA ADMIN — main.css
   Requires: design-tokens.css loaded first.
   No hardcoded hex. No gradients. No !important hacks.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Backward-compat aliases ─────────────────────────────────────────────── */
:root {
  --bg-base:        var(--bg-page);
  --bg-elevated:    var(--bg-hover);
  --success-muted:  var(--success-bg);
  --error-muted:    var(--error-bg);
  --warning-muted:  var(--warning-bg);
  --info-muted:     var(--info-bg);
  --success-subtle: var(--success-bg);
  --error-subtle:   var(--error-bg);
  --warning-subtle: var(--warning-bg);
  --border-color:   var(--border-default);
  --bg-tertiary:    var(--bg-hover);
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESET & BASE
   ═══════════════════════════════════════════════════════════════════════════ */

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

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow: hidden;
}

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

::selection { background: var(--accent-muted); color: var(--text-primary); }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ═══════════════════════════════════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════════════════════════════════ */

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

.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

.btn-primary {
  background: var(--accent);
  color: var(--text-inverse);
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:active:not(:disabled) { background: var(--accent-active); }

.btn-secondary {
  background: var(--bg-surface);
  border-color: var(--border-strong);
  color: var(--text-secondary);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-secondary); }

.btn-danger {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: var(--error-text);
}
.btn-danger:hover:not(:disabled) { background: var(--error); border-color: var(--error); color: var(--text-inverse); }

.btn-success {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success-text);
}
.btn-success:hover:not(:disabled) { background: var(--success); border-color: var(--success); color: var(--text-inverse); }

.btn-sm { padding: 5px 10px; font-size: var(--text-xs); border-radius: var(--radius-sm); }
.btn-lg { padding: 10px 20px; font-size: var(--text-base); }

/* Icon-only button — single canonical definition */
.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius-md);
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-icon:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-secondary); }
.btn-icon.btn-sm { width: 28px; height: 28px; }
.btn-icon.btn-success:hover { background: var(--success-bg); color: var(--success); }
.btn-icon.btn-danger:hover  { background: var(--error-bg);   color: var(--error); }

/* ═══════════════════════════════════════════════════════════════════════════
   FORMS
   ═══════════════════════════════════════════════════════════════════════════ */

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

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

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 8px 12px;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  background: var(--bg-surface);
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:hover, .form-select:hover, .form-textarea:hover { border-color: var(--accent); }
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-disabled); }
.form-textarea { min-height: 100px; resize: vertical; }
.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236b7280'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 15px;
  padding-right: 36px;
}

.form-hint  { font-size: var(--text-xs); color: var(--text-muted); margin-top: var(--space-1); }
.form-error { font-size: var(--text-xs); color: var(--error); margin-top: var(--space-1); }

.form-check { display: flex; align-items: center; gap: var(--space-2); cursor: pointer; }
.form-check input[type="checkbox"],
.form-check input[type="radio"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* Toggle switch */
.toggle { position: relative; width: 36px; height: 20px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border-strong);
  border-radius: var(--radius-full);
  transition: background var(--transition-normal);
  cursor: pointer;
}
.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: var(--bg-surface);
  border-radius: 50%;
  transition: transform var(--transition-normal);
  box-shadow: var(--shadow-sm);
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track::after { transform: translateX(16px); }

/* ═══════════════════════════════════════════════════════════════════════════
   CARDS
   ═══════════════════════════════════════════════════════════════════════════ */

.card {
  background: var(--bg-surface);
  border: 0.5px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 0.5px solid var(--border-default);
}
.card-title { font-size: var(--text-base); font-weight: 500; }
.card-body { padding: var(--space-5); }
.card-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-top: 0.5px solid var(--border-default);
  background: var(--bg-page);
}

/* ═══════════════════════════════════════════════════════════════════════════
   BADGES
   ═══════════════════════════════════════════════════════════════════════════ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: var(--text-xs);
  font-weight: 500;
  border-radius: var(--radius-full);
  background: var(--bg-hover);
  color: var(--text-muted);
  white-space: nowrap;
}
.badge-success { background: var(--success-bg); color: var(--success-text); }
.badge-warning { background: var(--warning-bg); color: var(--warning-text); }
.badge-error   { background: var(--error-bg);   color: var(--error-text); }
.badge-info    { background: var(--info-bg);     color: var(--info-text); }
.badge-accent  { background: var(--accent-muted); color: var(--accent); }
.badge-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

/* ═══════════════════════════════════════════════════════════════════════════
   TABLES
   ═══════════════════════════════════════════════════════════════════════════ */

.table-container {
  background: var(--bg-surface);
  border: 0.5px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: var(--bg-page);
  text-align: left;
  border-bottom: 0.5px solid var(--border-default);
}
.table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 0.5px solid var(--border-subtle);
  vertical-align: middle;
  color: var(--text-secondary);
}
.table td:first-child { color: var(--text-primary); font-weight: 500; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--bg-hover); }
.table-empty { padding: var(--space-12); text-align: center; color: var(--text-disabled); font-size: var(--text-sm); }

/* ═══════════════════════════════════════════════════════════════════════════
   STAT CARDS
   ═══════════════════════════════════════════════════════════════════════════ */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
}
.stat-card {
  background: var(--bg-surface);
  border: 0.5px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}
.stat-card-value { font-size: 1.75rem; font-weight: 500; letter-spacing: -0.02em; line-height: 1.1; }
.stat-card-label { font-size: var(--text-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-top: var(--space-1); }
.stat-card-change { font-size: var(--text-xs); display: flex; align-items: center; gap: 3px; margin-top: var(--space-2); }
.stat-card-change.positive { color: var(--success); }
.stat-card-change.negative { color: var(--error); }

/* ═══════════════════════════════════════════════════════════════════════════
   MODALS — clean system, no hacks
   ═══════════════════════════════════════════════════════════════════════════ */

.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}
.modal.active { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: var(--bg-overlay); }
.modal-content {
  position: relative;
  z-index: 1;
  background: var(--bg-surface);
  border: 0.5px solid var(--border-default);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.modal-content.modal-sm  { max-width: 420px; }
.modal-content.modal-lg  { max-width: 760px; }
.modal-content.modal-xl  { max-width: 1000px; }
.modal-content.modal-full { max-width: calc(100vw - 48px); height: calc(100vh - 48px); }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 0.5px solid var(--border-default);
  flex-shrink: 0;
}
.modal-title { font-size: var(--text-lg); font-weight: 500; }
.modal-body { padding: var(--space-6); flex: 1; overflow-y: auto; }
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 0.5px solid var(--border-default);
  flex-shrink: 0;
}
body:has(.modal.active) { overflow: hidden; }

/* ═══════════════════════════════════════════════════════════════════════════
   DROPDOWN
   ═══════════════════════════════════════════════════════════════════════════ */

.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--bg-surface);
  border: 0.5px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 180px;
  z-index: var(--z-dropdown);
  overflow: hidden;
}
.dropdown-menu.active { display: block; }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-sans);
}
.dropdown-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.dropdown-item.danger { color: var(--error-text); }
.dropdown-item.danger:hover { background: var(--error-bg); }
.dropdown-divider { height: 0.5px; background: var(--border-default); margin: var(--space-1) 0; }

/* ═══════════════════════════════════════════════════════════════════════════
   TABS
   ═══════════════════════════════════════════════════════════════════════════ */

.tabs {
  display: flex;
  border-bottom: 0.5px solid var(--border-default);
  margin-bottom: var(--space-6);
}
.tab {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -0.5px;
  transition: all var(--transition-fast);
  font-family: var(--font-sans);
}
.tab:hover { color: var(--text-secondary); }
.tab.active { color: var(--text-primary); border-bottom-color: var(--accent); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Admin tab variant */
.admin-tabs { display: flex; gap: 0; border-bottom: 0.5px solid var(--border-default); margin-bottom: var(--space-5); }
.admin-tab { padding: var(--space-3) var(--space-4); font-size: var(--text-sm); font-weight: 500; color: var(--text-muted); border: none; background: none; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -0.5px; transition: all var(--transition-fast); font-family: var(--font-sans); }
.admin-tab:hover { color: var(--text-secondary); }
.admin-tab.active { color: var(--text-primary); border-bottom-color: var(--accent); }

/* ═══════════════════════════════════════════════════════════════════════════
   ALERTS & TOASTS
   ═══════════════════════════════════════════════════════════════════════════ */

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  border: 0.5px solid;
}
.alert-success { background: var(--success-bg); border-color: var(--success-border); color: var(--success-text); }
.alert-warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-text); }
.alert-error   { background: var(--error-bg);   border-color: var(--error-border);   color: var(--error-text); }
.alert-info    { background: var(--info-bg);     border-color: var(--info-border);    color: var(--info-text); }

.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--text-primary);
  color: var(--bg-surface);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in var(--transition-normal) ease-out;
}
.toast-success { background: var(--success); color: var(--text-inverse); }
.toast-error   { background: var(--error);   color: var(--text-inverse); }
.toast-warning { background: var(--warning); color: var(--text-inverse); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ═══════════════════════════════════════════════════════════════════════════
   APP SHELL
   ═══════════════════════════════════════════════════════════════════════════ */

.app { display: none; height: 100vh; overflow: hidden; }
.app.active { display: flex; }

.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-surface);
  border-right: 0.5px solid var(--border-default);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--transition-slow);
  z-index: var(--z-sticky);
}
.sidebar-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 var(--space-5);
  border-bottom: 0.5px solid var(--border-default);
  flex-shrink: 0;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.10em;
  color: var(--text-primary);
  text-transform: uppercase;
}
.sidebar-logo-icon {
  width: 26px;
  height: 26px;
  background: var(--accent);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-inverse);
  flex-shrink: 0;
}
.sidebar-nav { flex: 1; padding: var(--space-4) var(--space-3); overflow-y: auto; }
.sidebar-section { margin-bottom: var(--space-6); }
.sidebar-section-title {
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-disabled);
  padding: 0 var(--space-3);
  margin-bottom: var(--space-2);
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 7px var(--space-3);
  color: var(--text-muted);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 400;
}
.sidebar-link:hover { background: var(--bg-hover); color: var(--text-secondary); }
.sidebar-link.active { background: var(--accent-muted); color: var(--accent); font-weight: 500; }
.sidebar-link-icon { width: 16px; height: 16px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sidebar-link-icon svg { width: 16px; height: 16px; flex-shrink: 0; }
.stat-card-icon { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-md); margin-bottom: var(--space-3); }
.stat-card-icon.accent  { background: var(--accent-muted); color: var(--accent); }
.stat-card-icon.success { background: var(--success-bg);   color: var(--success); }
.stat-card-icon.warning { background: var(--warning-bg);   color: var(--warning); }
.stat-card-icon.info    { background: var(--info-bg);      color: var(--info); }
.stat-card-icon svg { width: 16px; height: 16px; }
.security-card-icon { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; background: var(--bg-hover); border-radius: var(--radius-lg); margin-bottom: var(--space-3); color: var(--text-muted); }
.security-card-icon svg { width: 18px; height: 18px; }
.sidebar-link-badge {
  margin-left: auto;
  padding: 1px 6px;
  background: var(--accent-muted);
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: 500;
  border-radius: var(--radius-full);
}
.sidebar-footer { padding: var(--space-4); border-top: 0.5px solid var(--border-default); flex-shrink: 0; }
.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.sidebar-user:hover { background: var(--bg-hover); }
.sidebar-avatar {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-md);
  background: var(--accent-muted);
  border: 0.5px solid var(--accent-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  font-size: var(--text-xs);
  color: var(--accent);
  flex-shrink: 0;
}
.sidebar-user-name { font-size: var(--text-sm); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-primary); }
.sidebar-user-role { font-size: var(--text-xs); color: var(--text-disabled); }

/* Header */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  background: var(--bg-surface);
  border-bottom: 0.5px solid var(--border-default);
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: var(--space-4); min-width: 0; }
.header-breadcrumb { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); min-width: 0; }
.header-breadcrumb-item { color: var(--text-muted); white-space: nowrap; }
.header-breadcrumb-item.current { color: var(--text-primary); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.header-breadcrumb-sep { color: var(--border-strong); }
.header-right { display: flex; align-items: center; gap: var(--space-2); }

.header-search {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 12px;
  background: var(--bg-page);
  border: 0.5px solid var(--border-default);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--transition-fast);
  min-width: 200px;
}
.header-search:hover { border-color: var(--border-strong); }
.header-search-icon { color: var(--text-disabled); font-size: 13px; }
.header-search-text { flex: 1; font-size: var(--text-sm); color: var(--text-disabled); }
.header-search-kbd kbd {
  padding: 1px 5px;
  background: var(--bg-surface);
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* Header action buttons */
.header-deploy-btn,
.header-publish-btn,
.header-history-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 12px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 0.5px solid;
  font-family: var(--font-sans);
}
.header-deploy-btn { background: var(--accent); border-color: var(--accent); color: var(--text-inverse); }
.header-deploy-btn:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.header-deploy-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.header-deploy-btn.deploying { background: var(--warning); border-color: var(--warning); color: var(--text-inverse); }

.header-publish-btn { background: var(--success-bg); border-color: var(--success-border); color: var(--success-text); }
.header-publish-btn:hover:not(:disabled) { background: var(--success); border-color: var(--success); color: var(--text-inverse); }
.header-publish-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.header-history-btn { background: var(--bg-surface); border-color: var(--border-default); color: var(--text-muted); }
.header-history-btn:hover { background: var(--bg-hover); color: var(--text-secondary); }

.connection-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px 10px;
  background: var(--bg-page);
  border: 0.5px solid var(--border-default);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); flex-shrink: 0; }
.connection-status.offline .status-dot { background: var(--error); }
.connection-status.offline .status-text { color: var(--error-text); }

.notification-indicator {
  position: absolute;
  top: 5px; right: 5px;
  width: 7px; height: 7px;
  background: var(--error);
  border-radius: 50%;
  border: 1.5px solid var(--bg-surface);
}

/* Content area */
.content-area {
  flex: 1;
  padding: var(--space-6);
  overflow-y: auto;
  background: var(--bg-page);
  min-width: 0;
}

/* ═══════════════════════════════════════════════════════════════════════════
   PAGES
   ═══════════════════════════════════════════════════════════════════════════ */

.page {
  display: none !important;
  max-width: var(--content-max);
  margin: 0 auto;
  animation: page-in var(--transition-normal) ease-out;
}
.page.active { display: block !important; }
@keyframes page-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.page-title { font-size: var(--text-xl); font-weight: 500; color: var(--text-primary); letter-spacing: -0.01em; }
.page-description { color: var(--text-muted); font-size: var(--text-sm); margin-top: var(--space-1); }
.page-actions { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }

/* Admin page fix */
#page-admin { padding: 0; display: flex; flex-direction: column; height: auto; min-height: 100%; }
#page-admin .page-header { margin-bottom: var(--space-5); flex-shrink: 0; }

/* ═══════════════════════════════════════════════════════════════════════════
   LOGIN
   ═══════════════════════════════════════════════════════════════════════════ */

.login-screen { display: flex; height: 100vh; background: var(--bg-page); }
.login-visual { flex: 1; background: var(--accent); display: flex; align-items: center; justify-content: center; }
.login-visual-content { text-align: center; color: var(--text-inverse); }
.login-logo { font-size: 2rem; font-weight: 600; letter-spacing: 0.12em; margin-bottom: var(--space-3); }
.login-tagline { font-size: var(--text-base); opacity: 0.7; }
.login-form-side {
  width: 420px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-8);
  background: var(--bg-surface);
  border-left: 0.5px solid var(--border-default);
}
.login-form { width: 100%; }
.login-form h1 { font-size: var(--text-xl); font-weight: 500; margin-bottom: var(--space-1); }
.login-form > p { color: var(--text-muted); font-size: var(--text-sm); margin-bottom: var(--space-6); }
.login-error {
  background: var(--error-bg);
  border: 0.5px solid var(--error-border);
  color: var(--error-text);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
  display: none;
}
.login-error:not(:empty) { display: block; }
.login-success {
  background: var(--success-bg);
  border: 0.5px solid var(--success-border);
  color: var(--success-text);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
  display: none;
}
.login-success:not(:empty) { display: block; }
.login-divider {
  display: flex; align-items: center; gap: var(--space-3);
  color: var(--text-disabled); font-size: var(--text-xs); margin: var(--space-4) 0;
}
.login-divider::before, .login-divider::after { content: ''; flex: 1; height: 0.5px; background: var(--border-default); }
.login-links { display: flex; align-items: center; justify-content: center; gap: var(--space-3); margin-top: var(--space-5); font-size: var(--text-sm); color: var(--text-muted); }
.login-links a { color: var(--accent); }

/* ═══════════════════════════════════════════════════════════════════════════
   COMMAND PALETTE
   ═══════════════════════════════════════════════════════════════════════════ */

.command-palette {
  display: none;
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  align-items: flex-start;
  justify-content: center;
  padding-top: 120px;
  background: var(--bg-overlay);
}
.command-palette.active { display: flex; }
.command-palette-box {
  background: var(--bg-surface);
  border: 0.5px solid var(--border-default);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 560px;
  max-height: 60vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.command-palette-input-wrap {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 0.5px solid var(--border-default);
}
.command-palette-input { flex: 1; border: none; background: none; font-family: var(--font-sans); font-size: var(--text-base); color: var(--text-primary); outline: none; }
.command-palette-input::placeholder { color: var(--text-disabled); }
.command-palette-results { overflow-y: auto; padding: var(--space-2); }
.command-palette-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  transition: background var(--transition-fast);
}
.command-palette-item:hover,
.command-palette-item.focused { background: var(--bg-hover); color: var(--text-primary); }
.command-palette-item-icon { color: var(--text-disabled); width: 16px; height: 16px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.command-palette-item-icon svg { width: 15px; height: 15px; }
.command-palette-item-kbd {
  margin-left: auto;
  padding: 1px 5px;
  background: var(--bg-page);
  border: 0.5px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════════════════════════
   AI CHAT
   ═══════════════════════════════════════════════════════════════════════════ */

.ai-chat { display: flex; flex-direction: column; height: 100%; background: var(--bg-surface); }
.ai-messages { flex: 1; overflow-y: auto; padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-5); }
.ai-message { display: flex; flex-direction: column; gap: var(--space-2); max-width: 800px; }
.ai-message.user { align-self: flex-end; max-width: 600px; }
.ai-message-bubble { padding: var(--space-4) var(--space-5); border-radius: var(--radius-xl); font-size: var(--text-base); line-height: 1.7; }
.ai-message.user .ai-message-bubble { background: var(--accent); color: var(--text-inverse); border-radius: var(--radius-xl) var(--radius-xl) var(--radius-sm) var(--radius-xl); }
.ai-message.assistant .ai-message-bubble { background: var(--bg-page); border: 0.5px solid var(--border-default); border-radius: var(--radius-sm) var(--radius-xl) var(--radius-xl) var(--radius-xl); }
.ai-message-meta { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-xs); color: var(--text-disabled); padding: 0 var(--space-2); }

.ai-input-area { padding: var(--space-4) var(--space-6); border-top: 0.5px solid var(--border-default); background: var(--bg-surface); }
.ai-input-wrap {
  display: flex; align-items: flex-end; gap: var(--space-2);
  background: var(--bg-page);
  border: 0.5px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: var(--space-3) var(--space-4);
  transition: border-color var(--transition-fast);
}
.ai-input-wrap:focus-within { border-color: var(--accent); }
.ai-input {
  flex: 1; border: none; background: none;
  font-family: var(--font-sans); font-size: var(--text-base);
  color: var(--text-primary); resize: none; outline: none;
  min-height: 24px; max-height: 200px; line-height: 1.5;
}
.ai-input::placeholder { color: var(--text-disabled); }

.tool-call { background: var(--bg-page); border: 0.5px solid var(--border-default); border-radius: var(--radius-lg); overflow: hidden; font-size: var(--text-sm); margin: var(--space-2) 0; }
.tool-call-header { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3) var(--space-4); background: var(--bg-hover); cursor: pointer; user-select: none; }
.tool-call-name { font-weight: 500; color: var(--text-secondary); }
.tool-call-status { margin-left: auto; }
.tool-call-body { padding: var(--space-4); }

.pending-changes { background: var(--warning-bg); border: 0.5px solid var(--warning-border); border-radius: var(--radius-lg); padding: var(--space-4); }
.pending-changes-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-3); }
.pending-change-item { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) 0; font-size: var(--text-sm); border-bottom: 0.5px solid var(--border-subtle); }
.pending-change-item:last-child { border-bottom: none; }

/* Model selector */
.model-selector {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 5px 10px;
  background: var(--bg-page);
  border: 0.5px solid var(--border-default);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.model-selector:hover { border-color: var(--border-strong); color: var(--text-secondary); }

/* Streaming state */
.streaming-indicator {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-xs); color: var(--text-muted);
}
.streaming-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ═══════════════════════════════════════════════════════════════════════════
   CODE & MARKDOWN
   ═══════════════════════════════════════════════════════════════════════════ */

.markdown h1 { font-size: var(--text-xl); font-weight: 500; margin: var(--space-5) 0 var(--space-3); }
.markdown h2 { font-size: var(--text-lg); font-weight: 500; margin: var(--space-5) 0 var(--space-3); }
.markdown h3 { font-size: var(--text-base); font-weight: 500; margin: var(--space-4) 0 var(--space-2); }
.markdown p  { margin-bottom: var(--space-4); line-height: 1.7; }
.markdown ul, .markdown ol { margin: 0 0 var(--space-4) var(--space-5); }
.markdown li { margin-bottom: var(--space-1); line-height: 1.7; }
.markdown a  { color: var(--accent); text-decoration: underline; }
.markdown blockquote { border-left: 3px solid var(--border-strong); padding-left: var(--space-4); color: var(--text-muted); margin: var(--space-4) 0; }
.markdown hr { border: none; border-top: 0.5px solid var(--border-default); margin: var(--space-6) 0; }
.markdown table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); margin-bottom: var(--space-4); }
.markdown table th { padding: var(--space-2) var(--space-3); background: var(--bg-page); border: 0.5px solid var(--border-default); font-weight: 500; text-align: left; }
.markdown table td { padding: var(--space-2) var(--space-3); border: 0.5px solid var(--border-default); color: var(--text-secondary); }

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-hover);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}
pre {
  background: var(--bg-page);
  border: 0.5px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  overflow-x: auto;
  font-size: var(--text-sm);
  line-height: 1.7;
}
pre code { background: none; padding: 0; font-size: inherit; color: var(--text-primary); }
.code-block-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-hover);
  border-bottom: 0.5px solid var(--border-default);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.code-block-lang { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-muted); }

/* ═══════════════════════════════════════════════════════════════════════════
   EMPTY STATES & LOADING
   ═══════════════════════════════════════════════════════════════════════════ */

.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--space-12); text-align: center; gap: var(--space-3); }
.empty-state-icon { font-size: 2rem; opacity: 0.3; margin-bottom: var(--space-2); }
.empty-state-title { font-size: var(--text-base); font-weight: 500; color: var(--text-secondary); }
.empty-state-description { font-size: var(--text-sm); color: var(--text-disabled); max-width: 320px; }

.spinner { width: 20px; height: 20px; border: 2px solid var(--border-default); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.6s linear infinite; }
.spinner-sm { width: 14px; height: 14px; border-width: 1.5px; }
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton { background: var(--bg-hover); border-radius: var(--radius-md); animation: skeleton-pulse 1.4s ease-in-out infinite; }
@keyframes skeleton-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

.progress { height: 4px; background: var(--bg-hover); border-radius: var(--radius-full); overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); border-radius: var(--radius-full); transition: width var(--transition-slow); }
.progress-bar.success { background: var(--success); }
.progress-bar.warning { background: var(--warning); }
.progress-bar.error   { background: var(--error); }

/* ═══════════════════════════════════════════════════════════════════════════
   PROJECT CARDS
   ═══════════════════════════════════════════════════════════════════════════ */

.projects-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--space-4); }
.project-card {
  background: var(--bg-surface);
  border: 0.5px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.project-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.project-card.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-muted); }
.project-card-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: var(--space-3); }
.project-card-name { font-size: var(--text-base); font-weight: 500; color: var(--text-primary); }
.project-card-url { font-size: var(--text-xs); color: var(--text-disabled); margin-top: 2px; }
.project-card-footer { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-4); padding-top: var(--space-4); border-top: 0.5px solid var(--border-subtle); }

/* ═══════════════════════════════════════════════════════════════════════════
   DASHBOARD
   ═══════════════════════════════════════════════════════════════════════════ */

.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-5); }
.activity-item { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-3) 0; border-bottom: 0.5px solid var(--border-subtle); font-size: var(--text-sm); }
.activity-item:last-child { border-bottom: none; }
.activity-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--border-strong); margin-top: 6px; flex-shrink: 0; }
.activity-dot.success { background: var(--success); }
.activity-dot.error   { background: var(--error); }
.activity-dot.warning { background: var(--warning); }
.activity-time { margin-left: auto; color: var(--text-disabled); font-size: var(--text-xs); white-space: nowrap; }

.quick-actions { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: var(--space-3); }
.quick-action {
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2);
  padding: var(--space-4);
  background: var(--bg-surface);
  border: 0.5px solid var(--border-default);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: left;
}
.quick-action:hover { border-color: var(--accent); background: var(--accent-subtle); }
.quick-action-icon { width: 32px; height: 32px; background: var(--bg-hover); border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; }
.quick-action-icon svg { width: 16px; height: 16px; color: var(--text-muted); }
.quick-action-label { font-size: var(--text-sm); font-weight: 500; color: var(--text-secondary); }

/* ═══════════════════════════════════════════════════════════════════════════
   SETTINGS
   ═══════════════════════════════════════════════════════════════════════════ */

.settings-section { background: var(--bg-surface); border: 0.5px solid var(--border-default); border-radius: var(--radius-lg); overflow: hidden; margin-bottom: var(--space-5); }
.settings-section-header { padding: var(--space-4) var(--space-5); border-bottom: 0.5px solid var(--border-default); background: var(--bg-page); }
.settings-section-title { font-size: var(--text-base); font-weight: 500; }
.settings-section-description { font-size: var(--text-sm); color: var(--text-muted); margin-top: 2px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-6); padding: var(--space-4) var(--space-5); border-bottom: 0.5px solid var(--border-subtle); }
.settings-row:last-child { border-bottom: none; }
.settings-row-label { font-size: var(--text-sm); font-weight: 500; }
.settings-row-description { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }
.settings-row-control { flex-shrink: 0; }

/* ═══════════════════════════════════════════════════════════════════════════
   BILLING
   ═══════════════════════════════════════════════════════════════════════════ */

.plan-card { background: var(--bg-surface); border: 0.5px solid var(--border-default); border-radius: var(--radius-xl); padding: var(--space-6); }
.plan-card.current { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-muted); }
.plan-name { font-size: var(--text-lg); font-weight: 500; margin-bottom: var(--space-1); }
.plan-price { font-size: 2rem; font-weight: 500; letter-spacing: -0.02em; margin: var(--space-3) 0; }
.plan-price sup { font-size: var(--text-base); font-weight: 400; vertical-align: super; }
.plan-price span { font-size: var(--text-base); font-weight: 400; color: var(--text-muted); }
.plan-feature { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); padding: var(--space-2) 0; color: var(--text-secondary); }
.plan-feature-check { color: var(--success); }

/* ═══════════════════════════════════════════════════════════════════════════
   UTILITY CLASSES — replaces common inline styles
   ═══════════════════════════════════════════════════════════════════════════ */

.hidden       { display: none !important; }
.flex         { display: flex; }
.flex-col     { display: flex; flex-direction: column; }
.inline-flex  { display: inline-flex; }
.grid         { display: grid; }
.block        { display: block; }

.flex-center  { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-start   { display: flex; align-items: center; }
.flex-end     { display: flex; align-items: center; justify-content: flex-end; }
.flex-wrap    { flex-wrap: wrap; }
.flex-1       { flex: 1; min-width: 0; }
.flex-shrink-0 { flex-shrink: 0; }
.items-start  { align-items: flex-start; }

.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); }

.w-full { width: 100%; }
.w-auto { width: auto; }

.text-primary   { color: var(--text-primary) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-muted     { color: var(--text-muted) !important; }
.text-disabled  { color: var(--text-disabled) !important; }
.text-success   { color: var(--success) !important; }
.text-warning   { color: var(--warning) !important; }
.text-error     { color: var(--error) !important; }
.text-accent    { color: var(--accent) !important; }

.text-xs   { font-size: var(--text-xs); }
.text-sm   { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg   { font-size: var(--text-lg); }
.text-xl   { font-size: var(--text-xl); }

.font-normal { font-weight: 400; }
.font-medium { font-weight: 500; }
.font-semi   { font-weight: 600; }
.font-mono   { font-family: var(--font-mono); }
.truncate    { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mt-0  { margin-top: 0; }
.mt-2  { margin-top: var(--space-2); }
.mt-4  { margin-top: var(--space-4); }
.mt-6  { margin-top: var(--space-6); }
.mb-0  { margin-bottom: 0; }
.mb-4  { margin-bottom: var(--space-4); }
.mb-6  { margin-bottom: var(--space-6); }
.p-4   { padding: var(--space-4); }
.p-5   { padding: var(--space-5); }
.p-6   { padding: var(--space-6); }
.px-4  { padding-left: var(--space-4); padding-right: var(--space-4); }
.py-2  { padding-top: var(--space-2); padding-bottom: var(--space-2); }

.border        { border: 0.5px solid var(--border-default); }
.border-top    { border-top: 0.5px solid var(--border-default); }
.border-bottom { border-bottom: 0.5px solid var(--border-default); }
.rounded       { border-radius: var(--radius-md); }
.rounded-lg    { border-radius: var(--radius-lg); }
.rounded-xl    { border-radius: var(--radius-xl); }
.rounded-full  { border-radius: var(--radius-full); }

.opacity-50  { opacity: 0.5; }
.opacity-70  { opacity: 0.7; }
.overflow-hidden { overflow: hidden; }
.overflow-auto   { overflow: auto; }

/* ═══════════════════════════════════════════════════════════════════════════
   SIDEBAR VERSION LABEL
   ═══════════════════════════════════════════════════════════════════════════ */
.sidebar-version {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
  color: var(--text-disabled);
  border-top: 0.5px solid var(--border-subtle);
}

/* ═══════════════════════════════════════════════════════════════════════════
   DEPLOYING ANIMATION (replaces inline @keyframes)
   ═══════════════════════════════════════════════════════════════════════════ */
@keyframes pulse-deploy {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.65; }
}
.header-deploy-btn.deploying { animation: pulse-deploy 1.4s ease-in-out infinite; }

/* Admin tab-content visibility */
.admin-tab-content { display: none; }
.admin-tab-content.active { display: block; }
