/* ------------------------------------------------------------------
   Finance Document — shared stylesheet for the public page and the
   staff page.

   The look is deliberately plain: a document library is something people
   scan, not something they admire. Everything here serves that — one
   accent colour, generous white space, no gradients, no shadows beyond a
   hairline, and type sizes that stay readable on a phone held one-handed
   at a counter.
   ------------------------------------------------------------------ */

:root {
  --bg:         #f5f7fa;
  --surface:    #ffffff;
  --surface-2:  #f0f3f7;
  --border:     #dfe4ea;
  --border-2:   #c9d1da;
  --text:       #131a23;
  --muted:      #5c6773;
  --muted-2:    #8a949f;

  --accent:      #0f4c81;
  --accent-dark: #0b3a63;
  --accent-soft: #e7eff7;

  --danger:      #b42318;
  --danger-soft: #fdeceb;
  --ok:          #15803d;
  --ok-soft:     #e8f6ed;

  --radius:   10px;
  --radius-s: 6px;
  --gap:      16px;
  --maxw:     1080px;

  --shadow: 0 1px 2px rgba(19, 26, 35, .06);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--accent); }

/* Focus is never removed, only replaced — people navigate these forms
   with the keyboard. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 20px;
}

/* ---------- page frame: side panel + content ---------- */

:root { --side-w: 248px; }

/* The side panel is fixed to the left; everything else sits in .shell,
   pushed right by the panel's width. Below 900px the panel becomes a
   drawer opened from the top bar (see shell.js). */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--side-w);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  z-index: 30;
  overflow-y: auto;
}
.shell { margin-left: var(--side-w); min-height: 100vh; display: flex; flex-direction: column; }
/* Full width, or a centred .wrap in this flex column shrinks to its content. */
.shell > :not(dialog) { width: 100%; }
.shell > main { flex: 1 0 auto; }

/* `hidden` must win over component display rules such as .btn's inline-flex. */
[hidden] { display: none !important; }

.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--text); text-decoration: none;
  padding: 2px 6px 18px;
}
.brand img { width: 40px; height: auto; flex: none; }
.brand-name { font-size: 15px; font-weight: 700; line-height: 1.2; letter-spacing: -.1px; }

.side-label {
  margin: 6px 8px 8px;
  font-size: 11px; font-weight: 650; letter-spacing: .6px;
  text-transform: uppercase; color: var(--muted-2);
}
.side-nav ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.side-nav a, .side-foot a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-s);
  color: var(--muted);
  font-size: 14px; font-weight: 550;
  text-decoration: none;
}
.side-nav a:hover, .side-foot a:hover { background: var(--surface-2); color: var(--text); }
.side-nav a[aria-current="page"], .side-foot a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent-dark);
}
.side-nav svg, .side-foot svg { flex: none; }
.side-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }

.topbar { display: none; }
.side-backdrop { display: none; }

/* ---------- page heading ---------- */

.page-head { margin: 26px 0 4px; }
.page-head-row { display: flex; gap: 14px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; }
.page-kicker {
  margin: 0 0 4px;
  font-size: 12px; font-weight: 650; letter-spacing: .5px;
  text-transform: uppercase; color: var(--accent);
}
.page-title { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -.3px; line-height: 1.25; }
.page-sub   { margin: 6px 0 0; font-size: 14px; color: var(--muted); max-width: 70ch; }

.crumbs { margin: 22px 0 0; font-size: 13px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; }
.crumbs a { color: var(--accent); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

.btn-danger { color: var(--danger); border-color: #e8c3bf; background: var(--surface); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }

.btn-sm { padding: 6px 11px; font-size: 13px; }

input[type=text], input[type=search], input[type=email],
input[type=password], input[type=number], textarea, select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
textarea { resize: vertical; min-height: 74px; }

label { display: block; font-size: 13px; font-weight: 550; margin-bottom: 5px; }
.field { margin-bottom: 14px; }
.hint  { font-size: 12.5px; color: var(--muted); margin-top: 5px; }

/* ---------- toolbar (search + filter) ---------- */

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 22px 0 14px;
}
.toolbar .search { flex: 1 1 260px; }
.toolbar .filter { flex: 0 1 230px; }

.result-line {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 18px;
}

/* ---------- category groups ---------- */

.cat {
  margin-bottom: 26px;
}
.cat-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.cat-name  { margin: 0; font-size: 15px; font-weight: 650; }
.cat-count {
  font-size: 12px; color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1px 9px;
}
.cat-desc { margin: 0; font-size: 13px; color: var(--muted); flex: 1 1 100%; }

/* ---------- document rows ---------- */

.doc-list { display: grid; gap: 10px; }

.doc {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.doc-body { flex: 1 1 auto; min-width: 0; }
.doc-title { margin: 0; font-size: 15px; font-weight: 600; }
.doc-desc  { margin: 4px 0 0; font-size: 13.5px; color: var(--muted); }
.doc-meta  {
  margin-top: 7px;
  font-size: 12.5px;
  color: var(--muted-2);
  display: flex; gap: 6px; flex-wrap: wrap;
}
.doc-meta span:not(:last-child)::after { content: "·"; margin-left: 6px; }

.doc-actions { display: flex; gap: 8px; flex: none; align-items: center; flex-wrap: wrap; }

/* File-type chip. The colour is a quick visual sort, not information on
   its own — the extension is always spelled out inside it. */
.ftype {
  flex: none;
  width: 46px; height: 46px;
  border-radius: var(--radius-s);
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700; letter-spacing: .3px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  text-transform: uppercase;
  overflow: hidden;
}
.ft-pdf   { background: #fdecea; color: #b42318; border-color: #f6cfca; }
.ft-doc   { background: #e8f0fb; color: #12509c; border-color: #cbdcf3; }
.ft-xls   { background: #e7f6ec; color: #15803d; border-color: #c7e8d3; }
.ft-ppt   { background: #fdf0e6; color: #b45309; border-color: #f5ddc4; }
.ft-img   { background: #f1ecfb; color: #6d3bce; border-color: #ddd2f5; }
.ft-zip   { background: #eceff2; color: #475467; border-color: #d9dee4; }

/* ---------- notices ---------- */

.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border-2);
  border-radius: var(--radius);
}

.note {
  padding: 10px 13px;
  border-radius: var(--radius-s);
  font-size: 13.5px;
  margin-bottom: 14px;
}
.note-err { background: var(--danger-soft); color: var(--danger); border: 1px solid #f0c8c3; }
.note-ok  { background: var(--ok-soft);     color: var(--ok);     border: 1px solid #c6e6d2; }

/* ---------- footer ---------- */

.site-footer {
  margin-top: 40px;
  padding: 22px 0 34px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
.site-footer .wrap { display: flex; gap: 12px; justify-content: space-between; flex-wrap: wrap; }

/* ---------- admin ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.panel h2 { margin: 0 0 4px; font-size: 16px; font-weight: 650; }
.panel .panel-sub { margin: 0 0 16px; font-size: 13px; color: var(--muted); }

.login-wrap { max-width: 380px; margin: 60px auto; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.tabs { display: flex; gap: 8px; margin: 22px 0 18px; flex-wrap: wrap; }
.tab {
  padding: 7px 14px;
  border: 1px solid var(--border-2);
  border-radius: 20px;
  background: var(--surface);
  font: inherit; font-size: 13.5px; font-weight: 550;
  cursor: pointer;
}
.tab[aria-selected="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-dark);
}

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

table.list { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.list th {
  text-align: left; font-size: 12px; text-transform: uppercase;
  letter-spacing: .4px; color: var(--muted); font-weight: 600;
  padding: 8px 10px; border-bottom: 1px solid var(--border);
}
table.list td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }

/* ---------- dialog ---------- */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  width: min(520px, calc(100vw - 32px));
  box-shadow: 0 16px 48px rgba(19, 26, 35, .18);
}
dialog::backdrop { background: rgba(19, 26, 35, .42); }
.dlg-head { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.dlg-head h3 { margin: 0; font-size: 16px; }
.dlg-body { padding: 18px 20px; max-height: 62vh; overflow: auto; }
.dlg-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
  background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ---------- fill a form online ---------- */

.fill-wrap { max-width: 900px; }

.fill-head {
  display: flex; gap: 14px; align-items: flex-end; justify-content: space-between;
  flex-wrap: wrap;
  margin: 8px 0 16px;
}
.fill-title { flex: 1 1 320px; min-width: 0; }
.fill-title .hint { margin: 4px 0 0; }

#pages { display: grid; gap: 16px; }

/* A page is the rendered picture with the inputs laid over it. --k is
   on-screen pixels per PDF point, set from fill.js, so text inside the
   fields grows and shrinks with the page. */
.pdf-page {
  position: relative;
  width: 100%;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.pdf-page canvas { display: block; width: 100%; height: 100%; }

.pdf-field, .pdf-check { position: absolute; margin: 0; }

.pdf-page .pdf-field {
  padding: 0 calc(var(--k, 1) * 2px);
  border: 0;
  border-radius: 2px;
  background: rgba(15, 76, 129, .07);
  color: #000;
  font: calc(var(--k, 1) * var(--fs, 9) * 1px) / 1.2 Helvetica, Arial, sans-serif;
  min-height: 0;
  resize: none;
}
.pdf-page .pdf-field:hover { background: rgba(15, 76, 129, .12); }
.pdf-page .pdf-field:focus { background: #fff; outline: 2px solid var(--accent); outline-offset: 0; }
.pdf-page textarea.pdf-field { padding-top: calc(var(--k, 1) * 2px); }
/* Worked out by the page, not typed — no tint, so it does not invite a click. */
.pdf-page .pdf-field[readonly] { background: transparent; cursor: default; }
.pdf-page .pdf-field[readonly]:focus { outline: 1px dashed var(--border-2); }

.pdf-check { accent-color: var(--accent); cursor: pointer; }

/* ---------- narrow screens: side panel becomes a drawer ---------- */

@media (max-width: 900px) {
  .shell { margin-left: 0; }

  .topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 6px;
    padding: 8px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }
  .topbar .brand { padding: 0; }
  .topbar .brand img { width: 32px; }

  .menu-btn {
    display: grid; place-items: center;
    width: 40px; height: 40px;
    border: 0; border-radius: var(--radius-s);
    background: transparent; color: var(--text);
    cursor: pointer;
  }
  .menu-btn:hover { background: var(--surface-2); }

  .sidebar {
    transform: translateX(-100%);
    transition: transform .2s ease, visibility .2s;
    box-shadow: 0 16px 48px rgba(19, 26, 35, .18);
    visibility: hidden;
  }
  .side-open .sidebar { transform: none; visibility: visible; }
  .side-open .side-backdrop {
    display: block;
    position: fixed; inset: 0; z-index: 25;
    background: rgba(19, 26, 35, .42);
  }
  .page-title { font-size: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}

/* ---------- phone ---------- */

@media (max-width: 640px) {
  .doc { flex-wrap: wrap; }
  .doc-actions { width: 100%; }
  .doc-actions .btn { flex: 1 1 auto; }
  .grid-2 { grid-template-columns: 1fr; }
  table.list thead { display: none; }
  table.list td { display: block; border: 0; padding: 3px 0; }
  table.list tr { display: block; padding: 12px 0; border-bottom: 1px solid var(--border); }
}
