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

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --danger: #dc2626;
  --success: #16a34a;
  --badge-daily: #dbeafe;
  --badge-daily-text: #1d4ed8;
  --badge-weekly: #dcfce7;
  --badge-weekly-text: #15803d;
  --badge-monthly: #fef3c7;
  --badge-monthly-text: #b45309;
  --sidebar-w: 240px;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; }

/* --- Auth --- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 40px; width: 100%; max-width: 380px; box-shadow: 0 4px 24px rgba(0,0,0,.06); }
.auth-card h1 { font-size: 1.4rem; margin-bottom: 8px; }
.auth-card p { color: var(--text-muted); font-size: .9rem; margin-bottom: 28px; }

/* --- Forms --- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: 6px; }
.form-group input, .form-group select { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: .95rem; background: var(--surface); transition: border-color .15s; }
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--primary); }

/* --- Buttons --- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 10px 18px; border-radius: 8px; font-size: .9rem; font-weight: 500; cursor: pointer; border: none; transition: background .15s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 12px; font-size: .82rem; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* --- Alert --- */
.alert { padding: 10px 14px; border-radius: 8px; font-size: .88rem; margin-bottom: 16px; }
.alert-error { background: #fee2e2; color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: #dcfce7; color: var(--success); border: 1px solid #bbf7d0; }
.hidden { display: none !important; }

/* --- Layout --- */
.layout { display: flex; min-height: 100vh; }

/* --- Sidebar --- */
.sidebar { width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh; z-index: 10; }
.sidebar-header { padding: 20px 16px; border-bottom: 1px solid var(--border); }
.sidebar-header h2 { font-size: 1rem; font-weight: 700; color: var(--primary); }
.sidebar-header span { font-size: .78rem; color: var(--text-muted); }
.sidebar-nav { padding: 12px 8px; flex: 1; overflow-y: auto; }
.nav-section { font-size: .72rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; padding: 8px 8px 4px; }
.nav-item { display: block; padding: 8px 10px; border-radius: 6px; font-size: .88rem; color: var(--text); cursor: pointer; text-decoration: none; transition: background .1s; border: none; background: none; width: 100%; text-align: left; }
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: #eff6ff; color: var(--primary); font-weight: 500; }
.sidebar-footer { padding: 12px 8px; border-top: 1px solid var(--border); }

/* --- Main --- */
.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 24px; display: flex; align-items: center; gap: 12px; }
.topbar h1 { font-size: 1.1rem; font-weight: 600; flex: 1; }
.content { padding: 24px; flex: 1; }

/* --- Filters --- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.filters input, .filters select { padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: .88rem; background: var(--surface); }
.filters input { min-width: 220px; }
.filters input:focus, .filters select:focus { outline: none; border-color: var(--primary); }

/* --- Report Grid --- */
.report-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.report-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 18px; display: flex; flex-direction: column; gap: 10px; transition: box-shadow .15s; }
.report-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.08); }
.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card-title { font-size: .95rem; font-weight: 600; line-height: 1.35; }
.card-meta { font-size: .8rem; color: var(--text-muted); display: flex; gap: 10px; flex-wrap: wrap; }
.card-actions { display: flex; gap: 6px; margin-top: 4px; }

/* --- Badges --- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .75rem; font-weight: 500; }
.badge-daily { background: var(--badge-daily); color: var(--badge-daily-text); }
.badge-weekly { background: var(--badge-weekly); color: var(--badge-weekly-text); }
.badge-monthly { background: var(--badge-monthly); color: var(--badge-monthly-text); }
.badge-sub { background: #f1f5f9; color: var(--text-muted); }

/* --- Empty State --- */
.empty { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty svg { margin-bottom: 12px; opacity: .4; }
.empty p { font-size: .95rem; }

/* --- Report Viewer --- */
.viewer-wrap { display: flex; flex-direction: column; height: 100vh; }
.viewer-bar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 20px; display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.viewer-bar h1 { font-size: 1rem; font-weight: 600; flex: 1; }
.viewer-meta { font-size: .8rem; color: var(--text-muted); display: flex; gap: 12px; align-items: center; }
.viewer-frame { flex: 1; border: none; width: 100%; }

/* --- Admin Table --- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th { background: var(--bg); padding: 10px 14px; text-align: left; font-weight: 600; font-size: .8rem; color: var(--text-muted); border-bottom: 1px solid var(--border); }
td { padding: 10px 14px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }

/* --- Report table --- */
.report-row { cursor: pointer; }
.report-row:hover td { background: #eff6ff; }
.col-title { font-weight: 500; max-width: 320px; }
.col-actions-btns { width: 130px; text-align: right; white-space: nowrap; }
.row-action-btn { opacity: 0; transition: opacity .15s; margin-left: 4px; }
.report-row:hover .row-action-btn { opacity: 1; }
.text-muted { color: var(--text-muted); }

/* --- Modal --- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: var(--surface); border-radius: 12px; padding: 28px; width: 100%; max-width: 420px; box-shadow: 0 8px 40px rgba(0,0,0,.15); }
.modal h2 { font-size: 1.1rem; margin-bottom: 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* --- Spinner --- */
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Role badges */
.role-admin { background: #ede9fe; color: #6d28d9; }
.role-editor { background: #dbeafe; color: #1d4ed8; }
.role-viewer { background: #f1f5f9; color: #475569; }

/* --- Tabs --- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab-btn { padding: 8px 16px; font-size: .88rem; font-weight: 500; border: none; background: none; cursor: pointer; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color .15s, border-color .15s; }
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* --- Share tags --- */
.share-tag { display: inline-flex; align-items: center; gap: 4px; background: #eff6ff; color: var(--primary); border-radius: 99px; padding: 3px 10px; font-size: .78rem; font-weight: 500; }
.share-tag button { border: none; background: none; cursor: pointer; color: inherit; line-height: 1; padding: 0; font-size: .9rem; opacity: .7; }
.share-tag button:hover { opacity: 1; }
.share-list { display: flex; flex-wrap: wrap; gap: 6px; min-height: 28px; }
