:root {
    --primary: #1E3A8A;
    --secondary: #2563EB;
    --accent: #3B82F6;
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;
    --bg: #F8FAFC;
    --card: #FFFFFF;
    --border: #E2E8F0;
    --text-primary: #0F172A;
    --text-secondary: #64748B;
    --shadow: 0 4px 12px rgba(0,0,0,0.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: Inter, sans-serif; background: var(--bg); color: var(--text-primary); }
html { overflow-y: scroll; scrollbar-gutter: stable; }
html.guest-html { overflow-y: auto; scrollbar-gutter: auto; }
body:not(.guest-body) { height: 100vh; overflow: hidden; }
a { color: var(--secondary); text-decoration: none; }

h1 { font-size: 28px; font-weight: 700; line-height: 1.3; margin: 0 0 16px; }
h2 { font-size: 20px; font-weight: 600; line-height: 1.3; margin: 0 0 16px; }
h3 { font-size: 16px; font-weight: 600; line-height: 1.3; margin: 0 0 8px; }
p, li, td, th, input, button, select, textarea { font-size: 14px; line-height: 1.6; }
small, .small { font-size: 12px; line-height: 1.6; color: var(--text-secondary); }

/* Guest page styles are loaded from assets/css/guest-login.css */

.app-shell { min-height: 100vh; height: 100vh; overflow: hidden; }
.sidebar {
    width: 240px;
    background: #fff;
    border-right: 1px solid var(--border);
    padding: 10px 0;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 30;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
    -webkit-overflow-scrolling: touch;
    transition: transform .22s ease;
}
.sidebar-close {
    display: none;
    margin: 8px 12px 4px auto;
    height: 34px;
    font-size: 12px;
}
.main {
    margin-left: 240px;
    width: calc(100vw - 240px);
    min-height: 100vh;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s ease;
    z-index: 25;
}
.sidebar-backdrop.show {
    opacity: 1;
    visibility: visible;
}
.sidebar-brand { padding: 0 16px 16px; border-bottom: 1px solid var(--border); }
.sidebar-brand .primary { font-size: 17px; font-weight: 700; line-height: 1.3; margin: 0; }
.sidebar-brand .secondary { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.sidebar-group { margin-top: 10px; }
.sidebar-section { padding: 0 16px; margin: 0 0 8px; color: var(--text-secondary); font-size: 12px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; }
.menu-link { display: block; padding: 9px 16px; color: var(--text-primary); position: relative; border-radius: 0; font-size: 15px; }
.menu-link:hover { background: #F8FAFC; }
.menu-link.active { background: #EFF6FF; color: var(--secondary); font-weight: 600; }
.menu-link.active::before { content: ''; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; background: var(--secondary); border-radius: 0 3px 3px 0; }
.menu-link.danger { color: var(--danger); }
.sidebar.compact { padding: 6px 0; }
.sidebar.compact .sidebar-brand { padding: 0 12px 10px; }
.sidebar.compact .sidebar-brand .primary { font-size: 15px; }
.sidebar.compact .sidebar-brand .secondary { font-size: 12px; line-height: 1.3; }
.sidebar.compact .sidebar-group { margin-top: 8px; }
.sidebar.compact .sidebar-section { font-size: 11px; margin-bottom: 6px; padding: 0 12px; }
.sidebar.compact .menu-link { padding: 7px 12px; font-size: 14px; line-height: 1.35; }
.sidebar.compact-tight .sidebar-brand .primary { font-size: 14px; }
.sidebar.compact-tight .sidebar-brand .secondary { font-size: 11px; }
.sidebar.compact-tight .sidebar-group { margin-top: 5px; }
.sidebar.compact-tight .sidebar-section { font-size: 10px; margin-bottom: 4px; letter-spacing: .6px; }
.sidebar.compact-tight .menu-link { padding: 6px 12px; font-size: 13px; line-height: 1.3; }

/* Keep sidebar density consistent across all pages, even if compact classes are present. */
.sidebar.compact,
.sidebar.compact-tight {
    padding: 10px 0;
}
.sidebar.compact .sidebar-brand,
.sidebar.compact-tight .sidebar-brand {
    padding: 0 16px 16px;
}
.sidebar.compact .sidebar-brand .primary,
.sidebar.compact-tight .sidebar-brand .primary {
    font-size: 17px;
}
.sidebar.compact .sidebar-brand .secondary,
.sidebar.compact-tight .sidebar-brand .secondary {
    font-size: 13px;
    line-height: 1.6;
}
.sidebar.compact .sidebar-group,
.sidebar.compact-tight .sidebar-group {
    margin-top: 10px;
}
.sidebar.compact .sidebar-section,
.sidebar.compact-tight .sidebar-section {
    font-size: 12px;
    margin-bottom: 8px;
    padding: 0 16px;
    letter-spacing: 1px;
}
.sidebar.compact .menu-link,
.sidebar.compact-tight .menu-link {
    padding: 9px 16px;
    font-size: 15px;
    line-height: 1.6;
}

.topbar { height: 64px; background: #fff; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 24px; position: sticky; top: 0; z-index: 10; }
.global-search { flex: 1; max-width: 520px; }
.global-search input { width: 100%; height: 42px; border: 1px solid var(--border); border-radius: 8px; padding: 0 12px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.badge { font-size: 12px; background: #EFF6FF; color: var(--secondary); border-radius: 999px; padding: 6px 10px; }
.profile-menu { position: relative; }
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border); }
.avatar-fallback { width: 40px; height: 40px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 600; }
.profile-dropdown { display: none; position: absolute; right: 0; top: 46px; min-width: 220px; background: #fff; border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 12px; }
.profile-menu:hover .profile-dropdown { display: block; }
.profile-dropdown a { display: block; padding: 8px 0; }

.content { padding: 24px; display: flex; flex-direction: column; gap: 24px; overflow: auto; min-height: 0; }
.content > * { max-width: 100%; }
.page-footer { padding: 12px 24px 16px; color: var(--text-secondary); font-size: 12px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

.panel { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 20px; box-shadow: var(--shadow); }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(220px,1fr)); gap: 16px; }
.kpi-card { border: 1px solid var(--border); border-radius: 12px; padding: 20px; background: #fff; transition: transform .16s ease, box-shadow .16s ease; }
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.kpi-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
.kpi-number { font-size: 26px; font-weight: 700; line-height: 1.3; margin-bottom: 8px; }
.kpi-sub { font-size: 12px; color: var(--text-secondary); }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart-bars { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr 60px; gap: 8px; align-items: center; }
.bar-track { height: 10px; background: #F1F5F9; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--secondary); border-radius: 999px; }
.leader-card { display: flex; flex-direction: column; gap: 12px; }
.leader-item { border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.progress { height: 8px; background: #F1F5F9; border-radius: 999px; overflow: hidden; margin-top: 6px; }
.progress > span { display: block; height: 100%; background: var(--success); }

.table-head { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.table-head form { display: flex; gap: 8px; align-items: center; }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; background: #fff; }
thead th { background: #F1F5F9; color: var(--text-secondary); font-size: 12px; letter-spacing: .4px; text-transform: uppercase; }
th, td { border-bottom: 1px solid var(--border); padding: 12px; text-align: left; white-space: nowrap; }
tbody tr:hover { background: #F8FAFC; }
.pagination { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: end; }
.grid-form label { font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; display: block; }
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea { width: 100%; height: 42px; border: 1px solid var(--border); border-radius: 8px; padding: 0 12px; background: #fff; }
textarea { min-height: 84px; padding: 10px 12px; }
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):focus, select:focus, textarea:focus { outline: none; border-color: var(--secondary); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--secondary); }

.btn-primary, .btn-secondary, .btn-icon {
    height: 42px;
    border-radius: 8px;
    border: 1px solid transparent;
    padding: 0 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-primary { background: var(--secondary); color: #fff; }
.btn-secondary { background: #fff; color: var(--text-primary); border-color: var(--border); }
.btn-icon { background: #fff; color: var(--text-secondary); border-color: var(--border); }
.full { width: 100%; }

.alert { padding: 12px; border-radius: 8px; font-size: 14px; border: 1px solid transparent; }
.alert-danger { background: #FEE2E2; color: #991B1B; border-color: #FECACA; }
.alert-success { background: #D1FAE5; color: #065F46; border-color: #A7F3D0; }
.alert-warning { background: #FEF3C7; color: #92400E; border-color: #FDE68A; }

.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,0.45); display: none; align-items: center; justify-content: center; z-index: 50; }
.modal-overlay.show { display: flex; }
.modal-box { width: min(420px, 92vw); background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 20px; box-shadow: var(--shadow); }
.crop-modal-box { width: min(520px, 96vw); }
.crop-stage { display: grid; place-items: center; margin: 12px 0; }
#cropCanvas { width: min(420px, 84vw); height: auto; border-radius: 12px; border: 1px solid var(--border); background: #0F172A; cursor: grab; }
#cropCanvas.dragging { cursor: grabbing; }
.crop-controls { margin: 12px 0 16px; }
.crop-controls input[type="range"] { width: 100%; }
.crop-actions { display: flex; gap: 8px; justify-content: flex-end; }

.pricing-grid { display: grid; grid-template-columns: repeat(3, minmax(220px, 1fr)); gap: 16px; }
.price-card { border: 1px solid var(--border); border-radius: 12px; padding: 20px; background: #fff; box-shadow: var(--shadow); }
.price-card.popular { border-color: var(--secondary); }
.price { font-size: 26px; font-weight: 700; line-height: 1.3; margin: 8px 0; }
.pop-tag { font-size: 12px; color: #fff; background: var(--secondary); border-radius: 999px; padding: 3px 8px; margin-left: 8px; }

.login-footer, .app-legal { margin-top: 16px; font-size: 12px; color: var(--text-secondary); line-height: 1.7; }
.dashboard-legal { margin-top: -8px; color: var(--text-secondary); font-size: 11px; line-height: 1.7; }
.ai-assist-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 10px; }
.ai-assist-item { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: #fff; }
.ai-assist-item h3 { margin: 0 0 8px; font-size: 14px; }
.ai-assist-item p { margin: 0; white-space: pre-wrap; }
.ai-meta { margin-top: 8px; }

@media (max-width: 1024px) {
    .main { margin-left: 0; }
    .main { width: 100vw; }
    .sidebar { transform: translateX(-102%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar.open .sidebar-close { display: inline-flex; }
    .split { grid-template-columns: 1fr; }
    .pricing-grid { grid-template-columns: 1fr; }
    .grid-form { grid-template-columns: 1fr; }
    .top-actions .badge:nth-child(2) { display: none; }
}
@media (max-width: 860px) {
    .topbar { padding: 0 10px; gap: 8px; }
    .content { padding: 16px; }
    .page-footer { padding: 12px 16px 16px; }
    .global-search { max-width: 160px; }
    .top-actions { gap: 6px; }
    .top-actions .badge { display: none; }
    .top-actions .btn-primary { padding: 0 10px; font-size: 13px; }
    .profile-dropdown { right: -8px; min-width: 200px; }
    .ai-assist-grid { grid-template-columns: 1fr; }
}

.dashboard-copy { display: flex; flex-direction: column; gap: 14px; }
.copy-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.copy-head h1 { margin: 0; font-size: 28px; font-weight: 700; color: #1E293B; }
.copy-head-actions { display: flex; gap: 8px; align-items: center; }
.copy-quick-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.copy-quick-pill {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    border-radius: 10px;
    border: 1px solid #DBEAFE;
    background: #EFF6FF;
    color: #1E3A8A;
    font-weight: 600;
    text-decoration: none;
    padding: 0 10px;
}
.copy-quick-pill:hover { background: #DBEAFE; }
.copy-quick-pill.primary {
    background: #2563EB;
    color: #fff;
    border-color: #2563EB;
}
.copy-quick-pill.primary:hover { background: #1E3A8A; }
.copy-kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.copy-kpi { background: #fff; border: 1px solid #E2E8F0; border-radius: 10px; padding: 12px; min-height: 92px; }
.copy-kpi-link { color: inherit; display: block; transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease; }
.copy-kpi-link:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(15, 23, 42, 0.08); border-color: #93C5FD; }
.copy-kpi p { margin: 0; font-size: 12px; color: #64748B; line-height: 1.3; }
.copy-kpi h3 { margin: 8px 0 0; font-size: 22px; color: #0F172A; line-height: 1.2; }
.copy-kpi span { font-size: 11px; color: #16A34A; display: block; margin-top: 4px; }
.copy-grid { display: grid; grid-template-columns: 1.2fr 1.4fr; gap: 12px; align-items: start; }
.copy-panel { padding: 12px; border-radius: 10px; }
.copy-panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.copy-panel-head h2 { font-size: 18px; margin: 0; }
.copy-stage-row { display: grid; grid-template-columns: 92px 1fr 24px; align-items: center; gap: 8px; margin-bottom: 8px; }
.copy-stage-row span { font-size: 11px; color: #475569; font-weight: 600; }
.copy-stage-row strong { font-size: 11px; color: #475569; text-align: right; }
.copy-stage-track { height: 18px; background: #EFF6FF; border-radius: 8px; overflow: hidden; }
.copy-stage-track i { display: block; height: 100%; background: linear-gradient(90deg, #60A5FA, #3B82F6); border-radius: 8px; }
.copy-trend { height: 180px; background: linear-gradient(180deg, #F8FBFF, #EFF6FF); border-radius: 8px; border: 1px solid #DBEAFE; padding: 8px; }
.copy-trend svg { width: 100%; height: 100%; }
.copy-months { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; margin-top: 8px; }
.copy-months span { font-size: 11px; color: #64748B; text-align: center; }
.copy-table-wrap { border: 1px solid #E2E8F0; border-radius: 8px; overflow: hidden; }
.copy-table { width: 100%; border-collapse: collapse; }
.copy-table th, .copy-table td { padding: 8px 10px; border-bottom: 1px solid #F1F5F9; font-size: 12px; }
.copy-table th { background: #F8FAFC; color: #64748B; text-transform: none; letter-spacing: 0; }
.copy-table tbody tr:last-child td { border-bottom: none; }
.copy-side { display: flex; flex-direction: column; gap: 12px; }
.copy-mini-chart { height: 140px; background: #F8FAFC; border: 1px solid #E2E8F0; border-radius: 8px; padding: 8px; }
.copy-mini-chart svg { width: 100%; height: calc(100% - 24px); }
.copy-alert h3 { margin: 0 0 8px; font-size: 14px; color: #1E293B; }
.copy-alert p { margin: 0; font-size: 12px; color: #64748B; }

@media (max-width: 1280px) {
    .copy-quick-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .copy-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .copy-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
    .copy-head { flex-direction: column; align-items: flex-start; }
    .copy-quick-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .copy-kpis { grid-template-columns: repeat(1, minmax(0, 1fr)); }
}
