/* Zendrail design system — navy foundation, restrained gold accent, neutral surfaces.
   Light mode first. WCAG 2.2 AA targets: visible focus, contrast, 16px+ text, touch targets. */

:root {
  --navy-900: #0b1b33;
  --navy-800: #12294d;
  --navy-700: #1b3a66;
  --navy-600: #244e86;
  --blue-500: #2f6fd0;
  --blue-100: #e6effb;
  --gold-600: #b7791f;
  --gold-500: #d98b1e;
  --gold-100: #fbefd8;
  --ink: #18202b;
  --muted: #55607a;
  --line: #dde2ec;
  --surface: #ffffff;
  --canvas: #f5f7fb;
  --ok-700: #1c7a4a;
  --ok-100: #e2f4ea;
  --warn-700: #9a6a00;
  --warn-100: #fcefcf;
  --danger-700: #b3261e;
  --danger-100: #fbe4e2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(11, 27, 51, .06), 0 4px 16px rgba(11, 27, 51, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 16px; line-height: 1.55;
  color: var(--ink); background: var(--canvas);
}
h1, h2, h3, h4 { line-height: 1.2; color: var(--navy-900); margin: 0 0 .5rem; }
a { color: var(--blue-500); text-decoration: none; }
a:hover { text-decoration: underline; }
p { margin: 0 0 1rem; }

:focus-visible { outline: 3px solid var(--blue-500); outline-offset: 2px; border-radius: 4px; }

.skip-link {
  position: absolute; left: -999px; top: 0; background: var(--navy-900); color: #fff;
  padding: .6rem 1rem; z-index: 100;
}
.skip-link:focus { left: .5rem; top: .5rem; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 1.25rem; }
.narrow { max-width: 760px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: .5rem; justify-content: center;
  min-height: 44px; padding: .6rem 1.15rem; border-radius: var(--radius);
  border: 1px solid transparent; font-size: 1rem; font-weight: 600; cursor: pointer;
  background: var(--navy-700); color: #fff; transition: background .12s ease;
}
.btn:hover { background: var(--navy-800); text-decoration: none; }
.btn-primary { background: var(--blue-500); }
.btn-primary:hover { background: var(--navy-600); }
.btn-gold { background: var(--gold-500); color: #26200f; }
.btn-gold:hover { background: var(--gold-600); color: #fff; }
.btn-outline { background: transparent; color: var(--navy-700); border-color: var(--line); }
.btn-outline:hover { background: var(--blue-100); }
.btn-danger { background: var(--danger-700); }
.btn-sm { min-height: 36px; padding: .35rem .75rem; font-size: .9rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* Cards & surfaces */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.25rem;
}
.card + .card { margin-top: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 820px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.15rem; }
.stat .num { font-size: 2rem; font-weight: 700; color: var(--navy-800); }
.stat .label { color: var(--muted); font-size: .9rem; }

/* Badges (never color alone — always text) */
.badge { display: inline-flex; align-items: center; gap: .35rem; padding: .15rem .55rem; border-radius: 999px;
  font-size: .8rem; font-weight: 600; border: 1px solid; }
.badge-draft { background: var(--canvas); color: var(--muted); border-color: var(--line); }
.badge-published, .badge-active { background: var(--ok-100); color: var(--ok-700); border-color: #b7e2c8; }
.badge-warn, .badge-trial, .badge-pending { background: var(--warn-100); color: var(--warn-700); border-color: #edd79a; }
.badge-canceled, .badge-danger { background: var(--danger-100); color: var(--danger-700); border-color: #f0b6b1; }
.badge-info { background: var(--blue-100); color: var(--navy-700); border-color: #bcd4f2; }

/* Forms */
.field { margin-bottom: 1.1rem; }
.field label { display: block; font-weight: 600; margin-bottom: .35rem; color: var(--navy-800); }
.field .hint { color: var(--muted); font-size: .85rem; margin-top: .25rem; }
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: .55rem .7rem; font-size: 1rem; font-family: inherit;
  border: 1px solid var(--line); border-radius: var(--radius); background: #fff; color: var(--ink);
}
.textarea { min-height: 96px; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--blue-500); }
.field-error .input, .field-error .select, .field-error .textarea { border-color: var(--danger-700); }
.error-text { color: var(--danger-700); font-size: .85rem; margin-top: .3rem; }
.checkbox { display: flex; align-items: flex-start; gap: .55rem; }
.checkbox input { width: 20px; height: 20px; margin-top: .15rem; }
.required { color: var(--danger-700); }

/* Tables (with mobile card fallback) */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table.data { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.data th, table.data td { text-align: left; padding: .7rem .85rem; border-bottom: 1px solid var(--line); }
table.data th { background: var(--canvas); color: var(--navy-800); font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; }
table.data tr:last-child td { border-bottom: 0; }

/* Alerts */
.alert { padding: .8rem 1rem; border-radius: var(--radius); border: 1px solid; margin-bottom: 1.25rem; }
.alert-success { background: var(--ok-100); border-color: #b7e2c8; color: var(--ok-700); }
.alert-error { background: var(--danger-100); border-color: #f0b6b1; color: var(--danger-700); }
.alert-info { background: var(--blue-100); border-color: #bcd4f2; color: var(--navy-700); }

/* Tabs / segmented toggles (filter bars, list/map & view toggles) */
.tabs { display: inline-flex; flex-wrap: wrap; gap: .25rem; padding: .25rem; background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius); }
.tab { display: inline-flex; align-items: center; gap: .4rem; padding: .4rem .8rem; border-radius: 7px;
  font-weight: 600; font-size: .9rem; color: var(--navy-700); cursor: pointer; background: transparent; }
a.tab:hover { background: var(--blue-100); text-decoration: none; }
.tab.is-active, .tab[aria-current] { background: var(--blue-500); color: #fff; }

/* Definition-list detail pane (tenant / user / lead detail pages) */
dl.detail { margin: 0; display: grid; grid-template-columns: minmax(7rem, auto) 1fr; gap: .45rem 1.25rem; }
dl.detail dt { color: var(--muted); font-size: .85rem; font-weight: 600; }
dl.detail dd { margin: 0; color: var(--ink); overflow-wrap: anywhere; }
@media (max-width: 560px) { dl.detail { grid-template-columns: 1fr; gap: .1rem 0; }
  dl.detail dd { margin-bottom: .6rem; } }

/* Readable free-text block (messages, notes, article bodies) */
.prose { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; max-width: 70ch; color: var(--ink); }

/* App shell */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; background: var(--navy-900); color: #cdd7ea; flex-shrink: 0;
  display: flex; flex-direction: column; padding: 1rem .75rem;
}
.sidebar .brand { color: #fff; font-weight: 800; font-size: 1.25rem; padding: .5rem .75rem 1rem; letter-spacing: -.01em; }
.sidebar .brand .dot { color: var(--gold-500); }
.sidebar nav a { display: block; color: #cdd7ea; padding: .6rem .75rem; border-radius: 8px; font-weight: 500; }
.sidebar nav a:hover { background: var(--navy-700); color: #fff; text-decoration: none; }
.sidebar nav a[aria-current="page"] { background: var(--blue-500); color: #fff; }
.sidebar .nav-group { margin-top: 1rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: #7f8db0; padding: .25rem .75rem; }
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { background: #fff; border-bottom: 1px solid var(--line); padding: .75rem 1.25rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.topbar .tenant { font-weight: 600; color: var(--navy-800); }
.content { padding: 1.5rem 1.25rem 3rem; max-width: 1120px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }

/* Mobile drawer */
.drawer-toggle { display: none; }
.menu-btn { display: none; }
@media (max-width: 860px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; transform: translateX(-100%); transition: transform .2s ease; z-index: 50; }
  .drawer-toggle:checked ~ .sidebar { transform: translateX(0); }
  .menu-btn { display: inline-flex; }
}

/* Public (marketing / marketplace) header */
.public-header { background: var(--navy-900); color: #fff; }
.public-header .container { display: flex; align-items: center; justify-content: space-between; min-height: 64px; gap: 1rem; }
.public-header a { color: #dce4f2; }
.public-header .brand { color: #fff; font-weight: 800; font-size: 1.3rem; }
.public-header .brand .dot { color: var(--gold-500); }
.public-nav { display: flex; gap: 1.25rem; align-items: center; flex-wrap: wrap; }

.hero { background: linear-gradient(180deg, var(--navy-900), var(--navy-700)); color: #fff; padding: 3.5rem 0; }
.hero h1 { color: #fff; font-size: clamp(1.8rem, 4vw, 2.8rem); max-width: 20ch; }
.hero p { color: #cdd7ea; font-size: 1.15rem; max-width: 60ch; }

.section { padding: 3rem 0; }
.eyebrow { color: var(--gold-600); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; font-size: .8rem; }

.footer { background: var(--navy-900); color: #9fb0d0; padding: 2.5rem 0; margin-top: 3rem; font-size: .9rem; }
.footer a { color: #cdd7ea; }
.footer .cols { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 1.5rem; }
@media (max-width: 820px) { .footer .cols { grid-template-columns: 1fr 1fr; } }

.disclaimer { font-size: .82rem; color: #8091b4; border-top: 1px solid var(--navy-700); margin-top: 1.5rem; padding-top: 1.25rem; }

/* Marketplace search */
.search-bar { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.search-grid { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: .6rem; align-items: end; }
@media (max-width: 820px) { .search-grid { grid-template-columns: 1fr 1fr; } }
.listing { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.listing .price { font-size: 1.35rem; font-weight: 700; color: var(--navy-800); white-space: nowrap; }

.muted { color: var(--muted); }
.small { font-size: .87rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.5rem; }
.flex { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack > * + * { margin-top: 1rem; }
.tag-list { display: flex; flex-wrap: wrap; gap: .4rem; list-style: none; padding: 0; margin: .5rem 0 0; }
.tag-list li { background: var(--blue-100); color: var(--navy-700); padding: .2rem .6rem; border-radius: 6px; font-size: .85rem; }
.token { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--canvas); padding: .5rem .7rem; border-radius: 8px; border: 1px solid var(--line); word-break: break-all; display: inline-block; }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }

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

/* PDF field editor (client-side pdf.js preview + overlay) */
.pdf-editor-canvas { background: var(--canvas); border: 1px solid var(--line); border-radius: 8px; padding: 12px; max-height: 720px; overflow: auto; }
.pdf-editor-loading, .pdf-editor-error { color: var(--muted); text-align: center; padding: 1.5rem; }
.pdf-editor-error { color: var(--navy-700); }
.pdf-page { position: relative; margin: 0 auto 16px; box-shadow: 0 1px 6px rgba(0,0,0,.15); background: #fff; }
.pdf-page canvas { display: block; }
.pdf-page-badge { position: absolute; top: 4px; right: 4px; background: rgba(20,30,50,.7); color: #fff; font-size: .7rem; padding: .1rem .4rem; border-radius: 4px; pointer-events: none; }
/* overflow:visible so the corner × delete button (at negative offsets) is never clipped; the label truncates
   within its own span instead of via the box. */
.pdf-field { position: absolute; z-index: 2; background: rgba(37,99,235,.14); border: 1px solid var(--blue-500, #2563eb); color: var(--navy-700, #1e2a44); font-size: .7rem; line-height: 1.1; padding: 0 2px; border-radius: 2px; white-space: nowrap; max-width: 60%; overflow: visible; pointer-events: auto; }
.pdf-field-row { background: rgba(202,138,4,.16); border-color: var(--gold-500, #ca8a04); }
.pdf-field-editable { cursor: move; padding-right: 12px; user-select: none; touch-action: none; }
.pdf-field-editable.dragging { opacity: .85; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.pdf-field-label { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; pointer-events: none; }
.pdf-field-del { position: absolute; top: -9px; right: -9px; width: 18px; height: 18px; line-height: 16px; text-align: center; border-radius: 50%; border: 1px solid var(--red-500, #dc2626); background: #fff; color: var(--red-600, #dc2626); font-size: 13px; font-weight: 700; cursor: pointer; padding: 0; box-shadow: 0 1px 3px rgba(0,0,0,.3); z-index: 3; }
.pdf-field-del:hover { background: var(--red-500, #dc2626); color: #fff; }
.pdf-editor-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .6rem; padding: .6rem 0 .8rem; }
.pdf-tb-field { display: flex; flex-direction: column; gap: .15rem; }
.pdf-tb-lbl { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.pdf-editor-toolbar .select { min-height: 34px; }
.pdf-tb-req { display: flex; align-items: center; gap: .3rem; font-size: .85rem; }
.pdf-editor-hint { font-size: .82rem; color: var(--blue-600, #2563eb); font-weight: 600; align-self: center; }
.pdf-editor-canvas.placing .pdf-page { cursor: crosshair; outline: 2px dashed var(--blue-500, #2563eb); outline-offset: -2px; }
.pdf-editor-canvas.placing .pdf-page * { cursor: crosshair; }
/* Draggable field-type palette (drag a chip onto the form, or click then click to place). */
.pdf-palette-group { display: inline-flex; align-items: center; gap: .35rem; padding: 0 .2rem; }
.pdf-palette-lbl { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.pdf-palette-chips { display: flex; gap: .3rem; flex-wrap: wrap; }
.pdf-chip { cursor: grab; font-size: .78rem; line-height: 1.2; padding: .22rem .55rem; border-radius: 12px; border: 1px solid var(--blue-500, #2563eb); background: rgba(37,99,235,.1); color: var(--navy-700, #1e2a44); white-space: nowrap; }
.pdf-chip:hover { background: rgba(37,99,235,.22); }
.pdf-chip:active { cursor: grabbing; }
.pdf-chip-row { border-color: var(--gold-500, #ca8a04); background: rgba(202,138,4,.14); }
.pdf-chip-row:hover { background: rgba(202,138,4,.26); }
/* Inline properties popover for a selected placed field. */
.pdf-props { position: absolute; z-index: 6; width: 202px; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.22); padding: .5rem; font-size: .8rem; }
.pdf-props-title { font-weight: 600; margin-bottom: .4rem; }
.pdf-props-row { display: flex; align-items: center; justify-content: space-between; gap: .4rem; margin-bottom: .35rem; }
.pdf-props-lbl { font-size: .72rem; color: var(--muted); white-space: nowrap; }
.pdf-props-row .select { flex: 1; min-width: 0; }
.pdf-props-req { display: flex; align-items: center; gap: .3rem; margin: .1rem 0 .45rem; font-size: .82rem; }
.pdf-props-actions { display: flex; gap: .35rem; justify-content: flex-end; }
/* Draggable roster row-region band (drag its top = where rows start, its bottom = row height). */
.pdf-row-region { position: absolute; z-index: 1; box-sizing: border-box; background: rgba(202,138,4,.08); border: 1px dashed var(--gold-500, #ca8a04); pointer-events: none; }
.pdf-row-lines { position: absolute; inset: 0; }
.pdf-row-line { position: absolute; left: 0; right: 0; border-top: 1px dashed rgba(202,138,4,.5); }
.pdf-row-region-label { position: absolute; top: 15px; left: 4px; font-size: .66rem; font-weight: 600; color: var(--gold-700, #a16207); background: rgba(255,255,255,.78); padding: 0 3px; border-radius: 3px; pointer-events: none; }
.pdf-row-handle { position: absolute; left: 0; right: 0; height: 13px; display: flex; align-items: center; justify-content: center; font-size: .58rem; font-weight: 700; letter-spacing: .02em; color: #fff; background: var(--gold-500, #ca8a04); cursor: ns-resize; pointer-events: auto; z-index: 3; opacity: .85; user-select: none; touch-action: none; }
.pdf-row-handle:hover, .pdf-row-handle.dragging { opacity: 1; }
.pdf-row-handle-top { top: -1px; }
.pdf-row-handle-bottom { bottom: -1px; }

/* Staff fill screen — signature markers + inline signing pad. */
.req-star { color: var(--gold-600, #b45309); font-weight: 700; }
.pdf-fill-field { position: absolute; z-index: 2; display: inline-flex; align-items: center; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .72rem; line-height: 1.1; padding: .1rem .35rem; border-radius: 3px; cursor: pointer; background: rgba(37,99,235,.14); border: 1px dashed var(--blue-500, #2563eb); color: var(--navy-700, #1e2a44); }
.pdf-fill-field:hover { background: rgba(37,99,235,.24); }
.pdf-fill-field.is-required { border-style: solid; }
.pdf-fill-field.is-signed { background: rgba(22,163,74,.16); border-color: var(--green-600, #16a34a); border-style: solid; color: #14532d; }
.pdf-fill-pad { position: absolute; z-index: 5; width: 320px; max-width: 92vw; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.2); padding: .6rem; }
.pdf-fill-pad-title { font-weight: 600; font-size: .85rem; margin-bottom: .4rem; }
.pdf-fill-pad-toggle { display: flex; gap: .8rem; margin-bottom: .4rem; }
.pdf-fill-radio { font-size: .82rem; display: inline-flex; align-items: center; gap: .2rem; }
.pdf-fill-pad-typed .input { width: 100%; }
.pdf-fill-canvas { display: block; width: 100%; border: 1px solid #b9c2d6; border-radius: 6px; background: #fff; touch-action: none; margin-bottom: .35rem; }
.pdf-fill-pad-actions { display: flex; align-items: center; gap: .4rem; margin-top: .45rem; flex-wrap: wrap; }
.pdf-fill-pad-err { color: var(--navy-700, #b91c1c); font-size: .78rem; }
