:root {
    --ink: #14171f;
    --ink-soft: #4b5265;
    --paper: #f5f6f9;
    --surface: #ffffff;
    --line: #e6e8f0;
    --brand: #2f5b4f;
    --brand-dark: #1e3d34;
    --brand-soft: #e6efe9;
    --accent: #c8853a;
    --accent-soft: #fbeedd;
    --danger: #b3432f;
    --danger-soft: #f8e6e2;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(20, 23, 31, 0.04), 0 4px 16px rgba(20, 23, 31, 0.04);
}

* { box-sizing: border-box; }

/* Safety net: a few views set an inline pixel width on a search box or
   small filter input (e.g. style="width:260px") for a tidy desktop look.
   max-width here caps that at the container's actual width on a phone
   instead of letting it force the page to scroll sideways. */
img, input, select, textarea { max-width: 100%; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14.5px;
}

h1, h2, h3, h4, .brand-text, .page-title {
    font-family: 'Space Grotesk', sans-serif;
}

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

/* Sidebar — desktop default: visible, part of the flex layout.
   .sidebar-toggled hides it. On mobile (see media query below) the
   meaning flips: hidden by default, .sidebar-toggled shows it as an
   off-canvas panel. Same class, same JS toggle call, different CSS
   per breakpoint — see #sidebarToggle click handler in the layouts. */
.sidebar {
    width: 246px;
    flex-shrink: 0;
    background: var(--brand-dark);
    color: #e9efec;
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    transition: margin-left .2s ease;
}
.sidebar.sidebar-toggled { margin-left: -246px; }
.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 35;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px 22px;
}
.brand-mark {
    width: 32px; height: 32px;
    background: var(--accent);
    color: #241605;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    font-family: 'Space Grotesk', sans-serif;
}
.brand-logo { background: #fff; object-fit: contain; padding: 3px; flex-shrink: 0; }
.brand-text { font-weight: 600; font-size: 16px; color: #fff; letter-spacing: .2px; }

.nav-section {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #8ba39a;
    margin: 18px 10px 6px;
    font-weight: 600;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 8px;
    color: #cfe0d8;
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    margin-bottom: 2px;
}
.nav-link i { font-size: 15px; width: 18px; text-align: center; }
.nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-link.active { background: var(--accent); color: #241605; }

/* Main column */
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 14px;
    position: sticky;
    top: 0;
    z-index: 10;
}
.sidebar-toggle {
    border: none; background: none; font-size: 20px; color: var(--ink-soft); cursor: pointer;
}
.page-title { font-size: 19px; font-weight: 600; margin: 0; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-chip {
    display: flex; align-items: center; gap: 6px;
    font-size: 13px; color: var(--ink-soft);
}
.role-pill {
    background: var(--brand-soft); color: var(--brand-dark);
    padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .03em;
}

.quick-add-btn {
    width: 36px; height: 36px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: var(--brand-dark); color: #fff; border: none;
    font-size: 18px; line-height: 1; flex-shrink: 0;
}
.quick-add-btn:hover, .quick-add-btn:focus { background: var(--brand); color: #fff; }
.quick-add-menu { min-width: 220px; padding: 0; border-radius: 10px; overflow: hidden; }
.quick-add-menu li:not(:last-child) .dropdown-item { border-bottom: 1px solid var(--line); }
.quick-add-menu .dropdown-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 18px; font-size: 15px; color: var(--ink-soft);
}
.quick-add-menu .dropdown-item i { font-size: 15px; color: #4caf50; font-weight: 700; }
.quick-add-menu .dropdown-item:hover { background: var(--brand-soft); }

.content { padding: 22px 26px 40px; }

/* Cards */
.card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--line);
    font-weight: 600;
    font-family: 'Space Grotesk', sans-serif;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
}
.stat-card .stat-label { font-size: 12.5px; color: var(--ink-soft); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.stat-card .stat-value { font-size: 26px; font-weight: 700; font-family: 'Space Grotesk', sans-serif; margin-top: 4px; }
.stat-card .stat-icon {
    width: 40px; height: 40px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; margin-bottom: 10px;
}
.stat-icon.brand { background: var(--brand-soft); color: var(--brand-dark); }
.stat-icon.accent { background: var(--accent-soft); color: var(--accent); }
.stat-icon.danger { background: var(--danger-soft); color: var(--danger); }

/* Buttons */
.btn-primary {
    background: var(--brand-dark); border-color: var(--brand-dark);
}
.btn-primary:hover, .btn-primary:focus { background: var(--brand); border-color: var(--brand); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #241605; }
.btn-accent:hover { background: #b5762f; color: #fff; }

/* Tables */
.table thead th {
    font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
    color: var(--ink-soft); border-bottom: 2px solid var(--line); font-weight: 600;
}
.table td { vertical-align: middle; font-size: 13.5px; }

.badge-paid { background: var(--brand-soft); color: var(--brand-dark); }
.badge-partial { background: var(--accent-soft); color: var(--accent); }
.badge-due { background: var(--danger-soft); color: var(--danger); }

/* POS Terminal */
.pos-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; align-items: start; }
.pos-product-card {
    border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
    padding: 12px; cursor: pointer; transition: border-color .15s, transform .1s;
}
.pos-product-card:hover { border-color: var(--brand); transform: translateY(-1px); }
.pos-product-card .p-name { font-weight: 600; font-size: 13px; }
.pos-product-card .p-price { color: var(--brand-dark); font-weight: 700; font-family: 'Space Grotesk', sans-serif; }
.pos-cart { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; position: sticky; top: 78px; }
.pos-cart-item { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.pos-total-row { display: flex; justify-content: space-between; font-size: 14px; margin: 4px 0; }
.pos-total-row.grand { font-size: 19px; font-weight: 700; font-family: 'Space Grotesk', sans-serif; color: var(--brand-dark); border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }

/* Auth */
.auth-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(160deg, var(--brand-dark), #14261f 70%);
    padding: 20px;
}
.auth-card {
    background: var(--surface); border-radius: 14px; padding: 38px 36px;
    width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.auth-card .brand-mark { margin: 0 auto 14px; }
.auth-card h2 { text-align: center; font-size: 20px; margin-bottom: 4px; }
.auth-card p.subtitle { text-align: center; color: var(--ink-soft); font-size: 13px; margin-bottom: 24px; }

/* Small-screen support. Bootstrap's own grid (col-md-*, etc.) already
   stacks to a single column below md, and .table-responsive already
   scrolls wide tables horizontally instead of breaking layout — this
   block only handles the pieces that are custom to this app: the
   sidebar becoming an off-canvas drawer, and the POS split-screen
   collapsing to a single column. */
@media (max-width: 900px) {
    .pos-grid { grid-template-columns: 1fr; }
    .pos-cart { position: static; }

    .sidebar {
        position: fixed; left: 0; top: 0; z-index: 40;
        margin-left: -246px;
    }
    .sidebar.sidebar-toggled { margin-left: 0; }
    .sidebar-backdrop.show { display: block; }

    .topbar { padding: 12px 16px; }
    .page-title { font-size: 16px; }
    .user-chip .role-pill, .user-chip { white-space: nowrap; }
    .topbar-right { gap: 8px; }
    .topbar-right form button span,
    .topbar-right .btn span { display: none; }

    .content { padding: 16px 14px 32px; }
    .stat-card { padding: 14px 16px; }
}

@media (max-width: 480px) {
    .auth-card { width: 100%; padding: 28px 20px; }
    .auth-wrap { padding: 16px; }
    .content { padding: 12px 10px 28px; }
}
@media print {
    .sidebar, .topbar, .no-print, form { display: none !important; }
    .content { padding: 0 !important; }
    .card { border: none !important; box-shadow: none !important; }
}
