/* GateKeeper 2.0 — senior-staff-friendly: 18px+ text, high contrast, 48px tap targets. */
:root {
  --navy: #142C5C; --blue: #2F6BC0; --blue-d: #22549C; --sky: #6FA8DC; --bg: #F4F6FA; --card: #fff;
  --ink: #1A2233; --muted: #566074; --line: #D6DCE6; --ok: #1E7A4E; --warn: #9A5B00; --danger: #B42318;
  --radius: 12px; --tap: 48px;
}
* { box-sizing: border-box; }
html { font-size: 112.5%; -webkit-text-size-adjust: 100%; } /* 18px */
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--ink); background: var(--bg); line-height: 1.5; }
a { color: var(--blue-d); text-underline-offset: 3px; }
a:hover { color: var(--navy); }
:focus-visible { outline: 3px solid #F5A623; outline-offset: 2px; border-radius: 4px; }
h1 { font-size: 1.75rem; line-height: 1.2; margin: .2em 0 .6em; color: var(--navy); }
h2 { font-size: 1.25rem; margin: 0 0 .6em; color: var(--navy); }
h3 { font-size: 1.05rem; margin: 1.2em 0 .4em; color: var(--navy); }
.h-sub { font-size: 1rem; font-weight: 500; margin-left: .3em; }
p { margin: 0 0 .8em; }
code { font-size: .9em; background: #EEF2F8; padding: .1em .35em; border-radius: 5px; }
.wrap-any { word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.ok { color: var(--ok); font-weight: 600; }
.warn { color: var(--warn); font-weight: 600; }
.danger-text { color: var(--danger); }
.pre { white-space: pre-line; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: #fff; padding: .6em 1em; z-index: 10; }
.skip:focus { left: 1em; }
.dim { opacity: .65; }

/* Header */
.topbar { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: .5rem 1.25rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.brand { display: flex; align-items: center; gap: .75rem; text-decoration: none; }
.brand img { height: 52px; width: auto; display: block; }
.brand-app { font-weight: 700; color: var(--navy); font-size: 1.1rem; border-left: 2px solid var(--line); padding-left: .75rem; }
.who { display: flex; align-items: center; gap: .5rem; }
.who-name { text-decoration: none; color: var(--ink); font-weight: 600; }
.mainnav { max-width: 1280px; margin: 0 auto; padding: 0 1rem; display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: thin; }
.mainnav a { display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 .9rem; text-decoration: none; color: var(--ink); font-weight: 600; border-bottom: 4px solid transparent; white-space: nowrap; }
.mainnav a:hover { color: var(--blue-d); }
.mainnav a.active { color: var(--blue-d); border-bottom-color: var(--blue); }

.wrap { max-width: 1280px; margin: 0 auto; padding: 1.25rem; }
.foot { color: var(--muted); font-size: .85rem; padding-top: 0; padding-bottom: 2rem; }

/* Cards & layout */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; box-shadow: 0 1px 2px rgba(20, 44, 92, .04); }
.card.narrow { max-width: 640px; }
.card.empty { text-align: center; color: var(--muted); padding: 2rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .5rem; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 1.25rem; }
.card-list .card { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 { margin-bottom: 1.25rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .5rem; }
.page-head h1 { margin-bottom: .3em; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.crumbs { margin: 0 0 .25rem; }
.crumbs a { display: inline-flex; min-height: 40px; align-items: center; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4em; min-height: var(--tap); padding: 0 1.1rem; border-radius: 10px; border: 2px solid transparent; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.2; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-d); color: #fff; }
.btn-secondary { background: #fff; color: var(--blue-d); border-color: var(--blue); }
.btn-secondary:hover { background: #EEF4FC; color: var(--navy); }
.btn-ghost { background: transparent; color: var(--ink); border-color: transparent; }
.btn-ghost:hover { background: #EEF2F8; }
.btn-danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.linklike { background: none; border: 0; color: var(--blue-d); text-decoration: underline; font: inherit; cursor: pointer; padding: .5em 0; min-height: 40px; }
form.inline { display: inline; }

/* Forms */
label { display: block; font-weight: 600; margin: 0 0 .3rem; }
input, select, textarea { font: inherit; color: var(--ink); width: 100%; min-height: var(--tap); padding: .55rem .75rem; border: 2px solid #B8C2D3; border-radius: 10px; background: #fff; }
textarea { min-height: 6rem; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); outline: 3px solid rgba(47, 107, 192, .25); outline-offset: 0; }
input[type=color] { padding: .2rem; width: 6rem; }
input[aria-invalid=true], select[aria-invalid=true], textarea[aria-invalid=true] { border-color: var(--danger); background: #FFF7F6; }
.field-error { color: var(--danger); font-weight: 600; margin: .35rem 0 0; }
.hint { color: var(--muted); font-size: .875rem; margin: .35rem 0 0; }
label.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 500; margin: .4rem 0; cursor: pointer; }
label.check input { width: 24px; height: 24px; min-height: 0; margin-top: .15rem; flex: none; }
.stack > * + * { margin-top: .4rem; }
.stack label { margin-top: .9rem; }
.stack .btn { margin-top: 1.1rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem 1.25rem; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; }
.row-form { display: flex; gap: .6rem; flex-wrap: wrap; }
.row-form input { flex: 1 1 280px; width: auto; }

/* Filters */
.filters { display: grid; grid-template-columns: 2fr repeat(3, 1fr) auto; gap: .75rem 1rem; align-items: end; }
.filter-actions { display: flex; gap: .5rem; }

/* Tables */
.table-card { padding: 0; overflow: hidden; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .8rem 1rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table thead th { background: #F0F3F9; font-size: .9rem; color: var(--navy); white-space: nowrap; }
.table thead th a { color: inherit; text-decoration: none; display: inline-flex; min-height: 32px; align-items: center; }
.table thead th a:hover { text-decoration: underline; }
.table tbody tr:hover { background: #F8FAFD; }
.table .num { text-align: right; white-space: nowrap; }
.items-cell { max-width: 320px; }
.status-form.compact select { min-width: 10.5rem; }
.status-form:not(.compact) { max-width: 22rem; }

/* Badges & tags */
.badge { display: inline-block; padding: .25em .75em; border-radius: 999px; font-weight: 700; font-size: .9rem; background: var(--blue); color: #fff; }
.badge-none { background: #E5E8EE; color: var(--ink); }
.big-badge .badge { font-size: 1.05rem; padding: .35em 1em; }
.tag { display: inline-block; padding: .1em .55em; border-radius: 6px; font-size: .8rem; font-weight: 600; background: #EEF2F8; color: var(--navy); }
.tag-warn { background: #FFF1D6; color: #7A4700; }
.role { font-size: .75rem; font-weight: 700; padding: .15em .5em; border-radius: 6px; text-transform: uppercase; letter-spacing: .03em; }
.role-owner { background: var(--navy); color: #fff; }
.role-admin { background: #DDE9F8; color: var(--navy); }
.role-staff { background: #EEF2F8; color: var(--ink); }

/* Flash */
.flash { padding: .9rem 1.1rem; border-radius: 10px; margin-bottom: 1rem; border-left: 6px solid; font-weight: 500; }
.flash-success { background: #EAF6EF; border-color: var(--ok); }
.flash-error { background: #FDECEA; border-color: var(--danger); }
.flash-info { background: #EAF2FC; border-color: var(--blue); }
.flash-warn { background: #FFF6E0; border-color: #D08A00; }

/* Desk */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; text-decoration: none; color: var(--ink); }
.stat:hover { border-color: var(--blue); }
.stat-n { font-size: 2.4rem; font-weight: 800; color: var(--navy); line-height: 1.1; }
.stat-l { font-weight: 700; }
.stat-s { color: var(--muted); font-size: .85rem; }
.stat-warn { background: #FFF8E8; border-color: #F0C36D; }
.bucket-list { list-style: none; margin: 0; padding: 0; }
.bucket-list li { border-left: 6px solid var(--blue); margin-bottom: .5rem; background: #F7F9FC; border-radius: 8px; }
.bucket-list a { display: flex; justify-content: space-between; align-items: center; min-height: var(--tap); padding: .3rem 1rem; text-decoration: none; color: var(--ink); font-weight: 600; }
.bucket-list strong { font-size: 1.3rem; color: var(--navy); }
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: grid; grid-template-columns: 13rem 9rem 1fr; gap: .75rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.activity li:last-child { border-bottom: 0; }
.act-when { color: var(--muted); font-size: .9rem; }
.act-who { font-weight: 600; }
.diff { border-collapse: collapse; margin-top: .4rem; font-size: .85rem; width: 100%; }
.diff th, .diff td { border: 1px solid var(--line); padding: .3rem .5rem; text-align: left; word-break: break-word; }

.dl { display: grid; grid-template-columns: 9.5rem 1fr; gap: .45rem 1rem; margin: 0; }
.dl dt { color: var(--muted); font-weight: 600; }
.dl dd { margin: 0; }
.items { padding-left: 1.2rem; margin: 0; }
.items li { margin-bottom: .5rem; }
.tracking strong { font-size: 1.2rem; letter-spacing: .02em; }
.danger-zone { margin: 2rem 0 1rem; padding-top: 1rem; border-top: 1px dashed var(--line); }
.pager { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin: 1rem 0; }

/* Dialog */
dialog { border: 0; border-radius: 16px; padding: 0; max-width: 32rem; width: calc(100% - 2rem); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
dialog::backdrop { background: rgba(20, 30, 50, .55); }
.dialog-body { padding: 1.5rem; }
.dialog-body h2 { font-size: 1.35rem; }
.dialog-body p { font-size: 1.05rem; }
.dialog-actions { display: flex; gap: .75rem; justify-content: flex-end; margin-top: 1.25rem; flex-wrap: wrap; }

/* Public / auth */
body.public { display: flex; min-height: 100vh; align-items: flex-start; justify-content: center; padding: 2rem 1rem; }
.auth-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 2rem; width: 100%; max-width: 30rem; box-shadow: 0 4px 24px rgba(20, 44, 92, .08); }
.auth-logo { display: block; width: 240px; height: auto; margin: 0 auto .25rem; }
.auth-app { text-align: center; font-weight: 700; color: var(--navy); margin-bottom: 1.25rem; letter-spacing: .01em; font-size: 1.15rem; }
.auth-card h1 { font-size: 1.5rem; text-align: center; }
.code-input { font-size: 1.6rem; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }
.steps { padding-left: 1.3rem; }
.steps li { margin-bottom: .9rem; }
.qr { margin: .75rem 0; width: 220px; height: 220px; background: #fff; }
.qr svg, .qr img { width: 100%; height: 100%; display: block; }
.secret-key { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.15rem; letter-spacing: .08em; background: #EEF2F8; padding: .6rem .8rem; border-radius: 8px; word-break: break-all; }

/* Tablet */
@media (max-width: 1000px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .filter-q { grid-column: 1 / -1; }
  .card-list { grid-template-columns: 1fr; }
}
/* Phone: tables become stacked cards */
@media (max-width: 760px) {
  html { font-size: 106.25%; } /* 17px base; inputs stay ≥16px so iOS doesn't zoom */
  .wrap { padding: 1rem .75rem; }
  .topbar-inner { padding: .4rem .75rem; }
  .brand img { height: 40px; }
  .brand-app { font-size: .95rem; padding-left: .5rem; }
  .who-name { display: none; }
  .grid-2, .form-grid { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1 1 auto; }
  .table.responsive thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive tr { border-bottom: 8px solid var(--bg); padding: .5rem 0; }
  .table.responsive td { border: 0; padding: .35rem 1rem; display: grid; grid-template-columns: 7.5rem 1fr; gap: .5rem; }
  .table.responsive td::before { content: attr(data-label); font-weight: 600; color: var(--muted); font-size: .85rem; padding-top: .15rem; }
  .table.responsive td[data-label=""]::before { content: none; }
  .table.responsive td[data-label=""] { display: flex; gap: .5rem; }
  .table .num { text-align: left; }
  .status-form.compact select { min-width: 0; }
  .activity li { grid-template-columns: 1fr; gap: .1rem; }
  .dl { grid-template-columns: 1fr; gap: 0; }
  .dl dd { margin-bottom: .6rem; }
  .auth-card { padding: 1.25rem; }
  dialog .dialog-actions .btn { flex: 1 1 100%; }
}
@media print { .topbar, .mainnav, .actions, .danger-zone, .status-form, .foot { display: none !important; } body { background: #fff; } }
