/* Trellis admin design system.
   Principles (ADHD-informed): one primary action per view, strong visual
   hierarchy, generous whitespace, consistent placement, visible focus,
   reduced-motion respected, no surprise modals, chunked forms. */

:root {
  --ink: #16241d;
  --ink-2: #4a5a52;
  --ink-3: #6f7f76;
  --bg: #f3f6f4;
  --surface: #ffffff;
  --line: #dde5e0;
  --brand: #1d5c3f;
  --brand-strong: #164831;
  --brand-soft: #e7f0eb;
  --accent: #e07b39;
  --accent-soft: #fdf0e6;
  --danger: #b3261e;
  --danger-soft: #fbeae9;
  --warn: #8a6d00;
  --warn-soft: #fdf6dd;
  --ok: #1b6e3d;
  --ok-soft: #e3f2e8;
  --info: #21527d;
  --info-soft: #e7eff7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(22, 36, 29, 0.06), 0 4px 14px rgba(22, 36, 29, 0.05);
  --focus: 0 0 0 3px rgba(29, 92, 63, 0.35);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.55;
}
a { color: var(--brand); }
a:hover { color: var(--brand-strong); }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
::selection { background: var(--brand-soft); }

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

.skip-link {
  position: absolute; left: -9999px; top: 0; background: var(--brand); color: #fff;
  padding: 10px 16px; border-radius: 0 0 8px 0; z-index: 100; font-weight: 700;
}
.skip-link:focus { left: 0; }

/* ---- shell ---- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: #14352a; color: #dcebe2;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand-row { display: flex; align-items: center; padding-right: 18px; }
.sidebar .brand {
  display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px;
  color: #fff; font-weight: 800; font-size: 18px; text-decoration: none; letter-spacing: .2px;
}
.sidebar .brand svg { flex-shrink: 0; }
.sidebar .tenant-name {
  margin: 0 14px 12px; padding: 8px 12px; background: rgba(255,255,255,.1);
  border-radius: 8px; font-size: 13px; line-height: 1.4; color: #dcebe2; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nav-section { margin: 10px 0 2px; padding: 0 18px; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: #7fa38e; font-weight: 700; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 18px; color: #dcebe2;
  text-decoration: none; font-size: 14.5px; border-left: 3px solid transparent;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a[aria-current="page"] { background: rgba(255,255,255,.1); color: #fff; border-left-color: var(--accent); font-weight: 700; }
.nav svg { width: 18px; height: 18px; opacity: .85; flex-shrink: 0; }
.sidebar .foot { margin-top: auto; padding: 14px 18px; font-size: 12.5px; color: #9db8a9; }
.sidebar .foot a { color: #cfe2d6; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 12px 28px; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.topbar .search { flex: 1; max-width: 440px; position: relative; }
.topbar .search input { padding-left: 38px; }
.topbar .search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--ink-3); }
.topbar .spacer { flex: 1; }
.userchip { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink-2); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.content { padding: 26px 28px 60px; max-width: 1180px; width: 100%; margin: 0 auto; }

/* ---- page header ---- */
.page-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 26px; line-height: 1.2; letter-spacing: -0.3px; }
.page-head .sub { color: var(--ink-2); margin: 6px 0 0; max-width: 640px; }
.page-head .actions { margin-left: auto; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.crumbs { font-size: 13.5px; color: var(--ink-3); margin: 0 0 8px; }
.crumbs a { color: var(--ink-3); text-decoration: none; }
.crumbs a:hover { color: var(--brand); text-decoration: underline; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 8px 18px; border-radius: 9px; border: 1px solid transparent;
  font-size: 15px; font-weight: 700; cursor: pointer; text-decoration: none; line-height: 1.2;
  background: var(--brand); color: #fff; white-space: nowrap;
}
.btn:hover { background: var(--brand-strong); color: #fff; }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--line); font-weight: 600; }
.btn.secondary:hover { border-color: var(--ink-3); background: var(--surface); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #8f1e18; }
.btn.ghost { background: transparent; color: var(--brand); font-weight: 600; }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: 13.5px; border-radius: 8px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

/* ---- cards & grids ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .card-body { padding: 20px; }
.card .card-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.card .card-head h2 { margin: 0; font-size: 17px; }
.card .card-head .actions { margin-left: auto; display: flex; gap: 8px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1000px) { .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } .grid.cols-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 700px) { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } }

.stat { padding: 16px 18px; }
.stat .label { font-size: 13px; color: var(--ink-2); font-weight: 600; display: flex; gap: 8px; align-items: center; }
.stat .value { display: block; font-size: 26px; font-weight: 800; margin-top: 4px; letter-spacing: -0.4px; }
.stat .hint { display: block; font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }
.stat.link { display: block; text-decoration: none; color: inherit; }
.stat.link:hover { border-color: var(--brand); }

/* pipeline widget */
.pipeline { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 900px) { .pipeline { grid-template-columns: repeat(2, 1fr); } }
.pipeline a { text-decoration: none; color: inherit; }
.pipeline .stage { position: relative; }
.pipeline .stage .count { display: block; font-size: 30px; font-weight: 800; line-height: 1.2; }
.pipeline .stage .money { display: block; color: var(--ink-2); font-size: 13.5px; font-weight: 600; }
.pipeline .stage .todo { display: block; color: var(--accent); font-weight: 700; font-size: 13px; margin-top: 4px; }

/* ---- tables ---- */
.tablewrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14.5px; }
table.data th {
  text-align: left; font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-3); font-weight: 700; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.data td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: #fafcfb; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data a.rowlink { font-weight: 700; text-decoration: none; }
table.data a.rowlink:hover { text-decoration: underline; }
table.data .sub { color: var(--ink-3); font-size: 13px; margin-top: 1px; }

/* ---- badges ---- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 700; white-space: nowrap;
  background: var(--info-soft); color: var(--info);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.neutral { background: #eef1ef; color: var(--ink-2); }
.badge.accent { background: var(--accent-soft); color: #a35415; }
.badge.brand { background: var(--brand-soft); color: var(--brand); }

/* ---- forms ---- */
.field { margin-bottom: 18px; max-width: 560px; }
.field.wide { max-width: none; }
.field label { display: block; font-weight: 700; font-size: 14.5px; margin-bottom: 6px; }
.field .help { font-size: 13px; color: var(--ink-3); margin: 4px 0 6px; }
.field .error { font-size: 13.5px; color: var(--danger); margin-top: 6px; font-weight: 600; }
input[type="text"], input[type="email"], input[type="tel"], input[type="password"], input[type="number"],
input[type="date"], input[type="datetime-local"], input[type="url"], input[type="search"], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px;
  font: inherit; color: var(--ink); background: var(--surface); min-height: 42px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); }
.checkrow { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0; }
.checkrow input { width: 20px; height: 20px; min-height: 0; margin-top: 2px; accent-color: var(--brand); flex-shrink: 0; }
.checkrow label { font-weight: 600; font-size: 14.5px; }
.checkrow .help { display: block; font-weight: 400; color: var(--ink-3); font-size: 13px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 0 0 20px; background: var(--surface); }
legend { font-weight: 800; padding: 0 8px; font-size: 15px; }
.form-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
@media (max-width: 760px) { .form-cols { grid-template-columns: 1fr; } }
.sticky-save {
  position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%);
  padding: 18px 0 10px; display: flex; gap: 10px; align-items: center;
}

/* ---- misc ---- */
.flash { padding: 12px 16px; border-radius: 9px; margin-bottom: 18px; font-weight: 600; display: flex; gap: 10px; align-items: center; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--danger-soft); color: var(--danger); }
.flash.info { background: var(--info-soft); color: var(--info); }

.empty { text-align: center; padding: 48px 24px; color: var(--ink-2); }
.empty h3 { margin: 12px 0 6px; font-size: 18px; color: var(--ink); }
.empty p { margin: 0 auto 18px; max-width: 420px; }
.empty svg { width: 42px; height: 42px; color: var(--ink-3); }

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 20px; flex-wrap: wrap; }
.tabs a {
  padding: 9px 16px; text-decoration: none; color: var(--ink-2); font-weight: 700; font-size: 14.5px;
  border-bottom: 3px solid transparent; margin-bottom: -2px;
}
.tabs a[aria-current="page"] { color: var(--brand); border-bottom-color: var(--brand); }
.tabs a:hover { color: var(--brand); }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
.toolbar select, .toolbar input { min-height: 38px; width: auto; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0 10px 24px; border-left: 2px solid var(--line); margin-left: 8px; position: relative; }
.timeline li::before {
  content: ""; position: absolute; left: -7px; top: 16px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--brand); border: 2px solid #fff;
}
.timeline .when { font-size: 12.5px; color: var(--ink-3); }

.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; font-size: 14.5px; }
.kv dt { color: var(--ink-3); font-weight: 600; }
.kv dd { margin: 0; }
@media (max-width: 600px) { .kv { grid-template-columns: 1fr; } .kv dt { margin-top: 8px; } }

.pagination { display: flex; gap: 6px; margin-top: 18px; align-items: center; }
.pagination a, .pagination span { padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; font-size: 14px; background: var(--surface); }
.pagination [aria-current="page"] { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 700; }

.linksbox { background: var(--brand-soft); border-radius: 9px; padding: 12px 14px; font-size: 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.linksbox code { background: #fff; padding: 4px 8px; border-radius: 6px; font-size: 12.5px; word-break: break-all; }

.prose h1, .prose h2, .prose h3 { line-height: 1.25; }
.prose img { max-width: 100%; border-radius: 8px; }
.prose blockquote { border-left: 4px solid var(--brand); margin: 16px 0; padding: 4px 16px; color: var(--ink-2); background: var(--brand-soft); border-radius: 0 8px 8px 0; }

/* line item editor */
.items-editor table { width: 100%; border-collapse: collapse; }
.items-editor th { text-align: left; font-size: 12px; text-transform: uppercase; color: var(--ink-3); padding: 6px 8px; }
.items-editor td { padding: 6px 8px; vertical-align: top; }
.items-editor input, .items-editor textarea { min-height: 38px; }
.items-editor textarea { min-height: 38px; height: 38px; }
.items-editor .rm { color: var(--danger); background: none; border: none; cursor: pointer; font-size: 18px; padding: 8px; border-radius: 6px; }
.items-editor .rm:hover { background: var(--danger-soft); }
.totals { margin-left: auto; max-width: 320px; font-size: 15px; }
.totals .row { display: flex; justify-content: space-between; padding: 6px 0; }
.totals .row.grand { border-top: 2px solid var(--ink); font-weight: 800; font-size: 17px; margin-top: 4px; padding-top: 10px; }

/* compliance status blocks */
.comp-item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.comp-item:last-child { border-bottom: none; }
.comp-item .dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.dot.green { background: var(--ok); } .dot.amber { background: #d99a00; } .dot.red { background: var(--danger); } .dot.grey { background: var(--ink-3); }

/* responsive shell */
.menu-toggle { display: none; }
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { position: static; width: 100%; height: auto; }
  .sidebar .nav { display: none; }
  .sidebar.open .nav { display: block; }
  .menu-toggle { display: inline-flex; min-height: 44px; margin-left: auto; background: none; border: 1px solid rgba(255,255,255,.3); color: #fff; border-radius: 8px; padding: 8px 12px; font-weight: 700; }
  .content { padding: 18px 14px 50px; }
  .topbar { padding: 10px 14px; }
}

/* ---- print (quotes, invoices, RAMS, reports) ---- */
@media print {
  body { background: #fff; }
  .sidebar, .topbar, .no-print, .flash, .sticky-save { display: none !important; }
  .content { padding: 0; max-width: none; }
  .card { border: none; box-shadow: none; }
  a { color: inherit; text-decoration: none; }
}
