:root {
  --primary: #172033;
  --primary-2: #27344f;
  --accent: #4b66ff;
  --bg: #f3f5f8;
  --panel: #ffffff;
  --text: #1d2433;
  --muted: #697386;
  --border: #dde2ea;
  --green: #198754;
  --green-bg: #eaf7ef;
  --red: #c53b49;
  --red-bg: #fdeef0;
  --amber: #9a6700;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, "Segoe UI", Arial, sans-serif; color: var(--text); background: var(--bg); }
body:not(.authenticated) .app-shell { display: none; }
body.workspace-blocked .app-shell { display: none; }
[hidden] { display: none !important; }
.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.workspace-error { min-height: 100vh; place-items: center; padding: 20px; }
.workspace-error:not([hidden]) { display: grid; }
.backend-error { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 220px; overflow: auto; margin: 0; padding: 12px; border-radius: 8px; background: var(--red-bg); color: var(--red); font: 12px/1.5 Consolas, monospace; }
.auth-card { width: min(100%, 390px); display: grid; gap: 14px; background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: 0 16px 42px rgba(23,32,51,.08); }
.auth-card .brand-mark { margin-bottom: 4px; }
.auth-card h1 { margin: -8px 0 0; font-size: 24px; }
.auth-card label, .customer-form label { display: flex; flex-direction: column; gap: 7px; color: #4d5769; font-size: 13px; font-weight: 650; }
.auth-card .button { width: 100%; }
.muted { color: var(--muted); line-height: 1.5; margin: 0; }
.app-feedback { position: fixed; right: 20px; top: 96px; z-index: 60; max-width: min(420px, calc(100vw - 40px)); padding: 12px 16px; border-radius: 9px; color: #fff; background: var(--primary); box-shadow: 0 8px 24px rgba(23,32,51,.2); opacity: 0; pointer-events: none; transform: translateY(-8px); transition: opacity .16s, transform .16s; }
.app-feedback.visible { opacity: 1; transform: translateY(0); }
.app-feedback.error { background: var(--red); }
.loading-overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(243,245,248,.72); }
.loading-card { display: flex; align-items: center; gap: 12px; padding: 16px 20px; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 12px 30px rgba(23,32,51,.12); }
.spinner { width: 18px; height: 18px; border: 2px solid #d7dce5; border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.admin-session { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.customer-form { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 12px; margin-bottom: 20px; }
button, input, select, textarea { font: inherit; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px 1fr; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 248px; background: #fff; border-right: 1px solid var(--border); padding: 24px 14px; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 22px; }
.brand-mark { width: 42px; height: 42px; border-radius: 10px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 22px; }
.brand strong, .brand span { display: block; }
.brand strong { letter-spacing: 1.5px; }
.brand span { color: var(--muted); font-size: 12px; margin-top: 2px; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item { border: 0; border-radius: 8px; background: transparent; color: #4d5769; text-align: left; padding: 11px 12px; cursor: pointer; font-weight: 600; }
.nav-item:hover { background: #f5f7fb; color: var(--primary); }
.nav-item.active { background: var(--primary); color: #fff; }
.main { grid-column: 2; min-width: 0; }
.topbar { height: 82px; background: #fff; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 14px; padding: 0 32px; position: sticky; top: 0; z-index: 10; }
.topbar h1 { margin: 2px 0 0; font-size: 24px; }
.eyebrow { margin: 0; color: var(--muted); letter-spacing: 1.5px; font-size: 11px; }
.topbar-date { margin-left: auto; color: var(--muted); font-size: 14px; }
.menu-button { display: none; border: 0; background: transparent; font-size: 22px; }
.content { padding: 28px 32px 48px; }
.view { display: none; }
.view.active { display: block; }
.cards-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px; min-width: 0; }
.card-label { color: var(--muted); font-size: 13px; }
.card-value { display: block; font-size: 25px; font-weight: 750; margin-top: 8px; }
.card-detail { color: var(--muted); font-size: 12px; margin-top: 7px; }
.grid-two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-bottom: 16px; min-width: 0; }
.panel h2 { margin: 0 0 18px; font-size: 17px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; }
.badge { background: #edf1f7; color: var(--primary); border-radius: 20px; padding: 6px 10px; font-size: 12px; font-weight: 700; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid label, .invoice-layout label { display: flex; flex-direction: column; gap: 7px; color: #4d5769; font-size: 13px; font-weight: 650; }
.form-grid .wide { grid-column: 1 / -1; }
input, select, textarea { width: 100%; border: 1px solid #ccd4e0; border-radius: 8px; background: #fff; color: var(--text); padding: 10px 11px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(75, 102, 255, .11); }
input[readonly] { background: #f4f6f9; }
.checkbox-label { flex-direction: row !important; align-items: center; }
.checkbox-label input { width: 16px; }
.button-row { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.button { border: 0; border-radius: 8px; padding: 10px 14px; cursor: pointer; font-weight: 700; }
.button.primary { background: var(--primary); color: #fff; }
.button.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.button.danger { background: var(--red-bg); color: var(--red); }
.button.small { padding: 6px 8px; font-size: 12px; }
.breakdown-row { display: flex; justify-content: space-between; border-bottom: 1px solid #edf0f4; padding: 11px 0; font-size: 14px; }
.breakdown-row.total { border: 0; font-weight: 800; }
.summary-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 9px 0; border-bottom: 1px solid #edf0f4; }
.summary-row span { color: var(--muted); }
.summary-row strong { text-align: right; }
.status { border-radius: 9px; padding: 13px; font-weight: 750; }
.status.good { background: var(--green-bg); color: var(--green); }
.status.bad { background: var(--red-bg); color: var(--red); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; border-bottom: 1px solid #edf0f4; padding: 11px 8px; }
th { color: var(--muted); font-size: 12px; }
.history-heading { gap: 16px; }
.history-actions { display: flex; gap: 8px; }
.history-actions input { width: 220px; }
.validation-message { min-height: 20px; color: var(--red); font-weight: 650; }
.invoice-toolbar { display: flex; gap: 8px; margin-bottom: 16px; }
.invoice-layout { max-width: none; }
.invoice-page { display: none; max-width: 850px; margin: 18px auto 0; background: #fff; border: 1px solid var(--border); padding: 42px; }
.invoice-page.generated { display: block; }
.invoice-header { display: flex; justify-content: space-between; border-bottom: 2px solid var(--primary); padding-bottom: 18px; }
.invoice-header h2 { margin: 0; letter-spacing: 2px; }
.invoice-header p { margin: 5px 0 0; color: var(--muted); }
.invoice-meta { text-align: right; }
.invoice-customer { margin: 24px 0; }
.invoice-customer p { margin: 5px 0; }
.invoice-table { margin-top: 20px; }
.invoice-colours { margin-top: 20px; }
.invoice-totals { width: 280px; margin: 24px 0 0 auto; }
.invoice-totals .summary-row { border: 0; }
.invoice-totals .summary-row:last-child { border-top: 2px solid var(--primary); padding-top: 12px; font-size: 18px; }
.invoice-notes { margin-top: 28px; color: var(--muted); font-size: 13px; }
.colour-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.allocation-bar { height: 8px; border-radius: 99px; background: #e9edf4; overflow: hidden; margin: 12px 0; }
.allocation-bar span { height: 100%; display: block; background: var(--accent); }
.warning { background: var(--red-bg); color: var(--red); border-radius: 8px; padding: 10px; margin-top: 12px; }
.ok { background: var(--green-bg); color: var(--green); border-radius: 8px; padding: 10px; margin-top: 12px; }
@media (max-width: 1050px) {
  .cards-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { transform: translateX(-100%); transition: transform .2s; box-shadow: 6px 0 20px rgba(23,32,51,.12); }
  .sidebar.open { transform: translateX(0); }
  .main { margin: 0; }
  .menu-button { display: block; }
  .topbar { height: 70px; padding: 0 16px; }
  .topbar-date { display: none; }
  .admin-session { margin-left: auto; }
  .admin-session span { display: none; }
  .content { padding: 18px 14px 36px; }
  .cards-grid, .grid-two, .form-grid, .colour-grid { grid-template-columns: 1fr; }
  .history-heading { align-items: flex-start; flex-direction: column; }
  .history-actions { width: 100%; }
  .customer-form { grid-template-columns: 1fr; }
  .history-actions input { width: 100%; }
  .invoice-page { padding: 22px 16px; }
  .invoice-header { gap: 12px; }
  .invoice-totals { width: 100%; }
  .invoice-toolbar { flex-wrap: wrap; }
}
@media print {
  body { background: #fff; }
  .sidebar, .topbar, .no-print, .view:not(#invoiceView) { display: none !important; }
  .app-shell, .main, .content, #invoiceView { display: block; }
  .invoice-page { display: block !important; margin: 0; max-width: none; border: 0; padding: 20px; }
  .invoice-page.generated { display: block; }
}
