:root {
    --bg: #f4efe6;
    --paper: #fffdf8;
    --ink: #1c1914;
    --muted: #6d6558;
    --line: #e4d9c6;
    --brand: #0f6e56;
    --brand-ink: #e8fff6;
    --accent: #c45c26;
    --sidebar: #17231f;
    --sidebar-ink: #d7e4de;
    --danger: #9b2c2c;
    --ok: #0f6e56;
    --shadow: 0 12px 40px rgba(28, 25, 20, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: "Cairo", "Segoe UI", Tahoma, sans-serif;
    background: radial-gradient(circle at top left, #fff7ea, var(--bg) 42%);
    color: var(--ink);
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
.layout { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar {
    background: var(--sidebar);
    color: var(--sidebar-ink);
    padding: 28px 20px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
    width: 42px; height: 42px; border-radius: 12px;
    background: linear-gradient(135deg, #1ea37a, #0b4d3c);
    display: grid; place-items: center; font-weight: 800; color: white;
}
.brand b { display: block; color: white; font-size: 18px; }
.brand small { color: #93b0a6; }
.nav-label { margin: 12px 4px 6px; font-size: 12px; color: #8aa399; }
.sidebar nav a, .sidebar nav span {
    display: flex; gap: 10px; align-items: center;
    padding: 10px 12px; border-radius: 10px; color: #d7e4de;
}
.sidebar nav a.active, .sidebar nav a:hover { background: #234038; color: white; }
.workspace { padding: 24px 28px 48px; }
.topbar, .page-heading, .actions, .grid, .row { display: flex; gap: 12px; }
.topbar { justify-content: space-between; align-items: center; margin-bottom: 18px; }
.page-heading { justify-content: space-between; align-items: flex-end; margin-bottom: 18px; }
.page-heading h1 { margin: 4px 0 0; font-size: 30px; }
.eyebrow { margin: 0; color: var(--accent); font-size: 12px; letter-spacing: .12em; }
.muted { color: var(--muted); }
.card, .table-wrap, .stat {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
}
.card { padding: 20px; }
.stat { padding: 16px 18px; min-width: 150px; }
.stat b { display: block; font-size: 26px; margin-top: 6px; }
.grid { flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: right; }
th { font-size: 13px; color: var(--muted); background: #fbf6ee; }
.ledger-table { font-size: 13px; }
.ledger-table th, .ledger-table td {
    padding: 8px 10px;
    white-space: nowrap;
    font-size: 13px;
}
.ledger-table td.ledger-memo,
.ledger-table td.ledger-memo > div { white-space: nowrap; }
.btn, .icon-button {
    border: 0; border-radius: 12px; padding: 10px 14px; cursor: pointer;
    background: var(--brand); color: white; display: inline-flex; align-items: center; gap: 8px;
}
.btn.secondary { background: #ece4d4; color: var(--ink); }
.btn.danger { background: var(--danger); }
.btn.ghost, .icon-button { background: transparent; color: inherit; border: 1px solid var(--line); }
.icon-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
    padding: 0;
    border-radius: 10px;
    justify-content: center;
}
.icon-btn.with-text {
    width: auto;
    min-width: 34px;
    padding: 0 12px;
    gap: 8px;
}
.icon-btn.with-text span {
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
}
.icon-btn svg { width: 18px; height: 18px; display: block; }
.btn[hidden], .icon-btn[hidden] { display: none !important; }
.filter-chip {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--line);
    background: #ece4d4;
    color: var(--ink);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 13px;
}
.filter-chip.active { background: var(--brand); color: white; border-color: var(--brand); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field span { font-size: 13px; color: var(--muted); }
input, select, textarea {
    border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: white;
}
.badge {
    display: inline-flex; padding: 4px 10px; border-radius: 999px; font-size: 12px;
    background: #eee6d6; color: #5b5040;
}
.badge.draft { background: #eee6d6; }
.badge.accounting { background: #f7e3c6; color: #8a4b12; }
.badge.shipping { background: #d7eef7; color: #0b4f67; }
.badge.delivered { background: #dceee3; color: #1a5f3c; }
.badge.settled { background: #d9f3e8; color: #0f6e56; }
.badge.refusal_settled { background: #efe6d4; color: #6b4b1f; }
.badge.cancelled, .badge.refused { background: #f8d7d7; color: var(--danger); }
.badge.offer { background: #fde7d2; color: var(--accent); }
.alert { padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; }
.alert.success { background: #e4f7ee; color: #0f6e56; }
.alert.error { background: #fde8e8; color: var(--danger); }
.user-menu { display: flex; align-items: center; gap: 10px; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%; background: #1ea37a; color: white;
    display: grid; place-items: center; font-weight: 700;
}
.guest {
    min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.login-card { width: min(440px, 100%); padding: 32px; }
.login-card h1 { margin-top: 0; }
.search-box { position: relative; margin-bottom: 16px; }
.search-results {
    position: absolute; z-index: 5; right: 0; left: 0; top: 78px;
    background: var(--paper); border: 1px solid var(--line); border-radius: 14px;
    box-shadow: var(--shadow); max-height: 260px; overflow: auto;
}
.search-item, .search-empty { display: block; width: 100%; text-align: right; padding: 10px 14px; background: transparent; border: 0; border-bottom: 1px solid var(--line); color: inherit; }
.search-item:hover { background: #f6efe3; }
.search-item small { display: block; color: var(--muted); }
.search-empty { color: var(--muted); }
.search-select { position: relative; width: 100%; }
.search-select-input { width: 100%; }
.search-select-menu {
    position: absolute;
    z-index: 30;
    right: 0;
    left: 0;
    top: calc(100% + 4px);
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
    max-height: 260px;
    overflow: auto;
}
.search-select-menu .search-item.active { background: #f6efe3; }
.item-row .search-select { min-width: 0; }
.selected-customer { background: #e4f7ee; color: #0f6e56; padding: 10px 12px; border-radius: 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.selected-customer[hidden] { display: none; }
.phone-row, .item-row { display: grid; gap: 8px; margin-bottom: 8px; align-items: center; }
.phone-row { grid-template-columns: 1fr auto; }
.item-row { grid-template-columns: 2fr 90px 120px 120px auto; }
.dt-toolbar { display: flex; gap: 12px; align-items: flex-end; margin-bottom: 14px; }
.dt-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.dt-pager { display: flex; gap: 6px; flex-wrap: wrap; }
.dt-current { background: var(--brand) !important; color: white !important; }
.pager {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    margin-top: 16px;
}
.pager svg {
    width: 16px;
    height: 16px;
    display: block;
}
.pager .btn[aria-disabled="true"] {
    opacity: .45;
    pointer-events: none;
}
.dt-box { border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: #fffaf2; }
td.actions { display: flex; flex-wrap: nowrap; gap: 4px; width: 1%; white-space: nowrap; }
.bulk-check { width: 36px; text-align: center; }
.bulk-bar {
    position: sticky;
    bottom: 16px;
    margin-top: 16px;
    padding: 14px 16px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
}
.bulk-bar[hidden] { display: none !important; }
.bulk-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
}
.bulk-group[hidden] { display: none !important; }
.bulk-group .field { margin-bottom: 0; min-width: 160px; }
.bulk-shipping .field,
.bulk-collect .field { min-width: 240px; flex: 1; }
tr.account-main td { background: #efe6d4; font-weight: 800; }
tr.account-group td { background: #f6efe3; font-weight: 700; }
.account-name { display: inline-block; }
.totals { display: flex; justify-content: flex-end; align-items: baseline; gap: 24px; font-size: 18px; flex-wrap: wrap; }
.invoice {
    max-width: 860px; margin: 0 auto; background: white; padding: 36px;
    border: 1px solid var(--line); border-radius: 8px;
}
.print-only { display: none; }
@media print {
    .no-print { display: none !important; }
    .print-only { display: block !important; }
    .layout { display: block; }
    body { background: white; }
    .invoice, .table-wrap, .stat, .card { box-shadow: none; }
    .invoice { border: 0; }
}
@media (max-width: 900px) {
    .layout { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .grid-2, .grid-3, .item-row { grid-template-columns: 1fr; }
}
