:root,
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1419;
  --bg-elevated: #151c26;
  --card: #1a2332;
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8eef7;
  --muted: #8b9bb4;
  --accent: #3d8bfd;
  --accent-hover: #5a9dff;
  --accent-soft: rgba(61, 139, 253, 0.16);
  --ok: #3dd68c;
  --ok-soft: rgba(61, 214, 140, 0.12);
  --bad: #f07178;
  --bad-soft: rgba(240, 113, 120, 0.12);
  --warn: #e6c07b;
  --tab-h: 48px;
  --header-bg: rgba(15, 20, 25, 0.85);
  --glow-1: #1e3a5f;
  --glow-2: #1a2f45;
  --shadow: rgba(0, 0, 0, 0.35);
  --shadow-strong: rgba(0, 0, 0, 0.45);
  --hover-fill: rgba(255, 255, 255, 0.04);
  --row-hover: rgba(255, 255, 255, 0.03);
  --surface-inset: rgba(0, 0, 0, 0.28);
  --surface-soft: rgba(0, 0, 0, 0.12);
  --input-bg: rgba(0, 0, 0, 0.22);
  --pill-bg: rgba(255, 255, 255, 0.08);
  --overlay: rgba(4, 8, 16, 0.62);
  --overlay-strong: rgba(0, 0, 0, 0.55);
  --media-bg: #0a0e14;
  --editor-bg: #0c121a;
  --status-chip: rgba(255, 255, 255, 0.06);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #eef2f7;
  --bg-elevated: #ffffff;
  --card: #ffffff;
  --border: rgba(15, 23, 42, 0.12);
  --text: #152033;
  --muted: #5b6b82;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.12);
  --ok: #15803d;
  --ok-soft: rgba(21, 128, 61, 0.12);
  --bad: #dc2626;
  --bad-soft: rgba(220, 38, 38, 0.1);
  --warn: #b45309;
  --header-bg: rgba(255, 255, 255, 0.9);
  --glow-1: #dbeafe;
  --glow-2: #e0e7ff;
  --shadow: rgba(15, 23, 42, 0.1);
  --shadow-strong: rgba(15, 23, 42, 0.18);
  --hover-fill: rgba(15, 23, 42, 0.05);
  --row-hover: rgba(15, 23, 42, 0.035);
  --surface-inset: rgba(15, 23, 42, 0.04);
  --surface-soft: rgba(15, 23, 42, 0.035);
  --input-bg: rgba(15, 23, 42, 0.04);
  --pill-bg: rgba(15, 23, 42, 0.06);
  --overlay: rgba(15, 23, 42, 0.42);
  --overlay-strong: rgba(15, 23, 42, 0.45);
  --media-bg: #e8edf5;
  --editor-bg: #f8fafc;
  --status-chip: rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(1000px 500px at 15% -5%, var(--glow-1) 0%, transparent 55%),
    radial-gradient(800px 400px at 90% 10%, var(--glow-2) 0%, transparent 50%),
    var(--bg);
  color: var(--text);
}

/* 앱 화면일 때 문서 전체 스크롤 막고, 탭 콘텐츠만 스크롤 */
body:has(#view-app:not(.hidden)) {
  height: 100%;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ── Login / 비밀번호 변경 ── */
#view-login,
#view-change-password {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-brand {
  text-align: center;
  margin-bottom: 28px;
}

.login-brand h1 {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.login-brand p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.95rem;
}

.login-card {
  width: min(400px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: 0 20px 50px var(--shadow);
}

.login-card h2 {
  font-size: 1.2rem;
  font-weight: 650;
  margin-bottom: 6px;
}

.login-mode-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  padding: 4px;
  border-radius: 10px;
  background: var(--hover-fill);
  border: 1px solid var(--border);
}

.login-mode-tab {
  flex: 1;
  border: none;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--muted);
}

.login-mode-tab.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 3px var(--shadow);
}

.login-form .field {
  margin-bottom: 12px;
}

.login-form .field input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.login-form .field-with-action {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.login-form .field-with-action input {
  flex: 1 1 auto;
  min-width: 0;
}

.login-form .field-with-action .btn-ghost {
  flex: 0 0 auto;
  white-space: nowrap;
  padding: 8px 12px;
}

.field-status {
  margin-top: 6px;
  font-size: 0.8rem;
  min-height: 1.1em;
  color: var(--muted);
}

.field-status.is-ok {
  color: var(--accent);
}

.field-status.is-bad {
  color: var(--bad);
}

.login-form .field input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-form .btn-primary {
  margin-top: 8px;
}

.login-forgot-link {
  display: block;
  width: 100%;
  margin-top: 12px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.login-forgot-link:hover {
  color: var(--accent);
}

.login-card .hint {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 0.85rem;
  text-decoration: none;
}

a.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--hover-fill);
}

.login-error {
  margin-top: 14px;
  color: var(--bad);
  font-size: 0.85rem;
  min-height: 1.2em;
}

.login-error.login-ok {
  color: var(--accent);
}

/* ── App shell ── */
#view-app {
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tab-h);
  padding: 0 10px 0 8px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  z-index: 30;
}

.app-topbar .user-meta {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.user-badge {
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.75rem;
}

.theme-toggle {
  min-width: 72px;
  padding: 6px 10px;
  font-size: 0.8rem;
}

.app-topbar .btn-ghost {
  padding: 6px 10px;
  font-size: 0.8rem;
}

.login-theme-bar {
  position: absolute;
  top: 16px;
  right: 16px;
}

/* ── Tabs ── */
.tab-bar {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  gap: 2px;
  padding: 0;
  overflow-x: auto;
  background: transparent;
  border: none;
}

.tab-btn {
  flex: 0 0 auto;
  height: var(--tab-h);
  padding: 0 14px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-panels {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 20px;
  scrollbar-gutter: stable;
}

.tab-panel {
  display: none;
  animation: fadeIn 0.2s ease;
}

.tab-panel.active {
  display: block;
}

.tab-panel.active[data-panel="devices"],
.tab-panel.active[data-panel="logs"] {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.devices-table-panel,
.logs-table-panel {
  flex: 1 1 auto;
  min-height: 0;
}

.devices-table-panel > .table-wrap,
.logs-table-panel > .table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.panel-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.panel-toolbar h2 {
  font-size: 1.15rem;
  font-weight: 650;
}

.panel-toolbar .sub {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 2px;
}

.placeholder-box {
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: 14px;
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
}

.placeholder-box strong {
  display: block;
  color: var(--text);
  font-size: 1.05rem;
  margin-bottom: 8px;
}

/* ── Table ── */
.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: auto;
}

.table-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  gap: 8px;
}

.table-panel > .table-wrap {
  flex: 1 1 auto;
  min-height: 0;
}

table.devices {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.88rem;
  min-width: 900px;
  table-layout: fixed;
}

table.devices.is-resizable {
  width: max-content;
  max-width: none;
}

table.devices th,
table.devices td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
}

table.devices th:last-child,
table.devices td:last-child {
  border-right: 1px solid var(--border);
}

table.devices th:last-child .col-resize-handle {
  right: 0;
}

table.devices th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-inset);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  user-select: none;
}

table.devices tbody tr:hover {
  background: var(--row-hover);
}

table.devices tbody tr:last-child td {
  border-bottom: none;
}

table.devices .col-num,
table.devices .col-amount,
table.devices td.col-num,
table.devices td.col-amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.col-resize-handle {
  position: absolute;
  top: 0;
  right: -5px;
  width: 11px;
  height: 100%;
  cursor: col-resize;
  z-index: 3;
}

.col-resize-handle::after {
  content: "";
  position: absolute;
  top: 18%;
  bottom: 18%;
  left: 5px;
  width: 2px;
  border-radius: 1px;
  background: transparent;
  transition: background 0.12s ease;
}

table.devices th:hover .col-resize-handle::after,
.col-resize-handle.is-active::after {
  background: var(--accent);
}

body.is-col-resizing {
  cursor: col-resize !important;
  user-select: none !important;
}

body.is-col-resizing * {
  cursor: col-resize !important;
}

.table-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 0 2px;
}

.table-pager-meta {
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.table-pager-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.table-pager-actions .btn {
  min-width: 64px;
}

.table-pager-page {
  min-width: 64px;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.8rem;
  word-break: break-all;
}

table.devices td.mono {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}

.status-pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 650;
  background: var(--pill-bg);
  color: var(--muted);
}

.status-pill.online {
  color: var(--ok);
  background: var(--ok-soft);
}

.status-pill.offline {
  color: var(--bad);
  background: var(--bad-soft);
}

a.log-link {
  color: var(--accent);
  text-decoration: none;
}

a.log-link:hover {
  text-decoration: underline;
}

/* ── Sales ── */
.sales-period {
  margin: 0;
  flex-wrap: wrap;
}

.sales-ym-fields {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.sales-ym-fields[hidden] {
  display: none !important;
}

.sales-ym-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
  color: var(--muted);
}

.sales-ym-field input {
  width: 5.5rem;
  min-height: 34px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
}

.sales-top-row {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.sales-machine-filter {
  flex: 0 1 auto;
  width: min(720px, 100%);
  max-width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 12px;
  margin-bottom: 0;
}

.sales-machine-filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: nowrap;
}

.sales-machine-filter-summary {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.sales-machine-filter-label {
  font-weight: 600;
  font-size: 0.9rem;
}

.sales-machine-filter-meta {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.sales-machine-filter-actions,
.sales-machine-picker-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.sales-machine-picker {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-sizing: border-box;
}

.sales-machine-picker[hidden] {
  display: none !important;
}

.sales-machine-picker-backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.sales-machine-picker-panel {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  max-height: min(80vh, 680px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  box-shadow: 0 24px 64px var(--shadow-strong);
  padding: 14px;
}

body.sales-machine-picker-open {
  overflow: hidden;
}

.sales-machine-picker-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.sales-machine-search-field {
  display: block;
  flex: 1 1 220px;
  margin: 0;
}

.sales-machine-search-field input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.9rem;
}

.sales-machine-search-field input:focus {
  outline: none;
  border-color: rgba(61, 139, 253, 0.55);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.sales-machine-picker-hint {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.sales-machine-table-wrap {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: auto;
  flex: 1 1 auto;
  min-height: 180px;
  max-height: min(420px, 52vh);
  background: var(--surface-soft);
}

.sales-machine-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
}

.sales-machine-page-label {
  min-width: 72px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

table.sales-machine-table {
  min-width: 480px;
  margin: 0;
}

table.sales-machine-table th,
table.sales-machine-table td {
  padding: 7px 10px;
  font-size: 0.86rem;
}

table.sales-machine-table th.col-check,
table.sales-machine-table td.col-check {
  width: 56px;
  text-align: center;
  vertical-align: middle;
}

table.sales-machine-table tbody tr {
  cursor: pointer;
}

table.sales-machine-table tbody tr:hover {
  background: var(--hover-fill);
}

table.sales-machine-table tbody tr.is-selected {
  background: var(--accent-soft);
}

table.sales-machine-table input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  margin: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sales-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(96px, 132px));
  gap: 8px;
  margin: 0 0 0 auto;
  width: auto;
  flex: 0 1 auto;
  align-content: center;
}

.sales-stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  min-width: 0;
}

.sales-stat .label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.sales-stat .value {
  margin-top: 4px;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  word-break: break-word;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.sales-stat--err .value {
  color: var(--bad);
  font-size: 0.95rem;
  font-weight: 600;
}

.sales-sections {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr);
  align-items: stretch;
  gap: 16px;
  margin-bottom: 16px;
}

.sales-section {
  min-width: 0;
}

.sales-sections > .sales-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sales-sections > .sales-section > .table-panel {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 220px;
}

.sales-sections > .sales-section > .table-panel > .table-wrap {
  flex: 1 1 auto;
  min-height: 0;
}

.sales-section-title {
  font-size: 0.9rem;
  font-weight: 650;
  color: var(--muted);
  margin: 0 0 8px;
}

table.sales-by-machine {
  min-width: 520px;
}

table.sales-by-day {
  min-width: 0;
  width: max-content;
}

table.sales-by-entries {
  min-width: 720px;
}

@media (max-width: 900px) {
  .sales-sections {
    grid-template-columns: 1fr;
  }

  .sales-sections > .sales-section > .table-panel {
    min-height: 180px;
  }
}

.empty-state,
.error-state {
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
}

.error-state {
  color: var(--bad);
}

.loading-row td {
  text-align: center;
  color: var(--muted);
  padding: 28px;
}

/* ── Scrollbar (dark) ── */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(139, 155, 180, 0.45) transparent;
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: rgba(139, 155, 180, 0.35);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
  background: rgba(139, 155, 180, 0.55);
  border: 2px solid transparent;
  background-clip: padding-box;
}

*::-webkit-scrollbar-corner {
  background: transparent;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-accent {
  background: var(--accent);
  color: #fff;
  padding: 8px 14px;
  font-size: 0.85rem;
}

.btn-accent:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-danger {
  background: var(--bad-soft);
  color: var(--bad);
  border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent);
  padding: 8px 12px;
  font-size: 0.85rem;
}

.btn-danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--bad) 22%, transparent);
}

.manifest-meta {
  margin-left: 8px;
  color: var(--muted);
}

.inline-status {
  min-height: 1.2em;
  margin-bottom: 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

.inline-status.ok { color: var(--ok); }
.inline-status.err { color: var(--bad); }

.ai-balance-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
}

.ai-balance-text {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.ai-balance-text.ai-balance-ok { color: var(--ok); }
.ai-balance-text.ai-balance-error { color: var(--bad); }

.content-subtabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.content-subtab {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  cursor: pointer;
}

.content-subtab.active {
  background: var(--accent-soft);
  border-color: rgba(61, 139, 253, 0.45);
  color: var(--text);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.chip {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  cursor: pointer;
}

.chip.active {
  color: var(--text);
  border-color: rgba(61, 139, 253, 0.45);
  background: var(--accent-soft);
}

.catalog-panel {
  margin-top: 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px 16px;
}

#card-category-panel {
  margin-top: 12px;
  margin-bottom: 16px;
}

.card-category-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-category-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 6px 6px 6px 14px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.card-category-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.card-category-row .cat-label {
  flex: 1;
  min-width: 0;
  width: auto;
  color: var(--text);
  background: transparent;
  border: none;
  padding: 8px 4px;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-category-row .cat-label::placeholder {
  color: var(--muted);
  font-weight: 500;
}

.card-category-row .cat-label:focus {
  outline: none;
}

.cat-row-actions {
  display: flex;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
}

.cat-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 36px;
  padding: 0 10px;
  border-radius: 10px;
  font-size: 0.8rem;
  white-space: nowrap;
}

.cat-action-btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  display: block;
}

.card-cat-select {
  width: 100%;
  margin-top: 6px;
}

.catalog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.catalog-head h3 {
  font-size: 0.95rem;
  font-weight: 650;
}

.catalog-editor {
  width: 100%;
  margin-top: 10px;
  background: var(--editor-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.45;
  resize: vertical;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ── Content grid ── */
.content-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.content-empty,
.content-error {
  grid-column: 1 / -1;
  padding: 48px 20px;
  text-align: center;
  color: var(--muted);
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: 14px;
}

.content-error {
  color: var(--bad);
}

.card-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s ease, transform 0.12s ease;
}

.card-tile:hover {
  border-color: rgba(61, 139, 253, 0.45);
  transform: translateY(-1px);
}

.card-thumb {
  aspect-ratio: 3 / 4;
  background: var(--media-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
}

.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-thumb .no-img {
  color: var(--muted);
  font-size: 0.8rem;
  padding: 12px;
  text-align: center;
}

.card-meta {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-meta .id {
  font-weight: 700;
  font-size: 0.95rem;
}

.card-meta .label {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.3;
}

.card-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.flag {
  font-size: 0.68rem;
  font-weight: 650;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--status-chip);
  color: var(--muted);
}

.flag.on {
  color: var(--ok);
  background: var(--ok-soft);
}

.flag.off {
  color: var(--bad);
  background: var(--bad-soft);
}

.card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.card-actions .btn {
  flex: 1;
  min-width: 0;
  padding: 7px 8px;
  font-size: 0.78rem;
}

/* ── Modal ── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay-strong);
}

.modal-sheet {
  position: relative;
  width: min(440px, 100%);
  max-height: min(90vh, 720px);
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 24px 60px var(--shadow-strong);
  z-index: 1;
  scrollbar-gutter: stable;
}

.modal-sheet-wide {
  width: min(720px, 100%);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-head h3 {
  font-size: 1.1rem;
  font-weight: 650;
}

.upload-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.field input[type="text"],
.field input[type="tel"],
.field input[type="file"] {
  color: var(--text);
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
}

.field input[type="text"]:focus,
.field input[type="tel"]:focus {
  outline: none;
  border-color: var(--accent);
}

.field-hint {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}

.form-error {
  min-height: 1.2em;
  margin: 0;
  font-size: 0.85rem;
  color: var(--bad);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}

.modal-actions .btn {
  width: auto;
  min-width: 5.5rem;
  flex: 0 0 auto;
  white-space: nowrap;
  padding: 10px 16px;
}

.modal-actions .btn-primary {
  width: auto;
}

.modal-actions .modal-action-start {
  margin-right: auto;
}

.btn-table {
  padding: 4px 10px;
  font-size: 0.8rem;
  white-space: nowrap;
}

th.col-actions,
td.col-actions {
  width: 4.5rem;
  text-align: center;
}

.detail-body {
  display: grid;
  gap: 16px;
}

.detail-preview {
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  background: var(--media-bg);
  border-radius: 12px;
  border: 1px solid var(--border);
}

.detail-prompt {
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.78rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow: auto;
  color: var(--text);
}

/* ���� App releases (OTA) ���� */
.release-latest-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
}

.release-latest-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px 18px;
}

.release-latest-wide {
  grid-column: 1 / -1;
}

.release-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.release-hash {
  display: block;
  word-break: break-all;
  font-size: 0.78rem;
}

.release-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.btn-tiny {
  padding: 4px 10px;
  font-size: 0.8rem;
  min-height: 0;
}

.chip-ok {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ok, #1a7f4b) 18%, transparent);
  color: var(--ok, #1a7f4b);
  font-size: 0.75rem;
  font-weight: 600;
}

.field-check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field-check input[type="checkbox"] {
  width: auto;
}

.settlement-pane.hidden {
  display: none;
}

.settlement-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px 18px;
  margin-bottom: 16px;
}

.settlement-card h3 {
  font-size: 0.98rem;
  font-weight: 650;
  margin: 0 0 10px;
}

.settlement-card h3:not(:first-child) {
  margin-top: 18px;
}

.settlement-common-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin: 8px 0 14px;
}

.settlement-common-box {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--bg, transparent);
}

.settlement-common-box h4 {
  margin: 0 0 10px;
  font-size: 0.88rem;
}

.field-row-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.settlement-balance-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 4px;
}

.settlement-balance {
  min-height: 1.2em;
  font-weight: 650;
}

.settlement-summary {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
}

.settlement-summary .chip-stat {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.settlement-summary .chip-stat span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}

.settlement-summary .chip-stat strong {
  font-size: 0.95rem;
}

.settlement-batch-detail {
  margin-top: 12px;
}

.form-error {
  color: var(--bad);
  min-height: 1.2em;
  font-size: 0.85rem;
}

@media (max-width: 900px) {
  .field-row-4 {
    grid-template-columns: 1fr 1fr;
  }
}

/* =========================================================================
   AI 생성 탭
   ========================================================================= */

.tab-panel.active[data-panel="ai-gen"] {
  display: flex;
  flex-direction: column;
  min-height: 0;
  container-type: inline-size;
  container-name: ai-gen;
}

.ai-gen-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
  padding: 0 0 16px;
}

.ai-gen-input-col,
.ai-gen-result-col {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  box-sizing: border-box;
}

.ai-gen-input-col {
  padding-right: 4px;
}

.ai-gen-result-col {
  padding-left: 4px;
}

.ai-gen-textarea {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  resize: vertical;
  font-family: inherit;
  font-size: 0.95rem;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-inset);
  color: var(--text);
  min-height: 140px;
}
.ai-gen-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.ai-gen-options {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.ai-gen-option-model {
  grid-column: 1 / -1;
}

.ai-gen-options .field {
  min-width: 0;
}

.ai-gen-options select,
.ai-gen-input-col input,
.ai-gen-result-col input {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  color: var(--text);
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
}

.ai-gen-options select:focus,
.ai-gen-input-col input:focus,
.ai-gen-result-col input:focus {
  outline: none;
  border-color: var(--accent);
}

.ai-gen-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.ai-gen-prompt-box {
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  min-width: 0;
}
.ai-gen-prompt-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--muted);
}
.ai-gen-prompt-text {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--text);
  margin: 0;
  max-height: 220px;
  overflow-y: auto;
}

.ai-gen-preview-area {
  flex: 1 1 auto;
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
}

.ai-gen-preview-placeholder {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 32px;
  text-align: center;
}

.ai-gen-images {
  display: flex;
  gap: 16px;
  padding: 16px;
  width: 100%;
  box-sizing: border-box;
  flex-wrap: wrap;
  justify-content: center;
}

.ai-gen-image-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
}

.ai-gen-image-label {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0;
}

.ai-gen-preview-img {
  max-height: 420px;
  max-width: 100%;
  border-radius: 6px;
  object-fit: contain;
  box-shadow: 0 2px 12px var(--shadow);
}

.ai-gen-preview-thumb {
  max-height: 160px;
  max-width: 200px;
  border-radius: 6px;
  object-fit: contain;
  box-shadow: 0 2px 8px var(--shadow);
}

.ai-gen-elapsed {
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
  margin: 4px 0 0;
  width: 100%;
}

.ai-gen-upload-form {
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.ai-gen-card-id-input {
  font-size: 1rem;
  font-weight: 600;
}

.ai-gen-upload-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.ai-gen-prompt-json-details {
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  min-width: 0;
}
.ai-gen-prompt-json-details summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.ai-gen-library {
  margin-top: 28px;
}

.ai-library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-top: 12px;
}

@keyframes ai-spin {
  to { transform: rotate(360deg); }
}
.ai-gen-spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: ai-spin 0.7s linear infinite;
}

.ai-gen-spinner-inline {
  width: 13px;
  height: 13px;
  border-width: 2px;
  vertical-align: -2px;
  margin-right: 6px;
  border-top-color: currentColor;
  opacity: 0.9;
}

/* 패널 가로가 좁으면 입력(위) · 결과(아래) */
@container ai-gen (max-width: 980px) {
  .ai-gen-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .ai-gen-result-col {
    padding-left: 0;
  }
  .ai-gen-preview-area {
    min-height: 280px;
  }
}

@media (max-width: 1100px) {
  .ai-gen-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .ai-gen-result-col {
    padding-left: 0;
  }
}

@media (max-width: 600px) {
  .ai-gen-options {
    grid-template-columns: minmax(0, 1fr);
  }
  .ai-gen-actions,
  .ai-gen-upload-actions {
    flex-direction: column;
  }
}

