:root {
  color-scheme: light;
  --red: #b5121b;
  --red-dark: #7f0c12;
  --yellow: #ffd45a;
  --ink: #211b19;
  --muted: #746d69;
  --cream: #fff8e8;
  --paper: #fffdf8;
  --surface: #f4efe8;
  --line: #e6ddd2;
  --white: #fff;
  --green: #18794e;
  --blue: #2563a8;
  --shadow: 0 18px 55px rgba(43, 25, 19, .1);
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: #f6f2ec;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }

.site-header {
  position: sticky;
  z-index: 20;
  top: 0;
  color: var(--white);
  background: rgba(24, 19, 18, .97);
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  backdrop-filter: blur(14px);
}

.header-inner {
  display: flex;
  align-items: center;
  width: min(1440px, 100%);
  min-height: 76px;
  margin: 0 auto;
  padding: 0 clamp(18px, 4vw, 58px);
  gap: 34px;
}

.brand {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: block;
  width: 48px;
  height: 48px;
  overflow: hidden;
  background: #fff;
  border: 2px solid rgba(255,255,255,.85);
  border-radius: 12px;
  box-shadow: 0 5px 14px rgba(0, 0, 0, .22);
}
.brand-mark img { display: block; width: 100%; height: 100%; object-fit: contain; }

.brand strong,
.brand small { display: block; }
.brand strong { font-size: 1rem; letter-spacing: .02em; }
.brand small { margin-top: 1px; color: rgba(255,255,255,.58); font-size: .71rem; }

.main-nav { display: flex; align-self: stretch; align-items: stretch; gap: 3px; }
.main-nav a {
  display: grid;
  place-items: center;
  padding: 0 14px;
  color: rgba(255,255,255,.66);
  border-bottom: 3px solid transparent;
  font-size: .87rem;
  font-weight: 720;
  text-decoration: none;
}
.main-nav a:hover { color: var(--white); }
.main-nav a.active { color: var(--yellow); border-bottom-color: var(--yellow); }

.user-menu { display: flex; align-items: center; gap: 13px; margin-left: auto; }
.user-menu > span { display: block; text-align: right; }
.user-menu strong, .user-menu small { display: block; }
.user-menu strong { max-width: 180px; overflow: hidden; font-size: .81rem; text-overflow: ellipsis; white-space: nowrap; }
.user-menu small { color: rgba(255,255,255,.55); font-size: .69rem; }
.user-menu a, .link-button { color: rgba(255,255,255,.72); font-size: .79rem; font-weight: 700; }
.link-button { padding: 0; background: none; border: 0; text-decoration: underline; }
.user-menu form { margin: 0; }

.page-shell {
  width: min(1440px, 100%);
  min-height: calc(100vh - 132px);
  margin: 0 auto;
  padding: 42px clamp(18px, 4vw, 58px) 60px;
}

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 20px clamp(18px, 4vw, 58px) 34px;
  color: #8d8580;
  font-size: .75rem;
}

.page-heading { margin: 0 0 27px; }
.page-heading h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.25rem, 5vw, 4.1rem);
  line-height: .98;
  letter-spacing: -.045em;
}
.page-heading > p:last-child, .page-heading > div > p:last-child { max-width: 660px; margin: 12px 0 0; color: var(--muted); }
.split-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.heading-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.eyebrow { margin: 0 0 8px; color: var(--red); font-size: .73rem; font-weight: 880; letter-spacing: .14em; text-transform: uppercase; }
.lead { color: var(--muted); line-height: 1.6; }

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 11px;
  font-weight: 790;
  text-decoration: none;
  transition: transform .17s ease, box-shadow .17s ease, background .17s ease;
}
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: .45; }
.button-primary { color: var(--white); background: var(--red); box-shadow: 0 9px 18px rgba(181,18,27,.18); }
.button-primary:hover:not(:disabled) { background: var(--red-dark); box-shadow: 0 12px 24px rgba(181,18,27,.22); }
.button-secondary { color: var(--ink); background: var(--white); border-color: var(--line); }
.button-large { min-height: 52px; padding-inline: 24px; }

.panel, .receipt-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 19px;
  box-shadow: 0 8px 30px rgba(43,25,19,.055);
}
.panel { overflow: hidden; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 22px 24px 18px; }
.panel-heading h2 { margin: 0; font-size: 1.05rem; }
.panel-heading p { margin: 3px 0 0; color: var(--muted); font-size: .8rem; }
.panel-heading > a { color: var(--red); font-size: .82rem; font-weight: 800; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin: 0 0 22px; }
.stat-card { position: relative; min-height: 155px; padding: 22px; overflow: hidden; color: var(--ink); background: var(--white); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 8px 30px rgba(43,25,19,.05); }
.stat-card::after { position: absolute; width: 95px; height: 95px; right: -34px; bottom: -43px; content: ""; border-radius: 50%; background: rgba(181,18,27,.08); }
.stat-card span, .stat-card small { display: block; }
.stat-card span { color: var(--muted); font-size: .77rem; font-weight: 760; text-transform: uppercase; letter-spacing: .07em; }
.stat-card strong { display: block; margin: 17px 0 5px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.55rem, 3vw, 2.25rem); line-height: 1; }
.stat-card small { color: var(--muted); }
.stat-card-link { display: block; color: inherit; text-decoration: none; }
.stat-card-link .stat-card { height: 100%; transition: transform .17s ease, box-shadow .17s ease; }
.stat-card-link:hover .stat-card { transform: translateY(-2px); box-shadow: 0 12px 34px rgba(43,25,19,.11); }
.stat-red { color: var(--white); background: var(--red); border-color: var(--red); }
.stat-red span, .stat-red small { color: rgba(255,255,255,.7); }
.stat-red::after { background: rgba(255,212,90,.18); }
.stat-yellow { background: var(--yellow); border-color: #efc749; }
.stat-dark { color: var(--white); background: #1c1817; border-color: #1c1817; }
.stat-dark span, .stat-dark small { color: rgba(255,255,255,.62); }
.stat-cream { background: var(--cream); }
.client-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 15px 18px; border-top: 1px solid #eee7de; text-align: left; vertical-align: middle; }
th { color: #7d746f; background: #fbf9f6; font-size: .7rem; font-weight: 850; letter-spacing: .07em; text-transform: uppercase; white-space: nowrap; }
td { font-size: .86rem; }
td small { display: block; max-width: 380px; margin-top: 3px; color: var(--muted); }
.number { text-align: right; white-space: nowrap; }
.balance { color: var(--red-dark); font-weight: 800; }
.table-link { color: var(--red); font-weight: 850; }
.empty-cell { padding: 36px; color: var(--muted); text-align: center; }
.mini-action { display: inline-block; padding: 6px 9px; color: var(--red); background: #fff1f1; border: 0; border-radius: 8px; font-size: .73rem; font-weight: 850; text-decoration: none; white-space: nowrap; }
.mini-action-muted { color: #615a56; background: #ece8e4; }
.compact-form { margin: 0; }

.badge { display: inline-flex; align-items: center; min-height: 25px; padding: 4px 9px; border-radius: 99px; font-size: .69rem; font-weight: 850; white-space: nowrap; }
.badge-success { color: #12613e; background: #dcf5e8; }
.badge-info { color: #1d5793; background: #e1efff; }
.badge-warning { color: #725300; background: #fff1b9; }
.badge-danger { color: #9a1620; background: #ffe3e5; }
.badge-neutral { color: #615a56; background: #ece8e4; }

.two-column { display: grid; grid-template-columns: minmax(0, 1fr) minmax(310px, 410px); align-items: start; gap: 20px; }
.panel-stack { display: grid; gap: 20px; min-width: 0; }
.products-layout { grid-template-columns: minmax(0, 1fr) minmax(310px, 380px); }
.detail-columns { margin-top: 22px; grid-template-columns: minmax(0, 1.35fr) minmax(300px, .65fr); }
.form-panel { padding: 0 24px 24px; }
.form-panel .panel-heading { margin-inline: -24px; }
.narrow-panel { max-width: 570px; }

.stack-form { display: grid; gap: 15px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
label { display: block; color: #514a46; font-size: .77rem; font-weight: 760; }
input, select, textarea {
  width: 100%;
  min-height: 46px;
  margin-top: 7px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #d9d0c6;
  border-radius: 10px;
  outline: 0;
  transition: border-color .17s ease, box-shadow .17s ease;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(181,18,27,.1); }
input[readonly] { color: #615a56; background: #f4f0eb; cursor: default; }
.check-label { display: flex; align-items: center; gap: 9px; }
.check-label input { width: 18px; min-height: 18px; margin: 0; accent-color: var(--red); }
hr { width: 100%; margin: 3px 0; border: 0; border-top: 1px solid var(--line); }
.form-help { margin: 0; color: var(--muted); font-size: .78rem; }
.inline-form { display: flex; align-items: flex-end; gap: 10px; }
.inline-form select { margin: 0; }
.edit-layout { grid-template-columns: minmax(0, 1.2fr) minmax(310px, .8fr); }
.move-panel { border-color: #ead7a5; }
.history-note { margin: 0 0 18px; padding: 13px 14px; color: #644d13; background: #fff7dc; border: 1px solid #efddaa; border-radius: 11px; font-size: .79rem; line-height: 1.5; }
.filter-panel { margin-bottom: 20px; padding: 20px 22px; }
.filter-form { display: grid; grid-template-columns: minmax(170px,.7fr) minmax(220px,1.2fr) minmax(180px,.8fr) auto auto; align-items: end; gap: 12px; }
.filter-form input, .filter-form select { margin-top: 6px; }
.balances-stats { margin-top: 0; }
.report-definition { margin: 0 0 20px; padding: 14px 16px; color: #5d514c; background: var(--cream); border: 1px solid #eadfc6; border-radius: 12px; font-size: .82rem; line-height: 1.55; }
.report-panel + .report-panel { margin-top: 20px; }

.alert { margin: 0 0 20px; padding: 13px 15px; border-radius: 11px; font-size: .84rem; font-weight: 670; }
.alert-success { color: #12613e; background: #dcf5e8; border: 1px solid #b6e6cd; }
.alert-error { color: #8b151d; background: #fff0f1; border: 1px solid #f4c8cc; }

.delivery-form { display: grid; gap: 20px; }
.items-list { display: grid; gap: 13px; }
.item-row { padding: 17px; background: #faf7f2; border: 1px solid var(--line); border-radius: 14px; }
.item-top { display: grid; grid-template-columns: minmax(160px,.8fr) minmax(220px,1.4fr) 38px; align-items: end; gap: 11px; }
.item-numbers { display: grid; grid-template-columns: .65fr .8fr 1fr 1fr; align-items: end; gap: 11px; margin-top: 11px; }
.icon-button { width: 38px; height: 46px; color: var(--red); background: #fff; border: 1px solid #e8c9cb; border-radius: 10px; font-size: 1.35rem; }
.line-total { min-height: 46px; padding: 6px 11px; text-align: right; }
.line-total span, .line-total strong { display: block; }
.line-total span { color: var(--muted); font-size: .7rem; font-weight: 750; }
.line-total strong { margin-top: 3px; font-size: .98rem; }
.totals-panel { display: grid; grid-template-columns: minmax(0,1fr) minmax(300px,420px); gap: 32px; padding-top: 24px; }
.totals-editor { padding: 18px; background: #191514; border-radius: 15px; color: var(--white); }
.totals-editor label { color: rgba(255,255,255,.68); }
.totals-editor input { color: var(--white); background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.16); }
.totals-editor dl { margin: 17px 0; }
.totals-editor dl div { display: flex; justify-content: space-between; gap: 20px; padding: 7px 0; color: rgba(255,255,255,.68); }
.totals-editor dl dd { margin: 0; color: var(--white); font-weight: 780; }
.totals-editor .grand-total { margin-top: 7px; padding-top: 15px; border-top: 1px solid rgba(255,255,255,.14); color: var(--white); font-size: 1.13rem; font-weight: 850; }
.totals-editor .button { width: 100%; }

.receipt-card { padding: clamp(20px, 4vw, 45px); }
.receipt-card .brand { color: var(--ink); }
.receipt-card .brand small { color: var(--muted); }
.receipt-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 30px; padding-bottom: 24px; border-bottom: 3px solid var(--red); }
.receipt-head > div:first-child > p { margin: 13px 0 0; color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .08em; }
.receipt-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 7px; }
.receipt-meta > strong { font-family: Georgia, "Times New Roman", serif; font-size: 1.65rem; }
.receipt-meta > span:last-child { color: var(--muted); font-size: .83rem; }
.client-summary { display: grid; grid-template-columns: 1.2fr 1fr .75fr; gap: 22px; padding: 22px 0; }
.client-summary span, .client-summary strong, .client-summary small { display: block; }
.client-summary span, .receipt-notes span { margin-bottom: 5px; color: var(--muted); font-size: .67rem; font-weight: 830; letter-spacing: .08em; text-transform: uppercase; }
.client-summary strong { font-size: .92rem; }
.client-summary small { margin-top: 3px; color: var(--muted); }
.items-table { border: 1px solid var(--line); }
.receipt-bottom { display: grid; grid-template-columns: minmax(0,1fr) minmax(280px,380px); gap: 34px; padding-top: 24px; }
.receipt-notes p { margin: 0; color: var(--muted); line-height: 1.6; white-space: pre-wrap; }
.receipt-totals { margin: 0; }
.receipt-totals div { display: flex; justify-content: space-between; gap: 20px; padding: 7px 0; }
.receipt-totals dd { margin: 0; font-weight: 800; }
.receipt-totals .grand-total { margin-top: 6px; padding-top: 14px; border-top: 2px solid var(--ink); font-size: 1.12rem; }
.receipt-totals .balance-total { color: var(--red); font-size: 1.05rem; }
.legal-copy { margin: 25px 0 0; padding-top: 15px; color: #8d8580; border-top: 1px solid var(--line); font-size: .7rem; text-align: center; }
.help-card { padding: 27px; }
.help-card h2 { margin: 0; }
.help-card p:last-child { color: var(--muted); }

.empty-state { padding: 55px 25px; text-align: center; }
.empty-state h1, .empty-state h2 { margin: 0; }
.empty-state p { max-width: 520px; margin: 12px auto 22px; color: var(--muted); }
.error-code { display: block; color: var(--red); font-family: Georgia, serif; font-size: 4rem; font-weight: 800; }

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 25px;
  background:
    radial-gradient(circle at 82% 12%, rgba(255,212,90,.26), transparent 28rem),
    radial-gradient(circle at 15% 88%, rgba(181,18,27,.28), transparent 30rem),
    linear-gradient(140deg, #261715 0%, #120f0f 58%, #211412 100%);
}
.login-page .site-header, .login-page .site-footer { display: none; }
.login-page .page-shell { display: grid; width: 100%; min-height: auto; place-items: center; padding: 0; }
.login-card { width: min(100%, 475px); padding: clamp(27px, 5vw, 47px); background: rgba(255,253,248,.985); border: 1px solid rgba(255,255,255,.6); border-radius: 25px; box-shadow: 0 30px 90px rgba(0,0,0,.32); }
.login-brand { margin-bottom: 35px; }
.login-brand .brand { color: var(--ink); }
.login-brand .brand small { color: var(--muted); }
.login-card h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2.3rem, 8vw, 3.65rem); line-height: .96; letter-spacing: -.05em; }
.login-card .lead { margin: 17px 0 24px; }
.login-note { margin: 18px 0 0; color: var(--muted); font-size: .72rem; text-align: center; }

@media (max-width: 1050px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .client-stats { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .two-column, .detail-columns, .products-layout { grid-template-columns: 1fr; }
  .filter-form { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .form-panel { max-width: none; }
  .main-nav { order: 3; width: 100%; height: 46px; overflow-x: auto; }
  .header-inner { flex-wrap: wrap; padding-top: 12px; gap: 8px 22px; }
  .site-header { position: static; }
  .user-menu { margin-left: auto; }
}

@media (max-width: 720px) {
  .page-shell { padding-top: 28px; }
  .user-menu > span { display: none; }
  .main-nav a { padding-inline: 12px; font-size: .78rem; }
  .split-heading { align-items: flex-start; flex-direction: column; }
  .stats-grid, .client-stats { grid-template-columns: 1fr 1fr; }
  .stat-card { min-height: 135px; }
  .form-grid, .form-grid.three, .item-top, .item-numbers, .totals-panel, .client-summary, .receipt-bottom { grid-template-columns: 1fr; }
  .filter-form { grid-template-columns: 1fr; }
  .item-top .icon-button { justify-self: end; }
  .receipt-head { flex-direction: column; }
  .receipt-meta { align-items: flex-start; }
  .heading-actions { width: 100%; }
  .heading-actions .button { flex: 1; }
  .site-footer { flex-direction: column; }
}

@media (max-width: 470px) {
  .brand small { display: none; }
  .user-menu { gap: 8px; }
  .stats-grid, .client-stats { grid-template-columns: 1fr; }
  .panel-heading { align-items: flex-start; flex-direction: column; }
  .panel-heading .button { width: 100%; }
  th, td { padding: 13px 14px; }
}

@media print {
  body { background: #fff; }
  .site-header, .site-footer, .page-heading, .detail-columns, .alert { display: none !important; }
  .page-shell { width: 100%; padding: 0; }
  .receipt-card { border: 0; border-radius: 0; box-shadow: none; }
}
