:root {
    --primary: #a37e4e;
    --dark: #3f2d1f;
    --surface: #f8efe4;
    --muted: #e8d8c4;
    --line: #dfccb4;
    --danger: #9f2f28;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--muted);
    color: var(--dark);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
a { color: inherit; }
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 14px 22px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; text-decoration: none; font-size: 18px; }
nav { display: flex; gap: 12px; flex-wrap: wrap; }
nav a { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; text-decoration: none; }
.shell { max-width: 1120px; margin: 0 auto; padding: 22px; }
.hero {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}
h1, h2, h3 { margin: 0; }
h1 { font-size: 28px; }
h2 { font-size: 20px; margin-top: 28px; margin-bottom: 12px; }
h3 { font-size: 16px; margin-bottom: 10px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.add-grid { grid-template-columns: minmax(260px, .9fr) minmax(320px, 1.1fr); }
.stats-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 18px; }
.dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 18px; }
.card, table, .panel {
    background: var(--surface);
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(63, 45, 31, .12);
}
.card { padding: 16px; }
.stat-card { min-height: 94px; }
.label { color: #755c42; font-size: 13px; }
.value { margin-top: 4px; font-size: 26px; font-weight: 800; }
.total {
    background: var(--primary);
    color: var(--surface);
    padding: 22px;
    border-radius: 8px;
    font-size: 36px;
    font-weight: 800;
}
.panel { padding: 16px; margin-bottom: 14px; }
.panel > h2:first-child { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; align-items: end; }
label { display: grid; gap: 5px; font-size: 13px; font-weight: 700; }
input, select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: white;
    color: var(--dark);
    padding: 10px;
    font: inherit;
    min-height: 42px;
    box-shadow: inset 0 1px 0 rgba(63, 45, 31, .04);
}
select {
    height: 42px;
    appearance: none;
    padding-right: 34px;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--dark) 50%),
        linear-gradient(135deg, var(--dark) 50%, transparent 50%);
    background-position:
        calc(100% - 17px) 18px,
        calc(100% - 12px) 18px;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
}
input:focus, select:focus {
    outline: 2px solid rgba(163, 126, 78, .25);
    border-color: var(--primary);
}
input[type="checkbox"].switch {
    appearance: none;
    width: 46px;
    min-width: 46px;
    height: 26px;
    min-height: 26px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #d3c0aa;
    box-shadow: inset 0 1px 2px rgba(63, 45, 31, .18);
    cursor: pointer;
    transition: background .16s ease, border-color .16s ease;
}
input[type="checkbox"].switch::before {
    content: "";
    display: block;
    width: 20px;
    height: 20px;
    margin: 2px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 1px 3px rgba(63, 45, 31, .28);
    transition: transform .16s ease;
}
input[type="checkbox"].switch:checked {
    background: var(--primary);
    border-color: var(--primary);
}
input[type="checkbox"].switch:checked::before { transform: translateX(20px); }
label input[type="checkbox"].switch { justify-self: start; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 13px;
    border: 0;
    border-radius: 6px;
    background: var(--primary);
    color: var(--surface);
    font: inherit;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    gap: 7px;
    transition: transform .08s ease, filter .12s ease;
}
button:hover, .button:hover { filter: brightness(.96); }
button:active, .button:active { transform: translateY(1px); }
.button.secondary, button.secondary { background: var(--dark); }
.button.danger, button.danger { background: var(--danger); }
.button.ghost, button.ghost { background: transparent; color: var(--dark); border: 1px solid var(--line); }
button.icon-button {
    width: 40px;
    min-width: 40px;
    padding: 0;
}
svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
table { width: 100%; border-collapse: collapse; overflow: hidden; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #dfccb4; font-size: 13px; }
td:last-child, th:last-child { text-align: right; }
td.col-order, th.col-order, td.col-visible, th.col-visible { text-align: center; }
.col-order .order-input { margin: 0 auto; }
.col-visible .switch { margin: 0 auto; }
.catalogue-tree .category-row input[type="text"],
.catalogue-tree .category-row input:not([type]) {
    font-weight: 800;
}
.catalogue-tree .subcategory-row td {
    background: #fff8ef;
}
.catalogue-tree .subcategory-name-cell {
    padding-left: 34px;
}
.catalogue-tree .subcategory-name-cell input:not([type="hidden"]) {
    background: #fffdf9;
}
.stats-tree .category-row td {
    background: var(--surface);
}
.stats-tree .subcategory-row td {
    background: #fff8ef;
}
.stats-tree .stats-subcategory-cell {
    padding-left: 34px;
}
.table-wrap { overflow-x: auto; border-radius: 8px; }
.savebar {
    position: sticky;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 14px;
    padding: 12px;
    background: rgba(248, 239, 228, .96);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 -2px 10px rgba(63, 45, 31, .08);
}
.details-row td { background: #fff8ef; text-align: left !important; }
.payment-manager {
    margin-bottom: 18px;
}
.compact-payment-button {
    min-height: 34px;
    margin-top: 7px;
    padding: 6px 9px;
    font-size: 12px;
}
.payment-line-form {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 7px;
    max-width: 620px;
}
.payment-line-form select { width: 150px; min-width: 150px; }
.payment-line-form input { width: 120px; min-width: 100px; }
.payment-line-form button { white-space: nowrap; }
.payment-line-form button.icon-button {
    width: 40px;
    min-width: 40px;
    padding: 0;
}
.payment-dialog {
    width: min(380px, calc(100vw - 28px));
    max-height: calc(100vh - 28px);
    margin: auto;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--dark);
    box-shadow: 0 16px 44px rgba(63, 45, 31, .28);
}
.payment-dialog::backdrop {
    background: rgba(63, 45, 31, .5);
}
.payment-dialog-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}
.payment-dialog-head h2 { margin: 0 0 3px; }
.payment-mode-field {
    display: grid;
    gap: 7px;
}
.field-label {
    font-weight: 700;
}
.payment-mode-buttons {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}
.payment-mode-buttons button {
    min-height: 44px;
    font-size: 14px;
    background: white;
    color: var(--dark);
    border: 1px solid var(--line);
}
.payment-mode-buttons button.is-selected {
    background: var(--primary);
    color: var(--surface);
    border-color: var(--primary);
}
.payment-submit:disabled {
    cursor: not-allowed;
    opacity: .48;
}
.payment-amount-label { margin-top: 12px; }
.payment-amount-label input {
    height: 58px;
    text-align: right;
    font-size: 28px;
    font-weight: 800;
    background: white;
}
.payment-remaining {
    margin-top: 5px;
    text-align: right;
    font-size: 13px;
}
.numeric-pad {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-top: 14px;
}
.numeric-pad button {
    height: 50px;
    font-size: 20px;
}
.numeric-pad .numeric-clear {
    grid-column: 1 / -1;
    height: 42px;
}
.payment-submit {
    width: 100%;
    min-height: 48px;
    margin-top: 12px;
}
.order-editor {
    display: grid;
    gap: 8px;
}
.order-line-form {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) auto auto auto auto;
    gap: 7px;
    align-items: center;
    max-width: 760px;
    padding: 7px 0;
    border-bottom: 1px solid var(--line);
}
.order-line-title {
    min-width: 0;
}
.order-line-title .muted {
    display: block;
    margin-top: 2px;
    font-size: 12px;
}
.order-line-total {
    min-width: 86px;
    text-align: right;
    font-weight: 800;
}
.order-add-form {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto;
    gap: 8px;
    align-items: end;
    max-width: 760px;
    margin-top: 10px;
}
.order-line-form.is-loading,
.order-add-form.is-loading {
    opacity: .65;
}
.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.section-head h2 { margin: 0; }
.chart-panel { margin-top: 18px; }
.product-filter-panel {
    margin-top: 28px;
}
.product-filter-form {
    display: flex;
    align-items: end;
    gap: 10px;
    flex-wrap: wrap;
}
.product-filter-form label {
    min-width: min(360px, 100%);
}
.unsold-panel {
    margin-top: 18px;
}
.chart-wrap {
    width: 100%;
    overflow-x: auto;
}
.line-chart {
    display: block;
    width: 100%;
    min-width: 520px;
    height: auto;
}
.line-chart text {
    stroke-width: .5;
}
.chart-grid-line {
    stroke: #dfccb4;
    stroke-width: 1;
}
.chart-line {
    fill: none;
    stroke: var(--dark);
    stroke-width: 1;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.chart-point {
    fill: var(--primary);
    stroke: var(--surface);
    stroke-width: 3;
}
.chart-y-label,
.chart-x-label {
    fill: #755c42;
    font-size: 12px;
}
.chart-x-label {
    text-anchor: middle;
}
.compact-list {
    display: grid;
    gap: 8px 18px;
    margin: 0;
    padding: 0;
    list-style: none;
}
.compact-list.three-cols {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}
.compact-list li {
    min-width: 0;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
}
.compact-list strong,
.compact-list span {
    display: block;
    overflow-wrap: anywhere;
}
.compact-list span {
    margin-top: 2px;
    color: #755c42;
    font-size: 13px;
}
.bar-list { display: grid; gap: 12px; }
.bar-row { display: grid; gap: 7px; }
.bar-meta {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}
.bar-meta span { color: #755c42; font-size: 13px; text-align: right; }
.bar-track {
    width: 100%;
    overflow: hidden;
    background: #e8d8c4;
    border-radius: 999px;
}
.bar-track { height: 12px; }
.bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: inherit;
}
.bar-fill.alt { background: var(--dark); }
.order-input { max-width: 92px; }
.muted { color: #755c42; }
.change-due {
    margin-top: 3px;
    color: var(--danger);
    font-weight: 800;
}
.payment-warning {
    margin-top: 3px;
    color: #755c42;
    font-weight: 800;
}
.closure-grid {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}
.closure-status-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}
.closure-status-grid div {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff8ef;
}
.closure-status-grid strong,
.closure-status-grid span {
    display: block;
}
.closure-status-grid strong {
    font-size: 26px;
}
.closure-status-grid span {
    margin-top: 2px;
    color: #755c42;
}
.mb-2 { margin-bottom: 8px; }
.notice { padding: 12px 14px; background: #fff8ef; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 14px; }
.inline-form { display: inline; }
.date-picker {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.date-range-picker {
    display: flex;
    align-items: end;
    gap: 8px;
    flex-wrap: wrap;
}
.date-range-picker label,
.range-native {
    min-width: 150px;
}
.range-native {
    display: flex;
    align-items: end;
    gap: 8px;
    flex-wrap: wrap;
}
.range-enhanced { display: none; }
.date-range-picker.is-enhanced .range-enhanced {
    display: grid;
    min-width: 250px;
}
.date-range-picker.is-enhanced .range-native {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}
.date-picker input[type="date"] {
    width: 154px;
}
.daterangepicker .drp-calendar {
    max-width: none !important;
}
.daterangepicker .calendar-table {
    border-radius: 0 !important;
}
.daterangepicker .calendar-table table {
    width: auto !important;
    background: transparent !important;
    border-collapse: collapse !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    overflow: visible !important;
}
.daterangepicker .calendar-table th,
.daterangepicker .calendar-table td {
    width: 32px !important;
    min-width: 32px !important;
    height: 28px !important;
    padding: 0 !important;
    border-bottom: 0 !important;
    border-radius: 0 !important;
    text-align: center !important;
    vertical-align: middle !important;
}
.daterangepicker .calendar-table th {
    background: transparent !important;
    font-size: 12px !important;
}
.daterangepicker .drp-calendar.left {
    padding-right: 14px !important;
}
.daterangepicker .drp-calendar.right {
    border-left: 1px solid #e8d8c4;
    padding-left: 14px !important;
}
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
@media (max-width: 900px) {
    .compact-list.three-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
    .topbar, .hero { align-items: flex-start; flex-direction: column; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .compact-list.three-cols { grid-template-columns: 1fr; }
    .add-grid { grid-template-columns: 1fr; }
    .shell { padding: 14px; }
    .bar-meta { align-items: flex-start; flex-direction: column; gap: 2px; }
    .bar-meta span { text-align: left; }
    .order-line-form {
        grid-template-columns: 1fr repeat(3, 40px);
    }
    .order-line-total {
        grid-column: 1 / -1;
        grid-row: 2;
        text-align: left;
    }
    .order-add-form {
        grid-template-columns: 1fr;
    }
    th, td { padding: 9px 8px; }
}
