:root {
  --ink: #0b0b0d;
  --muted: #6f737a;
  --paper: #f5f5f3;
  --panel: #ffffff;
  --line: #d7d8dc;
  --accent: #d71920;
  --accent-dark: #940f16;
  --steel: #1c2028;
  --shadow: 0 18px 45px rgba(0, 0, 0, .1);
  color-scheme: light;
  font-family: "Segoe UI", Tahoma, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(215,25,32,.06) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(0deg, rgba(0,0,0,.04) 1px, transparent 1px) 0 0 / 28px 28px,
    var(--paper);
  color: var(--ink);
}

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

button, .file-button {
  min-height: 42px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 700;
}

button:hover, .file-button:hover { border-color: var(--ink); }
.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.ghost { background: transparent; }
.hidden { display: none !important; }

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(135deg, #050506, #181b22 58%, #8f1017);
}

.auth-screen.unlocked {
  display: none;
}

.auth-card {
  width: min(430px, 100%);
  background: #fff;
  border-radius: 10px;
  padding: 26px;
  box-shadow: 0 30px 90px rgba(0,0,0,.35);
  border-top: 6px solid var(--accent);
}

.auth-card img {
  width: 190px;
  height: 105px;
  object-fit: contain;
  display: block;
  margin-bottom: 10px;
}

.auth-card h1 {
  font-size: 2rem;
  margin-bottom: 8px;
}

.auth-card p {
  color: var(--muted);
  margin-bottom: 16px;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: linear-gradient(180deg, #070708, #171a21);
  color: #fff;
  border-right: 5px solid var(--accent);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 34px;
}
.brand-lockup img, .logo-picker img {
  width: 58px;
  height: 58px;
  border-radius: 8px;
  object-fit: cover;
  background: #fff;
}
.brand-lockup strong { display: block; font-size: 1.25rem; }
.brand-lockup span { color: #bfc2c8; }

.tabs {
  display: grid;
  gap: 10px;
}
.tab {
  width: 100%;
  text-align: left;
  background: transparent;
  color: #fffdf5;
  border-color: rgba(255,255,255,.18);
}
.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tab:hover {
  border-color: rgba(255,255,255,.55);
}

.logo-picker {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.logo-picker input {
  padding: 8px;
}

main {
  padding: 26px;
  max-width: 1280px;
  width: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
  padding: 16px 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 6px solid var(--accent);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
#signedInAs {
  color: var(--muted);
  font-weight: 700;
}
h1, h2, p { margin: 0; }
h1 {
  font-size: clamp(1.65rem, 2.8vw, 2.7rem);
  line-height: 1.05;
  letter-spacing: 0;
}
h2 { font-size: 1.7rem; }
.eyebrow {
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0;
  margin-bottom: 6px;
}

.view { display: none; }
.view.active { display: block; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.stat, .job-card, .job-form {
  background: rgba(255,255,255,.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.stat {
  padding: 16px;
  min-height: 104px;
  border-top: 4px solid var(--ink);
  position: relative;
}
.stat span { color: var(--muted); font-weight: 700; }
.stat strong { display: block; font-size: 2rem; margin-top: 10px; }
.stat small {
  display: block;
  color: var(--accent);
  font-weight: 800;
  margin-top: 8px;
}
.stat-income {
  cursor: pointer;
  border-top-color: var(--accent);
}
.income-popover {
  position: absolute;
  left: 14px;
  top: calc(100% - 6px);
  z-index: 20;
  width: min(320px, calc(100vw - 44px));
  display: none;
  gap: 10px;
  background: #0b0b0d;
  color: #fff;
  border-radius: 8px;
  padding: 14px;
  box-shadow: 0 20px 50px rgba(0,0,0,.28);
}
.income-popover div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid rgba(255,255,255,.16);
  padding-bottom: 8px;
}
.income-popover div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}
.income-popover span {
  color: #d7d8dc;
}
.income-popover strong {
  margin: 0;
  font-size: 1.1rem;
}
.stat-income:hover .income-popover,
.stat-income.popover-open .income-popover {
  display: grid;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 180px auto auto;
  gap: 10px;
  margin-bottom: 14px;
}
.customer-toolbar {
  grid-template-columns: 1fr;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 11px 12px;
}
input::placeholder, textarea::placeholder {
  color: #9ca0a7;
}
textarea { resize: vertical; }
.file-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  overflow: hidden;
}
.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.jobs-list {
  display: grid;
  gap: 12px;
}
.job-card {
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(160px, .7fr) auto;
  gap: 16px;
  align-items: center;
}
.customer-card {
  grid-template-columns: minmax(0, 1.4fr) minmax(180px, .5fr);
}
.job-main strong {
  display: block;
  font-size: 1.25rem;
}
.job-main span, .job-meta span, .email-log {
  color: var(--muted);
  display: block;
  margin-top: 4px;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 5px 10px;
  font-weight: 800;
  background: #eceef2;
}
.status-Ready { background: #ffe3e5; color: #9a1118; }
.status-Delivered { background: #dde1e8; color: #171a21; }
.status-Cancelled { background: #1c2028; color: #fff; }
.job-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}
.job-actions button {
  min-height: 36px;
  padding: 7px 10px;
}

.job-form {
  padding: 22px;
}
.form-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}
fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin: 0 0 16px;
}
legend {
  padding: 0 8px;
  color: var(--accent);
  font-weight: 900;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
label {
  display: grid;
  gap: 6px;
  font-weight: 800;
}
.wide { grid-column: 1 / -1; }
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

dialog {
  width: min(920px, calc(100vw - 24px));
  border: 0;
  border-radius: 8px;
  box-shadow: 0 30px 80px rgba(0,0,0,.25);
  padding: 0;
}
.dialog-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}
#invoicePreview { padding: 24px; }
#printArea {
  display: none;
}
.invoice {
  background: #fff;
  color: #111;
  padding: 28px;
  border: 1px solid #ddd;
}
.invoice-head {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 2px solid #111;
  padding-bottom: 16px;
  margin-bottom: 18px;
}
.invoice img {
  width: 220px;
  height: 120px;
  object-fit: contain;
  background: #fff;
}
.invoice table {
  width: 100%;
  border-collapse: collapse;
  margin: 18px 0;
}
.invoice th, .invoice td {
  border: 1px solid #d5d5d5;
  padding: 10px;
  text-align: left;
  vertical-align: top;
}
.terms {
  white-space: pre-line;
  font-size: .9rem;
  line-height: 1.45;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(30px);
  opacity: 0;
  background: var(--ink);
  color: #fff;
  border-radius: 999px;
  padding: 12px 16px;
  transition: .2s ease;
  z-index: 10;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 880px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
  }
  .brand-lockup { margin-bottom: 12px; }
  .tabs { grid-template-columns: repeat(4, 1fr); }
  .tab { text-align: center; padding-inline: 8px; }
  main { padding: 16px; }
  .topbar { align-items: flex-start; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .job-card { grid-template-columns: 1fr; }
  .job-actions { justify-content: flex-start; }
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  h1 { font-size: 2.25rem; }
  .topbar { flex-direction: column; }
  .top-actions { width: 100%; justify-content: stretch; }
  .top-actions button { flex: 1; }
  .topbar .primary { width: 100%; }
  .stats-grid, .toolbar { grid-template-columns: 1fr; }
  .tabs { gap: 6px; }
  .tab { font-size: .82rem; padding-inline: 4px; }
}

@media print {
  @page { margin: 8mm; }
  html, body {
    width: 100%;
    min-height: auto;
    margin: 0;
    padding: 0;
    background: #fff;
  }
  body > *:not(#printArea) { display: none !important; }
  #printArea {
    display: block !important;
    width: 100%;
    margin: 0;
    padding: 0;
  }
  dialog { display: none !important; }
  .dialog-bar { display: none !important; }
  .invoice {
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .invoice table { margin: 10px 0; }
  .invoice th, .invoice td { padding: 6px; }
  .invoice h2, .invoice h3, .invoice p { margin-top: 0; }
  .terms { font-size: .78rem; line-height: 1.25; }
}
