/**
 * Blue Beach Design System — Apple-Inspired
 * Shared styles loaded on every app page.
 * Page-specific styles remain inline in each HTML file.
 */

/* ── Design Tokens ── */
:root {
  --bg1: #060a12;
  --bg2: #0b1019;
  --bg3: #111827;
  --bg4: #1a2236;
  --text1: #f0f2f5;
  --text2: rgba(240,242,245,.65);
  --text3: rgba(240,242,245,.42);
  --accent: #3b82f6;
  --accent2: #818cf8;
  --green: #10b981;
  --gold: #f59e0b;
  --rose: #f43f5e;
  --font-h: 'Plus Jakarta Sans', sans-serif;
  --font-b: 'Inter', sans-serif;
  --font-m: 'JetBrains Mono', monospace;
  --border: rgba(255,255,255,.06);
  --border-h: rgba(255,255,255,.12);
  --radius: 16px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --shadow: 0 8px 32px rgba(0,0,0,.35);
  --shadow-sm: 0 2px 12px rgba(0,0,0,.2);
  --ease: 200ms ease;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; height: 100vh; }
@supports (height: 100dvh) { html { height: 100dvh; } }
body {
  font-family: var(--font-b);
  background: var(--bg1);
  color: var(--text1);
  font-size: 15px;
  line-height: 1.6;
  letter-spacing: -0.01em;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
input, button, select, textarea { font-family: inherit; font-size: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent2); }

/* ── Loading Spinner ── */
#loading-view {
  display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg1);
}
.spinner { width: 32px; height: 32px; border: 3px solid var(--border-h); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Login View ── */
#login-view { display: none; min-height: 100vh; align-items: center; justify-content: center; background: var(--bg1); }
#login-view.active { display: flex; }
.login-card { width: 100%; max-width: 400px; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); padding: 44px 36px 36px; box-shadow: var(--shadow); }
.login-logo { display: block; width: 56px; height: 56px; margin: 0 auto 16px; border-radius: 14px; }
.login-title { font-family: var(--font-h); font-weight: 700; font-size: 24px; text-align: center; margin-bottom: 28px; color: var(--text1); }
.login-error { margin-top: 14px; padding: 10px 14px; background: rgba(244,63,94,.12); border: 1px solid rgba(244,63,94,.25); border-radius: var(--radius-xs); color: var(--rose); font-size: 14px; display: none; }
.login-error.visible { display: block; }
.login-btn { display: block; width: 100%; padding: 12px 0; background: var(--accent); color: #fff; font-weight: 600; font-size: 15px; border: none; border-radius: var(--radius-sm); cursor: pointer; transition: background var(--ease); }
.login-btn:hover { background: #2563eb; }
.login-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Form Elements ── */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 14px; font-weight: 500; color: var(--text2); margin-bottom: 6px; }
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="text"],
.form-group select,
.form-group textarea { width: 100%; padding: 11px 14px; background: var(--bg2); border: 1px solid var(--border-h); border-radius: var(--radius-xs); color: var(--text1); font-size: 15px; outline: none; transition: border-color var(--ease); }
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--accent); }

/* ── App Shell ── */
#app-view { display: none; min-height: 100vh; }
#app-view.active { display: flex; }
.main-wrap { flex: 1; display: flex; flex-direction: column; min-height: 100vh; padding-bottom: 100px; }

/* ── Topbar ── */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 18px 32px; border-bottom: 1px solid var(--border); background: var(--bg2); position: sticky; top: 0; z-index: 50; }
.topbar-title { font-family: var(--font-h); font-weight: 700; font-size: 20px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-user { font-size: 14px; font-weight: 500; color: var(--text2); }

/* ── Page Content ── */
.page-content { flex: 1; padding: 32px; max-width: 1200px; width: 100%; }

/* ── Page Tabs ── */
.page-tabs {
  display: flex; gap: 2px; margin-bottom: 24px;
  background: var(--bg3); border-radius: var(--radius-xs); padding: 3px;
  border: 1px solid var(--border);
}
.page-tab {
  flex: 1; padding: 10px 0; text-align: center;
  font-size: 14px; font-weight: 600; color: var(--text3);
  border: none; background: none; cursor: pointer;
  border-radius: var(--radius-xs); transition: all var(--ease);
}
.page-tab:hover { color: var(--text2); }
.page-tab.active { background: var(--accent); color: #fff; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Stat Cards ── */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin-bottom: 28px; }
.stat-card { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; transition: border-color var(--ease); }
.stat-card:hover { border-color: var(--border-h); }
.stat-label { font-size: 13px; font-weight: 500; color: var(--text2); margin-bottom: 8px; }
.stat-value { font-family: var(--font-h); font-weight: 700; font-size: 32px; line-height: 1.2; letter-spacing: -0.02em; }
.stat-value.green { color: var(--green); }
.stat-value.blue { color: var(--accent); }
.stat-value.gold { color: var(--gold); }
.stat-value.rose { color: var(--rose); }
.stat-sub { font-size: 13px; color: var(--text2); margin-top: 4px; }

/* ── Filter Bar ── */
.filter-bar { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.filter-bar select,
.filter-bar input[type="text"],
.filter-bar input[type="date"] {
  padding: 10px 14px; background: var(--bg3); border: 1px solid var(--border-h); border-radius: var(--radius-xs);
  color: var(--text1); font-size: 14px; outline: none; transition: border-color var(--ease);
}
.filter-bar select:focus,
.filter-bar input:focus { border-color: var(--accent); }
.filter-bar input[type="text"] { flex: 1; min-width: 200px; }
.filter-bar select option { background: var(--bg3); color: var(--text1); }

/* ── Buttons ── */
.btn-primary {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 20px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 14px;
  border: none; border-radius: var(--radius-sm); cursor: pointer; transition: background var(--ease);
  white-space: nowrap;
}
.btn-primary:hover { background: #2563eb; }
.btn-primary svg { width: 16px; height: 16px; }
.btn-secondary {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 20px;
  background: var(--bg4); color: var(--text1); font-weight: 500; font-size: 14px;
  border: 1px solid var(--border-h); border-radius: var(--radius-sm); cursor: pointer; transition: background var(--ease), border-color var(--ease);
  white-space: nowrap;
}
.btn-secondary:hover { background: var(--bg3); border-color: var(--accent); }
.btn-danger {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 20px;
  background: rgba(244,63,94,.12); color: var(--rose); font-weight: 600; font-size: 14px;
  border: 1px solid rgba(244,63,94,.25); border-radius: var(--radius-sm); cursor: pointer; transition: background var(--ease);
}
.btn-danger:hover { background: rgba(244,63,94,.2); }
.btn-green {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 20px;
  background: rgba(16,185,129,.12); color: var(--green); font-weight: 600; font-size: 14px;
  border: 1px solid rgba(16,185,129,.25); border-radius: var(--radius-sm); cursor: pointer; transition: background var(--ease);
}
.btn-green:hover { background: rgba(16,185,129,.2); }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-outline {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 20px;
  background: transparent; color: var(--text2); font-weight: 500; font-size: 14px;
  border: 1px solid var(--border-h); border-radius: var(--radius-sm); cursor: pointer; transition: all var(--ease);
  white-space: nowrap;
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-gold {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 20px;
  background: rgba(245,158,11,.12); color: var(--gold); font-weight: 600; font-size: 14px;
  border: 1px solid rgba(245,158,11,.25); border-radius: var(--radius-sm); cursor: pointer; transition: background var(--ease);
}
.btn-gold:hover { background: rgba(245,158,11,.2); }

/* ── Table ── */
.tbl-wrap { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: left; padding: 12px 16px; font-size: 12px;
  color: var(--text2); font-weight: 600; border-bottom: 1px solid var(--border-h);
  background: var(--bg3);
}
.tbl th.right { text-align: right; }
.tbl th.center { text-align: center; }
.tbl td {
  padding: 14px 16px; font-size: 14px; border-bottom: 1px solid var(--border);
  color: var(--text1); vertical-align: middle;
}
.tbl td.right { text-align: right; }
.tbl td.center { text-align: center; }
.tbl td.mono { font-family: var(--font-m); font-size: 13px; }
.tbl tbody tr { cursor: pointer; transition: background var(--ease); }
.tbl tbody tr:hover { background: rgba(255,255,255,.02); }

/* ── Status Badges ── */
.badge { display: inline-block; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-active { background: rgba(16,185,129,.12); color: var(--green); }
.badge-draft { background: rgba(107,114,128,.15); color: #9ca3af; }
.badge-archived { background: rgba(107,114,128,.1); color: #6b7280; }
.badge-pending { background: rgba(245,158,11,.12); color: var(--gold); }
.badge-processing { background: rgba(59,130,246,.12); color: var(--accent); }
.badge-shipped { background: rgba(129,140,248,.12); color: var(--accent2); }
.badge-delivered { background: rgba(16,185,129,.12); color: var(--green); }
.badge-cancelled { background: rgba(244,63,94,.12); color: var(--rose); }
.badge-paid { background: rgba(16,185,129,.15); color: #34d399; }
.badge-unpaid { background: rgba(244,63,94,.12); color: var(--rose); }
.badge-refunded { background: rgba(107,114,128,.15); color: #9ca3af; }

/* ── Modal ── */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  z-index: 200; align-items: center; justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--bg3); border: 1px solid var(--border-h); border-radius: var(--radius);
  padding: 32px; max-width: 600px; width: 92%; box-shadow: var(--shadow);
  max-height: 90vh; overflow-y: auto;
}
.modal h3 { font-family: var(--font-h); font-weight: 700; font-size: 20px; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }

/* ── Modal Forms ── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.form-grid.three { grid-template-columns: 1fr 1fr 1fr; }
.form-field { margin-bottom: 0; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { display: block; font-size: 13px; font-weight: 500; color: var(--text2); margin-bottom: 6px; }
.form-field input,
.form-field select,
.form-field textarea {
  width: 100%; padding: 11px 14px; background: var(--bg2); border: 1px solid var(--border-h);
  border-radius: var(--radius-xs); color: var(--text1); font-size: 15px; outline: none;
  transition: border-color var(--ease);
}
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus { border-color: var(--accent); }
.form-field textarea { resize: vertical; min-height: 80px; }
.form-field select { cursor: pointer; }
.form-field select option { background: var(--bg3); color: var(--text1); }
.form-field input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(.7); }

/* ── Toggle Switch ── */
.toggle-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.toggle-label { font-size: 14px; font-weight: 500; color: var(--text2); }
.toggle {
  position: relative; width: 40px; height: 22px; background: var(--bg4); border-radius: 11px;
  cursor: pointer; transition: background var(--ease); border: 1px solid var(--border-h);
}
.toggle.active { background: var(--accent); border-color: var(--accent); }
.toggle::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  background: #fff; border-radius: 50%; transition: transform var(--ease);
}
.toggle.active::after { transform: translateX(18px); }

/* ── Charts ── */
.chart-card {
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px;
}
.chart-title { font-family: var(--font-h); font-weight: 700; font-size: 15px; margin-bottom: 16px; }
.bar-chart { display: flex; align-items: flex-end; gap: 4px; height: 140px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bar-fill { width: 100%; border-radius: 3px 3px 0 0; background: var(--accent); min-height: 2px; transition: height 500ms ease; }
.bar-label { font-size: 11px; color: var(--text3); }
.bar-value { font-size: 11px; color: var(--text2); font-family: var(--font-m); }

/* ── Dashboard Grid ── */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 24px; }
.dash-section { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.dash-section-title { font-family: var(--font-h); font-weight: 700; font-size: 15px; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; }
.dash-section-title .view-all { font-size: 13px; font-weight: 500; color: var(--accent); cursor: pointer; }
.dash-section-title .view-all:hover { color: var(--accent2); }

/* ── Empty State ── */
.empty-state { text-align: center; padding: 60px 24px; color: var(--text3); }
.empty-state svg { width: 48px; height: 48px; margin-bottom: 16px; opacity: .3; }
.empty-state p { font-size: 16px; margin-bottom: 20px; }

/* ── Toast ── */
.toast {
  position: fixed; top: 24px; right: 24px; padding: 14px 22px;
  background: var(--bg4); border: 1px solid var(--border-h); border-radius: var(--radius-sm);
  color: var(--text1); font-size: 14px; font-weight: 500; box-shadow: var(--shadow);
  z-index: 9999; transform: translateY(-100px); opacity: 0; transition: all .3s ease;
}
.toast.visible { transform: translateY(0); opacity: 1; }
.toast.success { border-color: rgba(16,185,129,.3); }
.toast.error { border-color: rgba(244,63,94,.3); }

/* ── Row Actions ── */
.row-actions { display: flex; gap: 4px; }
.row-action {
  background: none; border: none; color: var(--text3); cursor: pointer; padding: 4px;
  border-radius: var(--radius-xs); transition: color var(--ease), background var(--ease);
}
.row-action:hover { color: var(--text1); background: rgba(255,255,255,.06); }
.row-action.danger:hover { color: var(--rose); background: rgba(244,63,94,.1); }
.row-action svg { width: 16px; height: 16px; display: block; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-h); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.15); }

/* ── Responsive Defaults ── */

/* Tablet landscape */
@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 16px; }
  .page-content { max-width: 100%; }
}

/* Tablet portrait */
@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid.three { grid-template-columns: 1fr; }
  .dash-grid { grid-template-columns: 1fr; }
  .topbar { padding: 16px 20px; }
  .topbar-title { font-size: 18px; }
  .page-content { padding: 24px 20px; }
  .modal { padding: 24px; width: 95%; }
  .filter-bar input[type="text"] { min-width: 140px; }
  .tbl th, .tbl td { padding: 10px 12px; font-size: 13px; }
}

/* Large phone / small tablet */
@media (max-width: 768px) {
  .main-wrap { padding-bottom: 80px; }
  .topbar { padding: 12px 16px; }
  .topbar-title { font-size: 16px; }
  .topbar-right { gap: 10px; }
  .topbar-user { display: none; }
  .page-content { padding: 16px; }
  .stat-grid { grid-template-columns: 1fr 1fr !important; gap: 12px; }
  .stat-card { padding: 16px; }
  .stat-value { font-size: 24px; }
  .stat-label { font-size: 12px; }
  .modal { padding: 20px; max-width: 95vw; }
  .modal h3 { font-size: 18px; }
  .page-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .page-tab { padding: 8px 0; font-size: 13px; white-space: nowrap; min-width: 0; }
  .filter-bar { gap: 8px; }
  .filter-bar select,
  .filter-bar input[type="text"],
  .filter-bar input[type="date"] { padding: 8px 10px; font-size: 13px; }
  .filter-bar input[type="text"] { min-width: 100px; }
  .btn-primary, .btn-secondary, .btn-danger, .btn-green, .btn-outline, .btn-gold { padding: 8px 14px; font-size: 13px; }
  .chart-card { padding: 16px; }
  .dash-section { padding: 16px; }
  .empty-state { padding: 40px 16px; }
  .toast { top: 16px; right: 16px; left: 16px; text-align: center; }

  /* Multi-pane layouts: hide side panels */
  .folder-panel,
  .channel-panel,
  .contact-list-panel { position: fixed; left: -100%; top: 0; bottom: 0; z-index: 150; width: 280px !important; min-width: 0 !important; transition: left .25s ease; background: var(--bg2); box-shadow: 4px 0 24px rgba(0,0,0,.5); }
  .folder-panel.mobile-open,
  .channel-panel.mobile-open,
  .contact-list-panel.mobile-open { left: 0; }

  /* Message list / detail toggle */
  .msglist-panel { width: 100% !important; min-width: 0 !important; }
  .reader-panel { position: fixed; inset: 0; z-index: 140; display: none; background: var(--bg1); overflow-y: auto; padding-bottom: 80px; }
  .reader-panel.mobile-open { display: block; }
  .contact-detail-panel { position: fixed; inset: 0; z-index: 140; display: none; background: var(--bg1); overflow-y: auto; padding-bottom: 80px; }
  .contact-detail-panel.mobile-open { display: block; }

  /* Thread panel overlay */
  .thread-panel { position: fixed; right: -100%; top: 0; bottom: 0; z-index: 160; width: min(360px, 90vw) !important; transition: right .25s ease; background: var(--bg2); box-shadow: -4px 0 24px rgba(0,0,0,.5); }
  .thread-panel.mobile-open { right: 0; }
  .members-panel { display: none; }
}

/* Phone */
@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr !important; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 22px; }
  .login-card { padding: 28px 20px 24px; margin: 0 12px; }
  .login-title { font-size: 20px; }
  .topbar { padding: 10px 12px; }
  .page-content { padding: 12px; }
  .modal { padding: 16px; border-radius: var(--radius-sm); }
  .modal-actions { flex-direction: column; }
  .modal-actions button { width: 100%; justify-content: center; }
  .tbl th, .tbl td { padding: 8px 10px; font-size: 12px; }
  .badge { font-size: 11px; padding: 3px 8px; }
  .page-tabs { gap: 0; }

  /* Safe area for notched phones */
  .main-wrap { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
  .topbar { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
}

/* ══════════════════════════════════════════════════════
   ACCESSIBILITY MODE — Eye Impaired / Low Vision
   Toggle via body.a11y-large or body.a11y-high-contrast
   Activated from settings or accessibility toggle button
   ══════════════════════════════════════════════════════ */

/* Large Text Mode */
body.a11y-large {
  font-size: 18px !important;
}
body.a11y-large * {
  line-height: 1.7 !important;
}
body.a11y-large h1, body.a11y-large .page-title { font-size: 32px !important; }
body.a11y-large h2 { font-size: 26px !important; }
body.a11y-large h3 { font-size: 22px !important; }
body.a11y-large p, body.a11y-large span, body.a11y-large div, body.a11y-large li,
body.a11y-large td, body.a11y-large th, body.a11y-large label,
body.a11y-large .msg-bubble, body.a11y-large .cm-text, body.a11y-large .adv-msg-text {
  font-size: 18px !important;
}
body.a11y-large input, body.a11y-large textarea, body.a11y-large select,
body.a11y-large button, body.a11y-large .btn {
  font-size: 18px !important;
  padding: 14px 18px !important;
  min-height: 48px;
}
body.a11y-large .bb-sb-item-label { font-size: 16px !important; }
body.a11y-large .bb-sb-item { padding: 10px 16px !important; }
body.a11y-large .badge { font-size: 14px !important; padding: 4px 10px !important; }
body.a11y-large .stat-val, body.a11y-large .ceo-stat-value { font-size: 30px !important; }
body.a11y-large .stat-label, body.a11y-large .ceo-stat-label { font-size: 14px !important; }
body.a11y-large small { font-size: 15px !important; }

/* High Contrast Mode */
body.a11y-high-contrast {
  --bg1: #000000 !important;
  --bg2: #0a0a0a !important;
  --bg3: #141414 !important;
  --bg4: #1f1f1f !important;
  --text1: #ffffff !important;
  --text2: rgba(255,255,255,.9) !important;
  --text3: rgba(255,255,255,.7) !important;
  --border: rgba(255,255,255,.25) !important;
  --border-h: rgba(255,255,255,.5) !important;
  --accent: #60a5fa !important;
}
body.a11y-high-contrast * {
  color: inherit;
}
body.a11y-high-contrast .btn,
body.a11y-high-contrast button {
  border-width: 2px !important;
}
body.a11y-high-contrast input, body.a11y-high-contrast textarea, body.a11y-high-contrast select {
  border-width: 2px !important;
  border-color: rgba(255,255,255,.4) !important;
}
body.a11y-high-contrast input:focus, body.a11y-high-contrast textarea:focus, body.a11y-high-contrast select:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px rgba(96,165,250,.4) !important;
}
body.a11y-high-contrast a { text-decoration: underline !important; }
body.a11y-high-contrast .bb-sb-item.active { border-left: 4px solid var(--accent) !important; }

/* Reduced Motion */
body.a11y-reduced-motion *,
body.a11y-reduced-motion *::before,
body.a11y-reduced-motion *::after {
  animation-duration: 0.001ms !important;
  transition-duration: 0.001ms !important;
}

/* Accessibility Toggle Button (injected by JS below) */
.a11y-toggle {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 9999;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,.1);
  border: 2px solid rgba(255,255,255,.2);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, transform .15s;
  backdrop-filter: blur(10px);
}
.a11y-toggle:hover { background: rgba(255,255,255,.2); transform: scale(1.1); }
body.bb-sidebar-open .a11y-toggle { left: calc(240px + 16px); }
body.bb-sidebar-collapsed .a11y-toggle { left: calc(56px + 16px); }
@media (max-width: 768px) {
  body.bb-sidebar-open .a11y-toggle, body.bb-sidebar-collapsed .a11y-toggle { left: 16px; }
  .a11y-toggle { bottom: 16px; left: 16px; }
}

/* Accessibility Panel */
.a11y-panel {
  position: fixed;
  bottom: 80px;
  left: 24px;
  z-index: 9998;
  background: rgba(15,20,30,.95);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 16px;
  padding: 20px;
  width: 260px;
  display: none;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
}
.a11y-panel.open { display: block; }
body.bb-sidebar-open .a11y-panel { left: calc(240px + 16px); }
body.bb-sidebar-collapsed .a11y-panel { left: calc(56px + 16px); }
@media (max-width: 768px) {
  body.bb-sidebar-open .a11y-panel, body.bb-sidebar-collapsed .a11y-panel { left: 16px; }
  .a11y-panel { left: 16px; }
}
.a11y-panel-title {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 16px;
}
.a11y-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.a11y-option:last-child { border-bottom: none; }
.a11y-option-label {
  font-size: 14px;
  color: rgba(255,255,255,.8);
}
.a11y-option-toggle {
  width: 44px;
  height: 24px;
  border-radius: 12px;
  background: rgba(255,255,255,.15);
  border: none;
  cursor: pointer;
  position: relative;
  transition: background .2s;
}
.a11y-option-toggle.on { background: var(--accent, #3b82f6); }
.a11y-option-toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: left .2s;
}
.a11y-option-toggle.on::after { left: 23px; }

/* ══════════════════════════════════════════════════════
   APPLE-LEVEL POLISH — Seamless, Dynamic, Fluid
   ══════════════════════════════════════════════════════ */

/* ── Smooth Scrolling ── */
html { scroll-behavior: smooth; }
* { scroll-margin-top: 80px; }

/* ── Spring Transitions (Apple-style cubic bezier) ── */
:root {
  --spring: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out-quint: cubic-bezier(0.83, 0, 0.17, 1);
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 400ms;
}

/* ── View Transitions (page-level animation) ── */
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeSlideOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-4px); }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}

#app-view.active .page-content { animation: fadeSlideIn var(--duration-slow) var(--spring) both; }
.tab-content.active { animation: fadeSlideIn var(--duration-normal) var(--spring) both; }

/* ── Card Interactions (lift + glow) ── */
.stat-card,
.dash-section,
.chart-card {
  transition: transform var(--duration-normal) var(--spring),
              border-color var(--duration-normal) var(--spring),
              box-shadow var(--duration-normal) var(--spring);
}
.stat-card:hover,
.dash-section:hover,
.chart-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(0,0,0,.3), 0 0 0 1px rgba(59,130,246,.1);
}
.stat-card:active,
.dash-section:active { transform: translateY(0) scale(0.99); }

/* ── Button Press Effect ── */
.btn-primary, .btn-secondary, .btn-danger, .btn-green, .btn-outline, .btn-gold {
  transition: all var(--duration-fast) var(--spring);
  will-change: transform;
}
.btn-primary:active, .btn-secondary:active, .btn-danger:active,
.btn-green:active, .btn-outline:active, .btn-gold:active {
  transform: scale(0.97);
}

/* ── Focus Rings (Apple-style) ── */
:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(59,130,246,.4), 0 0 0 1px rgba(59,130,246,.8);
  border-radius: var(--radius-xs);
}
button:focus-visible, a:focus-visible { box-shadow: 0 0 0 3px rgba(59,130,246,.3); }

/* ── Skeleton Loading ── */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--bg3) 25%, var(--bg4) 50%, var(--bg3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.8s ease-in-out infinite;
  border-radius: var(--radius-xs);
}
.skeleton-text { height: 14px; width: 100%; margin-bottom: 8px; }
.skeleton-text.short { width: 60%; }
.skeleton-text.tiny { width: 40%; height: 12px; }
.skeleton-circle { border-radius: 50%; }
.skeleton-card { height: 120px; }

/* ── Glass Panels (frosted glass) ── */
.glass {
  background: rgba(11,16,25,.75);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid rgba(255,255,255,.08);
}
.glass-strong {
  background: rgba(11,16,25,.88);
  backdrop-filter: blur(40px) saturate(200%);
  -webkit-backdrop-filter: blur(40px) saturate(200%);
  border: 1px solid rgba(255,255,255,.1);
}

/* ── Topbar Glass Effect ── */
.topbar {
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  background: rgba(11,16,25,.8) !important;
}

/* ── Modal Animations ── */
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes modalOverlayIn {
  from { opacity: 0; backdrop-filter: blur(0); }
  to { opacity: 1; backdrop-filter: blur(4px); }
}
.modal-overlay.active { animation: modalOverlayIn var(--duration-normal) var(--ease-out-expo) both; }
.modal-overlay.active .modal { animation: modalIn var(--duration-slow) var(--spring) both; }

/* ── Toast Animations ── */
@keyframes toastSlideIn {
  from { opacity: 0; transform: translateX(40px) scale(0.95); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toastSlideOut {
  from { opacity: 1; transform: translateX(0) scale(1); }
  to { opacity: 0; transform: translateX(40px) scale(0.95); }
}
.toast.visible { animation: toastSlideIn var(--duration-normal) var(--spring) both; }
.toast.hiding { animation: toastSlideOut var(--duration-fast) ease-in both; }

/* ── List Row Hover (smooth reveal) ── */
.tbl tbody tr {
  transition: background var(--duration-fast) ease, transform var(--duration-fast) var(--spring);
}
.tbl tbody tr:hover { background: rgba(59,130,246,.04); }
.tbl tbody tr:active { transform: scale(0.998); }

/* ── Progress Bars (animated fill) ── */
.progress-bar {
  width: 100%; height: 6px; background: var(--bg4); border-radius: 3px; overflow: hidden;
}
.progress-fill {
  height: 100%; border-radius: 3px;
  transition: width 600ms var(--ease-out-expo);
}
.progress-fill.green { background: linear-gradient(90deg, #059669, #10b981); }
.progress-fill.blue { background: linear-gradient(90deg, #2563eb, #3b82f6); }
.progress-fill.yellow { background: linear-gradient(90deg, #d97706, #f59e0b); }
.progress-fill.red { background: linear-gradient(90deg, #dc2626, #ef4444); }

/* ── Agent Status Dots (pulse animation) ── */
.status-dot {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0;
}
.status-dot.active { background: #10b981; box-shadow: 0 0 6px rgba(16,185,129,.5); }
.status-dot.running { background: #06b6d4; animation: dotPulse 2s ease-in-out infinite; }
.status-dot.paused { background: #f59e0b; }
.status-dot.error { background: #ef4444; box-shadow: 0 0 6px rgba(239,68,68,.5); }
.status-dot.offline { background: #4b5563; }
@keyframes dotPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .5; transform: scale(1.3); }
}

/* ── Tab Transitions ── */
.page-tabs {
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.page-tab {
  transition: all var(--duration-fast) var(--spring);
  position: relative;
}
.page-tab.active {
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.page-tab:active { transform: scale(0.97); }

/* ── Drag and Drop (kanban) ── */
.dragging { opacity: .6; transform: rotate(2deg) scale(1.02); z-index: 100; }
.drag-over { background: rgba(59,130,246,.06); border: 2px dashed rgba(59,130,246,.3); }
.drop-target { transition: background var(--duration-fast) ease; }

/* ── Kanban Cards ── */
.kanban-card {
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px; cursor: grab; user-select: none;
  transition: transform var(--duration-fast) var(--spring),
              box-shadow var(--duration-fast) var(--spring),
              border-color var(--duration-fast) ease;
}
.kanban-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  border-color: var(--border-h);
}
.kanban-card:active { cursor: grabbing; transform: scale(1.02); }
.kanban-card.dragging { box-shadow: 0 16px 48px rgba(0,0,0,.4); }

/* ── Agent Cards ── */
.agent-card {
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; cursor: pointer;
  transition: all var(--duration-normal) var(--spring);
}
.agent-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
  border-color: rgba(59,130,246,.2);
}
.agent-card:active { transform: translateY(-1px) scale(0.99); }

/* ── Inline Editable ── */
.inline-edit {
  border: 1px solid transparent; padding: 2px 6px; border-radius: var(--radius-xs);
  transition: all var(--duration-fast) ease; cursor: text;
}
.inline-edit:hover { background: rgba(255,255,255,.04); border-color: var(--border); }
.inline-edit:focus { background: var(--bg4); border-color: var(--accent); outline: none; }

/* ── Collapsible Sections ── */
.collapsible-content {
  overflow: hidden;
  transition: max-height var(--duration-slow) var(--spring), opacity var(--duration-normal) ease;
  max-height: 0; opacity: 0;
}
.collapsible-content.open { max-height: 2000px; opacity: 1; }
.collapsible-trigger { cursor: pointer; user-select: none; }
.collapsible-trigger .chevron {
  transition: transform var(--duration-fast) var(--spring);
  display: inline-block;
}
.collapsible-trigger.open .chevron { transform: rotate(90deg); }

/* ── Notification Badge ── */
.notif-badge {
  min-width: 18px; height: 18px; border-radius: 9px;
  background: #ef4444; color: #fff; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 5px; animation: badgePop var(--duration-normal) var(--spring);
}
@keyframes badgePop {
  0% { transform: scale(0); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* ── Tooltip ── */
.tooltip-wrap { position: relative; }
.tooltip-text {
  position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%) scale(0.95);
  background: rgba(15,20,30,.95); backdrop-filter: blur(12px);
  border: 1px solid var(--border-h); border-radius: var(--radius-xs);
  padding: 6px 12px; font-size: 12px; color: var(--text1); white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: all var(--duration-fast) var(--spring);
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
}
.tooltip-wrap:hover .tooltip-text { opacity: 1; transform: translateX(-50%) scale(1); }

/* ── Number Counter Animation ── */
@keyframes countUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.stat-value { animation: countUp var(--duration-slow) var(--spring) both; }

/* ── Staggered List Animation ── */
@keyframes listItemIn {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}
.stagger-list > * {
  animation: listItemIn var(--duration-normal) var(--spring) both;
}
.stagger-list > *:nth-child(1) { animation-delay: 0ms; }
.stagger-list > *:nth-child(2) { animation-delay: 30ms; }
.stagger-list > *:nth-child(3) { animation-delay: 60ms; }
.stagger-list > *:nth-child(4) { animation-delay: 90ms; }
.stagger-list > *:nth-child(5) { animation-delay: 120ms; }
.stagger-list > *:nth-child(6) { animation-delay: 150ms; }
.stagger-list > *:nth-child(7) { animation-delay: 180ms; }
.stagger-list > *:nth-child(8) { animation-delay: 210ms; }
.stagger-list > *:nth-child(n+9) { animation-delay: 240ms; }

/* ── Hover Reveal Actions ── */
.hover-actions { opacity: 0; transition: opacity var(--duration-fast) ease; }
*:hover > .hover-actions { opacity: 1; }

/* ── Selection Highlight ── */
::selection { background: rgba(59,130,246,.3); }

/* ── Image Smoothing ── */
img { image-rendering: -webkit-optimize-contrast; }

/* ── Reduced Motion Support ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  html { scroll-behavior: auto; }
}
/* ═══════════════════════════════════════════════════
   RESPONSIVE PATCH — app.bluebeach.ai
   Append to design-system.css
   ═══════════════════════════════════════════════════ */

/* ── Tablet (1024px and below) ── */
@media (max-width: 1024px) {
  .page-content { padding: 20px; }
  .stat-grid, .stats-row, .sts { grid-template-columns: repeat(2, 1fr) !important; }
  .rev-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .rev-board { grid-template-columns: 1fr !important; }
  .ag-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)) !important; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)) !important; }
}

/* ── Mobile landscape / small tablet (768px) ── */
@media (max-width: 768px) {
  /* Core layout */
  .page-content { padding: 16px 12px; max-width: 100%; }
  .bb-main-body { padding: 12px !important; }
  .bb-main-header { padding: 10px 16px !important; font-size: 14px !important; }

  /* Grids → single column */
  .stat-grid, .stats-row, .sts, .rev-grid { grid-template-columns: 1fr !important; }
  .ag-grid { grid-template-columns: 1fr !important; }
  .card-grid { grid-template-columns: 1fr !important; }
  .rev-board { grid-template-columns: 1fr !important; }
  .brand-grid { grid-template-columns: 1fr !important; }

  /* Tables → horizontal scroll */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
  table th, table td { padding: 8px 10px; font-size: 12px; }

  /* Tabs → scrollable */
  .page-tabs, .period-tabs, .hq-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap !important; }
  .page-tabs::-webkit-scrollbar, .period-tabs::-webkit-scrollbar, .hq-tabs::-webkit-scrollbar { display: none; }
  .page-tab { white-space: nowrap; flex-shrink: 0; }

  /* Filter bars → stack */
  .filter-bar { flex-wrap: wrap !important; gap: 6px !important; }
  .filter-bar select, .filter-bar input { width: 100% !important; min-width: 0 !important; }
  .filter-bar .btn, .filter-bar button { width: 100%; }

  /* Cards */
  .card, .ag, .rev-card, .rev-panel { border-radius: 10px; }

  /* Modals → full width */
  .modal { width: 95vw !important; max-width: 95vw !important; padding: 16px !important; max-height: 90vh; overflow-y: auto; }
  .modal-overlay { padding: 12px; }

  /* Kanban → horizontal scroll */
  .kanban-board, .kb-board { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap !important; }
  .kanban-col, .kb-col { min-width: 260px; flex-shrink: 0; }

  /* Org chart → scroll */
  .org-chart { overflow-x: auto; }

  /* Graph → full width */
  #graph-container, .graph-wrap { width: 100% !important; height: 60vh !important; }

  /* Forms */
  .form-row { flex-direction: column !important; }
  .form-row > * { width: 100% !important; }
  .form-group { margin-bottom: 12px; }
  textarea { min-height: 100px; }

  /* Buttons → full width on mobile */
  .btn-row { flex-wrap: wrap; gap: 8px; }
  .btn-row .btn, .btn-row button { flex: 1; min-width: 120px; }

  /* Hide non-essential on mobile */
  .desktop-only { display: none !important; }

  /* Typography */
  h1 { font-size: 22px !important; }
  h2 { font-size: 18px !important; }
  h3 { font-size: 15px !important; }
  .subtitle { font-size: 13px !important; }
}

/* ── Phone portrait (480px and below) ── */
@media (max-width: 480px) {
  .page-content { padding: 12px 8px; }
  .bb-main-body { padding: 8px !important; }

  /* Even smaller stats */
  .stat-grid, .sts { gap: 8px !important; }
  .st, .stat-card { padding: 12px !important; }
  .st .st-v, .stat-value { font-size: 22px !important; }

  /* Card simplification */
  .card, .ag { padding: 10px !important; }
  .rev-card .big { font-size: 24px !important; }

  /* Tab bar */
  .page-tab, .hq-tab { padding: 8px 12px !important; font-size: 12px !important; }

  /* Table cells */
  table th, table td { padding: 6px 8px; font-size: 11px; }

  /* Buttons */
  .btn, button { font-size: 13px; padding: 8px 12px; }

  /* Timeline bars */
  .timeline-bar { height: 80px !important; }

  /* Leader rows */
  .leader-row { padding: 8px 0; gap: 8px; }
  .leader-revenue { font-size: 13px; }

  /* Agent cards → compact */
  .ag-out { display: none; }
  .ag-time { display: none; }
}

/* ── Safe area for iOS (notch) ── */
@supports (padding: env(safe-area-inset-top)) {
  .bb-main-header { padding-top: max(10px, env(safe-area-inset-top)) !important; }
  .bb-sidebar { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
  .page-content { padding-bottom: max(32px, env(safe-area-inset-bottom)); }
}

/* ── Touch targets ── */
@media (hover: none) and (pointer: coarse) {
  .bb-sb-item { padding: 8px 12px !important; min-height: 44px; display: flex; align-items: center; }
  .page-tab, .hq-tab { min-height: 44px; }
  button, .btn, a.btn { min-height: 44px; }
  .filter-bar select, .filter-bar input { min-height: 44px; }
}

/* ── Print ── */
@media print {
  .bb-sidebar, .bb-main-header, .bb-mobile-overlay, .hq-sidebar { display: none !important; }
  .bb-main { margin-left: 0 !important; }
  .page-content { max-width: 100%; padding: 0; }
}

/* ============================================================== */
/* HIDE LEGACY AI WIDGETS (per Adam directive 2026-05-22)         */
/* Blue Code widget (op-sonar-panel) supersedes these.            */
/* #bb-ai-btn     = ai-enhance.js FAB (Universal AI Sidebar)      */
/* #bb-ai-sidebar = ai-enhance.js slide-out panel                 */
/* Rollback: delete this block OR restore from .bak-pre-hide-     */
/* ai-enhance-2026-05-22. Companion: gm-fab hidden in god-mode.css*/
/* Reference: [[bluebeach-os-production-protection]]              */
/* ============================================================== */
#bb-ai-btn,
#bb-ai-sidebar {
  display: none !important;
}
