/* === REPORTS SAAS — Design System === */
:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --radius: 10px;
  --shadow-sm: 0 1px 3px rgba(15,23,42,.06);
  --shadow-md: 0 4px 16px rgba(15,23,42,.08);
  --sidebar-w: 260px;
  --transition: .15s ease;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: 'Inter', -apple-system, sans-serif; color: var(--text); background: var(--bg); line-height: 1.6; font-size: 14px; }
a { color: var(--primary); text-decoration: none; } a:hover { color: var(--primary-hover); }
h1,h2,h3 { margin: 0 0 8px; font-weight: 700; color: var(--text); }
h1 { font-size: 26px; } h2 { font-size: 20px; } h3 { font-size: 16px; }

/* === Layout === */
.layout { display: flex; min-height: 100vh; }
.main-content { flex: 1; margin-left: var(--sidebar-w); min-width: 0; }
.content { padding: 32px; max-width: 1200px; }
.content:has(.editor-root) { max-width: none; overflow: visible; }

/* === Sidebar === */
.sidebar { position: fixed; top: 0; left: 0; width: var(--sidebar-w); height: 100vh; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; z-index: 100; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 16px; font-size: 18px; font-weight: 800; color: var(--primary); }
.sidebar-nav { flex: 1; padding: 8px 12px; overflow-y: auto; }
.nav-section { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; padding: 16px 12px 6px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--text); font-weight: 500; transition: var(--transition); margin-bottom: 2px; }
.nav-item:hover { background: var(--surface-2); color: var(--primary); }
.nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.nav-item svg { flex-shrink: 0; opacity: .7; }
.nav-item.active svg, .nav-item:hover svg { opacity: 1; }
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }
.user-info { display: flex; align-items: center; gap: 10px; padding: 8px 12px; margin-bottom: 4px; }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: white; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }
.user-name { font-weight: 600; font-size: 13px; } .user-role { font-size: 12px; color: var(--muted); }
.logout-link { color: var(--muted) !important; font-size: 13px; }

/* Mobile */
.mobile-header { display: none; }
.burger { background: none; border: none; cursor: pointer; padding: 8px; }
@media (max-width: 768px) {
  html, body { overflow-x: hidden; max-width: 100vw; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-md); }
  .main-content { margin-left: 0; }
  .mobile-header { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50; }
  .mobile-title { font-weight: 700; font-size: 16px; }
  .content { padding: 16px; }
}

/* === Alerts / Messages === */
.messages-container { padding: 16px 32px 0; }
.alert { padding: 12px 16px; border-radius: var(--radius); font-weight: 500; position: relative; margin-bottom: 8px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.alert-success { background: var(--success-light); color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: var(--danger-light); color: #991b1b; border: 1px solid #fecaca; }
.alert-info { background: var(--primary-light); color: #1e40af; border: 1px solid #bfdbfe; }
.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fde68a; }
.alert-close { background: none; border: none; font-size: 18px; cursor: pointer; opacity: .6; }

/* === Auth pages === */
.auth-container { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 20px; }
.auth-toast-container { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 9999; width: 90%; max-width: 420px; pointer-events: none; }
.auth-toast-container .alert { pointer-events: auto; box-shadow: 0 4px 16px rgba(0,0,0,.1); animation: authSlideDown .35s ease-out; }
@keyframes authSlideDown { from { opacity: 0; transform: translateY(-16px); } to { opacity: 1; transform: translateY(0); } }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 40px; width: 100%; max-width: 420px; box-shadow: var(--shadow-md); }
.auth-card h1 { text-align: center; margin-bottom: 24px; }
.auth-card .auth-link { text-align: center; margin-top: 16px; font-size: 14px; color: var(--muted); }

/* === Page header === */
.page-header { margin-bottom: 24px; }
.page-header p { color: var(--muted); margin: 4px 0 0; }

/* === Cards === */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card h2 { margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }

/* === Grid === */
.grid { display: grid; gap: 16px; }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }

.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; transition: var(--transition); }
.stat-card:hover { border-color: rgba(37,99,235,.3); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.stat-card .label { font-weight: 700; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; margin-bottom: 4px; }
.stat-card .value { font-size: 28px; font-weight: 800; color: var(--text); }

/* === Buttons === */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 8px; font-weight: 600; font-size: 13px; border: 1px solid transparent; cursor: pointer; transition: var(--transition); text-decoration: none; white-space: nowrap; }
.btn-primary { background: var(--primary); color: white; } .btn-primary:hover { background: var(--primary-hover); color: white; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); } .btn-secondary:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: white; } .btn-danger:hover { background: #b91c1c; color: white; }
.btn-success { background: var(--success); color: white; } .btn-success:hover { background: #15803d; color: white; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* === Forms === */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; max-width: 480px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; background: white; color: var(--text); transition: var(--transition);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.form-group .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
/* Django form rendering */
form p { margin: 0 0 16px; }
form p label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
form p input, form p select { width: 100%; max-width: 480px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
form .helptext { font-size: 12px; color: var(--muted); display: block; margin-top: 4px; }
form ul.errorlist { list-style: none; padding: 0; margin: 4px 0 0; } form ul.errorlist li { color: var(--danger); font-size: 13px; }

/* === Tables === */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
thead { background: var(--surface-2); }
thead th { padding: 10px 14px; text-align: left; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; border-bottom: 1px solid var(--border); }
tbody td { padding: 10px 14px; border-bottom: 1px solid var(--border); }
tbody tr:hover { background: var(--primary-light); }
tbody tr:last-child td { border-bottom: none; }

/* Excel table */
.excel-table td { padding: 8px 12px; border-bottom: 1px solid #cbd5e1; border-right: 1px solid #cbd5e1; font-size: 13px; word-wrap: break-word; overflow-wrap: break-word; white-space: normal; }
.excel-table td:last-child { border-right: none; }
.excel-table td:first-child { padding-left: 6px; }
.excel-cell-num { text-align: right; font-variant-numeric: tabular-nums; }

/* === Badges === */
.badge { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-neutral { background: #f1f5f9; color: #475569; }

/* === Empty state === */
.empty-state { text-align: center; padding: 48px 20px; border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface); }
.empty-state p { color: var(--muted); margin: 8px 0; }
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; opacity: .5; }

/* === Upload zone === */
.upload-zone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 32px; text-align: center; transition: var(--transition); cursor: pointer; background: var(--surface); }
.upload-zone:hover, .upload-zone.dragover { border-color: var(--primary); background: var(--primary-light); }
.upload-zone p { color: var(--muted); margin: 8px 0; }
.upload-zone input[type="file"] { display: none; }

/* === Credentials display === */
.credential-box { background: #1e293b; color: #e2e8f0; padding: 16px 20px; border-radius: var(--radius); font-family: 'JetBrains Mono', monospace; font-size: 15px; display: flex; justify-content: space-between; align-items: center; margin: 8px 0; }
.credential-box .copy-btn { background: rgba(255,255,255,.15); border: none; color: white; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 600; }
.credential-box .copy-btn:hover { background: rgba(255,255,255,.25); }

/* === Toolbar === */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.search-box { display: flex; gap: 8px; } .search-box input { width: 260px; }

/* === Misc === */
.mt-2 { margin-top: 12px; } .mt-3 { margin-top: 16px; } .mt-4 { margin-top: 24px; }
.mb-2 { margin-bottom: 12px; } .mb-3 { margin-bottom: 16px; }
.text-muted { color: var(--muted); } .text-center { text-align: center; }
.back-link { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; font-weight: 500; margin-top: 24px; }
.back-link:hover { color: var(--primary); }

/* === Preview table === */
.preview-table { max-height: 400px; overflow: auto; }
.preview-table td { font-size: 12px; padding: 4px 8px; white-space: nowrap; }

/* === Column widths widget (create/edit) === */
.column-widths-widget { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; }
.column-width-row { display: flex; align-items: center; gap: 8px; }
.col-width-label { min-width: 1.5em; font-weight: 600; margin: 0; font-size: 13px; }
.col-width-input { width: 80px; padding: 6px 8px; font-size: 13px; }

/* === Report viewer === */
.report-viewer-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.report-viewer-toolbar-left { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.report-viewer-toolbar-right { display: flex; align-items: center; }
.report-search-input { width: 220px; max-width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
.report-viewer-wrap { overflow-x: auto; overflow-y: auto; max-height: 70vh; }
.report-viewer-table { table-layout: fixed; }
.report-viewer-table thead th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); box-shadow: 0 1px 0 var(--border); white-space: nowrap; }
.report-viewer-table th.report-col-header { position: relative; min-width: 60px; }
.report-viewer-table .report-col-header-text { display: block; overflow: hidden; text-overflow: ellipsis; }
.report-col-resize { position: absolute; top: 0; right: 0; width: 8px; height: 100%; cursor: col-resize; }
.report-col-resize:hover { background: var(--primary); opacity: 0.3; }
.report-col-resize::after { content: ""; position: absolute; right: 0; top: 0; bottom: 0; width: 2px; background: var(--border); }
.report-viewer-table tbody tr.report-row-no-match { display: none; }
.report-viewer-table td.report-cell { word-wrap: break-word; overflow-wrap: break-word; white-space: normal; }
.report-viewer-table td.report-cell:first-child { padding-left: 6px; }

/* === Mobile preview frame === */
.mobile-preview-card { margin-top: 20px; }
.mobile-preview-controls { display: flex; gap: 8px; margin-bottom: 16px; }
.preview-orientation-btn { padding: 8px 16px; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600; transition: var(--transition); }
.preview-orientation-btn:hover { background: var(--surface-2); }
.preview-orientation-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.mobile-preview-frame { margin: 0 auto; position: relative; background: #1a1a1a; border-radius: 36px; padding: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.3), 0 0 0 1px rgba(255,255,255,.1); transition: all 0.3s ease; }
.mobile-preview-frame[data-orientation="portrait"] { width: 375px; height: 667px; }
.mobile-preview-frame[data-orientation="landscape"] { width: 667px; height: 375px; }
.mobile-notch { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); width: 150px; height: 20px; background: #1a1a1a; border-radius: 0 0 16px 16px; z-index: 10; }
.mobile-screen { width: 100%; height: 100%; background: white; border-radius: 24px; overflow: hidden; position: relative; }
.mobile-content { width: 100%; height: 100%; overflow-x: auto; overflow-y: auto; padding: 8px; -webkit-overflow-scrolling: touch; }
.mobile-content table { font-size: 11px; }
.mobile-content .excel-table td { padding: 4px 6px; font-size: 11px; }
.mobile-content .report-toggle-btn { min-width: 32px; min-height: 32px; padding: 4px; }
.mobile-content .report-col-toggle { width: 32px; min-width: 32px; }
.mobile-content thead th { padding: 6px 8px; font-size: 10px; }

@media (max-width: 768px) {
  .report-viewer-toolbar { flex-direction: column; align-items: stretch; }
  .report-viewer-toolbar-left { justify-content: flex-start; }
  .report-search-input { width: 100%; font-size: 16px; }
  .report-viewer-wrap { max-height: none; overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; max-width: 100vw; }
  .report-viewer-table { table-layout: auto; }
  .report-viewer-table thead th { white-space: nowrap; }
  .report-viewer-table td.report-cell { word-wrap: break-word; overflow-wrap: break-word; white-space: normal; }
  .mobile-preview-frame[data-orientation="portrait"] { width: 100%; max-width: 375px; height: auto; min-height: 500px; }
  .mobile-preview-frame[data-orientation="landscape"] { width: 100%; max-width: 667px; height: auto; min-height: 300px; }
}

/* ====================================================================
   REPORT EDITOR — iPhone Mockup + Split-View + Settings Panel
   ==================================================================== */

.editor-root {
  position: relative;
  margin: -32px;
  padding: 24px 32px;
  min-height: calc(100vh - 100px);
}
@media (max-width: 768px) {
  .editor-root { margin: -16px; padding: 16px; }
}

/* --- Header bar --- */
.editor-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0; margin-bottom: 20px; gap: 12px; flex-wrap: wrap;
}
.editor-header-left { display: flex; align-items: center; gap: 12px; }
.editor-back-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 8px; color: var(--muted);
  transition: var(--transition);
}
.editor-back-btn:hover { background: var(--surface-2); color: var(--primary); }
.editor-title-area { display: flex; flex-direction: column; }
.editor-title-label { font-weight: 700; font-size: 16px; line-height: 1.2; }
.editor-filename { font-size: 12px; color: var(--muted); }
.editor-header-right { display: flex; align-items: center; gap: 12px; }
.editor-orientation-toggle { display: flex; gap: 4px; }
.editor-orient-btn {
  width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface);
  cursor: pointer; color: var(--muted); transition: var(--transition);
}
.editor-orient-btn:hover { background: var(--surface-2); color: var(--text); }
.editor-orient-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

/* --- Main body: split layout --- */
.editor-body {
  display: flex; gap: 24px; align-items: flex-start;
  transition: all 0.35s cubic-bezier(.4,0,.2,1);
}
.editor-preview-pane {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  transition: all 0.35s cubic-bezier(.4,0,.2,1);
}
.editor-hint {
  margin-top: 16px; font-size: 13px; color: var(--muted); text-align: center;
  animation: editorHintPulse 2s ease-in-out infinite;
}
@keyframes editorHintPulse {
  0%, 100% { opacity: .6; }
  50% { opacity: 1; }
}

/* --- Split mode activates side-by-side layout --- */
.editor-body.editor-split { }
.editor-body.editor-split .editor-preview-pane { flex: 1 1 0; min-width: 0; }

/* --- Settings panel (hidden by default, animates open) --- */
.editor-settings {
  width: 0; min-width: 0; max-width: 0; overflow: hidden; opacity: 0;
  background: var(--surface); border: 1px solid transparent; border-radius: var(--radius);
  transition: width 0.35s cubic-bezier(.4,0,.2,1), min-width 0.35s cubic-bezier(.4,0,.2,1),
    max-width 0.35s cubic-bezier(.4,0,.2,1), opacity 0.35s cubic-bezier(.4,0,.2,1),
    padding 0.35s cubic-bezier(.4,0,.2,1), border-color 0.35s cubic-bezier(.4,0,.2,1);
  flex-shrink: 0;
  padding: 0;
}
.editor-settings.editor-settings-open {
  width: 420px; min-width: 420px; max-width: 420px; opacity: 1; padding: 24px;
  overflow-y: auto; max-height: calc(100vh - 120px);
  border-color: var(--border);
  box-shadow: var(--shadow-md);
}
.editor-settings-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.editor-settings-header h3 { margin: 0; }
.editor-settings-close {
  width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
  border: none; background: var(--surface-2); border-radius: 6px; cursor: pointer; color: var(--muted);
  transition: var(--transition);
}
.editor-settings-close:hover { background: var(--danger-light); color: var(--danger); }
.editor-settings-body { display: flex; flex-direction: column; gap: 0; }

/* --- Editor form fields --- */
.editor-field { margin-bottom: 16px; }
.editor-field > label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.editor-field input[type="text"],
.editor-field input[type="number"],
.editor-field textarea,
.editor-field select {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; background: white; color: var(--text); transition: var(--transition);
  font-family: inherit;
}
.editor-field input:focus, .editor-field textarea:focus, .editor-field select:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.editor-field-error { border-color: var(--danger) !important; box-shadow: 0 0 0 3px rgba(220,38,38,.15) !important; }
.editor-hint-text { font-size: 12px; color: var(--muted); margin-top: 4px; }
.editor-select-sm { width: auto; max-width: 120px; margin-top: 6px; }

/* --- Column checkboxes grid --- */
.editor-columns-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
}
.editor-col-check {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 6px; cursor: pointer;
  font-size: 13px; transition: var(--transition); user-select: none;
}
.editor-col-check:hover { background: var(--surface-2); }
.editor-col-check input[type="checkbox"] { accent-color: var(--primary); width: 16px; height: 16px; margin: 0; }
.editor-col-check input[type="checkbox"]:checked + span { font-weight: 600; color: var(--primary); }

/* --- Column aliases (rename) --- */
.editor-aliases-list { display: flex; flex-direction: column; gap: 6px; }
.editor-alias-row {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); transition: var(--transition);
}
.editor-alias-row:hover { border-color: var(--primary); background: var(--primary-light); }
.editor-alias-letter {
  min-width: 22px; font-weight: 700; font-size: 12px; color: var(--primary);
  text-align: center; flex-shrink: 0;
}
.editor-alias-original {
  font-size: 12px; color: var(--muted); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 90px; flex-shrink: 0;
}
.editor-alias-arrow { color: var(--muted); font-size: 12px; flex-shrink: 0; }
.editor-alias-input {
  flex: 1; min-width: 0; padding: 4px 8px; border: 1px solid var(--border); border-radius: 5px;
  font-size: 13px; background: white; color: var(--text); transition: var(--transition);
  font-family: inherit;
}
.editor-alias-input:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.1);
}
.editor-alias-input::placeholder { color: var(--muted); opacity: .6; }

/* --- Alignment pill-group toggles --- */
.editor-align-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); transition: var(--transition);
}
.editor-align-pill {
  display: inline-flex; border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden; box-shadow: inset 0 1px 2px rgba(0,0,0,.04);
}
.editor-align-pill-btn {
  width: 36px; height: 30px; border: none; background: var(--surface);
  cursor: pointer; color: var(--muted); transition: var(--transition);
  display: inline-flex; align-items: center; justify-content: center;
  border-right: 1px solid var(--border); padding: 0;
}
.editor-align-pill-btn:last-child { border-right: none; }
.editor-align-pill-btn:hover { background: var(--surface-2); color: var(--text); }
.editor-align-pill-btn.active {
  background: var(--primary); color: white;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.15);
}
.editor-align-pill-btn svg { pointer-events: none; }

/* Legacy .editor-align-btn kept for bold toggles in level cards */
.editor-align-btn {
  width: 32px; height: 28px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--surface); cursor: pointer; font-size: 12px; font-weight: 700;
  color: var(--muted); transition: var(--transition); display: inline-flex;
  align-items: center; justify-content: center;
}
.editor-align-btn:hover { background: var(--surface-2); color: var(--text); }
.editor-align-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

/* --- Level color picker cards --- */
.editor-level-card {
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
  margin-bottom: 8px; background: var(--surface); transition: var(--transition);
}
.editor-level-card:hover { border-color: rgba(37,99,235,.25); }
.editor-level-card-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; gap: 8px;
}
.editor-level-card-title { display: flex; flex-direction: column; min-width: 0; }
.editor-level-card-name { font-weight: 700; font-size: 12px; color: var(--text); }
.editor-level-card-sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.editor-level-card-controls { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.editor-color-swatch {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 6px; cursor: pointer;
  border: 2px solid var(--border); transition: var(--transition);
  position: relative; overflow: hidden;
}
.editor-color-swatch:hover { border-color: var(--primary); }
.editor-color-swatch input[type="color"] {
  position: absolute; inset: -4px; width: calc(100% + 8px); height: calc(100% + 8px);
  opacity: 0; cursor: pointer; border: none;
}
.editor-color-swatch-sm { width: 24px; height: 24px; border-radius: 5px; }

.editor-level-bold-btn {
  width: 28px; height: 28px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); cursor: pointer; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; transition: var(--transition); padding: 0;
}
.editor-level-bold-btn:hover { background: var(--surface-2); color: var(--text); }
.editor-level-bold-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

.editor-level-card-preview {
  padding: 6px 10px; font-size: 12px; border-top: 1px solid var(--border);
}
.editor-level-card-preview span { display: block; }

/* --- Radio group --- */
.editor-radio-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.editor-radio {
  display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer;
}
.editor-radio input[type="radio"] { accent-color: var(--primary); margin: 0; }

/* --- Width sliders --- */
.editor-widths-sliders { display: flex; flex-direction: column; gap: 8px; }
.editor-width-row { display: flex; align-items: center; gap: 8px; }
.editor-width-label { min-width: 24px; font-weight: 700; font-size: 13px; color: var(--primary); text-align: center; }
.editor-width-slider {
  flex: 1; -webkit-appearance: none; appearance: none; height: 6px; border-radius: 3px;
  background: var(--surface-2); outline: none; cursor: pointer;
}
.editor-width-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--primary); cursor: pointer; border: 2px solid white;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.editor-width-slider::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--primary); cursor: pointer; border: 2px solid white;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.editor-width-value { min-width: 48px; text-align: right; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ====================================================================
   iPhone Mockup (pure CSS)
   ==================================================================== */

.iphone-mockup {
  position: relative;
  background: #0a0a0a;
  border-radius: 54px;
  padding: 14px;
  box-shadow:
    0 0 0 1px rgba(255,255,255,.08),
    0 30px 80px rgba(0,0,0,.45),
    inset 0 0 0 2px rgba(255,255,255,.05);
  transition: all 0.35s cubic-bezier(.4,0,.2,1);
  cursor: pointer;
}
.iphone-mockup[data-orientation="portrait"] { width: 340px; }
.iphone-mockup[data-orientation="landscape"] { width: 620px; }

/* Dynamic Island */
.iphone-island {
  position: absolute; top: 18px; left: 50%; transform: translateX(-50%);
  width: 100px; height: 28px;
  background: #000; border-radius: 20px; z-index: 12;
}

/* Status bar */
.iphone-statusbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 20px 2px;
  font-size: 12px; font-weight: 600; color: #1c1c1e; z-index: 11; position: relative;
}
.iphone-statusbar-right { display: flex; align-items: center; gap: 6px; color: #1c1c1e; }
.iphone-time { font-size: 14px; font-weight: 700; }

/* Screen */
.iphone-screen {
  background: #ffffff;
  border-radius: 40px;
  overflow: hidden;
  position: relative;
}
.iphone-mockup[data-orientation="portrait"] .iphone-screen { height: 580px; }
.iphone-mockup[data-orientation="landscape"] .iphone-screen { height: 300px; }

.iphone-content {
  width: 100%; height: calc(100% - 50px);
  overflow-x: auto; overflow-y: auto;
  padding: 40px 8px 8px;
  -webkit-overflow-scrolling: touch;
}

/* Home indicator */
.iphone-home-indicator {
  display: flex; align-items: center; justify-content: center;
  height: 20px; position: absolute; bottom: 4px; left: 0; right: 0;
}
.iphone-home-bar {
  width: 120px; height: 4px; background: #1c1c1e; border-radius: 3px; opacity: .25;
}

/* Placeholder */
.preview-placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; color: var(--muted); text-align: center;
}
.preview-placeholder p { font-size: 13px; margin-top: 12px; }

/* Loading spinner */
.preview-loading {
  display: flex; align-items: center; justify-content: center; height: 100%;
}
.preview-spinner {
  width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: editorSpin .7s linear infinite;
}
@keyframes editorSpin { to { transform: rotate(360deg); } }

/* ====================================================================
   Preview table inside iPhone (ep = editor-preview)
   Mirrors report-viewer-table + excel-table styles for 1:1 mobile match
   ==================================================================== */

.ep-table {
  width: 100%; border-collapse: collapse; table-layout: auto;
  max-width: 100%;
}
.ep-table .ep-col-toggle { width: 32px; min-width: 32px; max-width: 32px; }
.ep-table thead { background: var(--surface-2); }
.ep-th {
  padding: 8px 10px; font-size: 0.85em; font-weight: 700;
  text-transform: uppercase; letter-spacing: .3px; border-bottom: 2px solid #94a3b8;
  position: sticky; top: 0; z-index: 2; white-space: nowrap;
  text-align: left; box-shadow: 0 1px 0 #94a3b8;
}
.ep-th-text { display: block; overflow: hidden; text-overflow: ellipsis; }
.ep-resize-handle {
  position: absolute; top: 0; right: 0; width: 6px; height: 100%;
  cursor: col-resize; z-index: 3;
}
.ep-resize-handle:hover { background: var(--primary); opacity: .3; }
.ep-cell {
  padding: 8px 10px; border-bottom: 1px solid #cbd5e1;
  border-right: 1px solid #cbd5e1;
  word-wrap: break-word; overflow-wrap: break-word; white-space: normal;
}
.ep-cell:last-child { border-right: none; }
.ep-cell-toggle {
  width: 32px; min-width: 32px; text-align: center; vertical-align: middle;
  padding: 0 !important;
}

/* Group rows — mirrors excel-row-parent / excel-row-child */
.ep-row-parent td { background: #1e293b; color: #fff; font-weight: 700; }
.ep-row-child td { background: #f8fafc; }
.ep-row-child:hover td { background: var(--primary-light); }
.ep-group-collapsed + .ep-row-child { }
tr.ep-child-hidden { display: none; }

.ep-toggle-btn {
  border: none; background: transparent; cursor: pointer; color: inherit;
  width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px; font-size: 10px; padding: 0;
}
.ep-toggle-btn:hover { background: rgba(255,255,255,.2); }
.ep-chevron { font-size: 10px; }

/* Raw preview (all rows, for start_row selection) */
.ep-raw-table td { cursor: pointer; }
.ep-raw-row:hover td { background: var(--primary-light) !important; }
.ep-row-dimmed td { opacity: .35; }

/* Start row marker */
.ep-start-marker {
  position: absolute; left: 0; right: 0; pointer-events: none; z-index: 5;
}
.ep-start-marker-label {
  display: inline-block; background: var(--danger); color: white; font-size: 9px;
  font-weight: 700; padding: 1px 6px; border-radius: 4px;
}

/* ====================================================================
   Backdrop (mobile bottom-sheet overlay)
   ==================================================================== */
.editor-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 200; opacity: 0; transition: opacity .3s ease;
  pointer-events: none;
}

/* ====================================================================
   RESPONSIVE — mobile bottom-sheet, tablet stacked
   ==================================================================== */
@media (max-width: 768px) {
  .editor-body { flex-direction: column; align-items: center; }
  .editor-preview-pane { width: 100%; }

  .iphone-mockup { width: 100% !important; max-width: 340px; }

  .editor-settings {
    position: fixed; bottom: 0; left: 0; right: 0;
    width: 100% !important; min-width: 100% !important; max-width: 100% !important;
    max-height: 70vh; border-radius: 16px 16px 0 0;
    transform: translateY(100%); opacity: 1; overflow: hidden;
    z-index: 210; padding: 0;
    transition: transform 0.35s cubic-bezier(.4,0,.2,1);
  }
  .editor-settings-open {
    transform: translateY(0); padding: 20px;
    overflow-y: auto;
  }
  .editor-backdrop.editor-backdrop-visible {
    display: block; opacity: 1; pointer-events: auto;
  }

  .editor-columns-grid { grid-template-columns: 1fr; }
  .editor-header { padding: 8px 0; }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .editor-settings-open { width: 320px; min-width: 320px; }
  .iphone-mockup[data-orientation="portrait"] { width: 300px; }
  .iphone-mockup[data-orientation="landscape"] { width: 520px; }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .editor-settings, .editor-body, .editor-preview-pane,
  .iphone-mockup, .editor-backdrop, .editor-hint {
    transition: none !important;
    animation: none !important;
  }
}

/* ====================================================================
   VIEWER — no sidebar, top bar + compact report cards
   ==================================================================== */
.viewer-no-sidebar { flex-direction: column; }
.viewer-no-sidebar .viewer-main-content { margin-left: 0; }

/* Top bar */
.viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.viewer-bar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.viewer-bar-left svg { color: var(--primary); flex-shrink: 0; }
.viewer-bar-company {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}
.viewer-bar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}
.viewer-bar-user {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}
.viewer-bar-logout {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  transition: background .15s, color .15s;
}
.viewer-bar-logout:hover {
  background: #fee2e2;
  color: #dc2626;
}

/* Report cards */
.viewer-report-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.viewer-report-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  transition: border-color .15s, box-shadow .2s;
}
.viewer-report-card:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.viewer-report-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: #eff6ff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.viewer-report-icon svg { color: var(--primary); }
.viewer-report-name {
  flex: 1;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}
.viewer-report-arrow {
  flex-shrink: 0;
  color: #cbd5e1;
  transition: color .15s, transform .15s;
}
.viewer-report-card:hover .viewer-report-arrow {
  color: var(--primary);
  transform: translateX(2px);
}

@media (max-width: 768px) {
  .viewer-bar { padding: 10px 16px; }
  .viewer-bar-user { display: none; }
}
