/*
 * PD Stevens & Sons Ltd brand (docs/PDStevens;Brand Guidelines.pdf)
 *   Navy  Pantone 533 C  #1F2A44
 *   Red                  #ED1C24  (as used in the logo artwork; the guide's hex says FF0000)
 *   Blue  Pantone 285 C  #0072CE
 *   Font  Seravek (licensed; used when installed, otherwise humanist system fallbacks)
 * Logo: full colour on light backgrounds; white-out only on dark backgrounds or images.
 */
:root {
  --brand-navy: #1f2a44;
  --brand-red: #ed1c24;
  --brand-blue: #0072ce;

  --navy: var(--brand-navy);
  --navy-dark: #151d30;
  --blue: var(--brand-blue);
  --blue-dark: #005ba6;
  --blue-tint: #e6f1fb;
  --red: var(--brand-red);
  --red-dark: #c8141b;

  --bg: #f3f5f8;
  --surface: #ffffff;
  --border: #d8dde6;
  --text: var(--brand-navy);
  --muted: #5f6b80;
  --success-bg: #e3f6e8;
  --success-fg: #1d6b35;
  --error-bg: #fdeaea;
  --error-fg: #a3151b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(31, 42, 68, 0.08), 0 4px 12px rgba(31, 42, 68, 0.06);

  --font: "Seravek", "Gill Sans Nova", "Segoe UI", "Trebuchet MS", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--blue); }
h1, h2, h3 { margin: 0 0 6px; line-height: 1.2; color: var(--navy); }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 600; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.right { text-align: right; }
code { background: #eef1f5; padding: 1px 6px; border-radius: 4px; font-size: 13px; }

/* Top bar: white so the logo can be shown in full colour, as the guide requires */
.topbar {
  background: var(--surface);
  color: var(--navy);
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 24px;
  height: 64px;
  border-bottom: 3px solid var(--blue);
  box-shadow: 0 1px 4px rgba(31, 42, 68, 0.08);
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-logo { height: 38px; width: auto; display: block; }
.brand-app {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
  border-left: 1px solid var(--border);
  padding-left: 12px;
}
.nav { display: flex; gap: 2px; flex: 1; }
.nav a {
  color: var(--navy);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 6px;
  font-weight: 500;
}
.nav a:hover { background: var(--blue-tint); }
.nav a.active { background: var(--blue-tint); color: var(--blue); font-weight: 600; }
.userbox { display: flex; align-items: center; gap: 10px; }
.user-name { font-weight: 500; }
.inline { display: inline; }

/* Layout */
.content { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 28px 24px 48px; }
.auth-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 24px 8vw 24px 24px;
}
.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 16px; }
body.auth {
  background: var(--navy-dark) url("/img/login-bg.jpg") no-repeat left center;
  background-size: cover;
}
body.auth .footer { color: rgba(255, 255, 255, 0.55); }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.section-title { margin: 30px 0 12px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.panel-narrow { max-width: 520px; }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.tile {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.tile:hover { transform: translateY(-2px); border-color: var(--blue); box-shadow: 0 6px 18px rgba(31, 42, 68, 0.12); }
.tile p { color: var(--muted); margin: 0; font-size: 14px; }
.tile-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 8px;
  background: var(--blue-tint); color: var(--blue); font-size: 20px; margin-bottom: 12px;
}
.tile-primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.tile-primary h2 { color: #fff; }
.tile-primary p { color: rgba(255, 255, 255, 0.8); }
.tile-primary .tile-icon { background: var(--red); color: #fff; }
.tile-primary:hover { border-color: var(--red); }

/* Auth card */
.auth-card {
  background: var(--surface);
  border-radius: 14px;
  border-top: 4px solid var(--blue);
  padding: 34px 34px 30px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}
.auth-brand { text-align: center; margin-bottom: 26px; }
.auth-logo { width: 260px; max-width: 100%; height: auto; display: block; margin: 0 auto; }
.auth-app {
  margin: 14px 0 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--muted);
}

/* Forms */
.form { display: flex; flex-direction: column; gap: 16px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
.form label small { font-weight: 400; font-size: 12px; }
.form label.checkbox { flex-direction: row; align-items: center; gap: 10px; }
.form input[type="text"], .form input[type="password"], .form select {
  font: inherit;
  color: var(--text);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}
.form input:focus, .form select:focus { outline: 2px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }
.form input:disabled { background: #f0f2f5; color: var(--muted); }
.form-actions { display: flex; gap: 10px; margin-top: 6px; }

.btn {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-ghost { background: transparent; color: var(--navy); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--navy); }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-block { width: 100%; }

/* Badges + flash */
.badge { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; padding: 3px 8px; border-radius: 999px; }
.badge-admin { background: var(--red); color: #fff; }
.badge-user { background: var(--blue-tint); color: var(--blue); }
.flash { padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; }
.flash-success { background: var(--success-bg); color: var(--success-fg); }
.flash-error { background: var(--error-bg); color: var(--error-fg); }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.table tr:last-child td { border-bottom: none; }
.row-muted td { color: var(--muted); }

/* ---- Shared bits for list and setup screens ---- */
.small { font-size: 13px; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.pre { white-space: pre-wrap; }
.crumbs { margin: 0 0 4px; font-size: 13px; color: var(--muted); }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--blue); text-decoration: underline; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.page-head > .btn, .head-actions { flex-shrink: 0; white-space: nowrap; }
.empty { padding: 22px; margin: 0; color: var(--muted); }
.panel + .panel, .panel + .section-title { margin-top: 16px; }
.panel-flush { padding: 0; overflow: hidden; }
.panel-medium { max-width: 720px; }
.panel-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--border); background: #fafbfc; flex-wrap: wrap; }
.badge-muted { background: #e8ebf0; color: var(--muted); }
.btn-link { background: none; border: none; color: var(--blue); padding-left: 6px; padding-right: 6px; }
.btn-link:hover { text-decoration: underline; }
.callout { background: var(--blue-tint); border-left: 4px solid var(--blue); border-radius: 8px; padding: 12px 16px; margin-bottom: 18px; font-size: 14px; }
.hl { background: #d9f2c2; padding: 0 4px; border-radius: 3px; }

.searchbar { display: flex; gap: 8px; margin-bottom: 14px; }
.searchbar input { flex: 1; max-width: 460px; font: inherit; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; color: var(--text); }
.searchbar input:focus { outline: 2px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }

.table-scroll { overflow-x: auto; }
.table td.right, .table th.right { text-align: right; }
.table a { text-decoration: none; }
.table a:hover { text-decoration: underline; }
.row-group td { background: #f6f8fb; font-weight: 700; color: var(--navy); }
.matrix th.center, .matrix td.center { width: 120px; }
.matrix input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--blue); }

/* Forms: extra layouts */
.form textarea, .fieldset input[type="text"] {
  font: inherit; color: var(--text); padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: #fff; width: 100%;
}
.form textarea:focus, .fieldset input:focus { outline: 2px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }
.fieldset { border: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.fieldset legend { font-weight: 500; margin-bottom: 6px; padding: 0; }
.input-short { max-width: 220px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row > * { min-width: 0; }
.form-row input, .form-row select { width: 100%; }
.form-row-4 { grid-template-columns: repeat(4, 1fr); }
.form-inline { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 10px; }
.form-inline label { flex-direction: row; align-items: center; gap: 8px; }
.form-inline input[type="text"] { font: inherit; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; color: var(--text); }
.checks { display: flex; flex-wrap: wrap; gap: 8px 22px; }
.checks .checkbox, .form .checkbox { font-weight: 400; }
input[type="checkbox"] { accent-color: var(--blue); }
.panel-inline-form { margin-top: 12px; padding: 14px 18px; }
.panel-inline-form summary { cursor: pointer; color: var(--blue); font-weight: 500; }
.panel-inline-form form { margin-top: 14px; }
.body-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.body-row input[type="text"] { min-width: 240px; }
.body-add { padding-top: 14px; border-top: 1px solid var(--border); }
.body-add input[type="text"] { min-width: 280px; }

/* Spec library */
.jumpnav { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.jumpnav a { font-size: 13px; padding: 4px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--navy); text-decoration: none; }
.jumpnav a:hover { border-color: var(--blue); color: var(--blue); }
.jumpnav a.hl { background: #d9f2c2; border-color: #b9e39a; }
.spec-cat { scroll-margin-top: 16px; }
.spec-cat .table { table-layout: fixed; }
.spec-cat .table th:nth-child(2) { width: 130px; }
.spec-cat .table th:nth-child(3), .spec-cat .table th:nth-child(4) { width: 100px; }
.spec-cat .table th:nth-child(5) { width: 70px; }
.spec-cat .table th:nth-child(6) { width: 80px; }
.spec-cat-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--border); background: #fafbfc; }
.spec-cat-head form { flex: 1; min-width: 300px; }
.input-title { font-weight: 700 !important; min-width: 220px; }

/* Standard build form */
.build-form { gap: 16px; }
.build-form .panel { display: flex; flex-direction: column; gap: 14px; }
.build-form .panel + .panel { margin-top: 0; }
.spec-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; }
.spec-field { padding: 8px 10px; border-radius: 8px; margin: -8px -10px; }
.spec-field select { width: 100%; }
.hl-field { background: #eef9e4; }

/* Standard build view: estimate preview */
.build-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.build-side { display: flex; flex-direction: column; gap: 16px; }
.build-side .panel + .panel { margin-top: 0; }
.estimate { padding: 26px 30px; }
.estimate-label { font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); margin-bottom: 14px; }
.estimate-bar { background: var(--navy); color: #fff; font-weight: 600; padding: 4px 10px; margin: 0 0 6px; }
.estimate-title { font-weight: 600; font-size: 16px; margin-bottom: 16px; }
.estimate-sub { font-weight: 700; margin: 14px 0 4px; }
.dims { display: grid; grid-template-columns: 150px 1fr; gap: 4px 12px; margin: 0 0 16px; }
.dims dt { color: var(--muted); }
.dims dd { margin: 0; font-weight: 600; }
.spec-list { margin: 0 0 12px; padding-left: 20px; }
.spec-list li { padding: 2px 4px; margin: 1px 0; }
.spec-list li::marker { color: var(--blue); }
.hl-line { background: #d9f2c2; border-radius: 3px; }
.ref-chip { display: inline-block; font-size: 11px; font-weight: 700; color: var(--red); border: 1px solid var(--red); border-radius: 4px; padding: 0 5px; margin-left: 6px; vertical-align: 1px; }
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); margin: 0; }
.stat-value { font-size: 30px; font-weight: 700; margin: 2px 0 4px; }
.refs { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 8px 0 0; font-size: 14px; }
.refs dt { color: var(--muted); }
.refs dd { margin: 0; font-weight: 600; }

/* Extras and packages */
.callout-warn { background: #fff6e0; border-left-color: #e0a100; }
.badge-warn { background: #fff0c2; color: #8a5a00; }
.group-panel + .group-panel { margin-top: 16px; }
.group-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); background: #fafbfc; }
.group-head h2 { margin: 0; font-size: 16px; }
.extras-table { table-layout: fixed; }
.extras-table th:nth-child(1) { width: 110px; }
.extras-table th:nth-child(3) { width: 140px; }
.extras-table th:nth-child(4) { width: 90px; }
.extras-table th:nth-child(5) { width: 80px; }
.group-title { display: flex; align-items: baseline; gap: 12px; scroll-margin-top: 16px; }
.group-title .section-title { margin-bottom: 12px; }
.package-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.package-grid .panel + .panel { margin-top: 0; }
.package { display: flex; flex-direction: column; gap: 8px; }
.package-inactive { opacity: 0.6; }
.package-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.package-head h3 { margin: 0; font-size: 16px; }
.package-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.package-price { font-size: 20px; font-weight: 700; margin-left: auto; }
.package .estimate-sub { margin: 6px 0 0; }
.package .spec-list { margin-bottom: 4px; }
.package-notes { margin: 0; }
.package-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: auto; padding-top: 8px; }

/* Parts */
.input-medium { max-width: 360px; }
.part-rows { display: flex; flex-direction: column; gap: 8px; }
.part-row { display: grid; grid-template-columns: minmax(0, 1fr) 120px; gap: 10px; align-items: center; }
.part-row select { font: inherit; color: var(--text); padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; width: 100%; min-width: 0; }
.part-row .qty { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.part-row .qty input { width: 70px; font: inherit; padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; color: var(--text); }
.fieldset > .btn-link { align-self: flex-start; padding-left: 0; }
.suggest { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: -6px; }
.chip { font: inherit; font-size: 12px; font-family: ui-monospace, Consolas, monospace; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--navy); cursor: pointer; }
.chip:hover { border-color: var(--blue); color: var(--blue); }
.parts-table th:nth-child(1) { width: 120px; }

@media (max-width: 1000px) {
  .form-row-4 { grid-template-columns: 1fr 1fr; }
  .build-layout { grid-template-columns: 1fr; }
  .auth-content { justify-content: center; padding-right: 24px; }
  body.auth { background-position: 35% center; }
}

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 10px; }
  .brand-logo { height: 30px; }
  .brand-app { display: none; }
  .userbox { margin-left: auto; }
  .nav { order: 3; flex: 1 1 100%; overflow-x: auto; }
  .user-name { display: none; }
  .content { padding: 20px 16px 40px; }
  .page-head { flex-direction: column; }
  .form-row, .form-row-3, .form-row-4, .spec-grid { grid-template-columns: 1fr; }
  .build-layout { grid-template-columns: 1fr; }
  .estimate { padding: 18px; }
  .dims { grid-template-columns: 120px 1fr; }
  .searchbar input { max-width: none; }
  .table th, .table td { padding: 8px; }
  .spec-cat .table, .extras-table { table-layout: auto; }
  .package-grid { grid-template-columns: 1fr; }
}
