:root {
  --brand-plum: #5f4a78;
  --brand-plum-dark: #3f2f55;
  --brand-wine: #8e3f4a;
  --brand-coral: #f04b2c;
  --charcoal: #191715;
  --ink: #24211f;
  --stone: #f4f1ec;
  --stone-2: #ebe6dd;
  --warm-grey: #a9a59c;
  --wood: #c8a77d;
  --line: #e4ddd3;
  --white: #fffdfa;
  --success: #2f7d59;
  --warning: #ad761d;
  --danger: #b83c36;
  --info: #466c8f;
  --shadow: 0 18px 45px rgba(25, 23, 21, .10);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--stone); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(95, 74, 120, .06), rgba(240, 75, 44, .035) 40%, transparent 70%),
    var(--stone);
  font-size: 14px;
  line-height: 1.45;
}

a { color: inherit; }

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px 18px;
  color: #f7f1e8;
  background:
    linear-gradient(180deg, rgba(95, 74, 120, .30), transparent 36%),
    var(--charcoal);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  color: #fff;
  background: linear-gradient(135deg, var(--brand-plum), var(--brand-wine));
  font-weight: 900;
  letter-spacing: 0;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}

.brand-mark span {
  position: absolute;
  top: -8px;
  left: 6px;
  color: rgba(255,255,255,.32);
  font-size: 26px;
}

.brand-copy { display: grid; gap: 1px; }
.brand-copy strong { font-size: 17px; letter-spacing: 0; }
.brand-copy small { color: rgba(255,255,255,.68); font-size: 12px; }

.side-nav {
  display: grid;
  gap: 4px;
  overflow: auto;
  padding-right: 4px;
}

.side-nav a,
.logout-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 10px 12px;
  border-radius: 8px;
  color: rgba(255,255,255,.74);
  text-decoration: none;
  transition: background .15s ease, color .15s ease, transform .15s ease;
}

.side-nav a:hover,
.logout-link:hover {
  color: #fff;
  background: rgba(255,255,255,.07);
}

.side-nav a.active {
  color: #fff;
  background: linear-gradient(135deg, var(--brand-plum), rgba(142, 63, 74, .85));
  box-shadow: 0 10px 22px rgba(0,0,0,.22);
}

.side-nav svg,
.logout-link svg,
.btn svg,
.mini-btn svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.sidebar-foot {
  margin-top: auto;
  display: grid;
  gap: 12px;
}

.user-chip {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 8px;
  background: rgba(255,255,255,.04);
}

.user-chip > span {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(200, 167, 125, .20);
  color: #fff;
  font-weight: 800;
}

.user-chip strong,
.user-chip small { display: block; }
.user-chip small { color: rgba(255,255,255,.62); font-size: 11px; }

.main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.topbar h1,
.login-panel h1,
.login-card h2,
.panel h2,
.sale-hero h2,
.install-card h1 {
  margin: 0;
  letter-spacing: 0;
  line-height: 1.12;
  color: var(--ink);
}

.topbar h1 { font-size: 28px; }
.eyebrow {
  margin: 0 0 5px;
  color: var(--brand-plum);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.top-actions,
.panel-head,
.line-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.btn,
.mini-btn {
  border: 0;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 10px 14px;
  color: var(--ink);
  background: var(--white);
  text-decoration: none;
  cursor: pointer;
  font-weight: 750;
  box-shadow: inset 0 0 0 1px rgba(36, 33, 31, .10);
}

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--brand-plum), var(--brand-wine));
  box-shadow: 0 10px 20px rgba(95, 74, 120, .18);
}

.btn-secondary { background: var(--white); }
.btn-danger { color: #fff; background: var(--danger); }
.btn-full { width: 100%; }

.mini-btn {
  min-height: 28px;
  padding: 6px 8px;
  margin: 2px;
  font-size: 12px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric,
.panel,
.workflow-band,
.sale-hero,
.three-status,
.login-card,
.login-panel {
  border: 1px solid rgba(36, 33, 31, .10);
  border-radius: 8px;
  background: rgba(255, 253, 250, .88);
  box-shadow: var(--shadow);
}

.metric {
  display: flex;
  gap: 12px;
  align-items: center;
  min-height: 90px;
  padding: 16px;
}

.metric-icon {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #fff;
}

.metric-icon.plum { background: var(--brand-plum); }
.metric-icon.wine { background: var(--brand-wine); }
.metric-icon.coral { background: var(--brand-coral); }
.metric-icon.wood { background: #9a7142; }

.metric small,
.three-status small,
.sale-amount small,
.invoice-parties small,
.bar-row small {
  color: #776f66;
  display: block;
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 3px;
  font-size: 23px;
  line-height: 1;
}

.workflow-band {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  overflow: hidden;
  margin-bottom: 18px;
}

.workflow-band div {
  min-height: 120px;
  padding: 18px;
  border-right: 1px solid var(--line);
}

.workflow-band div:last-child { border-right: 0; }
.workflow-band span {
  color: var(--brand-coral);
  font-weight: 900;
}
.workflow-band strong {
  display: block;
  margin: 5px 0;
  font-size: 17px;
}
.workflow-band small { color: #675f56; }

.two-col,
.split-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.split-layout { grid-template-columns: 380px minmax(0, 1fr); align-items: start; }

.panel {
  min-width: 0;
  padding: 18px;
  margin-bottom: 18px;
}

.panel-head {
  margin-bottom: 14px;
}

.panel h2 {
  font-size: 18px;
}

.text-link,
.strong-link {
  color: var(--brand-plum);
  font-weight: 800;
  text-decoration: none;
}

.text-link:hover,
.strong-link:hover { text-decoration: underline; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.sale-detail-grid {
  grid-template-columns: minmax(0, 1fr);
}

.sale-detail-grid table {
  min-width: 620px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
  background: #fff;
}

th,
td {
  padding: 12px 13px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: #675f56;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .07em;
  background: #f9f6f1;
}

tr:last-child td { border-bottom: 0; }
td small { color: #756d64; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge-neutral { color: #5d5750; background: #eee9e1; }
.badge-success { color: #fff; background: var(--success); }
.badge-warning { color: #fff; background: var(--warning); }
.badge-danger { color: #fff; background: var(--danger); }
.badge-info { color: #fff; background: var(--info); }

.empty-state {
  display: grid;
  place-items: center;
  min-height: 130px;
  border: 1px dashed #d2c8ba;
  border-radius: 8px;
  color: #756d64;
  background: #faf7f2;
  text-align: center;
}

.compact-empty {
  min-height: 84px;
  padding: 14px;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.stack-form { display: grid; gap: 12px; }
.span-2 { grid-column: span 2; }

label {
  display: grid;
  gap: 6px;
  color: #5c554e;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid #d7cec2;
  border-radius: 8px;
  padding: 10px 11px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

textarea { resize: vertical; }

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand-plum);
  box-shadow: 0 0 0 3px rgba(95, 74, 120, .12);
}

.inline-form {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.inline-form select {
  min-height: 32px;
  padding: 6px 8px;
}

.sale-form {
  display: grid;
  gap: 18px;
}

.wide-form { max-width: 1200px; }

.line-editor {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbf8f3;
}

.line-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) minmax(180px, 1fr) 90px 130px;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid #eee6dc;
}

.sale-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  margin-bottom: 14px;
  background:
    linear-gradient(135deg, rgba(95,74,120,.10), rgba(200,167,125,.10)),
    rgba(255,253,250,.92);
}

.sale-hero h2 { font-size: 26px; margin-bottom: 6px; }
.sale-hero p { margin: 0; color: #675f56; }

.sale-amount {
  min-width: 190px;
  display: grid;
  justify-items: end;
  gap: 6px;
}

.sale-amount strong { font-size: 27px; }

.three-status {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  overflow: hidden;
  margin-bottom: 18px;
}

.three-status div {
  display: grid;
  gap: 6px;
  padding: 14px 16px;
  border-right: 1px solid var(--line);
}

.three-status div:last-child { border-right: 0; }

.totals,
.invoice-total {
  display: grid;
  justify-content: end;
  gap: 6px;
  margin-top: 14px;
}

.totals span,
.invoice-total span {
  min-width: 260px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
}

.action-panel form {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.action-panel form:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: 0;
}

.delivery-summary {
  display: grid;
  gap: 5px;
  margin-bottom: 12px;
  padding: 12px;
  border-radius: 8px;
  background: #fbf8f3;
}

.bar-list {
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) 2fr minmax(100px, auto);
  align-items: center;
  gap: 12px;
}

.bar-row span {
  height: 12px;
  border-radius: 999px;
  background: #eee8df;
  overflow: hidden;
}

.bar-row i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand-plum), var(--brand-coral));
}

.flash {
  margin-bottom: 14px;
  border-radius: 8px;
  padding: 11px 13px;
  border: 1px solid transparent;
  font-weight: 750;
}

.flash-success { color: #155a3a; background: #e8f5ee; border-color: #cbe8d8; }
.flash-error { color: #872b28; background: #fae7e4; border-color: #efc8c2; }

.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(25,23,21,.88), rgba(63,47,85,.84)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cg fill='none' stroke='%23c8a77d' stroke-opacity='.18'%3E%3Cpath d='M0 90h180M90 0v180'/%3E%3C/g%3E%3C/svg%3E");
}

.login-shell {
  width: min(1040px, 100%);
  display: grid;
  grid-template-columns: 1.15fr .85fr;
  gap: 18px;
}

.login-panel {
  min-height: 520px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 30px;
  color: #fff;
  background:
    linear-gradient(160deg, rgba(95, 74, 120, .82), rgba(25,23,21,.88)),
    var(--charcoal);
}

.login-panel h1 {
  max-width: 650px;
  color: #fff;
  font-size: 42px;
}

.login-panel p {
  max-width: 600px;
  color: rgba(255,255,255,.75);
  font-size: 16px;
}

.login-signal {
  display: flex;
  gap: 12px;
  align-items: center;
  max-width: 420px;
  padding: 14px;
  border-radius: 8px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
}

.login-signal span {
  width: 10px;
  height: 42px;
  border-radius: 999px;
  background: var(--brand-coral);
}

.login-signal small { color: rgba(255,255,255,.66); }

.login-card {
  align-self: center;
  padding: 28px;
  background: rgba(255,253,250,.96);
}

.login-card h2 { margin-bottom: 18px; font-size: 26px; }
.login-card label { margin-bottom: 13px; }
.login-brand { margin-bottom: 42px; }
.login-brand .brand-copy small { color: rgba(255,255,255,.7); }
.login-card .brand-copy small { color: #756d64; }

.install-shell { width: min(520px, 100%); }
.install-card { display: grid; gap: 14px; }
.install-card .brand { margin-bottom: 8px; }

.invoice-body {
  background: #d8d1c6;
  padding: 30px;
}

.invoice-sheet {
  position: relative;
  width: min(900px, 100%);
  margin: 0 auto;
  padding: 40px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 20px 55px rgba(0,0,0,.16);
  overflow: hidden;
}

.invoice-header,
.invoice-parties {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}

.invoice-header h1 {
  margin: 0;
  font-size: 34px;
}

.invoice-parties {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbf8f3;
}

.invoice-total {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.invoice-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-top: 28px;
}

.draft-watermark {
  position: absolute;
  inset: 38% auto auto 22%;
  transform: rotate(-24deg);
  color: rgba(184, 60, 54, .12);
  font-size: 92px;
  font-weight: 900;
  pointer-events: none;
}

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 88px minmax(0, 1fr); }
  .sidebar { padding: 18px 12px; }
  .brand-copy,
  .side-nav span,
  .logout-link { display: none; }
  .side-nav a { justify-content: center; }
  .user-chip { justify-content: center; }
  .user-chip div { display: none; }
  .metric-grid,
  .workflow-band { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col,
  .split-layout { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .app-shell { display: block; }
  .sidebar {
    position: relative;
    height: auto;
    min-height: auto;
  }
  .brand-copy,
  .side-nav span,
  .logout-link { display: initial; }
  .side-nav a { justify-content: flex-start; }
  .main { padding: 18px; }
  .topbar,
  .panel-head,
  .sale-hero,
  .invoice-header,
  .invoice-parties,
  .invoice-footer { flex-direction: column; align-items: stretch; }
  .metric-grid,
  .workflow-band,
  .three-status,
  .grid-form,
  .login-shell { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .line-row { grid-template-columns: 1fr; }
  .login-panel { min-height: auto; }
  .login-panel h1 { font-size: 30px; }
  .invoice-body { padding: 10px; }
  .invoice-sheet { padding: 22px; }
  .bar-row { grid-template-columns: 1fr; }
  table { min-width: 560px; }
}

@media print {
  body { background: #fff; }
  .invoice-body { padding: 0; background: #fff; }
  .invoice-sheet { width: 100%; box-shadow: none; }
  .no-print { display: none; }
}
