:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #059669;
    --danger: #dc2626;
    --warning: #d97706;
    --info: #7c3aed;
    --bg: #f4f6fb;
    --card-bg: #ffffff;
    --border: #e5e7eb;
    --text: #1f2937;
    --text-muted: #6b7280;
    --sidebar-w: 240px;
    --radius: 10px;
}

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

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

a { text-decoration: none; color: inherit; }

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

.sidebar {
    width: var(--sidebar-w);
    background: #111827;
    color: #e5e7eb;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    transition: margin-left .2s ease;
}
.sidebar-brand {
    display: flex; align-items: center; gap: .6rem;
    padding: 1rem 1.2rem;
    font-weight: 700; font-size: 1.05rem;
    border-bottom: 1px solid #1f2937;
}
.sidebar-brand-img { height: 48px; width: auto; display: block; }
.brand-icon { font-size: 1.4rem; }
.sidebar-nav { display: flex; flex-direction: column; padding: .8rem; gap: 2px; }
.sidebar-nav a {
    display: flex; align-items: center; gap: .7rem;
    padding: .65rem .8rem;
    border-radius: 8px;
    color: #cbd5e1;
    font-size: .9rem;
}
.sidebar-nav a:hover { background: #1f2937; color: #fff; }
.sidebar-nav a.active { background: var(--primary); color: #fff; }
.nav-icon { font-size: 1rem; }

.main-content { flex: 1; min-width: 0; }

.topbar {
    display: flex; align-items: center; gap: 1rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: .9rem 1.5rem;
    position: sticky; top: 0; z-index: 10;
}
.page-title { font-size: 1.15rem; font-weight: 600; flex: 1; }
.topbar-user { display: flex; align-items: center; gap: .8rem; font-size: .88rem; color: var(--text-muted); }
.icon-btn { background: none; border: none; font-size: 1.3rem; cursor: pointer; display: none; }

.content-area { padding: 1.5rem; max-width: 1400px; margin: 0 auto; }

/* ---------- Cards / Grid ---------- */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.3rem;
    margin-bottom: 1.3rem;
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap; gap: .6rem;
}
.card-header h2 { font-size: 1.05rem; font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.3rem; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.1rem; margin-bottom: 1.3rem; }
@media (max-width: 900px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .stat-grid { grid-template-columns: 1fr; } }

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem;
    display: flex; align-items: center; gap: .9rem;
}
.stat-icon { width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; flex-shrink: 0; }
.stat-value { font-size: 1.25rem; font-weight: 700; }
.stat-label { color: var(--text-muted); font-size: .82rem; }

/* ---------- Tables ---------- */
.table-responsive { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .87rem; }
.table th, .table td { padding: .65rem .7rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { color: var(--text-muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .02em; }
.table tbody tr:hover { background: #f9fafb; }
.actions { display: flex; gap: .4rem; }

.empty-state { text-align: center; color: var(--text-muted); padding: 2rem !important; white-space: normal; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: .2rem .55rem; border-radius: 999px; font-size: .74rem; font-weight: 600; }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #ede9fe; color: #5b21b6; }
.badge-warning { background: #fef3c7; color: #92400e; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1rem; border-radius: 8px; border: 1px solid transparent; font-size: .87rem; font-weight: 600; cursor: pointer; transition: .15s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: #f3f4f6; }
.btn-danger { background: #fff; border-color: #fecaca; color: var(--danger); }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: .35rem .65rem; font-size: .78rem; }
.btn-block { width: 100%; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 1rem; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group label { font-size: .82rem; font-weight: 600; color: var(--text); }
.form-group label small { font-weight: 400; color: var(--text-muted); }
input, select, textarea {
    padding: .55rem .7rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .87rem;
    font-family: inherit;
    background: #fff;
    color: var(--text);
    width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
input:disabled { background: #f3f4f6; color: var(--text-muted); }
.form-actions { display: flex; gap: .6rem; margin-top: .3rem; }
.form-card { max-width: 720px; }
.hint-text { color: var(--text-muted); font-size: .78rem; }

.filter-bar { display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: 1.1rem; }
.filter-bar input, .filter-bar select { width: auto; min-width: 160px; }

/* ---------- Alerts ---------- */
.alert { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: .87rem; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info { background: #ede9fe; color: #5b21b6; border: 1px solid #ddd6fe; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: .4rem; border-bottom: 1px solid var(--border); margin-bottom: 1.2rem; flex-wrap: wrap; }
.tab { padding: .6rem 1rem; font-size: .87rem; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab:hover { color: var(--text); }

.link { color: var(--primary); font-size: .85rem; font-weight: 600; }

/* ---------- Auth pages ---------- */
.auth-wrapper { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #eff6ff, #f4f6fb); padding: 1.5rem; }
.auth-card { background: #fff; border-radius: 14px; padding: 2.2rem; width: 100%; max-width: 380px; box-shadow: 0 10px 30px rgba(0,0,0,.06); border: 1px solid var(--border); }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: .4rem; margin-bottom: 1.5rem; text-align: center; }
.auth-brand .brand-icon { font-size: 2rem; }
.auth-brand h1 { font-size: 1.15rem; }
.auth-hint { text-align: center; margin-top: 1rem; font-size: .8rem; color: var(--text-muted); }

.nav-site-link { margin-top: .6rem; border-top: 1px solid #1f2937; padding-top: .9rem !important; color: #93c5fd !important; }

/* ---------- Bulk edit table ---------- */
.bulk-table input[type=number], .bulk-table input[type=text], .bulk-table select { padding: .4rem .5rem; font-size: .82rem; min-width: 90px; }
.bulk-table td { white-space: nowrap; }
.bulk-actions-bar { position: sticky; bottom: 0; background: #fff; padding: .8rem 0; border-top: 1px solid var(--border); margin-top: .5rem; }

/* ---------- Invoice / statement print styling ---------- */
.doc-sheet { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; max-width: 850px; margin: 0 auto; }
.doc-header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid var(--text); padding-bottom: 1rem; margin-bottom: 1.2rem; }
.doc-company h2 { font-size: 1.2rem; }
.doc-company p { font-size: .8rem; color: var(--text-muted); margin: 0; }
.doc-meta { text-align: right; font-size: .85rem; }
.doc-meta h3 { font-size: 1.3rem; letter-spacing: .05em; color: var(--primary); }
.doc-parties { display: flex; justify-content: space-between; gap: 2rem; margin-bottom: 1.4rem; flex-wrap: wrap; }
.doc-parties h4 { font-size: .78rem; text-transform: uppercase; color: var(--text-muted); margin-bottom: .3rem; }
.doc-totals { margin-left: auto; width: 280px; margin-top: 1rem; }
.doc-totals table { width: 100%; }
.doc-totals td { padding: .35rem 0; }
.doc-totals .grand-total td { font-weight: 700; font-size: 1.05rem; border-top: 2px solid var(--text); padding-top: .6rem; }
.doc-footer-note { margin-top: 2rem; font-size: .8rem; color: var(--text-muted); text-align: center; }
.print-toolbar { display: flex; justify-content: flex-end; gap: .6rem; margin-bottom: 1rem; max-width: 850px; margin-left: auto; margin-right: auto; }

/* ---------- Business Profile cover page (header + footer on printed docs) ---------- */
.doc-company .tin-line { font-size: .78rem; color: var(--text-muted); margin: .1rem 0 0; }
.doc-cover-footer { margin-top: 2.2rem; padding-top: .8rem; border-top: 2px solid var(--text); font-size: .78rem; color: var(--text-muted); display: flex; flex-wrap: wrap; justify-content: space-between; gap: .3rem 1.6rem; }
.doc-cover-footer strong { color: var(--text); }
.doc-cover-footer a { color: var(--primary); text-decoration: none; }
.doc-cover-footer a:hover { text-decoration: underline; }
.map-embed-wrap { position: relative; width: 100%; max-width: 520px; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.map-embed-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

@media print {
    .sidebar, .topbar, .print-toolbar, .no-print { display: none !important; }
    .main-content, .content-area { padding: 0 !important; margin: 0 !important; }
    .doc-sheet { border: none; padding: 0; max-width: 100%; }
    .card { border: none; padding: 0; }
    .print-only-title { display: block !important; margin-bottom: 1rem; }
    body { background: #fff; }
    @page { margin: 12mm; }
}

.print-hint { font-size: .78rem; color: var(--text-muted); margin-left: .3rem; }

/* ---------- Responsive sidebar ---------- */
@media (max-width: 860px) {
    .icon-btn { display: inline-block; }
    .sidebar { position: fixed; left: 0; top: 0; z-index: 100; margin-left: calc(-1 * var(--sidebar-w)); box-shadow: 4px 0 20px rgba(0,0,0,.15); }
    .sidebar.open { margin-left: 0; }
    .main-content { width: 100%; }
}
