:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --ink: #18212f;
  --muted: #687386;
  --line: #dfe5ec;
  --brand: #176b5d;
  --brand-2: #d7a642;
  --danger: #b93a3a;
  --warn: #fff2cf;
  --soft: #e8f3f0;
  --shadow: 0 12px 34px rgba(31, 42, 55, 0.1);
}

* { box-sizing: border-box; }

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(10, 15, 24, 0.82);
  padding: 20px;
}
.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 12px;
  padding: 24px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.32);
}
.login-card h1 { font-size: 24px; margin-bottom: 4px; }
.login-card button { width: 100%; }
.login-check {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-height: 20px;
  font-size: 12px;
}
.login-check input { width: 16px; height: 16px; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width, 260px) 1fr;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}

.hq-body {
  display: block;
}

.hq-shell {
  padding: 18px;
}

.hq-topbar {
  justify-content: space-between;
}

.hq-topbar > div:first-child {
  display: block;
}

.hq-workspace {
  grid-template-columns: minmax(360px, 0.75fr) minmax(560px, 1.25fr);
}
.hq-master-metrics { margin-top: 12px; }
.hq-tabs { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; }
.hq-tabs button.active { background: var(--brand); color: #fff; }
.hq-tab { display: none; }
.hq-tab.active { display: block; }
.hq-event-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
  padding: 10px;
  display: grid;
  gap: 8px;
}
#masterStateJson {
  width: 100%;
  min-height: 360px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
}

button, input, select, textarea { font: inherit; }
th[data-player-sort] { cursor: pointer; user-select: none; }
th[data-player-sort]:hover { background: #eef3f7; }

button {
  border: 0;
  border-radius: 6px;
  background: var(--brand);
  color: white;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}

button.secondary { background: #edf2f5; color: var(--ink); }
button.danger { background: #f2e5e5; color: var(--danger); }
button.small { padding: 7px 10px; font-size: 12px; }
button.tiny { padding: 4px 6px; font-size: 11px; margin-right: 4px; }

.sidebar {
  padding: 24px;
  background: #121923;
  color: white;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand { display: flex; gap: 12px; align-items: center; }
.brand > div { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; min-width: 0; }
.brand > div strong, .brand > div small { white-space: nowrap; }
.brand-mark {
  width: 128px;
  min-width: 128px;
  height: 70px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--brand-2);
  color: #111;
  font-weight: 900;
  overflow: hidden;
}
.brand-mark.has-image {
  background: transparent;
  border-radius: 0;
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; }
.brand small, .sidebar .side-card small { color: #aeb8c6; }
.side-card small, .eyebrow, .metric span, .panel-head span, .note { color: var(--muted); }

.nav { display: grid; gap: 8px; }
.nav-btn { background: transparent; color: #d8dee8; text-align: left; padding: 12px 14px; }
.nav-btn.active { background: #243143; color: white; }
.side-card { margin-top: auto; padding: 16px; border: 1px solid #334055; border-radius: 8px; display: grid; gap: 8px; }

.shell { padding: var(--shell-padding, 12px) 14px; min-width: 0; }
.topbar { display: flex; justify-content: flex-end; gap: 8px; align-items: center; margin-bottom: 8px; }
.topbar > div:first-child { display: none; }
.eyebrow { margin: 0 0 4px; text-transform: uppercase; font-size: 12px; font-weight: 800; letter-spacing: 0; }
.current-clock { margin-top: 6px; color: var(--muted); font-size: 13px; font-weight: 800; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 27px; }
h2 { margin-bottom: 0; font-size: 18px; }
h3 { margin-bottom: 0; font-size: 15px; }

.top-actions, .button-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.top-actions { width: 100%; justify-content: flex-end; flex-wrap: nowrap; }
.top-actions select { min-width: 220px; max-width: 520px; flex: 1; padding: 8px 10px; }
.top-actions button { padding: 8px 10px; }
.page { display: none; }
.page.active { display: block; }
.hidden { display: none !important; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 8px; }
.main-metrics { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.closing-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.metric, .panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius, 8px); box-shadow: var(--shadow); }
.metric { padding: 9px 11px; display: grid; gap: 3px; }
.metric span { font-size: 11px; }
.metric strong { font-size: 19px; }
.metric.accent { background: var(--soft); border-color: #c7e1da; }

.workspace { display: grid; gap: 10px; }
.two-col { grid-template-columns: minmax(360px, 0.8fr) minmax(500px, 1.2fr); }
#main .two-col { grid-template-columns: minmax(var(--main-left-width, 380px), 0.78fr) minmax(560px, 1.22fr); }
#main .workspace { min-height: calc(100vh - 104px); }
#main .panel { display: flex; flex-direction: column; }
#main .panel > .table-wrap { flex: 1; min-height: 0; }
#main .table-wrap.compact { max-height: none; }
.panel { padding: 12px; min-width: 0; }
.panel.mt { margin-top: 10px; }
.panel-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 8px; }
.panel-head.tight { margin-bottom: 6px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.settings-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
label { display: grid; gap: 4px; color: #3b4656; font-weight: 700; font-size: 12px; }
.check-label { display: flex; flex-direction: row; align-items: center; gap: 9px; min-height: 42px; padding-top: 23px; }
.check-label input { width: 18px; height: 18px; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 6px; background: #fff; padding: 7px 9px; color: var(--ink); }
textarea { resize: vertical; }
.full { grid-column: 1 / -1; }
.form-actions, .dialog-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; }
.pos-form-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; align-self: stretch; }
.pos-form-actions button { width: 100%; padding: 9px 10px; font-size: 13px; white-space: nowrap; }
.pos-form-actions #cancelEditBtn:not(.hidden) { grid-column: 1 / -1; }

.payment-box { border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: #fafbfc; }
.payment-box .panel-head { margin-bottom: 4px; }
.manual-receipt-box { margin-top: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: #fbfcfd; display: grid; grid-template-columns: 1fr; gap: 6px; }
.manual-receipt-box > h3, .manual-receipt-box > span { display: none; }
.point-transfer-box { margin-top: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: #fbfcfd; flex: 1; min-height: 310px; display: flex; flex-direction: column; }
.point-tools { display: grid; grid-template-columns: 0.75fr 1fr 1fr 1.15fr; gap: 6px; margin-bottom: 6px; }
.point-transfer-wrap { max-height: none; flex: 1; min-height: 230px; }
.manual-receipt-buttons { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
.manual-receipt-buttons button { padding: 6px 6px; font-size: 12px; }
.payment-rows, .method-editor, .unpaid-list { display: grid; gap: 6px; }
.payment-row { display: grid; grid-template-columns: 1fr 0.8fr auto auto; gap: 6px; align-items: center; }
.payment-total { display: flex; justify-content: space-between; margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line); }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.table-search { caption-side: top; padding: 8px; text-align: left; background: #f7f9fb; }
.table-search input { max-width: 220px; padding: 7px 9px; font-size: 12px; }
.check-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.mini-check { display: inline-flex; flex-direction: row; align-items: center; gap: 5px; border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px; background: #fafbfc; font-size: 12px; }
.mini-check input { width: 14px; height: 14px; }
.table-wrap.compact { max-height: calc(100vh - 184px); }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { background: #f7f9fb; color: #4b5666; font-size: 12px; }
.dense-table th, .dense-table td { padding: 4px 6px; font-size: 11.5px; line-height: 1.2; }
.dense-table small { font-size: 10px; color: var(--muted); }
.reg-table { min-width: 760px; }
.table-input { width: 100%; min-width: 74px; border: 1px solid var(--line); border-radius: 5px; padding: 4px 5px; font-size: 11.5px; background: #fff; }
.amount-input { min-width: 96px; text-align: right; font-weight: 800; }
.reg-table td { position: relative; overflow: visible; }
.inline-payment-menu { position: relative; min-width: 180px; }
.inline-payment-toggle { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; cursor: pointer; border: 1px solid var(--line); border-radius: 999px; background: #fff; padding: 4px 7px; font-size: 11px; }
.inline-payment-toggle:after { content: "v"; color: var(--muted); font-size: 10px; }
.inline-payment-methods { display: inline-flex; flex-wrap: wrap; gap: 4px; min-width: 0; }
.inline-payment-chip { display: inline-flex; align-items: center; border-radius: 999px; background: #eef3f6; color: var(--ink); padding: 2px 6px; font-weight: 900; }
.inline-payment-total { margin-left: auto; font-weight: 900; color: var(--brand); }
.inline-payment-grid { position: absolute; left: 0; top: calc(100% + 4px); z-index: 30; display: grid; gap: 4px; min-width: 210px; padding: 7px; border: 1px solid var(--line); box-shadow: 0 10px 24px rgba(24,33,47,0.16); border-radius: 8px; background: #fff; }
.inline-payment-row { display: grid; grid-template-columns: 72px 1fr; gap: 4px; align-items: center; }
.inline-payment-row span { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.inline-total-input { background: #f6f8fa; color: var(--ink); }
.memo-cell { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
.unpaid-row { background: var(--warn); }
.unpaid-badge { display: inline-flex; padding: 3px 7px; border-radius: 999px; background: #e8a526; color: #211600; font-weight: 900; }

.pill { display: inline-flex; align-items: center; min-width: 34px; justify-content: center; border-radius: 999px; padding: 3px 7px; background: #edf2f5; font-size: 11px; font-weight: 800; }
.prize-editor, .payout-editor, .expense-editor, .summary-list { display: grid; gap: 10px; }
.inline-row { display: grid; grid-template-columns: 0.7fr 1fr 1fr 1fr auto; gap: 10px; align-items: end; }
.payout-row { display: grid; grid-template-columns: 0.5fr 0.9fr 1fr 0.9fr 0.9fr 1fr; gap: 10px; align-items: end; }
.expense-row, .method-row { display: grid; grid-template-columns: 1.2fr 1fr auto; gap: 10px; align-items: end; }
.summary-item { display: flex; justify-content: space-between; padding: 11px 13px; border: 1px solid var(--line); border-radius: 8px; background: #fafbfc; }
.payment-summary-item { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; }
.payment-summary-item:not(:has(.button-row)) { grid-template-columns: 1fr auto; }
.collapsible-section { margin-top: 12px; border: 1px solid var(--line); border-radius: 8px; background: #fafbfc; padding: 10px; }
.collapsible-section summary { cursor: pointer; font-size: 13px; font-weight: 900; color: #3b4656; }
.collapsible-section .summary-list { margin-top: 10px; }
.note { margin: 12px 0 0; font-size: 13px; }

.filter-bar { display: grid; grid-template-columns: 0.8fr 1fr 1fr 1.2fr 1fr; gap: 10px; margin-bottom: 14px; }
.closing-filter { grid-template-columns: 0.8fr 1fr 1fr 0.9fr auto; align-items: end; }
.point-filter { grid-template-columns: 0.7fr 1fr 1fr 1.3fr; align-items: end; }
.point-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.point-table { min-width: 460px; }
.point-status { display: inline-flex; justify-content: center; min-width: 58px; border-radius: 999px; padding: 3px 8px; background: #edf2f5; font-weight: 900; }
.point-status.done { background: #e1f4ed; color: #176b5d; }
.point-status.hold { background: #fff2cf; color: #7b5200; }
.detail-box { margin-top: 14px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: #fafbfc; }
.detail-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.detail-grid span { padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: white; }
.unpaid-card { display: grid; grid-template-columns: 1.3fr 0.7fr 0.7fr 0.7fr auto; gap: 8px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fffaf0; }
.unpaid-card div { display: grid; gap: 3px; }
.unpaid-card span { color: var(--muted); font-size: 12px; }
.unpaid-total-row { border-color: #b9d6cc; background: #eef8f5; }
.unpaid-event-list { display: grid; gap: 6px; }
.unpaid-event-row { padding: 8px 11px; background: #f7fbfa; }
.unpaid-group-card { background: #fff4dc; border-color: #ead09a; }
.logo-preview-row { display: flex; gap: 10px; align-items: center; justify-content: space-between; border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: #fafbfc; }
.logo-preview { display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: 13px; }
.logo-preview img { width: 120px; height: 70px; object-fit: contain; border-radius: 8px; border: 1px solid var(--line); background: white; }
.backup-actions { align-items: end; }
.backup-file-label { display: inline-grid; width: auto; }
.backup-file-label input { max-width: 230px; }

dialog { border: 0; border-radius: 8px; padding: 0; box-shadow: 0 22px 70px rgba(0, 0, 0, 0.28); }
dialog::backdrop { background: rgba(11, 16, 24, 0.55); }
.receipt { width: 58mm; padding: 0; font-family: Arial, "Malgun Gothic", sans-serif; color: #000; white-space: normal; font-size: 12px; background: white; }
.receipt-designer { display: grid; grid-template-columns: minmax(420px, 1fr) 430px; gap: 18px; align-items: start; }
.receipt-controls { min-width: 0; }
.receipt-controls details { margin-top: 14px; border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #fafbfc; }
.receipt-controls summary { cursor: pointer; font-weight: 900; margin-bottom: 10px; }
.receipt-controls details label { margin-top: 10px; }
.receipt-preview-pane { position: sticky; top: 16px; border: 1px solid var(--line); border-radius: 8px; padding: 14px; background: #f8fafc; min-height: 430px; overflow: auto; }
.receipt.preview { border: 1px dashed var(--line); box-shadow: inset 0 0 0 1px #fff; max-width: none; min-height: 520px; overflow: visible; transform: scale(1.28); transform-origin: top left; margin-bottom: 150px; }
.receipt-grid-preview {
  background-image:
    linear-gradient(rgba(23, 107, 93, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 107, 93, 0.12) 1px, transparent 1px);
  background-size: 5mm 5mm;
}
.receipt-save-row { margin-top: 10px; display: flex; justify-content: flex-end; }
.receipt-copy-panel {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  background: #fafbfc;
}
.receipt-drag-target { cursor: move; touch-action: none; outline: 1px dashed transparent; outline-offset: 2px; }
.receipt-drag-target:hover { outline-color: #3678ff; }
.dialog-actions { padding: 14px; border-top: 1px solid var(--line); }
.ticket { width: 79mm; height: 118mm; padding: 2mm 0 3mm; background: white; overflow: hidden; }
.ticket-logo { text-align: center; padding: 0 3mm 3.5mm; }
.stars { width: 31mm; margin: 0 auto 1mm; display: flex; justify-content: space-between; font-size: 10px; font-weight: 900; line-height: 1; transform: translate(var(--receipt-stars-x, 0mm), var(--receipt-stars-y, 0mm)); }
.anpt-logo { font-size: var(--receipt-logo-font, 40px); line-height: 0.88; font-weight: 1000; font-style: italic; letter-spacing: -3px; transform: translate(var(--receipt-logo-x, 0mm), var(--receipt-logo-y, 0mm)) skew(-8deg); }
.tour { margin-top: 1.5mm; font-size: var(--receipt-tour-font, 7px); font-weight: 900; letter-spacing: 1.1px; font-style: italic; transform: translate(var(--receipt-tour-x, 0mm), var(--receipt-tour-y, 0mm)); }
.ticket-title { border-top: 2px solid #000; border-bottom: 2px solid #000; text-align: center; padding: 2mm 1mm 2.2mm; display: grid; gap: 0.8mm; transform: translateY(var(--receipt-title-y, 0mm)); }
.ticket-title strong { font-size: var(--receipt-title-font, 16px); line-height: 1.05; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ticket-title span { font-size: 15px; line-height: 1.05; font-weight: 900; white-space: nowrap; }
.ticket-body { display: grid; grid-template-columns: 42mm 30mm; gap: 1mm; padding: 15mm 2mm 0; align-items: center; }
.ticket-lines { display: grid; gap: 1.4mm; font-size: var(--receipt-info-font, 13px); align-self: start; padding-top: 2mm; transform: translate(var(--receipt-info-x, 0mm), var(--receipt-info-y, 0mm)); }
.ticket-lines div { display: grid; grid-template-columns: 17mm 1fr; gap: 1.5mm; align-items: baseline; }
.ticket-lines span { font-size: 13px; font-weight: 500; }
.ticket-lines strong { font-size: 15px; font-weight: 900; white-space: nowrap; }
.ticket-code { font-size: var(--receipt-code-font, 34mm); line-height: 0.8; font-weight: 1000; text-align: center; letter-spacing: -3px; align-self: center; transform: translate(var(--receipt-code-x, 0mm), var(--receipt-code-y, 0mm)); }
.ticket-footer { margin: 6mm auto 0; width: 62mm; border: 1px solid #3678ff; padding: 0.7mm 1mm; font-size: var(--receipt-footer-font, 10px); font-weight: 900; white-space: nowrap; text-align: center; transform: translate(var(--receipt-footer-x, 0mm), var(--receipt-footer-y, 0mm)); }
.manual-ticket { width: 79mm; height: 70mm; padding: 5mm 6mm; display: grid; grid-template-rows: auto auto 1fr auto auto auto; gap: 3mm; align-items: center; background: white; }
.manual-logo { text-align: center; font-size: 30px; line-height: 1; font-weight: 1000; font-style: italic; letter-spacing: -1px; }
.manual-event { text-align: center; font-size: 14px; font-weight: 900; border-top: 2px solid #000; border-bottom: 2px solid #000; padding: 2mm 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.manual-kind { text-align: center; font-size: 24px; font-weight: 1000; }
.manual-row { display: grid; grid-template-columns: 19mm 1fr; gap: 4mm; font-size: 15px; align-items: baseline; }
.manual-row strong { font-size: 18px; white-space: nowrap; }
.manual-footer { border: 1px solid #3678ff; padding: 1mm; text-align: center; font-size: 10px; font-weight: 900; white-space: nowrap; }

@media (max-width: 1200px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .nav { grid-template-columns: repeat(6, minmax(120px, 1fr)); overflow: auto; }
  .topbar, .two-col { grid-template-columns: 1fr; display: grid; }
  .metric-grid, .main-metrics, .closing-grid, .settings-grid, .filter-bar, .point-summary, .receipt-designer { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .receipt-preview-pane { position: static; }
}

@media (max-width: 760px) {
  .shell { padding: 14px; }
  .form-grid, .settings-grid, .metric-grid, .main-metrics, .closing-grid, .inline-row, .payout-row, .expense-row, .payment-row, .method-row, .filter-bar, .point-tools, .point-summary, .detail-grid, .unpaid-card, .receipt-designer { grid-template-columns: 1fr; }
}

@media print {
  body > *:not(dialog) { display: none !important; }
  dialog, dialog[open] { display: block; position: static; box-shadow: none; }
  .dialog-actions { display: none; }
}
