:root {
  --ink: #17130b;
  --ink-2: #5f5745;
  --ink-3: #736a55;
  --paper: #f7f3e9;
  --card: #ffffff;
  --line: #e4dcc9;
  --gold: #c9a227;
  --gold-deep: #94700a;
  --gold-soft: #f6edd0;
  --night: #15110a;
  --night-2: #2a2316;
  --good: #1c7345;
  --bad: #b3261e;
  --bad-soft: #fbeae8;
  --radius: 10px;
  --num: ui-monospace, Menlo, Consolas, monospace;
}
* { box-sizing: border-box }
html, body { margin: 0; height: 100% }
body { background: var(--paper); color: var(--ink); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif }
h1, h2, h3 { margin: 0; line-height: 1.2 }
h1 { font-size: 24px } h2 { font-size: 17px }
a { color: inherit }
button, input, select { font: inherit; color: inherit }
input, select { width: 100%; height: 42px; padding: 0 10px; border: 1px solid #cfc5ad; border-radius: 8px; background: #fff; min-width: 0 }
input[type=color] { padding: 3px; width: 46px }
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; flex: none; accent-color: var(--gold-deep); margin: 0 }
[hidden] { display: none !important }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid var(--gold); outline-offset: 1px }
label.f { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--ink-2) }
label.f small { font-weight: 400; color: var(--ink-3) }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 0 16px; border-radius: 8px; border: 1px solid #cfc5ad; background: #fff; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap }
.btn:hover { background: var(--gold-soft) }
.btn.primary { background: var(--night); border-color: var(--night); color: #f6d976 }
.btn.primary:hover { background: var(--night-2) }
.btn.danger { color: var(--bad); border-color: #e3b5b1 }
.btn.danger:hover { background: var(--bad-soft) }
.btn.small { min-height: 34px; padding: 0 10px; font-size: 13px }
.btn:disabled { opacity: .45; cursor: not-allowed }
.muted { color: var(--ink-3) }
.num { font-variant-numeric: tabular-nums }
.right { text-align: right }

/* shell */
.shell { display: grid; grid-template-columns: 196px minmax(0, 1fr); min-height: 100vh }
.side { background: var(--night); color: #efe6cf; padding: 18px 12px; display: flex; flex-direction: column; gap: 3px; position: sticky; top: 0; height: 100vh }
.brand { padding: 2px 10px 18px }
.brand b { display: block; color: #f6d976; font-size: 18px; letter-spacing: .01em }
.brand span { font-size: 12px; color: #b5aa8e }
.side a { display: block; padding: 11px 12px; border-radius: 8px; text-decoration: none; font-weight: 600 }
.side a:hover { background: var(--night-2) }
.side a.on { background: var(--gold); color: var(--night) }
.side .out { margin-top: auto; background: none; border: 0; color: #b5aa8e; text-align: left; padding: 10px 12px; cursor: pointer }
.main { padding: 24px; min-width: 0 }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px }
.stack { display: grid; gap: 18px }
.empty { padding: 48px 20px; text-align: center; color: var(--ink-2) }
.empty .btn { margin-top: 14px }

/* sell */
.sell { display: grid; grid-template-columns: minmax(0, 1fr) 372px; min-height: 100vh; margin: -24px }
.sell-left { padding: 24px; min-width: 0 }
.sell-top { display: flex; gap: 16px; align-items: end; justify-content: space-between; flex-wrap: wrap; margin-bottom: 18px }
.sell-top label { flex: 1 1 260px; max-width: 420px }
.sell-top select { height: 48px; font-size: 17px; font-weight: 700 }
.today { display: flex; gap: 22px }
.today div { text-align: right }
.today b { display: block; font-size: 20px; font-variant-numeric: tabular-nums }
.today span { font-size: 12px; color: var(--ink-3) }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px }
.tile { position: relative; text-align: left; min-height: 124px; padding: 14px 14px 12px 20px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; overflow: hidden; display: flex; flex-direction: column; gap: 2px; transition: transform .06s }
.tile:before { content: ""; position: absolute; inset: 0 auto 0 0; width: 7px; background: var(--c) }
.tile:hover { border-color: var(--gold-deep) }
.tile:active { transform: scale(.98) }
.tile b { font-size: 19px; line-height: 1.2; overflow-wrap: anywhere }
.tile .p { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums }
.tile .s { margin-top: auto; font-size: 13px; color: var(--ink-3) }
.tile kbd { position: absolute; top: 9px; right: 9px; min-width: 22px; text-align: center; font: 600 12px var(--num); background: var(--paper); border: 1px solid var(--line); border-radius: 5px; padding: 1px 4px; color: var(--ink-2) }
.tile:disabled { opacity: .5; cursor: not-allowed }
.tile .n { position: absolute; right: 9px; bottom: 9px; background: var(--night); color: #f6d976; border-radius: 99px; min-width: 28px; height: 28px; display: grid; place-items: center; font-weight: 700; padding: 0 7px }

.panel { background: #fff; border-left: 1px solid var(--line); display: flex; flex-direction: column; height: 100vh; position: sticky; top: 0 }
.panel-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 18px }
.panel-foot { border-top: 1px solid var(--line); padding: 14px 18px; display: grid; gap: 10px }
.line { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; padding: 12px 0; border-bottom: 1px solid var(--line) }
.line b { overflow-wrap: anywhere }
.line .t { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right }
.qty { display: flex; align-items: center; gap: 4px }
.qty button { width: 40px; height: 40px; border: 1px solid #cfc5ad; border-radius: 8px; background: #fff; font-size: 20px; font-weight: 700; cursor: pointer }
.qty button:hover { background: var(--gold-soft) }
.qty input { width: 58px; text-align: center; font-weight: 700 }
.line .price { display: flex; align-items: center; gap: 6px; justify-self: end }
.line .price span { font-size: 12px; color: var(--ink-3) }
.line .price input { width: 92px; text-align: right }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--paper); padding: 4px; border-radius: 9px }
.seg button { height: 38px; border: 0; border-radius: 6px; background: transparent; font-weight: 600; cursor: pointer }
.seg button.on { background: var(--night); color: #f6d976 }
.gobar { display: grid; gap: 10px }
.total { display: flex; justify-content: space-between; align-items: baseline; font-size: 15px }
.total b { font-size: 28px; font-variant-numeric: tabular-nums }
.go { width: 100%; min-height: 62px; font-size: 18px }
.go kbd { font: 600 12px var(--num); border: 1px solid #6b5a2c; padding: 1px 6px; border-radius: 4px; margin-left: 6px }
.hint { color: var(--ink-3); text-align: center; padding: 46px 10px; font-size: 15px }
.printbox { display: grid; gap: 8px; font-size: 13px }
.printbox .row { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; align-items: center }
.printbox select { height: 36px }
.printbox .custom { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 6px; align-items: center }
.printbox .custom input { height: 36px; text-align: center }
.printbox h3 { font-size: 12px; color: var(--ink-2); font-weight: 600 }
.issued { display: flex; flex-direction: column; height: 100%; gap: 12px }
.ok { background: #e6f3eb; color: var(--good); font-weight: 700; padding: 12px 14px; border-radius: 8px }
.ok span { display: block; font-weight: 500; font-size: 13px; color: #245c3e; font-family: var(--num) }
.acts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px }
.scan { display: flex; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 14px }
.scan img { width: 84px; height: 84px; display: block }
.issued iframe { flex: 1 1 auto; min-height: 320px; width: 100%; border: 0; border-radius: 10px; background: #100d07 }

/* tables and stats */
.tbl-wrap { overflow-x: auto }
table { width: 100%; border-collapse: collapse; font-size: 14px }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3); padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap }
td { padding: 9px 10px; border-bottom: 1px solid #efe9da; vertical-align: middle }
th.right, td.right { text-align: right }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0 }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 7px; vertical-align: -1px }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px }
.stat span { font-size: 13px; color: var(--ink-2) }
.stat b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; line-height: 1.25; overflow-wrap: anywhere }
.stat.hero { background: var(--night); border-color: var(--night); color: #fff }
.stat.hero span { color: #cdbf9c } .stat.hero b { color: #f6d976 }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 18px }
input[type=date] { -webkit-appearance: none; appearance: none }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end }
.filters label { flex: 0 1 190px }
.tag { display: inline-block; font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 99px; background: #e6f3eb; color: var(--good) }
.tag.void, .tag.closed { background: var(--bad-soft); color: var(--bad) }
.mono { font-family: var(--num); font-weight: 600; white-space: nowrap }
.row-acts { display: flex; gap: 6px; justify-content: flex-end }
.meter { height: 6px; background: var(--paper); border-radius: 3px; overflow: hidden; margin-top: 4px; min-width: 80px }
.meter i { display: block; height: 100%; background: var(--gold-deep); border-radius: 3px }

/* chart */
.chart { position: relative; height: 210px; margin-top: 12px; display: grid; grid-template-columns: 68px minmax(0, 1fr); grid-template-rows: 1fr 24px }
.chart .y { position: relative; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums }
.chart .y span { position: absolute; right: 8px; transform: translateY(50%); white-space: nowrap }
.chart .plot { position: relative; display: flex; align-items: stretch; gap: 2px; border-bottom: 1px solid #b9af97 }
.chart .grid { position: absolute; left: 0; right: 0; border-top: 1px solid #efe9da }
.chart .col { position: relative; flex: 1 1 0; min-width: 0; display: flex; align-items: flex-end; justify-content: center; cursor: default; background: transparent; border: 0; padding: 0 }
.chart .col:hover { background: var(--gold-soft) }
.chart .col i { display: block; width: 100%; max-width: 44px; background: var(--gold-deep); border-radius: 4px 4px 0 0; position: relative }
.chart .x { grid-column: 2; display: flex; gap: 2px; font-size: 12px; color: var(--ink-3) }
.chart .x span { flex: 1 1 0; min-width: 0; text-align: center; white-space: nowrap; overflow: visible; padding-top: 5px; display: flex; justify-content: center }
#tip { position: fixed; z-index: 60; background: var(--night); color: #fff; padding: 7px 10px; border-radius: 6px; font-size: 13px; pointer-events: none; white-space: nowrap }
#tip b { color: #f6d976 }

/* event detail */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); gap: 12px }
.cats { display: grid; gap: 8px }
.cat-row { display: grid; grid-template-columns: 46px minmax(140px, 2fr) minmax(90px, 1fr) minmax(90px, 1fr) 70px minmax(70px, auto) 44px; gap: 8px; align-items: center }
.cat-row.h { font-size: 12px; font-weight: 600; color: var(--ink-3) }
.cat-add { padding-top: 12px; margin-top: 4px; border-top: 1px solid var(--line) }
.icon-x { width: 40px; height: 40px; border: 1px solid transparent; border-radius: 8px; background: none; cursor: pointer; color: var(--bad); font-size: 18px }
.icon-x:hover { background: var(--bad-soft) }
.event-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); gap: 12px }
.event-card { display: block; text-decoration: none; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px }
.event-card:hover { border-color: var(--gold-deep) }
.event-card h2 { overflow-wrap: anywhere }
.event-card .nums { display: flex; gap: 24px; margin-top: 12px }
.event-card .nums b { display: block; font-size: 19px; font-variant-numeric: tabular-nums }
.event-card .nums span { font-size: 12px; color: var(--ink-3) }

/* access editor */
.acc { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px }
.acc-main { display: flex; gap: 10px; align-items: center; cursor: pointer }
.acc-sub { display: grid; gap: 8px; margin: 10px 0 2px 30px }
.acc-sub label, .acc-cats label { display: flex; gap: 8px; align-items: center; cursor: pointer }
.acc-cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-left: 28px }
.acc-cats .dot { margin-right: 0; flex: none }
dialog { max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow-y: auto }

/* dialogs, login, toast */
dialog { border: 0; border-radius: 12px; padding: 22px; width: min(460px, calc(100vw - 32px)); box-shadow: 0 14px 50px rgb(0 0 0 / .3) }
dialog::backdrop { background: rgb(15 11 4 / .55) }
dialog h2 { margin-bottom: 12px }
dialog .dlg-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px }
.login { min-height: 100vh; display: grid; place-items: center; background: var(--night); padding: 16px }
.login form { background: #fff; padding: 28px; border-radius: 14px; width: min(360px, 100%); display: grid; gap: 14px }
.login h1 { color: var(--ink) }
.login input { height: 50px; font-size: 18px }
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 70; display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)) }
.toast { background: var(--night); color: #fff; padding: 12px 16px; border-radius: 8px; font-weight: 600; text-align: center }
.toast.err { background: var(--bad) }

/* Touch screens: no zoom when typing, finger-sized controls, no keyboard hints. */
@media (pointer: coarse) {
  input, select { font-size: 16px }
  .btn.small { min-height: 44px; padding: 0 14px; font-size: 14px }
  .printbox select, .printbox .custom input { height: 44px }
  .tile, .btn, .qty button, .seg button { touch-action: manipulation }
  .tile kbd, .go kbd { display: none }
}

/* Tablets, foldables opened wide, phones held sideways: top bar, tickets and sale side by side. */
@media (max-width: 900px) {
  :root { --nav: calc(56px + env(safe-area-inset-top)) }
  .shell { grid-template-columns: minmax(0, 1fr) }
  .side { position: sticky; top: 0; z-index: 30; height: var(--nav); flex-direction: row; align-items: center; overflow-x: auto; padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left)); gap: 2px; -webkit-overflow-scrolling: touch }
  .brand { display: none }
  .side a { padding: 9px 11px; white-space: nowrap }
  .side .out { margin: 0 0 0 auto; white-space: nowrap; flex: none }
  .main { padding: 16px max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)) }
  .sell { margin: -16px; margin-left: calc(-1 * max(16px, env(safe-area-inset-left))); margin-right: calc(-1 * max(16px, env(safe-area-inset-right))); grid-template-columns: minmax(0, 1fr) 320px; min-height: calc(100vh - var(--nav)); min-height: calc(100dvh - var(--nav)) }
  .sell-left { padding: 16px }
  .panel { top: var(--nav); height: calc(100vh - var(--nav)); height: calc(100dvh - var(--nav)) }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)) }
}

/* Short screens: the whole sale panel scrolls so the Issue button is always reachable. */
@media (max-height: 500px) and (min-width: 600px) {
  .panel { overflow-y: auto }
  .panel-body { overflow: visible; flex: none }
  .issued iframe { height: 420px; flex: none }
  .go { min-height: 48px }
}

/* Phones and folded screens: one column, with Issue fixed to the bottom of the screen. */
@media (max-width: 599px) {
  .sell { grid-template-columns: minmax(0, 1fr); min-height: 0 }
  .panel { position: static; height: auto; border-left: 0; border-top: 1px solid var(--line); padding-bottom: calc(92px + env(safe-area-inset-bottom)) }
  .panel-body { overflow: visible }
  .issued iframe { height: 560px; flex: none }
  .hint { padding: 22px 10px }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)) }
  .tile { min-height: 108px }
  .gobar { position: fixed; z-index: 25; left: 0; right: 0; bottom: 0; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 14px; background: #fff; border-top: 1px solid var(--line); padding: 10px max(16px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)) }
  .gobar .total { display: block }
  .gobar .total span { display: block; font-size: 12px; color: var(--ink-3) }
  .gobar .total b { font-size: 20px; white-space: nowrap }
  .gobar .go { min-height: 54px; font-size: 17px }
  .cat-row.h { display: none }
  .cat-row { grid-template-columns: 46px 1fr 1fr; padding-bottom: 10px; border-bottom: 1px solid var(--line) }
  .cat-row .wide { grid-column: span 2 }
  .chart { grid-template-columns: 58px minmax(0, 1fr) }
  .filters label { flex: 1 1 calc(50% - 5px) }
  #tk-list table, #tk-list tbody, #tk-list td { display: block }
  #tk-list thead { display: none }
  #tk-list tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 10px; padding: 12px 0; border-bottom: 1px solid var(--line) }
  #tk-list td { padding: 0; border: 0 }
  #tk-list td:nth-child(1) { grid-row: 1; grid-column: 1 }
  #tk-list td:nth-child(7) { grid-row: 1; grid-column: 2; text-align: right }
  #tk-list td:nth-child(2) { grid-column: 1 / -1; color: var(--ink-3); font-size: 13px }
  #tk-list td:nth-child(6) { text-align: right }
  #tk-list td:nth-child(8) { grid-column: 1 / -1; margin-top: 8px }
  #tk-list .row-acts { justify-content: flex-start }
}
@media print {
  @page { size: A4; margin: 14mm }
  body { background: #fff }
  .side, .filters, .no-print, #toasts { display: none !important }
  .shell { display: block }
  .main { padding: 0 }
  .card, .stat { break-inside: avoid; border-color: #bbb }
  .stat.hero { background: #fff; color: #000 } .stat.hero span, .stat.hero b { color: #000 }
  .chart .col i { -webkit-print-color-adjust: exact; print-color-adjust: exact }
}

/* iPhone Duo opened (about 626 points wide) still gets tickets and sale side by side. */
@media (min-width: 600px) and (max-width: 760px) {
  .sell { grid-template-columns: minmax(0, 1fr) 296px }
  .panel-body, .panel-foot { padding-left: 14px; padding-right: 14px }
  .line .price input { width: 80px }
}

.stack { grid-template-columns: minmax(0, 1fr) }
@media (max-width: 760px) {
  .cat-row.h { display: none }
  .cat-row { grid-template-columns: 46px 1fr 1fr; padding-bottom: 10px; border-bottom: 1px solid var(--line) }
  .cat-row .wide { grid-column: span 2 }
}
