:root {
    --color-primary: #c81e1e;
    --color-primary-hover: #a51515;
    --color-primary-light: #fdeaea;
    --color-ink: #14161a;

    --color-danger: #dc2626;
    --color-danger-hover: #b91c1c;
    --color-danger-light: #fee2e2;

    --color-success: #059669;
    --color-success-light: #d3f8ea;

    --color-warning-light: #fef3c7;
    --color-warning-text: #92400e;

    --color-text: #1f2328;
    --color-text-muted: #6b7280;
    --color-border: #e5e7eb;
    --color-surface: #ffffff;
    --color-bg: #f5f5f7;

    --radius-sm: 8px;
    --radius-md: 12px;
    --font-family: 'Segoe UI', Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font-family);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 15px;
    line-height: 1.5;
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { color: var(--color-primary-hover); }

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

/* ---------- Sidebar ---------- */
.sidebar {
    width: 260px; flex-shrink: 0; background: var(--color-ink); color: #cfd2d8;
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand {
    display: flex; align-items: center; justify-content: space-between; padding: 20px 20px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand-text { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 1.05rem; }
.sidebar-brand img { height: 62px; width: auto; object-fit: contain; background: white; }
.sidebar-close { display: none; background: none; border: none; color: #fff; font-size: 1.4rem; cursor: pointer; }
.sidebar nav { padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
    display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: var(--radius-sm);
    color: #cfd2d8; font-weight: 500; font-size: 0.9rem; transition: background 0.15s, color 0.15s;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar nav a.active { background: var(--color-primary); color: #fff; }
.nav-group {
    padding: 16px 12px 6px; font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.06em; color: #8890a0;
}
.sidebar-overlay { display: none; }

/* ---------- Topbar / main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    background: var(--color-surface); padding: 14px 28px; display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid var(--color-border); gap: 12px; position: sticky; top: 0; z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.hamburger-btn {
    display: none; background: none; border: 1px solid var(--color-border); border-radius: var(--radius-sm); padding: 6px 10px;
    font-size: 1.125rem; cursor: pointer; color: var(--color-text);
}
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 0.875rem; flex-wrap: wrap; }
.user-chip { display: flex; align-items: center; gap: 9px; color: var(--color-text-muted); }
.user-avatar {
    width: 30px; height: 30px; border-radius: 50%; background: var(--color-primary-light); color: var(--color-primary);
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.8rem;
}
.btn-logout {
    background: var(--color-danger-light); color: var(--color-danger); padding: 7px 14px; border-radius: var(--radius-sm);
    font-weight: 600; font-size: 0.85rem;
}
.btn-logout:hover { background: #ffd2db; color: var(--color-danger-hover); }

.content { padding: 28px 32px; max-width: 1400px; }

/* ---------- Page header / cards ---------- */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px; flex-wrap: wrap; gap: 12px; }
.page-header h1 { font-size: 1.5rem; margin: 0; }
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 22px; margin-bottom: 22px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: var(--radius-sm);
    font-size: 0.875rem; font-weight: 600; border: none; cursor: pointer; transition: background 0.15s, box-shadow 0.15s;
    white-space: nowrap;
}
.btn-primary { background: var(--color-primary); color: #fff; box-shadow: 0 1px 2px rgba(200,30,30,0.3); }
.btn-primary:hover { background: var(--color-primary-hover); color: #fff; }
.btn-secondary { background: #f3f4f7; color: var(--color-text); border: 1px solid var(--color-border); }
.btn-secondary:hover { background: #e9eaf0; }
.btn-danger { background: var(--color-danger-light); color: var(--color-danger); }
.btn-danger:hover { background: #ffd2db; }
.btn-sm { padding: 6px 11px; font-size: 0.8rem; }
.btn-sm svg { width: 13px; height: 13px; }
.btn-icon { padding: 6px; width: 30px; height: 30px; gap: 0; justify-content: center; }
table td > .btn, table td > form { margin-right: 6px; }

/* ---------- Forms ---------- */
.form-row { display: flex; gap: 20px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 220px; }
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 6px; }
input[type="text"], input[type="email"], input[type="tel"], input[type="number"], input[type="password"],
input[type="date"], select, textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--color-border); border-radius: var(--radius-sm);
    font-size: 0.9rem; font-family: inherit; background: #fff; color: var(--color-text);
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); }
.hint { font-size: 0.78rem; color: var(--color-text-muted); margin-top: 5px; }

/* ---------- Tables ---------- */
.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-text-muted); font-weight: 700; background: #fafafb; }
tbody tr:hover { background: #fafafb; }
.empty-state { padding: 30px; text-align: center; color: var(--color-text-muted); }

/* ---------- List toolbar / pagination ---------- */
.list-toolbar { display: flex; gap: 12px; margin-bottom: 16px; align-items: center; flex-wrap: wrap; }
.list-toolbar .search-input { flex: 1; min-width: 200px; }
.list-toolbar .page-size-select { width: auto; flex-shrink: 0; }
.list-toolbar .filter-input { width: auto; flex-shrink: 0; }
.list-meta { font-size: 0.875rem; color: var(--color-text-muted); margin-bottom: 12px; }
.pagination { display: flex; gap: 6px; align-items: center; justify-content: center; flex-wrap: wrap; margin-top: 20px; }
.pagination button {
    border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text); padding: 6px 12px;
    border-radius: var(--radius-sm); font-size: 0.875rem; cursor: pointer; font-weight: 500;
}
.pagination button.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- Badges & alerts ---------- */
.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; }
.badge-draft { background: #f3f4f7; color: var(--color-text-muted); }
.badge-sent { background: #dbeafe; color: #1d4ed8; }
.badge-accepted { background: var(--color-success-light); color: #047857; }
.badge-rejected { background: var(--color-danger-light); color: var(--color-danger); }
.badge-intra { background: var(--color-success-light); color: #047857; }
.badge-inter { background: #dbeafe; color: #1d4ed8; }

.alert { padding: 13px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 0.875rem; font-weight: 500; border: 1px solid transparent; }
.alert-success { background: var(--color-success-light); color: #047857; border-color: #a7f3d4; }
.alert-error { background: var(--color-danger-light); color: var(--color-danger-hover); border-color: #fecdd6; }

/* ---------- Dashboard stat tiles ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 18px; margin-bottom: 24px; }
.stat-tile { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 20px; }
.stat-tile .label { font-size: 0.78rem; color: var(--color-text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-tile .value { font-size: 1.7rem; font-weight: 700; margin-top: 6px; }
.stat-tile .icon { width: 38px; height: 38px; border-radius: 10px; background: var(--color-primary-light); color: var(--color-primary); display: flex; align-items: center; justify-content: center; margin-bottom: 10px; }

/* ---------- Line item builder (quotations/invoices) ---------- */
.items-table { width: 100%; border-collapse: collapse; margin-bottom: 6px; }
.items-table th { font-size: 0.7rem; }
.items-table td { padding: 8px; }
.items-table input, .items-table select { padding: 7px 9px; font-size: 0.85rem; }
.items-table .col-desc { min-width: 220px; }
.items-table .col-num { width: 90px; }
.items-table .col-amt { width: 110px; text-align: right; }
.items-table .amount-cell { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.item-remove-btn { background: var(--color-danger-light); color: var(--color-danger); border: none; border-radius: var(--radius-sm); width: 30px; height: 30px; cursor: pointer; }
.item-remove-btn:hover { background: #ffd2db; }
.totals-box { max-width: 340px; margin-left: auto; margin-top: 14px; }
.totals-box .row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 0.9rem; }
.totals-box .row.grand { border-top: 2px solid var(--color-ink); margin-top: 6px; padding-top: 10px; font-size: 1.1rem; font-weight: 700; }
.totals-box .row span:last-child { font-variant-numeric: tabular-nums; }

/* ---------- Login page ---------- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--color-ink); }
.login-card { background: #fff; border-radius: var(--radius-md); padding: 40px; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.login-card .logo-area { text-align: center; margin-bottom: 22px; }
.login-card .logo-area img { height: 60px; margin-bottom: 10px; }
.login-card h1 { font-size: 1.25rem; text-align: center; margin: 0 0 24px; }
.login-card .btn-primary { width: 100%; justify-content: center; padding: 11px; }

@media (max-width: 900px) {
    .sidebar {
        position: fixed; top: 0; left: 0; bottom: 0; width: 260px; transform: translateX(-100%);
        transition: transform 0.25s; z-index: 300;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-close { display: block; }
    .sidebar-overlay {
        display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 250;
    }
    .sidebar-overlay.open { display: block; }
    .hamburger-btn { display: inline-flex; }
    .content { padding: 16px; }
    .topbar { padding: 12px 16px; }
    .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .page-header > div { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; }
    .form-row .form-group { min-width: 100%; }
    .form-row > .card { min-width: 100%; }
    .card { padding: 16px; }
    .stat-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
    th, td { padding: 9px 8px; font-size: 0.82rem; }
    .list-toolbar .search-input { min-width: 100%; }
    .list-toolbar .filter-input, .list-toolbar .page-size-select { flex: 1; min-width: 120px; }
    .totals-box { max-width: 100%; }
}

/* ---------- Print / PDF letterhead (view + dompdf share this) ---------- */
.doc-sheet { background: #fff; max-width: 820px; margin: 0 auto; padding: 30px 36px; font-family: 'Times New Roman', Georgia, serif; color: #111; line-height: 1.3; }
.doc-sheet th, .doc-sheet td { padding: 0; border-bottom: none; vertical-align: top; }
.doc-header { text-align: center; }
.doc-header .brand { display: inline-block; }
.doc-header .brand img { height: 86px; width: auto; max-width: 380px; -o-object-fit: contain; object-fit: contain; }
.doc-header .brand .name { color: #cc0000; font-size: 1.6rem; font-weight: 700; font-family: Georgia, serif; }
.doc-meta-block { text-align: right; font-size: 0.85rem; line-height: 1.3; }
.doc-address-row { display: flex; justify-content: space-between; margin-top: 10px; font-size: 0.85rem; gap: 20px; line-height: 1.3; }
.doc-address-row .left strong { display: block; }
.doc-rule { border-top: 4px solid #000; margin: 14px 0 4px; }
.doc-rule.thin { border-top: 1px solid #000; margin-top: 2px; }
.doc-title { text-align: center; font-size: 1.35rem; font-weight: 700; margin: 18px 0; }
.doc-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 0.85rem; }
.doc-table th, .doc-table td { border: 1px solid #333; padding: 7px 9px; }
.doc-table th { background: #f0f0f0; color: #000000; font-weight: 700; }
.doc-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.doc-notes { margin-top: 26px; font-size: 0.9rem; }
.doc-notes ul { margin: 8px 0 0 20px; padding: 0; }
.doc-footer-note { text-align: center; font-style: italic; margin-top: 50px; font-size: 0.9rem; }
.doc-bill-to { margin-top: 14px; font-size: 0.85rem; border: 1px solid #333; padding: 8px 10px; }
.doc-total-words { margin-top: 10px; font-size: 0.85rem; }
.doc-bank { margin-top: 10px; font-size: 0.8rem; border-top: 1px solid #333; padding-top: 8px; display: flex; justify-content: space-between; gap: 20px; }
.doc-sign { text-align: right; font-size: 0.85rem; }
.doc-sign .space { height: 50px; }
@media print {
    .no-print { display: none !important; }
    body { background: #fff; }
    .doc-sheet { box-shadow: none; padding: 0; }
}
