:root {
  --primary:        #0A2540;
  --primary-mid:    #1E3A5F;
  --accent:         #2563EB;
  --accent-light:   #EFF6FF;
  --success:        #059669;
  --success-light:  #ECFDF5;
  --warning:        #D97706;
  --warning-light:  #FFFBEB;
  --danger:         #DC2626;
  --danger-light:   #FEF2F2;
  --border:         #E5E7EB;
  --border-strong:  #D1D5DB;
  --text-primary:   #111827;
  --text-secondary: #6B7280;
  --text-tertiary:  #9CA3AF;
  --background:     #F9FAFB;
  --surface:        #FFFFFF;
  --sidebar-width:  220px;
  --radius:         6px;
  --radius-lg:      10px;
  --shadow-sm:      0 1px 3px rgba(0,0,0,.06);
  --shadow:         0 4px 12px rgba(0,0,0,.08);
  --shadow-lg:      0 8px 24px rgba(0,0,0,.12);
  --font: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--background);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}

/* AUTH PAGES */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--background);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.auth-logo-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}

.auth-card h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.auth-subtitle {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

/* APP SHELL */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100vh;
  overflow: hidden;
  transition: grid-template-columns 0.25s ease;
}
.app-shell.sidebar-collapsed {
  grid-template-columns: 52px 1fr;
}

/* SIDEBAR */
.sidebar {
  background: var(--primary);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  width: var(--sidebar-width);
  transition: width 0.25s ease;
  flex-shrink: 0;
}
.app-shell.sidebar-collapsed .sidebar {
  width: 52px;
}

.sidebar-top { overflow-y: auto; flex: 1; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  min-height: 60px;
  position: relative;
}

.sidebar-logo {
  object-fit: contain;
  flex-shrink: 0;
  height: 28px;
  width: auto;
  max-width: 120px;
  transition: height 0.2s ease, max-width 0.2s ease, opacity 0.2s ease;
}
.app-shell.sidebar-collapsed .sidebar-logo {
  height: 22px;
  max-width: 22px;
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  overflow: hidden;
  opacity: 1;
  transition: opacity 0.15s ease, width 0.25s ease;
  white-space: nowrap;
}
.app-shell.sidebar-collapsed .sidebar-brand-text {
  opacity: 0;
  width: 0;
  pointer-events: none;
}

.sidebar-brand-name {
  color: #fff;
  font-weight: 700;
  font-size: 14px;
}

.sidebar-brand-sub {
  color: rgba(255,255,255,0.5);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* Sidebar toggle button — absolutely positioned so it's always reachable */
.sidebar-toggle-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,0.5);
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
  z-index: 1;
}
.sidebar-toggle-btn:hover {
  color: #fff;
  background: rgba(255,255,255,0.1);
}
/* When collapsed, center the button in the 52px brand area */
.app-shell.sidebar-collapsed .sidebar-toggle-btn {
  right: auto;
  left: 50%;
  transform: translate(-50%, -50%);
}
.sidebar-toggle-icon {
  transition: transform 0.25s ease;
}
.app-shell.sidebar-collapsed .sidebar-toggle-icon {
  transform: rotate(180deg);
}

.sidebar-nav {
  padding: 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: var(--radius);
  color: rgba(255,255,255,0.65);
  text-decoration: none;
  font-weight: 500;
  font-size: 13.5px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  overflow: hidden;
}
.nav-icon { flex-shrink: 0; }

.nav-label {
  overflow: hidden;
  opacity: 1;
  transition: opacity 0.15s ease;
  white-space: nowrap;
}
.app-shell.sidebar-collapsed .nav-label {
  opacity: 0;
  width: 0;
  pointer-events: none;
}

.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: rgba(255,255,255,0.15); color: #fff; }

/* Tooltip on hover when collapsed */
.app-shell.sidebar-collapsed .nav-item {
  justify-content: center;
  padding: 10px;
  position: relative;
}
.app-shell.sidebar-collapsed .nav-item::after {
  content: attr(title);
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--primary-mid);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: var(--radius);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 100;
  box-shadow: var(--shadow);
}
.app-shell.sidebar-collapsed .nav-item:hover::after {
  opacity: 1;
}

.sidebar-bottom {
  padding: 10px 6px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  margin-bottom: 8px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

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

.user-name {
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  color: rgba(255,255,255,0.5);
  font-size: 11px;
  text-transform: capitalize;
}

.notif-bell {
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius);
  position: relative;
  flex-shrink: 0;
}
.notif-bell:hover { color: #fff; background: rgba(255,255,255,0.1); }

.notif-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logout-btn {
  width: 100%;
  background: none;
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.65);
  padding: 7px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  overflow: hidden;
  white-space: nowrap;
}
.logout-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }
.app-shell.sidebar-collapsed .logout-btn {
  padding: 7px;
  border-color: transparent;
}
.app-shell.sidebar-collapsed .logout-btn .nav-label {
  opacity: 0;
  width: 0;
  pointer-events: none;
}

/* MAIN CONTENT */
#main-content {
  overflow-y: auto;
  background: var(--background);
}

/* PAGE HEADER */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 28px 0;
  margin-bottom: 24px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* FORMS */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 5px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--surface);
  transition: border-color 0.15s;
  outline: none;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.form-group input:disabled,
.form-group textarea:disabled,
.form-group select:disabled {
  background: var(--background);
  color: var(--text-secondary);
  cursor: not-allowed;
}

.form-group textarea { resize: vertical; min-height: 80px; }

.form-error {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid rgba(220,38,38,0.2);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 13px;
  margin-top: 8px;
}

.password-wrap { position: relative; display: flex; align-items: center; }
.password-wrap input { padding-right: 60px; }
.toggle-pw {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  font-weight: 600;
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn--primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn--primary:hover { background: #1d4ed8; border-color: #1d4ed8; }
.btn--secondary { background: var(--surface); color: var(--text-primary); border-color: var(--border-strong); }
.btn--secondary:hover { background: var(--background); border-color: var(--border-strong); }
.btn--danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn--danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn--ghost { background: transparent; color: var(--text-secondary); border-color: transparent; }
.btn--ghost:hover { background: var(--background); color: var(--text-primary); }
.btn--sm { padding: 5px 10px; font-size: 12px; }
.btn--full { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* CARDS */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

/* STATUS BADGES */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-draft        { background: #F3F4F6; color: #6B7280; }
.badge-pending      { background: #FEF3C7; color: #92400E; }
.badge-ready        { background: var(--success-light); color: var(--success); }
.badge-in_progress  { background: var(--accent-light); color: var(--accent); }
.badge-requires     { background: var(--danger-light); color: var(--danger); }
.badge-scheduled    { background: #DBEAFE; color: #1E40AF; }
.badge-deployed     { background: var(--primary); color: #fff; }

.badge-admin    { background: #EDE9FE; color: #5B21B6; }
.badge-designer { background: #FEF3C7; color: #92400E; }
.badge-creator  { background: var(--accent-light); color: var(--accent); }

/* TABLES */
.table-wrap { overflow-x: auto; }

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

th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-secondary);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--background); }

/* TOAST */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  background: var(--primary);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-lg);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  max-width: 340px;
  animation: slideIn 0.2s ease;
}
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-warning { background: var(--warning); color: #fff; }

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

/* MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-container {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

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

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

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-secondary);
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--text-primary); }

.modal-body { padding: 24px; }

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* NOTIFICATIONS */
.notif-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 340px;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 900;
  display: flex;
  flex-direction: column;
}

.notif-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}

.notif-panel-header span { flex: 1; }

.notif-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-secondary);
}

.notif-list { flex: 1; overflow-y: auto; }

.notif-item {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.notif-item:hover { background: var(--background); }
.notif-item.unread { background: var(--accent-light); }
.notif-item.unread:hover { background: #dbeafe; }

.notif-title { font-weight: 600; font-size: 13px; margin-bottom: 3px; }
.notif-message { font-size: 12.5px; color: var(--text-secondary); margin-bottom: 4px; }
.notif-time { font-size: 11px; color: var(--text-tertiary); }

/* STATS GRID */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}

.stat-label {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* EMAIL LIST CARD */
.email-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  color: inherit;
}
.email-card:hover { box-shadow: var(--shadow); border-color: var(--accent); }
.email-card:hover .email-card-delete-btn { opacity: 1; }

.email-card-delete-btn {
  opacity: 0;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-tertiary);
  font-size: 13px;
  padding: 4px 8px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s;
  line-height: 1;
}
.email-card-delete-btn:hover {
  background: var(--danger-light);
  border-color: var(--danger);
  color: var(--danger);
}

.email-card-info { flex: 1; min-width: 0; }

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

.email-card-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.email-card-owner {
  color: var(--text-tertiary);
  font-style: italic;
}

.email-card-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* SECTION HEADER */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title {
  font-size: 16px;
  font-weight: 700;
}

/* MISC */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state svg { opacity: 0.3; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.text-sm { font-size: 12.5px; }
.text-muted { color: var(--text-secondary); }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }

/* SEARCH + FILTER BAR */
.filter-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  padding: 16px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.filter-bar input,
.filter-bar select {
  padding: 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 13.5px;
  font-family: var(--font);
  background: var(--surface);
  outline: none;
}

.filter-bar input:focus,
.filter-bar select:focus {
  border-color: var(--accent);
}

.filter-bar input { min-width: 220px; }

/* Timeline */
.timeline { list-style: none; }
.timeline-item {
  display: flex;
  gap: 12px;
  padding-bottom: 16px;
  position: relative;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: 11px;
  top: 24px;
  bottom: 0;
  width: 1px;
  background: var(--border);
}
.timeline-item:last-child::before { display: none; }
.timeline-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-light);
  border: 2px solid var(--accent);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.timeline-content { flex: 1; padding-top: 2px; }
.timeline-label { font-weight: 600; font-size: 13px; }
.timeline-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* BANNER ALERTS */
.banner {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 12px;
}
.banner-warning { background: var(--warning-light); color: #92400E; border: 1px solid rgba(217,119,6,0.2); }
.banner-danger  { background: var(--danger-light);  color: var(--danger); border: 1px solid rgba(220,38,38,0.2); }
.banner-info    { background: var(--accent-light);  color: var(--accent); border: 1px solid rgba(37,99,235,0.15); }

/* LOADING SKELETON */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: var(--radius);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
