:root {
  --blue: #176db3;
  --blue-dark: #123f61;
  --green: #249b2a;
  --ink: #273943;
  --muted: #6b7f89;
  --line: #d6e3e9;
  --bg: #f5f8fa;
  --soft-blue: #eef6fb;
  --soft-green: #eff8ef;
  --danger: #b84d45;
  --shadow: 0 12px 35px rgba(20, 62, 88, .09);
}

* { box-sizing: border-box; }
html { font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--bg); }
body { margin: 0; min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 6px; color: var(--green); font-size: .72rem; font-weight: 800; letter-spacing: .12em; }
h1, h2, h3 { color: var(--blue-dark); margin: 0; }
h1 { font-size: clamp(1.65rem, 3vw, 2.25rem); }
h2 { font-size: 1.25rem; }

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 15% 15%, #e9f7eb 0, transparent 30%), radial-gradient(circle at 85% 80%, #e4f2fb 0, transparent 34%), #f8fbfc; }
.auth-card { width: min(430px, 100%); padding: 38px; border: 1px solid var(--line); border-radius: 24px; background: white; box-shadow: var(--shadow); }
.auth-logo { width: 220px; max-width: 80%; height: auto; margin: 0 0 25px; }
.auth-card h1 { margin-bottom: 8px; }
.auth-card .muted { margin: 0 0 24px; line-height: 1.5; }

.app { min-height: 100vh; display: grid; grid-template-columns: 245px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 28px 20px 20px; background: white; border-right: 1px solid var(--line); display: flex; flex-direction: column; z-index: 10; }
.brand-logo { width: 170px; height: auto; }
.brand-caption { color: var(--muted); font-weight: 700; font-size: .76rem; letter-spacing: .08em; margin: 5px 7px 34px; text-transform: uppercase; }
.sidebar nav { display: grid; gap: 7px; }
.nav-btn { width: 100%; display: flex; align-items: center; gap: 12px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); font-weight: 700; text-align: left; padding: 12px 14px; }
.sidebar a.nav-btn, .top-actions a.btn { text-decoration: none; }
.nav-btn span { width: 22px; font-size: 1.25rem; }
.nav-btn:hover, .nav-btn.active { background: var(--soft-blue); color: var(--blue); }
.sidebar-bottom { margin-top: auto; display: grid; gap: 5px; }

.workspace { min-width: 0; padding: 0 34px 50px; }
.topbar { position: sticky; top: 0; z-index: 5; min-height: 118px; display: flex; align-items: center; justify-content: space-between; gap: 20px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(12px); }
.top-actions { display: flex; gap: 10px; }
.view { display: none; animation: fade .18s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: .3; transform: translateY(3px); } }

.btn { border: 1px solid var(--line); border-radius: 10px; padding: 10px 15px; background: white; color: var(--ink); font-weight: 800; box-shadow: 0 3px 10px rgba(15, 48, 68, .04); }
.btn.primary { border-color: var(--blue); background: var(--blue); color: white; }
.btn.primary:hover { background: #0f5e9d; }
.btn.ghost:hover { border-color: var(--blue); color: var(--blue); }
.btn.small { padding: 7px 11px; font-size: .82rem; }
.btn.wide { width: 100%; margin-top: 8px; }
.text-btn { border: 0; background: transparent; color: var(--blue); font-weight: 800; }
.danger { color: var(--danger) !important; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: white; border: 1px solid var(--line); border-radius: 16px; padding: 20px; box-shadow: 0 5px 18px rgba(20, 62, 88, .04); }
.stat-card .label { color: var(--muted); font-size: .8rem; font-weight: 700; }
.stat-card strong { display: block; margin-top: 7px; font-size: 1.8rem; color: var(--blue-dark); }
.stat-card.alert { background: #fff9f6; border-color: #edd8cd; }
.stat-card.alert strong { color: #b65c3d; }

.panel { overflow: hidden; background: white; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 5px 18px rgba(20, 62, 88, .04); }
.panel-head { padding: 18px 20px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 15px; }
.search { width: min(520px, 100%); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 12px 15px; color: var(--muted); background: #f9fbfc; text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
td { padding: 13px 15px; border-top: 1px solid var(--line); vertical-align: middle; font-size: .86rem; }
td strong { color: var(--blue-dark); }
.right { text-align: right; }
.row-actions { white-space: nowrap; }
.row-actions button { border: 0; background: transparent; color: var(--blue); font-weight: 700; padding: 4px 7px; }
.empty { padding: 45px 25px; text-align: center; color: var(--muted); }
.stock-low { color: #b65c3d; font-weight: 800; }
.profit-positive { color: var(--green); font-weight: 800; }
.badge { display: inline-block; border-radius: 999px; padding: 5px 9px; font-size: .7rem; font-weight: 800; background: var(--soft-blue); color: var(--blue); }
.badge.confirmed { background: #fff5dc; color: #8a6500; }
.badge.delivered { background: var(--soft-green); color: #1d7b22; }
.badge.cancelled { background: #fff0ee; color: var(--danger); }

.filter-pills { display: flex; gap: 7px; overflow-x: auto; }
.pill { border: 1px solid var(--line); border-radius: 999px; background: white; padding: 8px 12px; color: var(--muted); font-weight: 700; }
.pill.active { border-color: var(--blue); color: var(--blue); background: var(--soft-blue); }

label { display: grid; gap: 6px; color: var(--blue-dark); font-size: .78rem; font-weight: 800; }
input, select, textarea { width: 100%; border: 1px solid #cbdbe2; border-radius: 9px; background: white; color: var(--ink); padding: 10px 11px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23, 109, 179, .11); }
textarea { resize: vertical; }
.stack { display: grid; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.span-2 { grid-column: span 2; }

.modal { width: min(720px, calc(100% - 28px)); max-height: calc(100vh - 34px); overflow: auto; border: 1px solid var(--line); border-radius: 18px; padding: 0; box-shadow: 0 22px 70px rgba(12, 42, 59, .25); }
.modal::backdrop { background: rgba(12, 34, 47, .48); backdrop-filter: blur(3px); }
.modal form, .modal > div { padding: 24px; }
.modal.compact { width: min(480px, calc(100% - 28px)); }
.order-modal { width: min(970px, calc(100% - 28px)); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 1.6rem; line-height: 1; padding: 4px 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

.line-head { display: flex; align-items: center; justify-content: space-between; margin: 22px 0 9px; }
.order-lines { display: grid; gap: 8px; }
.order-line { display: grid; grid-template-columns: minmax(220px, 2fr) 90px 120px 115px 34px; gap: 8px; align-items: center; border-radius: 10px; padding: 8px; background: #f7fafb; border: 1px solid var(--line); }
.line-total { text-align: right; font-weight: 800; color: var(--blue-dark); }
.order-summary { margin: 14px 0 20px auto; width: min(420px, 100%); display: grid; gap: 6px; }
.order-summary > div { display: flex; justify-content: space-between; padding: 7px 10px; }
.order-summary .profit { background: var(--soft-green); border-radius: 9px; color: #1d7b22; }
.order-detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 15px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0; }
.detail-box { border: 1px solid var(--line); background: #f9fbfc; border-radius: 10px; padding: 13px; }

.toast { position: fixed; z-index: 100; top: 18px; left: 50%; transform: translate(-50%, -130%); min-width: 260px; max-width: calc(100% - 30px); padding: 12px 16px; border-radius: 10px; background: var(--blue-dark); color: white; box-shadow: var(--shadow); transition: transform .22s ease; text-align: center; font-weight: 700; }
.toast.show { transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }
.mobile-nav { display: none; }

@media (max-width: 950px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .workspace { padding: 0 18px 92px; }
  .topbar { min-height: 100px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mobile-nav { position: fixed; z-index: 20; bottom: 0; left: 0; right: 0; display: grid; grid-template-columns: repeat(4, 1fr); background: rgba(255,255,255,.96); border-top: 1px solid var(--line); padding: 7px max(8px, env(safe-area-inset-right)) calc(7px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); box-shadow: 0 -8px 24px rgba(20,62,88,.08); }
  .mobile-nav button { display: grid; place-items: center; gap: 2px; border: 0; background: transparent; color: var(--muted); font-size: 1.2rem; }
  .mobile-nav button.active { color: var(--blue); }
  .mobile-nav small { font-size: .64rem; font-weight: 700; }
}

@media (max-width: 660px) {
  .topbar { align-items: flex-start; padding: 20px 0 14px; min-height: 112px; }
  .top-actions { display: none; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar .btn { width: 100%; }
  .stat-grid { gap: 10px; }
  .stat-card { padding: 15px; }
  .stat-card strong { font-size: 1.45rem; }
  .form-grid, .detail-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .modal form, .modal > div { padding: 18px; }
  .order-line { grid-template-columns: 1fr 72px 92px 32px; }
  .order-line .line-product { grid-column: span 4; }
  .line-total { display: none; }
  th:nth-child(n+4), td:nth-child(n+4) { display: none; }
  .row-actions { display: table-cell !important; }
}
