/* === REPORTS SAAS — Design System === */
.skip-nav{position:absolute;left:-9999px;top:auto;width:1px;height:1px;overflow:hidden;z-index:9999;background:#2563eb;color:#fff;padding:12px 24px;border-radius:0 0 8px 0;font-weight:600;text-decoration:none}
.skip-nav:focus{left:0;top:0;width:auto;height:auto;overflow:visible}

: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; height: 100dvh; 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; min-height: 0; 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); flex-shrink: 0; }
.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; }
.bottom-nav { display: none; }
.mobile-profile-btn { margin-left: auto; text-decoration: none; }

@media (max-width: 768px) {
  html, body { overflow-x: hidden; max-width: 100vw; }
  .sidebar { display: none !important; }
  .main-content { margin-left: 0; padding-bottom: 72px; width: 100%; }
  .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; }
  .mobile-logo { height: 24px; width: auto; max-width: 120px; object-fit: contain; }
  .content { padding: 16px; width: 100%; max-width: 100%; }
  
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 100;
    padding: 4px 0;
    padding-bottom: max(4px, env(safe-area-inset-bottom));
  }
  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 4px;
    color: var(--muted);
    text-decoration: none;
    font-size: 10px;
    font-weight: 500;
    transition: color .15s;
  }
  .bottom-nav-item.active { color: var(--primary); }
  .bottom-nav-item:hover { color: var(--primary); }
  .bottom-nav-item svg { opacity: .6; }
  .bottom-nav-item.active svg { opacity: 1; }
  .bottom-nav-logout { color: var(--danger); }
  .bottom-nav-logout svg { opacity: .7; }
  .bottom-nav-logout:hover { color: var(--danger); }
}

@media (max-width: 768px) {
  .messages-container { padding: 12px 16px 0; }
}

/* === 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; flex-direction: column; align-items: center; justify-content: center; background: var(--bg); padding: 20px; }
.auth-logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; color: var(--text); text-decoration: none; margin-bottom: 24px; letter-spacing: -.02em; transition: opacity .2s; }
.auth-logo:hover { opacity: .7; }
.auth-logo svg { flex-shrink: 0; }
.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; }
.icon-btn { display:inline-flex;align-items:center;justify-content:center;width:32px;height:32px;border-radius:8px;color:var(--muted);transition:all .15s;text-decoration:none;border:1px solid transparent; }
.icon-btn:hover { background:rgba(37,99,235,.06);color:var(--primary);border-color:rgba(37,99,235,.15); }

/* === 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; }

/* Styled file input */
input[type="file"] {
  width: 100%; max-width: 480px; padding: 10px 14px; border: 2px dashed var(--border); border-radius: 10px;
  font-size: 13px; color: var(--muted); background: var(--bg); cursor: pointer; transition: var(--transition);
}
input[type="file"]:hover { border-color: var(--primary); background: var(--primary-light); }
input[type="file"]::file-selector-button {
  padding: 6px 14px; border: none; border-radius: 6px; background: var(--primary); color: white;
  font-weight: 600; font-size: 12px; cursor: pointer; margin-right: 12px; transition: var(--transition);
}
input[type="file"]::file-selector-button:hover { background: var(--primary-hover); }

/* Styled search inputs */
input[type="search"], .search-input {
  padding: 10px 14px 10px 36px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 14px; background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3b8' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z'/%3E%3C/svg%3E") 12px center no-repeat;
  transition: var(--transition);
}
input[type="search"]:focus, .search-input:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

/* === 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; }

/* Pulsing dot for active badge */
.badge-success-pulse { gap: 6px; }
.badge-success-pulse::before {
  content: ''; display: block; width: 7px; height: 7px; border-radius: 50%;
  background: #16a34a; box-shadow: 0 0 0 0 rgba(22,163,74,.5);
  animation: badgePulse 2s ease-in-out infinite;
}
@keyframes badgePulse { 0%,100% { box-shadow: 0 0 0 0 rgba(22,163,74,.45); } 50% { box-shadow: 0 0 0 5px rgba(22,163,74,0); } }

/* Badge fade-in */
.report-card-badges .badge { animation: badgeFadeIn .4s ease-out both; }
.report-card-badges .badge:nth-child(2) { animation-delay: .1s; }
@keyframes badgeFadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* === 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: 6px; color: var(--muted); font-size: 13px; font-weight: 600; margin-top: 24px;
  padding: 8px 16px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border);
  transition: all .2s ease; box-shadow: var(--shadow-sm);
}
.back-link:hover { color: var(--primary); background: var(--primary-light); border-color: rgba(37,99,235,.2); transform: translateX(-2px); }

/* === 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 card container === */
.report-card {
  background: #fff; border-radius: 16px; border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,.04), 0 4px 24px rgba(0,0,0,.06);
  overflow: hidden; margin-bottom: 24px;
}
.report-card-header {
  display: flex; align-items: center; gap: 14px; padding: 20px 24px;
  border-bottom: 1px solid var(--border); background: linear-gradient(to bottom, #f8fafc, #fff);
}
.report-card-icon {
  width: 44px; height: 44px; border-radius: 12px; background: linear-gradient(135deg, var(--primary), #6366f1);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(37,99,235,.25);
}
.report-card-icon svg { color: #fff; }
.report-card-meta { flex: 1; min-width: 0; }
.report-card-title { font-size: 18px; font-weight: 700; color: var(--text); margin: 0; line-height: 1.3; }
.report-card-desc { font-size: 13px; color: var(--muted); margin: 2px 0 0; }
.report-card-badges { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.report-card-badges .badge { font-size: 11px; padding: 2px 8px; }
.report-card-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.report-card-body { padding: 0; }

/* === Report viewer === */
.report-viewer-toolbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; background: rgba(248,250,252,.85); border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 3;
  box-shadow: 0 1px 3px rgba(0,0,0,.03);
}
.report-viewer-toolbar-left { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.report-viewer-toolbar-right { display: flex; align-items: center; gap: 8px; }
.report-search-input {
  width: 260px; max-width: 100%; padding: 8px 14px 8px 36px;
  border: 1px solid var(--border); border-radius: 10px; font-size: 14px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2394a3b8' viewBox='0 0 24 24'%3E%3Cpath d='M21 21l-4.35-4.35M11 19a8 8 0 100-16 8 8 0 000 16z' stroke='%2394a3b8' stroke-width='2' fill='none'/%3E%3C/svg%3E") 12px center no-repeat;
  transition: border-color .15s, box-shadow .15s;
}
.report-search-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); outline: none; }
.report-viewer-wrap { overflow-x: auto; overflow-y: auto; max-height: 70vh; }
.report-viewer-table { table-layout: fixed; border-collapse: separate; border-spacing: 0; }
.report-viewer-table thead th {
  position: sticky; top: 0; z-index: 2; white-space: nowrap;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid #cbd5e1; border-right: 1px solid #cbd5e1;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  padding: 12px 14px;
}
.report-viewer-table thead th:last-child { border-right: none; }
.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: none; }
.report-viewer-table tbody tr.report-row-no-match { display: none; }
.report-viewer-table tbody tr { transition: background .15s ease, box-shadow .15s ease; }
.report-viewer-table tbody tr:hover td { background: rgba(37,99,235,.035) !important; }
.report-viewer-table td.report-cell {
  word-wrap: break-word; overflow-wrap: break-word; white-space: normal;
  padding: 10px 14px; font-variant-numeric: tabular-nums; font-feature-settings: 'tnum';
  line-height: 1.5; transition: background .15s ease;
}
.report-viewer-table td.report-cell:first-child { padding-left: 14px; }
.report-viewer-table tbody tr:last-child td { border-bottom: none; }

/* Summary/total row */
.report-viewer-table tbody tr[data-level="0"] { position: relative; }
.report-viewer-table tbody tr[data-level="0"] td {
  border-top: 2px solid rgba(255,255,255,.2);
  font-weight: 700; letter-spacing: .01em;
}
.report-viewer-table tbody tr[data-level="0"] td:first-child {
  box-shadow: inset 4px 0 0 0 var(--primary);
}

/* === Report chart container === */
.report-chart-card {
  background: linear-gradient(170deg, #fff 60%, #f0f4ff); border-radius: 16px; border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,.04), 0 4px 24px rgba(0,0,0,.06);
  padding: 24px; margin-top: 20px;
}
.report-chart-card canvas { border-radius: 8px; }

/* === 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-card { border-radius: 8px; margin-left: -12px; margin-right: -12px; margin-bottom: 16px; width: calc(100% + 24px); }
  .report-card-header { flex-direction: row; align-items: center; gap: 10px; padding: 12px 14px; }
  .report-card-icon { width: 36px; height: 36px; border-radius: 10px; }
  .report-card-icon svg { width: 18px; height: 18px; }
  .report-card-meta { flex: 1; min-width: 0; }
  .report-card-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .report-card-desc { display: none; }
  .report-card-badges { margin-top: 2px; }
  .report-card-badges .badge { font-size: 10px; padding: 1px 6px; }
  .report-card-actions { display: flex; flex-shrink: 0; }
  .report-card-actions .btn-secondary { display: none; }
  .report-card-actions .btn-primary { padding: 6px 10px; font-size: 12px; }
  .report-viewer-toolbar { flex-direction: column; align-items: stretch; padding: 8px 10px; }
  .report-viewer-toolbar-left { justify-content: flex-start; }
  .report-search-input { width: 100%; font-size: 16px; padding-left: 36px; }
  .report-viewer-wrap {
    max-height: none;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    max-width: 100%;
    margin: 0;
  }
  .report-viewer-table { table-layout: auto; max-width: none; }
  .report-viewer-table thead th { white-space: nowrap; max-width: none; }
  .report-viewer-table td.report-cell { word-wrap: break-word; overflow-wrap: break-word; white-space: normal; max-width: none; }
  .report-viewer-table col { max-width: none; }
  .report-chart-card { border-radius: 8px; padding: 12px; margin-left: -12px; margin-right: -12px; margin-top: 12px; width: calc(100% + 24px); }
  .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: stretch;
  min-height: calc(100vh - 56px);
  transition: all 0.35s cubic-bezier(.4,0,.2,1);
}
.editor-preview-pane {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: 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: #1a1a1e;
  border-radius: 28px;
  padding: 7px;
  box-shadow:
    0 24px 64px rgba(0,0,0,.18),
    0 0 0 1px rgba(255,255,255,.08) inset,
    0 0 0 2px rgba(0,0,0,.25);
  transition: all 0.35s cubic-bezier(.4,0,.2,1);
  cursor: pointer;
}
.iphone-mockup[data-orientation="portrait"] {
  aspect-ratio: 9 / 19.5;
  height: calc(100vh - 120px);
  max-height: 720px;
  max-width: 340px;
  min-height: 420px;
  width: auto;
  display: flex;
  flex-direction: column;
}
.iphone-mockup[data-orientation="landscape"] { width: 620px; }

/* Dynamic Island */
.iphone-island {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  width: 80px; height: 22px;
  background: #000; border-radius: 14px; 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: 22px;
  overflow: hidden;
  position: relative;
}
.iphone-mockup[data-orientation="portrait"] .iphone-screen { flex: 1; min-height: 0; }
.iphone-mockup[data-orientation="landscape"] .iphone-screen { height: 300px; }

.iphone-content {
  width: 100%; height: calc(100% - 50px);
  overflow-x: auto; overflow-y: auto;
  padding: 6px 0 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: separate; border-spacing: 0; table-layout: auto;
  max-width: 100%; border-radius: 8px; overflow: hidden;
}
.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.8em; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 1px solid #cbd5e1; border-right: 1px solid #cbd5e1;
  position: sticky; top: 0; z-index: 2; white-space: nowrap;
  text-align: left;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.ep-th:last-child { border-right: none; }
.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: 7px 10px; border-bottom: 1px solid #cbd5e1;
  border-right: 1px solid #cbd5e1;
  word-wrap: break-word; overflow-wrap: break-word; white-space: normal;
  font-variant-numeric: tabular-nums; transition: background .1s;
}
.ep-cell:last-child { border-right: none; }
.ep-cell-toggle {
  width: 32px; min-width: 32px; text-align: center; vertical-align: middle;
  padding: 0 !important;
}

/* Hover on preview rows */
.ep-row:hover td { filter: brightness(.94); }

/* Group rows */
.ep-row-parent td { font-weight: 700; border-top: 2px solid rgba(255,255,255,.15); }
.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; }

/* Preview chart container inside mockup */
.ep-chart-wrap {
  padding: 8px; background: #fff; border-radius: 8px;
  margin: 8px 4px; box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

/* 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: auto !important; max-width: 300px; height: auto; max-height: 60vh; aspect-ratio: 9 / 19.5; margin: 0 auto; }

  .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"] {
    aspect-ratio: 9 / 19.5;
    height: calc(100vh - 60px);
    max-height: 750px;
    min-height: 450px;
    width: auto;
    display: flex;
    flex-direction: column;
  }
  .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);
}

.viewer-bar-profile-btn {
  display: none;
  text-decoration: none;
}

@media (max-width: 768px) {
  .viewer-bar { padding: 10px 16px; }
  .viewer-bar-user { display: none; }
  .viewer-bar-profile-btn { display: flex; align-items: center; }
  .viewer-bar-logout-text { display: none; }
}

/* === Tablet (769px-1024px) === */
@media (min-width: 769px) and (max-width: 1024px) {
  :root { --sidebar-w: 220px; }
  .sidebar-brand { padding: 16px 14px 12px; font-size: 16px; }
  .sidebar { height: 100vh; height: 100dvh; }
  .sidebar-nav { flex: 1; min-height: 0; overflow-y: auto; }
  .sidebar-footer { flex-shrink: 0; }
  .nav-item { padding: 8px 10px; font-size: 13px; }
  .content { padding: 24px; }
  .grid-3 { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}

/* === Global responsive polish === */
@media (max-width: 768px) {
  h1 { font-size: 22px; }
  h2 { font-size: 18px; }
  .card { padding: 16px; border-radius: 12px; }
  .card h2 { margin-bottom: 12px; padding-bottom: 10px; }
  .page-header { margin-bottom: 16px; }
  .page-header h1 { font-size: 20px; }
  .btn { padding: 10px 16px; font-size: 14px; }
  .grid-3 { grid-template-columns: 1fr; }
  .auth-card { padding: 28px 20px; }
  .auth-card h1 { font-size: 22px; }
  .form-group input, .form-group select, .form-group textarea,
  form p input, form p select { max-width: 100%; font-size: 16px; }
  input[type="file"] { max-width: 100%; }
  table { font-size: 13px; }
  .stat-card { padding: 16px; }
}

/* === Smooth transitions everywhere === */
.card { transition: box-shadow .2s ease; }
.card:hover { box-shadow: var(--shadow-sm); }

/* === Responsive visibility === */
.desktop-only { display: block; }
.mobile-only { display: none !important; }
@media (max-width: 768px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: flex !important; }
}

/* === Member cards (mobile) === */
.member-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; transition: border-color .15s;
}
.member-card:hover { border-color: rgba(37,99,235,.3); }
.member-card-top {
  display: flex; align-items: center; gap: 12px;
}
.member-card-avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--primary);
  color: white; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; flex-shrink: 0;
}
.member-card-info { flex: 1; min-width: 0; }
.member-card-name { font-weight: 600; font-size: 14px; }
.member-card-login { font-size: 12px; color: var(--muted); }
.member-card-badges { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; }
.member-card-actions {
  display: flex; gap: 8px; margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* === Report mobile cards === */
.report-mobile-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; transition: border-color .15s;
}
.report-mobile-card:hover { border-color: rgba(37,99,235,.3); }
.report-mobile-card-top {
  display: flex; align-items: center; gap: 12px; padding: 14px;
  text-decoration: none; color: var(--text);
}
.report-mobile-icon {
  width: 40px; height: 40px; border-radius: 10px; background: #eff6ff;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.report-mobile-icon svg { color: var(--primary); }
.report-mobile-card-actions {
  display: flex; gap: 8px; padding: 0 14px 14px;
}

/* === Styled search (global) === */
.search-input {
  padding: 10px 14px 10px 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%2394a3b8' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z'/%3E%3C/svg%3E") 12px center no-repeat;
  transition: var(--transition);
  -webkit-appearance: none;
}
.search-input:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
@media (max-width: 768px) {
  .search-input { font-size: 16px; padding: 12px 14px 12px 40px; }
}

/* ====================================================================
   MOBILE FIX PACK — comprehensive fixes for all pages
   ==================================================================== */
@media (max-width: 768px) {

  /* --- Prevent ANY overflow (exclude tables and their children for scrollable report viewer) --- */
  *:not(table):not(colgroup):not(col):not(thead):not(tbody):not(tr):not(th):not(td):not(.table-wrap):not(.report-viewer-wrap):not(.report-card):not(.report-chart-card),
  *::before, *::after { max-width: 100%; }
  .content { overflow-wrap: break-word; word-break: break-word; }
  .content:not(:has(.report-viewer-wrap)) { overflow-x: hidden; }

  /* --- Credential box overflow fix --- */
  .credential-box {
    flex-direction: column; gap: 10px; align-items: stretch;
    font-size: 13px; padding: 14px; word-break: break-all;
  }
  .credential-box .copy-btn { align-self: flex-end; }

  /* --- Branding grid: 1 column on mobile --- */
  .card div[style*="grid-template-columns:1fr 1fr"] {
    display: flex !important; flex-direction: column !important; gap: 20px !important;
  }

  /* --- Settings nav cards: single column, full width --- */
  div[style*="minmax(240px"] {
    display: flex !important; flex-direction: column !important; gap: 12px !important;
  }
  div[style*="minmax(240px"] > a {
    padding: 16px !important;
  }

  /* --- Subscription grid: 1 column --- */
  div[style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* --- Pricing cards: 1 column --- */
  div[style*="minmax(280px"] {
    grid-template-columns: 1fr !important;
  }

  /* --- Limits grid: 2 columns fixed --- */
  div[style*="minmax(150px"] {
    grid-template-columns: 1fr 1fr !important;
  }

  /* --- Table mobile: scroll hint, compact --- */
  .table-wrap:not(.report-viewer-wrap) { margin: 0 -16px; border-radius: 0; border-left: none; border-right: none; }
  .table-wrap:not(.report-viewer-wrap) table { min-width: 500px; }
  thead th { padding: 8px 10px; font-size: 11px; }
  tbody td { padding: 8px 10px; font-size: 13px; }

  /* --- Toolbar: stack vertically --- */
  .toolbar {
    flex-direction: column; align-items: stretch; gap: 12px;
  }
  .search-box { flex-direction: column; }
  .search-box input { width: 100% !important; font-size: 16px; }

  /* --- Actions: wrap nicely --- */
  .actions { gap: 8px; }
  .actions .btn { flex: 1; justify-content: center; min-width: 0; }
  td .actions { flex-wrap: nowrap; }
  td .actions .btn { flex: none; }

  /* --- Upload zone: compact --- */
  .upload-zone { padding: 20px 16px; }

  /* --- Alert overflow --- */
  .alert { font-size: 13px; gap: 8px; }

  /* --- Payment history table: hide ID column --- */
  .card table th:nth-child(4),
  .card table td:nth-child(4) { display: none; }

  /* --- Buttons: no overflow --- */
  .btn { white-space: normal; text-align: center; }
  .btn-sm { font-size: 13px; padding: 8px 12px; }

  /* --- Form max-width removal --- */
  .form-group input, .form-group select, .form-group textarea,
  form p input, form p select, input[type="file"],
  input[type="search"], .search-input, .report-search-input {
    max-width: 100% !important; width: 100% !important;
  }

  /* --- Settings form grid: 1 column --- */
  .card div[style*="grid-template-columns:1fr 1fr"][style*="max-width:480px"] {
    grid-template-columns: 1fr !important;
  }

  /* --- Code input centered --- */
  input[style*="letter-spacing:8px"] {
    max-width: 200px !important; margin: 0 auto; display: block;
  }

  /* --- Page price font smaller on mobile --- */
  span[style*="font-size:32px"] { font-size: 26px !important; }

  /* --- Empty state compact --- */
  .empty-state { padding: 32px 16px; }

  /* --- Back link spacing --- */
  .back-link { margin-top: 16px; margin-bottom: 16px; }
}

/* ─── Icon picker (report editor) ─── */
.editor-icon-picker {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.editor-icon-btn {
  width: 42px; height: 42px; border: 2px solid var(--border); border-radius: 10px;
  background: var(--surface); cursor: pointer; display: inline-flex;
  align-items: center; justify-content: center; color: var(--muted);
  transition: all .15s ease; padding: 0;
}
.editor-icon-btn:hover { border-color: var(--primary); color: var(--primary); background: rgba(37,99,235,.04); }
.editor-icon-btn.active { border-color: var(--primary); color: var(--primary); background: rgba(37,99,235,.08); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.editor-icon-btn svg { pointer-events: none; }
