:root {
  --wine: #7d243e;
  --wine-dark: #5e1730;
  --rose: #d98699;
  --rose-soft: #f7e9ed;
  --cream: #fffaf6;
  --paper: #ffffff;
  --ink: #2f2930;
  --muted: #746b72;
  --line: #eadde1;
  --green: #23856b;
  --green-soft: #e3f4ef;
  --amber: #b76a15;
  --amber-soft: #fff0d9;
  --red: #c33e4d;
  --red-soft: #fde8ea;
  --blue: #476f9e;
  --shadow: 0 10px 30px rgba(79, 36, 49, .09);
}

* { box-sizing: border-box; }
.hidden { display: none !important; }
html { min-height: 100%; background: var(--cream); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: linear-gradient(135deg, #fffaf6 0%, #f9f2f4 100%); font-family: Inter, "Segoe UI", Arial, sans-serif; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 245px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 24px 18px; color: #fff; background: linear-gradient(180deg, var(--wine-dark), #842c48 72%, #652039); display: flex; flex-direction: column; box-shadow: 8px 0 30px rgba(80, 20, 43, .12); z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 24px; border-bottom: 1px solid rgba(255,255,255,.16); }
.brand-mark { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; background: #fff; color: var(--wine); font-weight: 900; letter-spacing: -.05em; box-shadow: 0 8px 20px rgba(0,0,0,.12); }
.brand strong { display: block; font-size: 18px; }
.brand small, .local-status small { display: block; margin-top: 2px; color: rgba(255,255,255,.68); }
.nav-list { display: grid; gap: 5px; margin-top: 22px; overflow-y: auto; padding-right: 2px; }
.nav-item { border: 0; padding: 11px 12px; color: rgba(255,255,255,.79); background: transparent; border-radius: 10px; display: flex; align-items: center; gap: 11px; text-align: left; font-weight: 650; }
.nav-item span { width: 19px; text-align: center; opacity: .9; }
.nav-item:hover, .nav-item.active { color: #fff; background: rgba(255,255,255,.15); }
.nav-item.active { box-shadow: inset 3px 0 0 #ffd3dc; }
.local-status { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 14px 10px 0; border-top: 1px solid rgba(255,255,255,.16); font-size: 13px; }
.status-dot { width: 10px; height: 10px; background: #67e2b8; border-radius: 50%; box-shadow: 0 0 0 5px rgba(103,226,184,.13); }

.main-column { min-width: 0; }
.topbar { min-height: 92px; padding: 19px 28px; display: flex; align-items: center; gap: 15px; background: rgba(255,255,255,.78); border-bottom: 1px solid var(--line); backdrop-filter: blur(14px); position: sticky; top: 0; z-index: 10; }
.topbar h1 { margin: 0; font-size: 25px; letter-spacing: -.02em; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.top-actions { margin-left: auto; display: flex; gap: 9px; align-items: center; }
.content { padding: 26px 28px 50px; max-width: 1500px; width: 100%; margin: 0 auto; }
.menu-button { display: none !important; }

.button { min-height: 39px; padding: 9px 14px; border-radius: 9px; border: 1px solid transparent; font-weight: 750; transition: .16s ease; display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.button:hover { transform: translateY(-1px); }
.button.primary { color: #fff; background: var(--wine); box-shadow: 0 7px 16px rgba(125,36,62,.18); }
.button.primary:hover { background: var(--wine-dark); }
.button.ghost { color: var(--wine); background: #fff; border-color: var(--line); }
.button.danger { color: var(--red); background: var(--red-soft); border-color: #f4c9ce; }
.button.small { min-height: 31px; padding: 6px 10px; font-size: 12px; }
.icon-button { width: 38px; height: 38px; display: grid; place-items: center; border: 0; border-radius: 10px; color: var(--muted); background: transparent; font-size: 22px; }
.icon-button:hover { background: var(--rose-soft); color: var(--wine); }
.file-button input { display: none; }

.hero { border-radius: 18px; padding: 24px 26px; margin-bottom: 18px; color: #fff; background: linear-gradient(120deg, var(--wine-dark), var(--wine) 62%, #a04a63); box-shadow: var(--shadow); display: flex; align-items: center; justify-content: space-between; gap: 20px; overflow: hidden; position: relative; }
.hero::after { content: ""; position: absolute; width: 260px; height: 260px; border: 52px solid rgba(255,255,255,.06); border-radius: 50%; right: -80px; top: -110px; }
.hero h2 { margin: 4px 0 7px; font-size: clamp(22px, 3vw, 33px); }
.hero p { margin: 0; color: rgba(255,255,255,.78); max-width: 630px; }
.hero .button { position: relative; z-index: 1; color: var(--wine); background: #fff; white-space: nowrap; }
.eyebrow { color: var(--rose); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; font-weight: 850; }
.hero .eyebrow { color: #ffd4de; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.metric-card, .panel { background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: 15px; box-shadow: var(--shadow); }
.metric-card { padding: 18px; min-height: 129px; position: relative; overflow: hidden; }
.metric-card::after { content: ""; width: 74px; height: 74px; border-radius: 50%; background: var(--rose-soft); position: absolute; right: -20px; bottom: -30px; }
.metric-label { color: var(--muted); font-size: 12px; font-weight: 750; text-transform: uppercase; letter-spacing: .045em; }
.metric-value { margin-top: 12px; font-size: clamp(23px, 2.6vw, 31px); font-weight: 900; color: var(--wine-dark); letter-spacing: -.04em; }
.metric-note { margin-top: 7px; color: var(--muted); font-size: 12px; }
.metric-card.positive .metric-value { color: var(--green); }
.metric-card.warning .metric-value { color: var(--amber); }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, .75fr); gap: 18px; }
.panel { padding: 19px; min-width: 0; }
.panel-header, .section-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 15px; }
.panel h3, .section-heading h2 { margin: 0; font-size: 17px; }
.panel-subtitle { color: var(--muted); font-size: 12px; margin-top: 4px; }
.chart-wrap { height: 285px; position: relative; }
#salesChart { width: 100%; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 13px; color: var(--muted); font-size: 12px; }
.legend span::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; background: var(--legend); }

.alert-list, .compact-list { display: grid; gap: 9px; }
.alert-item, .compact-item { padding: 12px; border: 1px solid var(--line); border-radius: 11px; display: flex; align-items: center; justify-content: space-between; gap: 12px; background: #fff; }
.alert-item { border-color: #f4cbd0; background: var(--red-soft); }
.alert-item strong, .compact-item strong { display: block; font-size: 13px; }
.alert-item small, .compact-item small { display: block; margin-top: 3px; color: var(--muted); }
.empty-state { padding: 34px 20px; text-align: center; color: var(--muted); background: #fff; border: 1px dashed #d9c7cd; border-radius: 13px; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.search { min-width: 240px; flex: 1; position: relative; }
.search input { width: 100%; padding-left: 38px; }
.search::before { content: "⌕"; position: absolute; left: 13px; top: 8px; color: var(--muted); font-size: 19px; }
.filter-group { display: flex; gap: 8px; flex-wrap: wrap; }
.table-card { background: #fff; border: 1px solid var(--line); border-radius: 15px; overflow: hidden; box-shadow: var(--shadow); }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; min-width: 760px; }
th { padding: 12px 13px; text-align: left; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .045em; background: #fbf7f8; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px 13px; border-bottom: 1px solid #f0e7ea; font-size: 13px; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fffafb; }
.order-tone-a { background: #fff; }
.order-tone-b { background: #fbf1f4; }
.number { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.strong { font-weight: 800; }
.danger-text { color: var(--red); font-weight: 800; }
.positive-text { color: var(--green); font-weight: 800; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; padding: 5px 8px; border-radius: 999px; font-size: 11px; font-weight: 800; background: #eee7ea; color: #65565d; white-space: nowrap; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.blue { background: #e8eff8; color: var(--blue); }

.modal-backdrop { position: fixed; inset: 0; padding: 20px; background: rgba(41, 21, 30, .55); backdrop-filter: blur(5px); display: grid; place-items: center; z-index: 50; }
.modal-backdrop.hidden { display: none; }
.modal { width: min(850px, 100%); max-height: calc(100vh - 40px); overflow: hidden; display: flex; flex-direction: column; border-radius: 18px; background: #fff; box-shadow: 0 30px 80px rgba(47,15,30,.28); }
.modal-header { padding: 19px 22px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: flex-start; }
.modal-header h2 { margin: 4px 0 0; font-size: 22px; }
.modal-body { padding: 21px 22px 24px; overflow-y: auto; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: grid; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { color: #5e5359; font-size: 12px; font-weight: 800; }
input, select, textarea { width: 100%; border: 1px solid #dacbd0; border-radius: 9px; padding: 10px 11px; color: var(--ink); background: #fff; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--rose); box-shadow: 0 0 0 3px rgba(217,134,153,.16); }
textarea { resize: vertical; min-height: 82px; }
.form-actions { margin-top: 20px; display: flex; justify-content: flex-end; gap: 9px; }
.check-field { display: flex; align-items: center; gap: 8px; min-height: 42px; }
.check-field input { width: auto; }

.items-editor { margin-top: 18px; padding-top: 17px; border-top: 1px solid var(--line); }
.items-editor-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.items-editor-head h3 { margin: 0; font-size: 15px; }
.item-row { display: grid; grid-template-columns: minmax(180px, 2fr) 90px 125px 125px 36px; gap: 8px; align-items: end; margin-bottom: 8px; padding: 10px; border-radius: 10px; background: #fbf7f8; }
.item-row .field label { font-size: 10px; }
.item-total { min-height: 41px; display: flex; align-items: center; justify-content: flex-end; font-weight: 850; color: var(--wine); }
.items-total { text-align: right; margin-top: 12px; font-size: 18px; font-weight: 900; color: var(--wine-dark); }

.settings-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, .65fr); gap: 18px; }
.info-box { padding: 15px; border-radius: 12px; background: var(--rose-soft); color: #62404c; font-size: 13px; line-height: 1.55; }
.info-box strong { color: var(--wine-dark); }
.toast { position: fixed; right: 24px; bottom: 24px; max-width: 360px; padding: 13px 16px; border-radius: 10px; color: #fff; background: #33272d; box-shadow: 0 14px 35px rgba(0,0,0,.2); transform: translateY(25px); opacity: 0; pointer-events: none; transition: .22s ease; z-index: 80; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: var(--red); }
.print-area { display: none; }

@media (max-width: 1080px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid, .settings-grid { grid-template-columns: 1fr; }
  .top-actions .ghost { display: none; }
}

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; transform: translateX(-105%); width: 255px; transition: .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .menu-button { display: grid !important; }
  .topbar { padding: 15px; min-height: 78px; }
  .topbar h1 { font-size: 20px; }
  .content { padding: 17px 14px 40px; }
  .top-actions { gap: 4px; }
  .top-actions .button.primary { padding: 8px 10px; font-size: 12px; }
  .hero { align-items: flex-start; flex-direction: column; padding: 21px; }
  .metric-grid { grid-template-columns: 1fr; }
  .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .item-row { grid-template-columns: 1fr 80px 110px; }
  .item-row .price-field { grid-column: 1 / 2; }
  .item-row .item-total { grid-column: 2 / 3; }
  .modal-backdrop { padding: 7px; }
}

@media print {
  body { background: #fff; }
  .app-shell, .modal-backdrop, .toast { display: none !important; }
  .print-area { display: block; color: #222; padding: 24px; font-family: Arial, sans-serif; }
  .print-header { display: flex; justify-content: space-between; border-bottom: 3px solid #7d243e; padding-bottom: 16px; margin-bottom: 20px; }
  .print-header h1 { margin: 0; color: #7d243e; }
  .print-meta { text-align: right; font-size: 12px; }
  .print-customer { margin: 20px 0; padding: 14px; background: #f7eef1; }
  .print-table { min-width: 0; }
  .print-table th { background: #7d243e !important; color: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-total { margin-top: 18px; text-align: right; font-size: 22px; font-weight: 900; color: #7d243e; }
  .print-note { margin-top: 35px; font-size: 12px; color: #555; }
}
