:root {
  color-scheme: light;
  --ink: #172c35;
  --muted: #475569;
  --text-secondary: #334155;
  --line: #e0e7e9;
  --accent: #022b5f;
  --accent-dark: #011e43;
  --brand-aqua: #9cdbe4;
  --brand-soft: #edf8fa;
  --brand-border: #c6e8ed;
}
* { box-sizing: border-box; }
body { margin: 0; background: #f5f7f8; color: var(--ink); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 14px; -webkit-font-smoothing: antialiased; }
a { text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--brand-aqua); outline-offset: 3px; }
button:disabled { cursor: not-allowed; opacity: .6; }
.app-sidebar { width: 216px; background: #fff; border-right: 1px solid var(--line); position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 40; }
.app-main { margin-left: 216px; min-height: 100vh; }
.sidebar-brand { display: flex; align-items: center; justify-content: center; flex-shrink: 0; padding: 8px 16px; background: #fff; border-bottom: 1px solid var(--line); }
.sidebar-logo { display: block; width: 116px; height: auto; }
.login-brand { display: flex; justify-content: center; margin-bottom: 24px; }
.login-logo { display: block; width: 144px; height: auto; border-radius: 12px; }
.nav-link { display: flex; align-items: center; gap: 11px; padding: 10px 12px; margin: 3px 0; border-radius: 7px; color: var(--text-secondary); font-size: 14px; font-weight: 500; }
.nav-link:hover { color: var(--accent-dark); background: var(--brand-soft); }
.nav-link.active { background: var(--brand-aqua); color: var(--accent); font-weight: 650; }
.nav-icon { width: 17px; height: 17px; flex-shrink: 0; opacity: .85; }
.topbar { height: 70px; background: #fff; border-bottom: 1px solid var(--line); padding: 0 32px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.page-content { padding: 30px 32px 40px; max-width: 1600px; margin: 0 auto; }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-heading h1 { font-size: 25px; letter-spacing: -.75px; font-weight: 650; line-height: 1.3; margin: 0; }
.page-heading p { color: var(--muted); font-size: 14px; line-height: 1.6; margin-top: 6px; }
.eyebrow { text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); font-size: 10px; font-weight: 700; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: 9px; box-shadow: 0 2px 3px rgb(23 44 53 / 2%); overflow: hidden; }
.panel-heading { padding: 17px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-title { font-size: 14px; font-weight: 650; letter-spacing: -.2px; }
.btn-primary, .btn-secondary, .btn-danger, .btn-quiet { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 36px; border-radius: 6px; padding: 8px 13px; font-size: 14px; font-weight: 600; line-height: 1.4; white-space: nowrap; transition: background .15s ease, border-color .15s ease; }
.btn-primary { background: var(--accent); color: #fff; border: 1px solid var(--accent); box-shadow: 0 1px 2px rgb(23 44 53 / 8%); }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-secondary { background: #fff; color: var(--text-secondary); border: 1px solid #d7e0e3; }
.btn-secondary:hover { background: #f5f8f9; border-color: #b9c7cc; }
.btn-danger { background: #b93c3c; color: #fff; border: 1px solid #b93c3c; }
.btn-danger:hover { background: #a43232; }
.btn-quiet { border: 1px solid transparent; color: var(--muted); background: transparent; }
.btn-quiet:hover { background: #edf3f4; color: var(--ink); }
.text-link { color: var(--accent); font-weight: 550; }
.text-link:hover { color: var(--accent-dark); text-decoration: underline; }
.form-input, input:not([type=checkbox]):not([type=radio]):not([type=hidden]):not([type=submit]), select, textarea { width: 100%; min-width: 0; border: 1px solid #d5dfe3; border-radius: 6px; background: #fff; padding: 9px 11px; color: var(--ink); line-height: 1.4; min-height: 38px; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 3px solid var(--brand-aqua); outline-offset: 0; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 15px; height: 15px; vertical-align: middle; }
input[type=file] { padding: 7px 9px !important; font-size: 14px; }
input[type=file]::file-selector-button { background: var(--brand-soft); border: 0; padding: 4px 9px; border-radius: 4px; color: var(--accent); margin-right: 10px; cursor: pointer; }
textarea { resize: vertical; min-height: 92px; }
.field { min-width: 0; }
.field:has(textarea) { grid-column: 1 / -1; }
.field label { display: block; font-size: 14px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.field .helptext { margin-top: 6px; font-size: 14px; line-height: 1.6; color: var(--muted); }
.field .helptext ul { padding-left: 16px; list-style: disc; }
.field .errorlist { margin: 6px 0 0; list-style: none; padding: 0; font-size: 14px; color: #b63737; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: #df9d9d; }
.field a { color: var(--accent); text-decoration: underline; }
.required-mark { color: var(--accent); margin-left: 2px; }
.error-summary { border: 1px solid #efc7c7; color: #a23838; background: #fff7f7; border-radius: 7px; padding: 12px 15px; font-size: 14px; line-height: 1.6; }
.error-summary ul { margin: 0; padding-left: 18px; list-style: disc; }
.notice { padding: 12px 15px; border-radius: 7px; border: 1px solid #d0e6dd; background: #edf8f2; color: #267056; font-size: 14px; margin-bottom: 20px; }
.notice.error { background: #fff4f3; color: #a63636; border-color: #edc9c4; }
.notice.warning { background: #fffaed; color: #8c6518; border-color: #efe0b7; }
.table-scroll { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; white-space: nowrap; text-align: left; font-size: 14px; }
.data-table thead { background: #f8fafb; }
.data-table th { padding: 0; font-weight: 600; color: var(--muted); font-size: 14px; letter-spacing: .1px; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 1; background: #f8fafb; }
.data-table th .sort-link { display: flex; align-items: center; gap: 10px; padding: 13px 18px; color: inherit; }
.data-table th .sort-link:hover, .data-table th.sorted .sort-link { color: var(--accent); }
.data-table .sort-symbol { margin-left: auto; color: var(--muted); font-size: 14px; }
.data-table th.sorted .sort-symbol { color: var(--accent); }
.data-table td { border-bottom: 1px solid #edf1f3; padding: 13px 18px; color: var(--text-secondary); height: 58px; max-width: 360px; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #fbfdfd; }
.data-table .cell-content { display: block; max-width: 330px; overflow: hidden; text-overflow: ellipsis; }
.data-table .actions-cell { text-align: right; padding-right: 18px; }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; align-items: center; }
.row-action { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; flex-shrink: 0; border: 1px solid #e0e7e9; border-radius: 5px; background: #fff; color: var(--muted); }
.row-action:hover { color: var(--accent); border-color: var(--brand-border); background: var(--brand-soft); }
.row-action.danger:hover { color: #b93c3c; border-color: #efc7c7; background: #fff7f7; }
.action-icon { display: block; flex-shrink: 0; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border-radius: 5px; background: #f0f3f5; color: var(--muted); font-size: 10px; font-weight: 600; line-height: 1.2; }
.badge::before { content: ""; width: 4px; height: 4px; border-radius: 100%; background: currentColor; }
.badge.pending { color: #ac7b21; background: #fff5de; }
.badge.on_route, .badge.on-route, .badge.route { color: #477cbd; background: #edf4fe; }
.badge.delivered, .badge.active, .badge.success { color: #19806a; background: #e8f6ef; }
.badge.paid { color: #7563b6; background: #f1edfc; }
.badge.inactive { color: #8a6a6a; background: #f8eeee; }
.empty-state { text-align: center; padding: 54px 24px; }
.empty-state .empty-icon { margin: 0 auto 14px; width: 43px; height: 43px; background: var(--brand-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; border: 1px solid var(--brand-border); border-radius: 12px; }
.empty-state h3 { font-weight: 600; font-size: 14px; color: var(--text-secondary); }
.empty-state p { max-width: 320px; margin: 6px auto 17px; font-size: 14px; line-height: 1.7; color: var(--muted); }
.stat-card { background: white; border: 1px solid var(--line); border-radius: 9px; padding: 19px 20px; min-width: 0; }
.stat-value { margin-top: 12px; color: var(--accent); font-size: 27px; font-weight: 650; line-height: 1.15; letter-spacing: -.8px; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 14px; color: var(--muted); font-weight: 550; }
.stat-detail { margin-top: 9px; font-size: 14px; color: var(--muted); }
.detail-label { color: var(--muted); font-size: 14px; margin-bottom: 5px; }
.detail-value { color: var(--text-secondary); font-size: 14px; line-height: 1.6; overflow-wrap: anywhere; }
.line-item { border: 1px solid #e1e8eb; border-radius: 7px; padding: 16px; background: #fbfdfd; }
.permission-table th, .permission-table td { padding: 14px 18px; }
.permission-table th:not(:first-child), .permission-table td:not(:first-child) { text-align: center; }
.mobile-menu, .sidebar-overlay { display: none; }
.pagination-link { border: 1px solid #dce4e7; border-radius: 5px; background: #fff; display: inline-flex; min-width: 30px; height: 30px; padding: 0 9px; align-items: center; justify-content: center; font-size: 14px; color: var(--muted); }
.pagination-link:hover { background: var(--brand-soft); border-color: var(--brand-border); color: var(--accent); }
.pagination-link.disabled { color: var(--muted); background: #fafbfc; pointer-events: none; }
.money { font-variant-numeric: tabular-nums; }
.sale-page .sale-back { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 12px; color: var(--muted); font-size: 14px; }
.sale-page .sale-back:hover { color: var(--accent-dark); }
.sale-page .page-heading { gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.sale-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.sale-main { min-width: 0; display: grid; gap: 16px; }
.sale-page .panel-heading { padding: 12px 16px; }
.sale-page .panel-title { font-size: 14px; }
.sale-meta dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 18px; margin: 0; padding: 12px 16px; }
.sale-meta-field { display: grid; grid-template-columns: 90px minmax(0, 1fr); align-items: start; gap: 8px; }
.sale-meta .detail-label { margin-bottom: 0; line-height: 1.6; }
.sale-meta .detail-value { margin: 0; font-size: 14px; }
.sale-meta-notes { grid-column: 1 / -1; display: grid; grid-template-columns: 90px minmax(0, 1fr); align-items: start; gap: 8px; }
.sale-items .data-table th, .sale-items .data-table td { padding: 10px 14px; height: 44px; }
.sale-items .item-name { display: block; max-width: 260px; white-space: normal; overflow-wrap: anywhere; }
.sale-totals { display: flex; justify-content: flex-end; border-top: 1px solid var(--line); padding: 12px 16px; }
.sale-totals dl { width: 260px; max-width: 100%; margin: 0; }
.sale-total-row { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; padding: 6px 0; font-size: 14px; }
.sale-total-row dt { color: var(--muted); }
.sale-total-row dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.sale-total-final { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); font-weight: 600; }
.sale-total-final dt { color: var(--ink); }
.sale-total-final dd { color: var(--accent); font-size: 20px; }
.sale-status { min-width: 0; }
.sale-status .panel-heading { flex-wrap: wrap; }
.sale-status-list { margin: 0; padding: 0; list-style: none; }
.sale-status-entry { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px; border-bottom: 1px solid #edf1f3; }
.sale-status-entry:last-child { border-bottom: 0; }
.sale-status-entry time { color: var(--muted); font-size: 14px; }
@media (min-width: 1100px) { .sale-layout { grid-template-columns: minmax(0, 1fr) 300px; } }
.sale-layout.sale-layout-single { grid-template-columns: minmax(0, 1fr); }
@media (max-width: 639px) { .sale-meta dl { grid-template-columns: minmax(0, 1fr); } }
@media (min-width: 1600px) { .page-content { padding-top: 36px; } }
@media (max-width: 1023px) { .topbar { padding: 0 22px; } .page-content { padding: 24px 22px 32px; } .app-sidebar { width: 192px; } .app-main { margin-left: 192px; } }
@media (max-width: 767px) {
  .app-sidebar { transform: translateX(-100%); width: 228px; transition: transform .2s ease; }
  .sidebar-open .app-sidebar { transform: translateX(0); }
  .sidebar-open .sidebar-overlay { display: block; position: fixed; inset: 0; background: rgb(23 44 53 / 30%); z-index: 30; }
  .app-main { margin-left: 0; }
  .mobile-menu { display: inline-flex; }
  .topbar { height: 62px; padding: 0 16px; }
  .page-content { padding: 22px 16px 30px; }
  .page-heading { align-items: flex-start; gap: 12px; margin-bottom: 20px; }
  .page-heading h1 { font-size: 22px; }
  .page-heading p { font-size: 14px; }
  .stat-card { padding: 15px; }
  .stat-value { font-size: 24px; }
  .data-table th .sort-link, .data-table td { padding-left: 14px; padding-right: 14px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; } }

.brand-avatar { background: var(--brand-soft); border-color: var(--brand-border); color: var(--accent); }
.brand-stat-icon { background: var(--brand-soft); color: var(--accent); }
.brand-back:hover { color: var(--accent); }

/* Phone navigation and layouts. */
.bottom-nav { display: none; }
.app-main, .page-content, .panel, .panel-heading > div { min-width: 0; }
@media (max-width: 767px) {
  .bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex; background: #fff; border-top: 1px solid var(--brand-border); box-shadow: 0 -3px 16px rgb(2 43 95 / 7%); padding: 6px max(6px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left)); }
  .bottom-nav-item { flex: 1; min-width: 0; min-height: 54px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 4px 2px; color: var(--muted); background: transparent; border: 0; border-radius: 8px; font-size: 12px; line-height: 1.3; font-weight: 600; }
  .bottom-nav-item .nav-icon { width: 22px; height: 22px; opacity: 1; }
  .bottom-nav-item.active, .bottom-nav-item:hover { color: var(--accent); background: var(--brand-soft); }
  .page-content { padding: 20px 14px calc(96px + env(safe-area-inset-bottom)); }
  .topbar { position: sticky; top: 0; z-index: 20; background: #fff; }
  .sidebar-open { overflow: hidden; }
  .sidebar-open .sidebar-overlay { z-index: 40; }
  .app-sidebar { z-index: 50; width: min(300px, 88vw); padding-bottom: env(safe-area-inset-bottom); }
  .sidebar-close { position: absolute; top: 8px; right: 8px; width: 44px; height: 44px; }
  .sidebar-logo { width: 96px; }
  .page-heading { flex-wrap: wrap; }
  .page-heading > div { min-width: 0; max-width: 100%; }
  .page-heading h1 { overflow-wrap: anywhere; }
  .panel-heading { flex-wrap: wrap; padding: 14px; gap: 10px; }
  .btn-primary, .btn-secondary, .btn-danger, .btn-quiet, .row-action, .pagination-link { min-height: 44px; }
  .row-action, .pagination-link { min-width: 44px; }
  .nav-link { min-height: 44px; }
  input:not([type=checkbox]):not([type=radio]):not([type=hidden]):not([type=submit]), select, textarea { font-size: 16px !important; min-height: 44px; }
  input[type=checkbox], input[type=radio] { width: 20px; height: 20px; }
  .table-scroll { overscroll-behavior-x: contain; }
  .data-table td { max-width: 240px; }
  .data-table .cell-content { max-width: 220px; }
  .empty-state { padding: 28px 14px; }
  .sale-meta dl { grid-template-columns: minmax(0, 1fr); }
  .sale-totals dl { width: 100%; }
  .stat-value { font-size: clamp(18px, 5.5vw, 24px); overflow-wrap: anywhere; }
}

.record-layout { width: 75%; min-width: 0; margin-inline: auto; }
@media (max-width: 1399px) { .record-layout .sale-layout { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 1023px) { .record-layout { width: 100%; } }

.sale-form-fields .field:has(textarea) { grid-column: auto; }
.sale-form-fields textarea { min-height: 44px; height: 44px; }
@media (min-width: 1024px) {
  .sale-form-fields { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
  .sale-form-fields textarea { min-height: 38px; height: 38px; }
}

.discount-control { position: relative; }
.discount-control > input { padding-right: 72px !important; }
.discount-chips { position: absolute; right: 4px; top: 4px; bottom: 4px; display: flex; align-items: stretch; gap: 2px; padding: 2px; border-radius: 5px; background: var(--brand-soft); }
.discount-chips label { position: relative; display: flex; margin: 0; cursor: pointer; }
.discount-chips input[type=radio] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.discount-chips span { display: flex; align-items: center; justify-content: center; min-width: 26px; padding: 0 5px; border-radius: 4px; color: var(--muted); font-size: 12px; font-weight: 600; }
.discount-chips input:checked + span { background: var(--accent); color: #fff; }
.discount-chips input:focus-visible + span { outline: 2px solid var(--brand-aqua); outline-offset: 2px; }

/* Compact customer create/edit forms. */
.customer-compact .brand-back { margin-bottom: 10px; }
.customer-compact .page-heading { margin-bottom: 12px; }
.customer-compact .customer-fields { padding: 14px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 12px; }
.customer-compact .field:has(textarea) { grid-column: auto; }
.customer-compact .field label { margin-bottom: 4px; }
.customer-compact .form-input { padding: 7px 9px; min-height: 36px; }
.customer-compact textarea.form-input { height: 36px; resize: vertical; }
.customer-compact .field .helptext { margin-top: 3px; font-size: 12px; line-height: 1.3; }
.customer-compact form > :last-child { margin-top: 12px; padding-top: 0; }
@media (max-width: 1199px) { .customer-compact .customer-fields { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 767px) {
  .customer-compact .customer-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 12px; gap: 10px; }
  .customer-compact .form-input { min-height: 44px; font-size: 16px; }
  .customer-compact textarea.form-input { height: 44px; }
}
@media (max-width: 359px) { .customer-compact .customer-fields { grid-template-columns: minmax(0, 1fr); } }

.gender-chips { border: 0; padding: 0; margin: 0; min-width: 0; }
.gender-chips legend { padding: 0; margin-bottom: 4px; font-size: 14px; font-weight: 600; color: var(--text-secondary); }
.gender-chip-options { display: flex; gap: 6px; }
.field .gender-chip { position: relative; flex: 1; margin: 0; cursor: pointer; }
.gender-chip input[type=radio] { position: absolute; width: 1px; height: 1px; min-height: 0; padding: 0; margin: 0; opacity: 0; }
.gender-chip span { display: flex; justify-content: center; align-items: center; min-height: 36px; padding: 6px 10px; border: 1px solid #d5dfe3; border-radius: 999px; background: #fff; }
.gender-chip input:checked + span { color: var(--accent); background: var(--brand-soft); border-color: var(--accent); }
.gender-chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.gender-chip:hover span { border-color: var(--accent); }
@media(max-width:767px) { .gender-chip span { min-height: 44px; } }

/* Keep the four expense fields together without oversized note areas. */
.expense-compact { width: 100%; max-width: 1100px; }
.expense-compact .customer-fields { grid-template-columns: minmax(0, 1fr) minmax(0, .75fr) minmax(220px, 1.25fr) minmax(0, 1.25fr); }
@media(max-width:1199px) { .expense-compact .customer-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media(max-width:599px) {
  .expense-compact .field:has(input[type=datetime-local]), .expense-compact .field:has(textarea) { grid-column: 1 / -1; }
}
@media(max-width:359px) { .expense-compact .customer-fields { grid-template-columns: minmax(0, 1fr); } }

.category-select-create { position: relative; }
.category-select-create select { padding-right: 44px; appearance: none; }
.category-create-button { position: absolute; right: 3px; top: 3px; bottom: 3px; width: 32px; border: 0; border-radius: 4px; color: var(--accent); background: var(--brand-soft); font-size: 24px; line-height: 1; }
.category-create-button:hover { background: var(--brand-aqua); }
.category-dialog { position: fixed; inset: 0; margin: auto; width: min(420px, calc(100% - 28px)); max-height: calc(100dvh - 28px); overflow-y: auto; padding: 0; border: 1px solid var(--line); border-radius: 12px; background: white; color: var(--ink); box-shadow: 0 20px 70px #022b5f33; }
.category-dialog::backdrop { background: #022b5f73; }
.category-dialog-body { padding: 16px; display: grid; gap: 12px; }
.category-dialog-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); }
#category-create-status:empty { display: none; }
@media(max-width:767px) { .category-create-button { width: 40px; top: 0; bottom: 0; }.category-select-create select { padding-right: 46px; } }
