/* pdfform — light by default, dark by choice.
 *
 * Every colour in this file resolves from a token. Nothing downstream writes
 * a literal grey, because a hardcoded colour is how a dark mode ends up
 * three-quarters finished and nobody notices until someone flips the switch.
 */

:root {
  color-scheme: light;
  --bg:            #f6f7f9;
  --surface:       #ffffff;
  --surface-2:     #f0f2f5;
  --surface-sunk:  #e8ebf0;
  --border:        #d8dde5;
  --border-strong: #b9c1cd;
  --text:          #16181d;
  --text-muted:    #5f6875;
  --text-faint:    #8b95a3;

  --accent:        #2b5bd7;
  --accent-hover:  #2149b3;
  --accent-soft:   rgba(43, 91, 215, .10);
  --accent-text:   #ffffff;

  --ok:            #16794a;
  --ok-soft:       rgba(22, 121, 74, .12);
  --warn:          #9a6100;
  --warn-soft:     rgba(154, 97, 0, .14);
  --danger:        #b3261e;
  --danger-soft:   rgba(179, 38, 30, .12);

  --shadow:        0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .08);
  --shadow-sm:     0 1px 2px rgba(16, 24, 40, .08);
  --radius:        10px;
  --radius-sm:     7px;
  --header-h:      54px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:            #0e1014;
  --surface:       #171a20;
  --surface-2:     #1e222a;
  --surface-sunk:  #0a0c0f;
  --border:        #2b313c;
  --border-strong: #3d4655;
  --text:          #e8eaee;
  --text-muted:    #9aa3b2;
  --text-faint:    #6f7887;

  --accent:        #6f9bff;
  --accent-hover:  #86adff;
  --accent-soft:   rgba(111, 155, 255, .16);
  --accent-text:   #0b1020;

  --ok:            #56d39c;
  --ok-soft:       rgba(86, 211, 156, .15);
  --warn:          #ecb45a;
  --warn-soft:     rgba(236, 180, 90, .16);
  --danger:        #ff9a92;
  --danger-soft:   rgba(255, 154, 146, .15);

  --shadow:        0 1px 2px rgba(0, 0, 0, .5), 0 8px 28px rgba(0, 0, 0, .45);
  --shadow-sm:     0 1px 2px rgba(0, 0, 0, .5);
}

@media (prefers-color-scheme: dark) {
  /* First visit only — an explicit choice stamps data-theme and wins. */
  :root:not([data-theme]) { color-scheme: dark; }
  :root:not([data-theme]) {
    --bg: #0e1014; --surface: #171a20; --surface-2: #1e222a; --surface-sunk: #0a0c0f;
    --border: #2b313c; --border-strong: #3d4655;
    --text: #e8eaee; --text-muted: #9aa3b2; --text-faint: #6f7887;
    --accent: #6f9bff; --accent-hover: #86adff; --accent-soft: rgba(111,155,255,.16);
    --accent-text: #0b1020;
    --ok: #56d39c; --ok-soft: rgba(86,211,156,.15);
    --warn: #ecb45a; --warn-soft: rgba(236,180,90,.16);
    --danger: #ff9a92; --danger-soft: rgba(255,154,146,.15);
    --shadow: 0 1px 2px rgba(0,0,0,.5), 0 8px 28px rgba(0,0,0,.45);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; }

/* The shell and the tab strip set display explicitly, which otherwise beats
 * the hidden attribute and leaves an empty editor sitting under the upload
 * card. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
code, .mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace; }

/* ------------------------------------------------------------------ header */

.topbar {
  height: var(--header-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40;
}
.brand { font-weight: 650; letter-spacing: -.01em; font-size: 15px; text-decoration: none; color: var(--text); }
.brand span { color: var(--text-faint); font-weight: 400; }
.topbar .spacer { flex: 1 1 auto; min-width: 0; }
.filename {
  font-size: 13px; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 42ch;
}

.pill {
  font-size: 11.5px; padding: 2.5px 9px; border-radius: 99px;
  border: 1px solid var(--border); color: var(--text-muted); background: var(--surface-2);
  white-space: nowrap;
}
.pill.warn { color: var(--warn); border-color: var(--warn); background: var(--warn-soft); }
.pill.ok   { color: var(--ok);   border-color: var(--ok);   background: var(--ok-soft); }

/* ------------------------------------------------------------------ controls */

button, .btn {
  font: inherit; font-size: 13.5px; font-weight: 500;
  padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 7px;
  transition: background .12s, border-color .12s, color .12s;
}
button:hover, .btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
button:disabled { opacity: .45; cursor: not-allowed; }
button:disabled:hover { background: var(--surface); border-color: var(--border); }

.btn-primary, button.primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-text);
}
.btn-primary:hover, button.primary:hover {
  background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-text);
}
button.danger { color: var(--danger); border-color: var(--border); }
button.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
button.icon { padding: 7px 9px; }

/* Every text-like input, listed by exclusion rather than by name — Django
 * renders EmailField as type="email" and a named list quietly misses it. */
input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="submit"]),
select {
  font: inherit; font-size: 14px;
  padding: 8px 10px; width: 100%;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
input::placeholder { color: var(--text-faint); }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible,
[contenteditable]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input[type="color"] { padding: 3px; height: 36px; width: 46px; cursor: pointer; }
label.field { display: block; font-size: 12px; font-weight: 550; color: var(--text-muted);
  margin: 0 0 5px; letter-spacing: .01em; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden; background: var(--surface); }
.seg button { border: 0; border-radius: 0; padding: 7px 12px; background: transparent; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
.seg button[aria-pressed="true"]:hover { background: var(--accent-hover); }

/* ------------------------------------------------------------------ layout */

.shell { display: grid; grid-template-columns: 1fr 340px; height: calc(100dvh - var(--header-h)); }

.canvas-pane { display: flex; flex-direction: column; min-width: 0; background: var(--surface-sunk); }
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 14px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.toolbar .spacer { flex: 1 1 auto; }

.scroller { flex: 1 1 auto; overflow: auto; padding: 24px; display: flex; justify-content: center; }
.page-stack { display: flex; flex-direction: column; gap: 20px; align-items: center; }

.page-frame {
  position: relative; background: #fff; box-shadow: var(--shadow);
  border-radius: 3px; line-height: 0; flex: 0 0 auto;
}
.page-frame img { display: block; border-radius: 3px; max-width: none; }
.page-frame.drawing { cursor: crosshair; }
/* While a drawing tool is active the existing boxes must not swallow the
 * press. On a dense form they cover most of the page, and without this you
 * can only draw in the margins. */
.page-frame.drawing .box { pointer-events: none; }

.side { border-left: 1px solid var(--border); background: var(--surface);
  overflow: auto; display: flex; flex-direction: column; }
.side section { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.side h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-faint); margin: 0 0 10px; font-weight: 650; }

.hint { font-size: 12.5px; color: var(--text-muted); margin: 8px 0 0; line-height: 1.5; }
.hint kbd { font-size: 11px; padding: 1px 5px; border: 1px solid var(--border);
  border-bottom-width: 2px; border-radius: 4px; background: var(--surface-2); font-family: inherit; }

/* ------------------------------------------------------------------ boxes on the page */

.box {
  position: absolute; border-radius: 2px; cursor: text;
  border: 1px solid var(--box-line, rgba(43, 91, 215, .55));
  background: var(--box-fill, rgba(43, 91, 215, .07));
  transition: background .1s, border-color .1s;
}
.box:hover { background: var(--box-fill-hover, rgba(43, 91, 215, .16)); }
.box.unlabelled { --box-line: rgba(154, 97, 0, .6); --box-fill: rgba(154, 97, 0, .08);
  --box-fill-hover: rgba(154, 97, 0, .18); }
.box.manual { --box-line: rgba(22, 121, 74, .7); --box-fill: rgba(22, 121, 74, .08);
  --box-fill-hover: rgba(22, 121, 74, .18); border-style: dashed; }
.box.selected { outline: 2px solid var(--accent); outline-offset: 1px; z-index: 5; }
.box.filled { background: transparent; border-color: transparent; }
.box.filled:hover { border-color: var(--box-line); }

.box .entry {
  position: absolute; inset: 0; width: 100%; height: 100%;
  border: 0; background: transparent; padding: 0 2px;
  font-family: Helvetica, Arial, sans-serif; color: var(--ink-preview, #0d1a4d);
  line-height: 1; display: flex; align-items: flex-end;
  white-space: pre; overflow: hidden; outline: none;
}
.box .entry:empty::before { content: ""; }
.box.sig .entry { color: var(--ok); font-style: italic; justify-content: center;
  align-items: center; }

.box .grip {
  position: absolute; right: -4px; bottom: -4px; width: 9px; height: 9px;
  background: var(--accent); border: 1px solid var(--surface); border-radius: 2px;
  cursor: nwse-resize; display: none;
}
.box.manual.selected .grip { display: block; }
.box .kill {
  position: absolute; right: -9px; top: -10px; width: 18px; height: 18px;
  border-radius: 50%; border: 1px solid var(--border); background: var(--surface);
  color: var(--danger); font-size: 12px; line-height: 1; padding: 0;
  display: none; align-items: center; justify-content: center;
}
.box.manual.selected .kill { display: flex; }

.marquee { position: absolute; border: 1px dashed var(--accent);
  background: var(--accent-soft); pointer-events: none; border-radius: 2px; }

/* ------------------------------------------------------------------ field list */

.row { display: flex; gap: 8px; align-items: center; padding: 5px 0; }
.row .name {
  flex: 0 0 40%; font-size: 12.5px; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer;
}
.row .name:hover { color: var(--accent); }
.row input { flex: 1 1 auto; padding: 5px 8px; font-size: 13px; }
.row.is-manual .name { color: var(--ok); }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 11.5px; color: var(--text-muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px;
  vertical-align: baseline; }

.note { font-size: 13px; padding: 9px 11px; border-radius: var(--radius-sm); margin-top: 10px; }
.note.ok   { background: var(--ok-soft); color: var(--ok); }
.note.err  { background: var(--danger-soft); color: var(--danger); }
.note.warn { background: var(--warn-soft); color: var(--warn); }

/* ------------------------------------------------------------------ dropzone + cards */

.drop {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  padding: 34px 20px; text-align: center; color: var(--text-muted);
  cursor: pointer; background: var(--surface); transition: .14s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.drop strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

.centre { max-width: 620px; margin: 0 auto; padding: 44px 20px; }
.card { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); }
.card + .card { margin-top: 14px; }
.card h1 { font-size: 20px; margin: 0 0 6px; letter-spacing: -.015em; }
.card .sub { color: var(--text-muted); font-size: 14px; margin: 0 0 18px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--text-faint); font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .06em; font-weight: 650; }
tbody tr:nth-child(even) { background: var(--surface-2); }
tbody tr:hover { background: var(--accent-soft); }

.empty { text-align: center; color: var(--text-muted); padding: 40px 20px; font-size: 14px; }

/* ------------------------------------------------------------------ small screens */

.tabs { display: none; }

@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .tabs { display: inline-flex; }
  .side { border-left: 0; border-top: 1px solid var(--border); }
  body[data-pane="page"] .side { display: none; }
  body[data-pane="fields"] .canvas-pane { display: none; }
  .scroller { padding: 12px; }
  .filename { max-width: 20ch; }
  /* 16px keeps iOS from zooming the whole page when an input takes focus */
  input:not([type="checkbox"]):not([type="radio"]):not([type="color"]),
  select { font-size: 16px; }
  .row { flex-wrap: wrap; }
  .row .name { flex: 1 1 100%; }
}

@media print { .topbar, .toolbar, .side { display: none; } }
