:root {
  color-scheme: light;
  --page: #f5f7f8;
  --surface: #ffffff;
  --ink: #20333e;
  --muted: #61717b;
  --line: #dce3e6;
  --accent: #13766d;
  --accent-hover: #0e5d56;
  --accent-soft: #eaf5f2;
  --action-border: #429287;
  --action-surface: #e5f2ee;
  --action-hover: #d8ebe5;
  --brand-version: #b0b6b2;
  --blue-soft: #edf2fb;
  --blue: #365f9a;
  --loan-mark: #d5eae3;
  --loan-tile: #f0f7f4;
  --loan-tile-hover: #e5f1eb;
  --return-mark: #d9e5f5;
  --return-tile: #f1f5fb;
  --return-tile-hover: #e7eef9;
  --correction-mark: #e0e5e9;
  --correction-tile: #f4f6f8;
  --correction-tile-hover: #ebeff3;
  --warning: #8c5210;
  --warning-soft: #fff3df;
  --danger: #a3423a;
  --focus: #2266b5;
  --radius: 12px;
  --space: 24px;
  --card-gap: 10px;
  --control-height: 48px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--page);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 280px; }
button, input { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button, input { touch-action: manipulation; }
button { color: inherit; }
button:focus-visible, input:focus-visible, a:focus-visible, .history-list:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
button:disabled { cursor: default; }
h1, h2, h3, p { margin: 0; }
.app-shell { display: flex; flex-direction: column; width: min(100% - 48px, 960px); height: 100dvh; margin: 0 auto; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
.app-header { height: 92px; flex: 0 0 auto; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; flex-direction: column; align-items: flex-start; font-size: 26px; font-weight: 750; line-height: 1.3; }
.brand-version { margin-top: 2px; color: var(--brand-version); font-size: 10px; font-weight: 400; }
.tabs { display: grid; flex: 0 0 auto; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 5px; border: 1px solid var(--line); background: #eaf0f1; border-radius: var(--radius); }
.tabs button { position: relative; min-height: 32px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 20px; font-weight: 650; }
.tabs button[aria-selected='true'] { background: var(--surface); color: var(--accent); box-shadow: 0 1px 4px #20333e12; }
main { flex: 1 1 0; min-height: 0; margin-top: 24px; }
.panel { height: 100%; min-height: 0; overflow-y: auto; }
.entry-form { width: 100%; margin: 0; }
.input-card, .history-toolbar, .history-list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.input-card { padding: 28px 32px 32px; }
.input-card + .input-card { margin-top: var(--card-gap); }
.field-grid, .form-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px 24px; }
.qr-actions { display: flex; justify-content: center; margin-bottom: var(--card-gap); }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 12px; min-height: var(--control-height); padding: 10px 18px; border: 1px solid transparent; border-radius: 8px; font-weight: 650; line-height: 1.4; }
.primary { color: white; background: var(--accent); }
.primary:disabled { color: #7c8b88; background: #e0e7e5; border-color: #d2dcd8; }
.secondary { background: white; border-color: #cbd7db; }
.clear-button { color: var(--muted); background: transparent; font-size: 17px; font-weight: 500; }
.danger-outline { background: white; border-color: #e1c2bf; color: var(--danger); }
.qr-button, .export-button { color: var(--accent); background: var(--action-surface); border-color: var(--action-border); border-width: 2px; font-size: 18px; font-weight: 700; }
.qr-button { width: 50%; min-width: min(100%, 160px); font-size: 18px; padding: 10px 12px; }
.field { min-width: 0; }
.field label { display: flex; gap: 8px; align-items: center; min-height: 24px; margin-bottom: 6px; font-size: 13px; font-weight: 600; }
.visitor-card .field label, .visitor-card .field input { font-size: 17px; }
.field input { width: 100%; min-width: 0; height: 50px; border: 1px solid #cbd7db; background: #fff; color: var(--ink); border-radius: 7px; padding: 10px 12px; font-size: 16px; scroll-margin: 24px; }
.field input:focus { border-color: var(--accent); }
.form-actions { margin-top: var(--card-gap); }
.form-actions .button { font-size: 17px; }
.form-hint { font-size: 14px; font-weight: 400; color: var(--muted); }
.card-fields { min-width: 0; margin: 0; padding: 0; border: 0; }
.card-fields legend { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; max-width: 100%; padding: 0; margin-bottom: 10px; font-size: 17px; font-weight: 600; }
.card-fields legend > span:first-child { white-space: nowrap; }
.history-panel { display: flex; flex-direction: column; gap: 20px; overflow: visible; }
.history-toolbar { position: relative; z-index: 1; display: grid; flex: 0 0 auto; grid-template-columns: max-content minmax(100px, 1fr) 44px; gap: 24px; align-items: center; padding: 24px 32px; }
.history-statuses { display: grid; grid-template-columns: max-content max-content; gap: 10px 24px; align-items: start; text-align: left; }
.history-list { flex: 1 1 0; min-height: 0; overflow-y: auto; overscroll-behavior-y: contain; padding: 0 20px 16px; scrollbar-gutter: stable; }
.metric-label { display: block; color: var(--muted); font-size: 11px; line-height: 1.5; margin-bottom: 5px; }
.history-toolbar strong { display: block; font-size: 14px; font-weight: 650; font-variant-numeric: tabular-nums; }
.persist-value { color: var(--warning); }
.persist-value[data-protected='true'] { color: var(--accent); }
.persist-value[data-protected='null'] { color: var(--muted); }
.export-button { justify-self: stretch; width: 100%; min-width: 0; padding: 10px 16px; }
.export-recovery { grid-column: 1 / -1; padding: 10px 12px; border-radius: 6px; background: var(--warning-soft); color: var(--warning); font-size: 13px; }
.icon-button { display: inline-flex; align-items: center; justify-content: center; width: 44px; min-width: 44px; height: 44px; border: 1px solid transparent; border-radius: 8px; background: transparent; }
.hamburger { width: 18px; height: 14px; border-top: 2px solid currentColor; border-bottom: 2px solid currentColor; position: relative; }
.hamburger::before { content: ''; position: absolute; top: 4px; left: 0; right: 0; border-top: 2px solid currentColor; }
.menu-anchor { position: relative; }
.dropdown { position: absolute; top: calc(100% + 7px); right: 0; width: 190px; padding: 6px; border: 1px solid var(--line); border-radius: 9px; background: white; box-shadow: 0 8px 32px #20333e20; z-index: 3; }
.dropdown button { display: block; text-align: left; width: 100%; min-height: 48px; border: 0; border-radius: 5px; background: white; padding: 12px; font-size: 13px; }
.danger-text { color: var(--danger); }
.history-date { margin: 24px 0 10px; color: var(--muted); font-size: 12px; font-weight: 600; }
.history-row { display: grid; grid-template-columns: 34px minmax(0, 1fr) 12px; align-items: center; gap: 12px; min-height: 72px; width: 100%; text-align: left; border: 1px solid var(--line); border-radius: 8px; background: white; padding: 10px 14px; margin: 7px 0; }
.event-mark { display: grid; place-items: center; width: 32px; height: 32px; background: var(--accent-soft); color: var(--accent); border-radius: 8px; font-size: 20px; }
.history-row.loan { background: var(--loan-tile); }
.history-row.return { background: var(--return-tile); }
.history-row.correction { background: var(--correction-tile); }
.loan .event-mark { background: var(--loan-mark); }
.return .event-mark { background: var(--return-mark); color: var(--blue); }
.correction .event-mark { color: var(--muted); background: var(--correction-mark); font-size: 19px; }
.row-description { display: block; min-width: 0; }
.row-title { display: block; font-size: 14px; font-weight: 650; overflow-wrap: anywhere; }
.row-heading { display: flex; align-items: center; justify-content: flex-start; flex-wrap: wrap; gap: 5px 12px; margin-bottom: 4px; }
.event-label { font-size: 13px; font-weight: 650; color: var(--muted); }
.saved-badge, .unsaved-badge { padding: 1px 6px; border-radius: 4px; font-size: 10px; font-weight: 500; }
.saved-badge { color: var(--accent); background: var(--accent-soft); }
.unsaved-badge { color: var(--warning); background: var(--warning-soft); }
.history-empty { padding: 32px 0; text-align: center; color: var(--muted); font-size: 14px; }
.loan .event-label { color: var(--accent); }.return .event-label { color: var(--blue); }
.inactive-label { font-size: 10px; color: var(--danger); background: #f9eeec; padding: 0 6px; border-radius: 3px; }
.inactive .row-title { color: var(--muted); text-decoration: line-through; }
.row-time { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.row-chevron { font-size: 22px; color: #83919b; }
dialog { color: var(--ink); background: white; border: 1px solid var(--line); padding: 0; }
dialog::backdrop { background: #152a3a66; }
.bottom-sheet { position: fixed; inset: auto 0 0; width: min(100%, 640px); max-width: 100%; max-height: min(88dvh, 780px); margin: 0 auto; border-radius: 20px 20px 0 0; border-bottom: 0; overflow: auto; overscroll-behavior: contain; }
.sheet-handle { width: 36px; height: 4px; margin: 10px auto 0; border-radius: 4px; background: #d3dbdf; }
.sheet-header { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 16px var(--space) 20px; border-bottom: 1px solid var(--line); }
.eyebrow { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
h2 { font-size: 20px; font-weight: 700; }
.close-button { font-size: 27px; font-weight: 300; background: #f4f6f7; }
.sheet-body { padding: 20px var(--space) 24px; }
.detail-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); margin-bottom: 22px; }
.status-active, .status-inactive { font-size: 11px; padding: 2px 8px; border-radius: 4px; }
.status-active { color: var(--accent); background: var(--accent-soft); }.status-inactive { color: var(--danger); background: #f9eeec; }
.detail-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 24px; margin: 0; }
.detail-pair { min-width: 0; }
dt { font-size: 12px; color: var(--muted); margin-bottom: 5px; }
dd { margin: 0; font-size: 15px; font-weight: 550; white-space: pre-wrap; overflow-wrap: anywhere; }
.target-reference { display: flex; align-items: center; gap: 16px; border: 1px solid var(--line); background: var(--page); border-radius: 8px; padding: 12px; margin-bottom: 22px; font-size: 13px; }
.target-reference .metric-label { margin: 0; }
.detail-subheading { font-size: 13px; margin: 28px 0 16px; padding-top: 20px; border-top: 1px solid var(--line); }
.sheet-actions { display: flex; gap: 12px; padding: 18px var(--space) max(20px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.sheet-actions .button { flex: 1; }
.notice-dialog { width: min(100% - 40px, 380px); max-height: 85dvh; padding: 28px; border-radius: 16px; overflow: auto; }
.notice-marker { display: grid; place-items: center; height: 32px; width: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; margin-bottom: 16px; }
.notice-dialog h2 { font-size: 18px; }
.notice-dialog p { font-size: 14px; color: var(--muted); margin: 12px 0 24px; line-height: 1.8; }
.notice-dialog .button { width: 100%; }
.field input[aria-invalid='true'] { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 12px; margin-top: 6px; overflow-wrap: anywhere; }
.notice-dialog .field-error { color: var(--danger); font-size: 12px; margin: 6px 0 0; }
#device-error:empty { display: none; }
.form-feedback { min-height: 1.5em; margin: 8px 0 0; font-size: 13px; color: var(--accent); }
.button:disabled { cursor: default; }
#device-form .button { margin-top: 16px; }
.scanner-dialog { width: min(100% - 24px, 560px); max-height: 90dvh; border-radius: 16px; overflow: auto; overscroll-behavior: contain; }
.scanner-dialog .sheet-header { padding: 16px 20px; }
#scanner-video { display: block; width: 100%; height: min(50dvh, 400px); object-fit: cover; background: #14232b; }
.scanner-message { padding: 16px 20px; font-size: 14px; min-height: 72px; }
.qr-replacement { padding: 0 20px 20px; font-size: 14px; }
.replacement-actions { display: flex; gap: 12px; margin-top: 16px; }
.replacement-actions .button { flex: 1; }
.danger-solid { color: white; background: var(--danger); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
@media (hover: hover) {
  .secondary:hover, .icon-button:hover, .dropdown button:hover { background: #f0f5f5; }
  .primary:not(:disabled):hover { background: var(--accent-hover); }
  .qr-button:hover, .export-button:hover { background: var(--action-hover); }
  .clear-button:hover { background: #eaf0ef; }
  .history-row:hover { border-color: #9ebbb7; }
  .history-row.loan:hover { background: var(--loan-tile-hover); }
  .history-row.return:hover { background: var(--return-tile-hover); }
  .history-row.correction:hover { background: var(--correction-tile-hover); }
  .danger-outline:hover { background: #fcf3f2; }
}
@media (max-width: 760px) {
  .history-toolbar { grid-template-columns: minmax(0, 1fr) 44px; gap: 14px 12px; }
  .history-statuses { grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
}
@media (max-width: 540px) {
  :root { --space: 20px; }
  .app-shell { width: calc(100% - 24px); }
  .app-header { height: 76px; }
  main { margin-top: 16px; }
  .input-card { padding: 24px 16px; }
  .field-grid, .form-actions { gap: 18px 12px; }
  .export-button { font-size: 16px; }
  .field input { padding: 9px 10px; }
  .history-panel { gap: 16px; }
  .history-toolbar { gap: 12px 8px; padding: 20px 12px; }
  .history-list { padding: 0 12px 12px; }
  .history-toolbar strong { font-size: 12px; }
  .history-row { grid-template-columns: 28px minmax(0, 1fr) 12px; gap: 8px; padding: 10px; min-height: 72px; }
  .event-mark { width: 28px; height: 28px; font-size: 19px; }
  .row-title { font-size: 13px; }
  .event-label { font-size: 12px; }
  .row-time { font-size: 11px; }
}
@media (max-width: 350px) {
  .app-shell { width: calc(100% - 16px); }
  .input-card { padding-left: 12px; padding-right: 12px; }
  .export-button { font-size: 16px; }
  .history-statuses { gap: 8px; }
  .history-toolbar strong { font-size: 11px; }
  .history-row { grid-template-columns: minmax(0, 1fr) 12px; gap: 6px; }
  .event-mark { display: none; }
}
@media (prefers-reduced-motion: no-preference) {
  .button, .tabs button { transition: background-color .12s ease; }
  .bottom-sheet[open] { animation: sheet-enter .16s ease-out; }
  @keyframes sheet-enter { from { transform: translateY(24px); opacity: .5; } to { transform: translateY(0); opacity: 1; } }
}
