:root {
  --paper: #f6f2ea;
  --paper-deep: #ece5d8;
  --sheet: #fffdf9;
  --ink: #17140f;
  --ink-soft: #5d554a;
  --line: #e2d9c8;
  --gold: #b8902f;
  --gold-deep: #8f6d1d;
  --gold-glow: rgba(184, 144, 47, 0.18);
  --night: #15130f;
  --ok: #2f6b3f;
  --err: #a3321f;

  --font-display: "Fraunces", Georgia, serif;
  --font-ui: "Manrope", system-ui, sans-serif;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-xl: clamp(1.5rem, 1.2rem + 1vw, 2rem);

  --radius-sm: 6px;
  --radius-lg: 14px;
  --shadow-sheet: 0 1px 0 rgba(0, 0, 0, 0.04), 0 18px 40px -18px rgba(60, 40, 10, 0.35);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --fast: 150ms;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 500px at 85% -10%, var(--gold-glow), transparent 60%),
    var(--paper);
  color: var(--ink);
  font: 400 var(--text-base)/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-soft); font-size: var(--text-sm); }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px clamp(16px, 4vw, 40px);
  background: var(--night); color: #f3ead6;
  border-bottom: 2px solid var(--gold);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { border-radius: 8px; object-fit: cover; }
.brand-name { display: block; font: 650 1.125rem/1.1 var(--font-display); letter-spacing: 0.01em; }
.brand-sub { display: block; font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: #c9b88f; }
.link-btn { background: none; border: 0; color: #e8dcc0; font: 600 var(--text-sm) var(--font-ui); cursor: pointer; padding: 6px 8px; border-radius: var(--radius-sm); }
.link-btn:hover { color: #fff; }
.link-btn:focus-visible, .btn:focus-visible, input:focus-visible, .job:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font: 700 var(--text-base) var(--font-ui); cursor: pointer; text-decoration: none;
  transition: transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease), background var(--fast);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn-gold { background: linear-gradient(180deg, #c9a13d, var(--gold)); color: #1a1408; box-shadow: 0 6px 18px -8px var(--gold-deep); }
.btn-gold:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 10px 24px -10px var(--gold-deep); }
.btn-ink { background: var(--ink); color: #fff; }
.btn-ink:hover:not(:disabled) { background: #000; transform: translateY(-1px); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); width: 100%; margin-top: 10px; }
.btn-ghost:hover { border-color: var(--gold); }

/* Login */
.login { display: grid; place-items: center; min-height: calc(100vh - 70px); padding: 24px; }
.login-card {
  width: min(380px, 100%); padding: 32px; background: var(--sheet);
  border: 1px solid var(--line); border-top: 4px solid var(--gold);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sheet);
  display: grid; gap: 10px;
}
.login-card h1 { margin: 0; font: 650 var(--text-xl) var(--font-display); }
.login-card p { margin: 0 0 8px; color: var(--ink-soft); }
.login-card label { font-weight: 600; font-size: var(--text-sm); }
input[type="password"], input[type="search"] {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; font: inherit; color: inherit;
}
.form-error { color: var(--err); min-height: 1.2em; margin: 0; font-size: var(--text-sm); }

/* Workspace */
.workspace {
  display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: clamp(16px, 3vw, 36px);
  padding: clamp(16px, 3vw, 32px) clamp(16px, 4vw, 40px); max-width: 1320px; margin: 0 auto;
}
.jobs-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.jobs-head h1 { margin: 0; font: 650 var(--text-xl) var(--font-display); }
.count { font-size: var(--text-sm); color: var(--ink-soft); }
.search { display: block; margin-bottom: 12px; }

.job-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: calc(100vh - 250px); overflow: auto; padding-right: 4px; }
.job {
  width: 100%; text-align: left; display: grid; grid-template-columns: auto 1fr; gap: 2px 12px;
  padding: 12px 14px; background: rgba(255, 253, 249, 0.6); border: 1px solid transparent;
  border-radius: 10px; cursor: pointer; font: inherit; color: inherit;
  transition: background var(--fast), border-color var(--fast), transform var(--fast) var(--ease);
}
.job:hover { background: var(--sheet); border-color: var(--line); }
.job[aria-current="true"] { background: var(--sheet); border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-glow); }
.job-num { grid-row: span 3; align-self: start; font: 650 1.125rem/1 var(--font-display); color: var(--gold-deep); min-width: 2.2ch; padding-top: 2px; }
.job-customer { font-weight: 700; }
.job-meta { font-size: var(--text-sm); color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { justify-self: start; margin-top: 4px; padding: 2px 8px; border-radius: 999px; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; background: var(--paper-deep); color: var(--ink-soft); }
.pill[data-status="in progress"] { background: #f3e6c4; color: #6e5313; }
.pill[data-status="scheduled"] { background: #dfe9f3; color: #234a6e; }
.pill[data-status="complete rated"], .pill[data-status="complete unrated"] { background: #dcebdc; color: var(--ok); }

/* Detail */
.empty { text-align: center; padding: clamp(40px, 10vh, 120px) 24px; color: var(--ink-soft); border: 1.5px dashed var(--line); border-radius: var(--radius-lg); }
.empty h2 { font: 650 1.5rem var(--font-display); color: var(--ink); margin: 14px 0 6px; }
.empty p { max-width: 380px; margin: 0 auto; }
.empty-mark { display: inline-grid; place-items: center; width: 64px; height: 64px; border-radius: 50%; border: 2px solid var(--gold); color: var(--gold-deep); font: 650 1.25rem var(--font-display); }

.sheet {
  position: relative; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sheet); padding: clamp(20px, 3vw, 36px);
  animation: rise 360ms var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.sheet-top { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; justify-content: space-between; border-bottom: 1px solid var(--line); padding-bottom: 18px; margin-bottom: 20px; }
.back { display: none; }
.eyebrow { font-size: 0.72rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold-deep); font-weight: 700; }
.sheet h2 { margin: 2px 0 4px; font: 650 clamp(1.6rem, 1.2rem + 1.4vw, 2.4rem)/1.1 var(--font-display); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-bottom: 24px; }
.field-label { font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-soft); font-weight: 700; margin-bottom: 4px; }
.field-value { white-space: pre-line; }
.section-title { font: 650 1.05rem var(--font-display); margin: 0 0 10px; display: flex; align-items: center; gap: 10px; }
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.items { list-style: none; margin: 0 0 24px; padding: 0; counter-reset: item; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.item-name { font-weight: 700; }
.item-name::before { counter-increment: item; content: counter(item) ". "; color: var(--gold-deep); }
.item-desc { grid-column: 1; color: var(--ink-soft); font-size: var(--text-sm); white-space: pre-line; }
.item-qty { grid-row: 1; grid-column: 2; font-variant-numeric: tabular-nums; font-weight: 600; }
.item-qty::before { content: "Qty "; color: var(--ink-soft); font-weight: 500; font-size: var(--text-sm); }
.notes { margin: 0 0 8px; padding-left: 18px; }
.guarantee { display: flex; align-items: center; gap: 8px; margin-top: 18px; font-size: var(--text-sm); color: var(--ok); font-weight: 600; }
.toast { margin-top: 12px; font-size: var(--text-sm); }
.toast[data-tone="error"] { color: var(--err); }

.skeleton { height: 64px; border-radius: 10px; background: linear-gradient(90deg, var(--paper-deep), #f3eee4, var(--paper-deep)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; }
  .job-list { max-height: none; }
  .workspace[data-view="detail"] .jobs { display: none; }
  .workspace[data-view="list"] .detail { display: none; }
  .back { display: inline-flex; margin-bottom: 12px; padding: 0; background: none; border: 0; color: var(--gold-deep); font: 700 var(--text-sm) var(--font-ui); cursor: pointer; }
  .grid3 { grid-template-columns: 1fr; gap: 12px; }
  .actions, .actions .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
