:root {
  --bg: #f5f7fa; --panel: #ffffff; --ink: #1f2933; --muted: #6b7280;
  --line: #e3e8ef; --brand: #1d6f6f; --brand-dark: #155454;
  --accent: #2563eb; --danger: #b91c1c; --ok: #15803d; --warn: #b45309;
  --chip: #eef2f7;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--chip); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

.topbar {
  background: var(--brand); color: #fff; padding: 10px 20px;
  display: flex; align-items: center; gap: 22px; flex-wrap: wrap;
}
.brand { color: #fff; font-weight: 700; font-size: 16px; }
.topbar nav { display: flex; gap: 16px; flex-wrap: wrap; }
.topbar nav a { color: #d7ece9; font-weight: 500; }
.topbar nav a:hover { color: #fff; text-decoration: none; }

main { max-width: 1100px; margin: 24px auto; padding: 0 20px; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.hint { color: var(--muted); }

.cards { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 26px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 16px 20px; min-width: 150px; flex: 1;
}
.card .num { font-size: 28px; font-weight: 700; color: var(--brand); }
.card.highlight { background: var(--brand); color: #fff; }
.card.highlight .num { color: #fff; }
a.card { text-decoration: none; transition: filter .1s, transform .1s; }
a.card:hover { filter: brightness(1.06); transform: translateY(-1px); }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 18px 20px; margin: 18px 0;
}
.detail-grid { display: grid; grid-template-columns: 1fr; gap: 0; }

table.data { width: 100%; border-collapse: collapse; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
table.data th, table.data td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { background: #f0f3f7; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
table.data tr:last-child td { border-bottom: none; }
table.data.tight th, table.data.tight td { padding: 7px 10px; }
.scroll-x { overflow-x: auto; }

table.kv { width: 100%; border-collapse: collapse; }
table.kv th { text-align: left; width: 180px; color: var(--muted); font-weight: 500; padding: 6px 8px; vertical-align: top; }
table.kv td { padding: 6px 8px; }

.row-actions { display: flex; gap: 10px; align-items: center; white-space: nowrap; }
.row-actions form { display: inline; margin: 0; }
.empty { color: var(--muted); font-style: italic; }
.count { color: var(--muted); font-weight: 400; font-size: 13px; }

.btn {
  display: inline-block; background: var(--brand); color: #fff; border: none;
  padding: 8px 14px; border-radius: 7px; cursor: pointer; font-size: 13.5px; font-weight: 600;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn.ghost { background: #eef2f7; color: var(--ink); }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
button.link { background: none; border: none; padding: 0; cursor: pointer; color: var(--accent); font-size: 13.5px; }
button.link.danger { color: var(--danger); }

.record-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; max-width: 760px; }
.record-form .form-actions { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-weight: 600; font-size: 13px; }
.field input[type=text], .field input[type=email], .field input[type=number],
.field input[type=date], .field select, .field textarea, textarea.sql, textarea {
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; font: inherit; width: 100%;
}
.field input[type=checkbox] { width: 18px; height: 18px; }
.help { color: var(--muted); font-size: 12px; }
.req { color: var(--danger); }

.inline-add { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.inline-add input, .inline-add select { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font: inherit; }
.inline-add .chk { display: flex; align-items: center; gap: 4px; font-size: 13px; }

.badge { background: var(--chip); color: var(--muted); font-size: 11px; padding: 1px 6px; border-radius: 20px; font-weight: 600; vertical-align: middle; }
.pill { background: var(--chip); border-radius: 20px; padding: 3px 11px; font-weight: 600; margin-right: 6px; }
.pill.ok { background: #dcfce7; color: var(--ok); }
.pill.warn { background: #fef3c7; color: var(--warn); }

.status { text-transform: capitalize; font-weight: 600; padding: 2px 9px; border-radius: 20px; font-size: 12px; }
.status.active { background: #dcfce7; color: var(--ok); }
.status.prospect { background: #dbeafe; color: var(--accent); }
.status.inactive, .status.discontinued { background: #f3f4f6; color: var(--muted); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-weight: 500; }
.flash.ok { background: #dcfce7; color: var(--ok); }
.flash.err { background: #fee2e2; color: var(--danger); }
.warn-text { color: var(--warn); }
.muted-text { color: var(--muted); }
/* per-field old→new changes in the orders import "records updated" report */
ul.change-list { margin: 0; padding-left: 16px; font-size: 12.5px; line-height: 1.45; }
ul.change-list li { margin: 1px 0; }

pre.examples, pre { background: #0f172a; color: #e2e8f0; padding: 14px 16px; border-radius: 8px; overflow-x: auto; font-size: 12.5px; line-height: 1.5; }
textarea.sql { font-family: ui-monospace, Menlo, monospace; }
details summary { cursor: pointer; font-weight: 600; }

/* top-bar user box */
.user-box { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-box .who { color: #d7ece9; font-size: 13px; }
.user-box form { margin: 0; }
button.link.logout { color: #d7ece9; font-weight: 600; }
button.link.logout:hover { color: #fff; }

/* auth pages */
.auth-wrap { min-height: 70vh; display: flex; align-items: center; justify-content: center; }
.auth-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 30px 32px; width: 100%; max-width: 380px; box-shadow: 0 6px 24px rgba(15,23,42,.06); }
.auth-card h1 { font-size: 20px; margin-bottom: 6px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.auth-form .btn { margin-top: 4px; }
.auth-alt { margin-top: 16px; font-size: 13.5px; }
.auth-alt a { color: var(--brand); }

/* MFA setup / security page */
.mfa-setup { display: flex; gap: 28px; flex-wrap: wrap; align-items: flex-start; margin-top: 12px; }
.mfa-setup .qr { flex: 0 0 auto; }
.mfa-setup .qr svg { width: 180px; height: 180px; border: 1px solid var(--line); border-radius: 8px; }
code.secret { display: inline-block; font-size: 15px; letter-spacing: 1px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; word-break: break-all; }
.recovery-codes { columns: 2; max-width: 360px; margin: 12px 0 0; padding-left: 20px; }
.recovery-codes li { margin-bottom: 6px; }
.recovery-codes code { font-size: 15px; letter-spacing: 1px; }
.mfa-actions { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-top: 12px; }

/* Cells stay on one line by default (td.nowrap, set in the template when the
   value is < 100 chars). Values 100+ chars get no .nowrap and wrap — break
   long unbroken strings (e.g. emails) so they don't overflow the column. */
td.nowrap { white-space: nowrap; }
.data td { overflow-wrap: anywhere; }

/* pagination bar */
.pager { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 14px 0 4px; }
.pager-info { color: var(--muted); font-size: 13px; margin-right: auto; }

tr.sum-total td { border-top: 2px solid var(--line); }

/* orders */
th a.sort { color: inherit; text-decoration: none; white-space: nowrap; }
th a.sort:hover { text-decoration: underline; }
th a.sort.active { color: var(--brand-dark); }
.order-card { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
.order-head { display: flex; gap: 10px; align-items: baseline; margin-bottom: 6px; }
h3.sub { margin: 16px 0 6px; font-size: 14px; color: var(--brand-dark); }
a.who { text-decoration: none; }
a.who:hover { text-decoration: underline; }

/* inline set-password menu in users table */
details.menu { display: inline; }
details.menu > summary { color: var(--accent); font-weight: 400; list-style: none; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu .inline-add { margin-top: 8px; }

/* custom-field rows + dropdown option management */
.cf-row { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin-bottom: 12px; }
.cf-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.cf-head form { margin: 0; }
.cf-options { margin-top: 12px; padding-left: 4px; }
.cf-options table.data { max-width: 520px; }
.locked { color: var(--muted); font-size: 12.5px; }

/* list-page search */
.search-bar { display: flex; gap: 8px; align-items: center; margin: 4px 0 14px; }
.search-bar input[type=search] {
  flex: 1; max-width: 460px; border: 1px solid var(--line); border-radius: 7px;
  padding: 8px 11px; font: inherit;
}
.btn.small, a.btn.small { padding: 7px 12px; }

.inline-toggle { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.inline-toggle select { border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font: inherit; }
.muted { color: var(--muted); }

/* help / docs page */
.toc ol { margin: 8px 0 0; padding-left: 20px; columns: 2; }
.toc li { margin-bottom: 4px; }
section.panel h2 { color: var(--brand-dark); border-bottom: 1px solid var(--line); padding-bottom: 8px; }
section.panel ul, section.panel ol { padding-left: 22px; }
section.panel li { margin-bottom: 6px; }
.rel-list li { margin-bottom: 9px; }
.callout { background: #fff7ed; border: 1px solid #fed7aa; border-left: 4px solid var(--warn);
  border-radius: 8px; padding: 12px 14px; margin-top: 10px; }
.er-diagram { width: 100%; min-width: 680px; height: auto; }
.er-diagram .erbox { fill: #eef5f4; stroke: var(--brand); stroke-width: 1.5; }
.er-diagram .erbox.primary { fill: var(--brand); stroke: var(--brand-dark); }
.er-diagram .ertext { fill: var(--brand-dark); font: 600 13px -apple-system, sans-serif; text-anchor: middle; }
.er-diagram .erbox.primary + .ertext, .er-diagram .primary ~ .ertext { fill: #fff; }
.er-diagram .ersub { fill: var(--muted); font: 11px -apple-system, sans-serif; text-anchor: middle; }
.er-diagram .erline { stroke: #94a3b8; stroke-width: 1.6; }
.er-diagram .erline.dashed { stroke-dasharray: 5 4; }
.er-diagram .erlabel { fill: #64748b; font: 600 11px -apple-system, sans-serif; }
.legend { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.legend .solid, .legend .dash { display: inline-block; width: 26px; height: 0; vertical-align: middle;
  border-top: 2px solid #94a3b8; margin-right: 5px; }
.legend .dash { border-top-style: dashed; }

/* Dashboard adoption bar chart */
.bar-chart { display: block; width: 100%; height: auto; }
.bar-chart rect { transition: opacity .1s; }
.bar-chart rect:hover { opacity: .82; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 8px 0 2px; }
.chart-legend .legend-item { color: var(--ink); font-size: 12.5px; display: inline-flex; align-items: center; }
.chart-legend .swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; }
