:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--portal-text);
  background: var(--portal-page);
  --portal-page: light-dark(var(--brand-page), #141d30);
  --portal-surface: light-dark(#fff, #1c2840);
  --portal-text: light-dark(var(--brand-ink), #f0f4ff);
  --portal-muted: light-dark(var(--brand-muted), #c2cde2);
  --portal-border: light-dark(var(--brand-line), #364760);
  --portal-link: light-dark(var(--brand-blue), #aac4ff);
  --portal-link-hover: light-dark(var(--brand-deep), #fff);
  --portal-soft: light-dark(var(--brand-wash), #273d6a);
  --portal-focus: light-dark(var(--brand-focus), #90b5ff);
  --border: var(--portal-border);
  --muted: var(--portal-muted);
  --radius: 12px;
}

html[data-customer-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; line-height: 1.5; }
a { color: var(--portal-link); }
a:hover { color: var(--portal-link-hover); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .5; cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--portal-focus); outline-offset: 3px; }

.skip-link {
  position: fixed;
  top: .5rem;
  left: 1rem;
  z-index: 3;
  padding: .5rem 1rem;
  background: var(--portal-surface);
  transform: translateY(-150%);
}
.skip-link:focus { transform: none; }

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 238px minmax(0, 1fr);
}
.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100dvh;
  overflow: auto;
  padding: 32px 20px;
  border-right: 1px solid var(--border);
  background: linear-gradient(165deg, var(--portal-surface) 25%, var(--portal-page));
}
.brand {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  color: inherit;
  text-decoration: none;
  font-size: 18px;
  font-weight: 750;
  line-height: 1.25;
}
.brand:hover { color: var(--portal-link-hover); }
.brand-sub { display: block; color: var(--muted); font-size: 12px; font-weight: 500; }
.sidebar nav { display: grid; gap: 6px; margin-top: 42px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 650;
  text-decoration: none;
}
.nav-icon { width: 1.25rem; flex: none; text-align: center; font-size: 18px; line-height: 1; }
.nav-item:hover { background: var(--portal-page); }
.nav-item.active { background: var(--portal-soft); color: var(--portal-link); }
.workspace { min-width: 0; }
.customer-area .app-shell { height: 100dvh; min-height: 0; }
.customer-area .workspace { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; }
.customer-area main { width: 100%; max-width: none; overflow: auto; }
.customer-area main > .customer-content { max-width: 1300px; margin-inline: auto; }
.topbar {
  min-height: 72px;
  padding: 12px clamp(20px, 3vw, 40px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  background: var(--portal-surface);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 14px;
}
.topbar-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
main {
  max-width: 1380px;
  margin-inline: auto;
  padding: clamp(20px, 3vw, 40px);
}
.page-heading { margin-bottom: 24px; }
.project-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
h1, h2, h3, p { margin: 0; overflow-wrap: anywhere; }
h1 { font-size: clamp(1.65rem, 3vw, 2.125rem); line-height: 1.2; letter-spacing: -.025em; }
h2 { font-size: 1.125rem; line-height: 1.35; }
h3 { font-size: 1rem; }
.page-heading p { margin-top: 8px; white-space: pre-line; }
.muted { color: var(--muted); }
.eyebrow {
  margin-bottom: 5px;
  color: var(--portal-link);
  font-size: .75rem;
  font-weight: 750;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.panel {
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--portal-surface);
  box-shadow: 0 2px 4px #22273108;
}
.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 18px clamp(15px, 3vw, 24px);
  border-bottom: 1px solid var(--border);
}
.panel-heading > div { min-width: 0; }
.panel-body { padding: clamp(15px, 3vw, 24px); }
.panel-body > h2 { margin-bottom: 14px; }
.panel-body > p { white-space: pre-line; }
.status-badge {
  padding: 4px 9px;
  border-radius: 5px;
  background: light-dark(#edf0f5, #25334d);
  color: light-dark(#4b576b, #d2dcf0);
  font-size: .875rem;
  font-weight: 650;
}
.section-detail { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.section-detail:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.record-list { margin: 8px 0 0; padding: 0; list-style: none; }
.record-list > li { padding: 10px 0; overflow-wrap: anywhere; }
.record-list > li + li { border-top: 1px solid var(--border); }
.record-row { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 6px 16px; }
.record-row .muted { font-size: .875rem; }
details summary { cursor: pointer; font-weight: 650; }
details[open] summary, .message { margin-bottom: 12px; }
.message { white-space: pre-wrap; }
.empty-state { padding: 36px 20px; text-align: center; color: var(--muted); }

.project-status-section { margin-bottom: 26px; }
.project-list-title, .project-status-section h2 { margin-bottom: 12px; }
[data-status] {
  --status-foreground: light-dark(var(--status-ink, var(--brand-deep)), var(--status-tint, var(--portal-text)));
  --status-background: light-dark(var(--status-tint, var(--brand-wash)),
    color-mix(in srgb, var(--status-tint, var(--portal-text)) 13%, var(--portal-surface)));
}
.project-status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(125px, 1fr));
  gap: 10px;
}
.project-status-card {
  display: grid;
  gap: 3px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-top: 3px solid var(--status-foreground);
  border-radius: 8px;
  background: linear-gradient(150deg, var(--status-background), var(--portal-surface) 70%);
  color: var(--status-foreground);
  font-size: .875rem;
  font-weight: 650;
  text-decoration: none;
}
.project-status-card strong { color: var(--portal-text); font-size: 1.4rem; }
.project-status-card:hover,
.project-status-card[aria-current="true"] {
  background: var(--status-background);
  border-color: var(--status-foreground);
  color: var(--status-foreground);
}
.status-badge[data-status] { display: inline-block; background: var(--status-background); color: var(--status-foreground); }
.project-filters { grid-template-columns: minmax(0, 2fr) repeat(2, minmax(0, 1fr)) auto; align-items: start; }
.project-filters > .errorlist { grid-column: 1 / -1; }
.project-filters .errorlist { margin-top: 6px; }
.project-filter-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding-top: 25px; }
.project-row {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  align-items: start;
  gap: 12px 24px;
  margin-bottom: 10px;
  padding: 15px 18px;
}
.project-row h3 a { color: inherit; }
.project-row p { font-size: .875rem; }
.project-facts { display: flex; flex-wrap: wrap; gap: 12px 24px; margin: 0; }
.project-row .project-facts > div { flex: 1 1 105px; }
.project-facts dt { color: var(--muted); font-size: .8125rem; font-weight: 650; }
.project-facts dd { margin: 4px 0 0; overflow-wrap: anywhere; }
.project-facts dd > span:not(.status-badge) { display: block; }
.project-pagination { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px 18px; margin-top: 18px; }
.project-back { margin-bottom: 12px; font-size: .875rem; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 7px;
  font-size: .875rem;
  font-weight: 650;
  text-align: center;
}
.button.primary { background: light-dark(var(--brand-blue), #355ed3); color: white; }
.button.primary:hover:not(:disabled) { background: light-dark(var(--brand-deep), #2548b2); }
.button.secondary { border-color: light-dark(#d7dce3, var(--border)); background: var(--portal-surface); color: light-dark(#3f4857, var(--portal-text)); }
.button.secondary:hover { background: var(--portal-page); }
[data-theme-toggle][aria-pressed="true"] { background: var(--portal-soft); color: var(--portal-text); }
.button.compact { min-height: 36px; padding: 5px 11px; }
.text-button {
  padding: 6px 0;
  border: 0;
  background: none;
  color: var(--portal-link);
  font-weight: 650;
}
.text-button:hover { text-decoration: underline; }
.inline-actions, .panel-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.form-stack { display: grid; gap: 14px; }
.form-stack > button { justify-self: start; }
.form-stack label { display: block; color: light-dark(#424b59, var(--portal-muted)); font-size: .875rem; font-weight: 650; }
.form-stack input:not([type="checkbox"], [type="radio"], [type="hidden"]),
.form-stack :is(textarea, select) {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid light-dark(#aeb7c3, #5b6b86);
  border-radius: 6px;
  background: var(--portal-surface);
  color: light-dark(#222731, var(--portal-text));
  font-size: 1rem;
  font-weight: 400;
}
.form-stack textarea { min-height: 90px; resize: vertical; }
.project-create-address, .project-create-planning { max-inline-size: 38rem; }
.project-create-locality {
  display: grid;
  grid-template-columns: minmax(0, 7.5rem) minmax(0, 1fr);
  gap: 12px;
}
.project-planning-field {
  display: grid;
  grid-template-columns: minmax(0, 11rem) minmax(0, 1fr);
  gap: 6px 12px;
  align-items: center;
}
.project-planning-field select { inline-size: auto; max-inline-size: 100%; }
.project-date-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.project-date-controls [hidden] { display: none; }
.form-stack .project-date-controls input[name="opening_date"] { inline-size: 8.5rem; max-inline-size: 100%; }
.project-date-picker { position: relative; }
.form-stack input.project-calendar-input:not(.project-calendar-input-visible) {
  position: absolute;
  inset: 0 auto auto 0;
  inline-size: 1px;
  block-size: 1px;
  min-block-size: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}
.form-stack input.project-calendar-input-visible { inline-size: auto; }
@media (max-width: 600px) {
  .project-planning-field { grid-template-columns: minmax(0, 1fr); }
}
.form-stack input[type="file"] { max-width: 100%; }
.form-stack input:is([type="checkbox"], [type="radio"]) { accent-color: var(--portal-link); }
.form-stack fieldset {
  min-width: 0;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.form-stack legend { padding: 0 4px; font-weight: 650; }
.measurement-row { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.signature-pad {
  display: block;
  width: 360px;
  max-width: 100%;
  height: auto;
  margin-bottom: 10px;
  border: 1px solid #aeb7c3;
  background: white;
  touch-action: none;
}
.errorlist {
  margin: 0;
  padding: 9px 12px 9px 30px;
  border-radius: 6px;
  background: light-dark(#fff0f0, #48262a);
  color: light-dark(#921823, #ffa9af);
}
.helptext { display: block; color: var(--muted); font-size: .875rem; }

.auth-layout .app-shell { display: block; }
.auth-layout :is(.sidebar, .topbar) { display: none; }
.auth-layout main { display: grid; place-items: center; min-height: 100dvh; }
.login-card {
  width: min(100%, 420px);
  padding: clamp(22px, 6vw, 36px);
  border: 1px solid var(--border);
  border-radius: 16px;
  background: white;
  box-shadow: 0 12px 60px #1e293b0d;
}
.login-card .brand { margin-bottom: 24px; }
.login-card h1 { margin-bottom: 20px; font-size: 1.625rem; }
.login-card .form-stack > .button { justify-self: stretch; }

@media (max-width: 1080px) {
  .project-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 850px) {
  .app-shell { display: block; }
  .customer-area .app-shell { display: grid; grid-template: auto minmax(0, 1fr) / minmax(0, 1fr); }
  .customer-area .sidebar { max-height: 30dvh; }
  .sidebar {
    position: static;
    height: auto;
    padding: 12px 20px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
  }
  .sidebar nav { display: flex; flex-wrap: wrap; margin: 0; }
  .topbar { min-height: 52px; }
}

@media (max-width: 620px) {
  .project-filters, .project-row { grid-template-columns: 1fr; }
  .project-filter-actions { padding-top: 0; }
}

@media (max-width: 480px) {
  .measurement-row { grid-template-columns: 1fr 1fr; }
  .measurement-row label:first-child { grid-column: 1 / -1; }
}
