* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: #fff;
  color: #000;
  font-family: monospace;
  font-size: 13px;
  height: 100%;
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-rows: 36px 30px auto auto 1fr;
  height: 100vh;
}

/* NAV / HEADER */
header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  border-bottom: 1px solid #ccc;
  background: #f5f5f5;
}
.logo { font-weight: bold; font-size: 14px; }
.sheet-name { font-size: 11px; border: 1px solid #ccc; padding: 1px 5px; }
.spacer { flex: 1; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #ccc; flex-shrink: 0; }
.status-dot.live { background: green; }
.status-dot.loading { background: orange; }
.status-dot.error { background: red; }
.status-text { font-size: 11px; }
.cell-count { font-size: 11px; color: #555; }
.nav-tabs { display: flex; gap: 4px; }
.nav-tab {
  padding: 0 10px;
  font-size: 11px;
  color: #333;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  height: 36px;
}
.nav-tab:hover, .nav-tab.active { border-color: #999; background: #e8e8e8; }
.nav-tab svg { display: none; }

/* SHEET TABS */
.sheet-tab-bar {
  display: flex;
  align-items: center;
  padding: 0 8px;
  background: #f0f0f0;
  border-bottom: 1px solid #ccc;
  overflow-x: auto;
  gap: 2px;
}
.sheet-tab {
  padding: 2px 10px;
  font-size: 11px;
  cursor: pointer;
  border: 1px solid #ccc;
  background: #fff;
  white-space: nowrap;
}
.sheet-tab.active { background: #ddd; font-weight: bold; }
.sheet-tab.tab-active-today { background: #d4ffd4; }
.sheet-tab.tab-force { background: #fff3cd; }
.sheet-tab.tab-disabled { opacity: 0.4; cursor: not-allowed; }
.tab-dot { display: none; }
.tab-date-badge { font-size: 9px; margin-left: 4px; color: #555; }
.sheet-tab-loading { font-size: 11px; color: #888; padding: 2px 8px; }

/* DEBUG BAR */
.debug-day-bar {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  background: #fff3cd;
  border-bottom: 1px solid #f0ad4e;
  font-size: 11px;
}
.debug-day-bar.visible { display: flex; }
.debug-day-input { width: 44px; padding: 1px 4px; border: 1px solid #ccc; }
.today-badge { font-size: 11px; margin-left: auto; }

/* AUTO-ID BANNER */
.auto-id-banner {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background: #fff3cd;
  border-bottom: 1px solid #ccc;
  font-size: 11px;
}
.auto-id-banner.visible { display: flex; }
.auto-id-progress { height: 6px; flex: 1; background: #ddd; }
.auto-id-progress-bar { height: 100%; background: #555; transition: width 0.2s; }

/* TOOLBAR */
.toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-bottom: 1px solid #ccc;
  background: #f5f5f5;
  overflow-x: auto;
}
.btn {
  padding: 3px 8px;
  border: 1px solid #aaa;
  background: #fff;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  font-family: monospace;
}
.btn:hover { background: #e8e8e8; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn svg { display: none; }
.divider { width: 1px; height: 18px; background: #ccc; margin: 0 2px; }
.auto-label { font-size: 11px; }
.interval-select { font-size: 11px; padding: 2px 4px; border: 1px solid #aaa; background: #fff; font-family: monospace; }
.countdown-badge { font-size: 11px; display: none; }
.search-wrap { margin-left: auto; position: relative; }
.search-icon { display: none; }
.search-input { padding: 3px 6px; border: 1px solid #aaa; font-size: 11px; width: 160px; font-family: monospace; }

/* TABLE */
.table-wrap { overflow: auto; position: relative; background: #fff; }
table { border-collapse: collapse; min-width: 100%; font-size: 12px; }

.rn {
  width: 36px; min-width: 36px; max-width: 36px;
  text-align: center; font-size: 10px; color: #888;
  background: #f5f5f5;
  border-right: 1px solid #ddd;
  position: sticky; left: 0; z-index: 2;
}
thead th.rn { z-index: 4; }

thead th {
  background: #f0f0f0;
  color: #333;
  font-size: 11px;
  font-weight: bold;
  padding: 0;
  border-bottom: 2px solid #aaa;
  border-right: 1px solid #ddd;
  white-space: nowrap;
  position: sticky; top: 0; z-index: 3;
  min-width: 110px;
  vertical-align: top;
}
thead th:last-child { border-right: none; }

.th-inner { display: flex; flex-direction: column; }
.th-top { display: flex; align-items: center; gap: 4px; padding: 4px 6px; cursor: pointer; }
.th-top:hover { background: #e0e0e0; }
.th-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.sort-icon { font-size: 9px; opacity: 0.5; }
thead th.sorted-asc .sort-icon::after { content: '↑'; opacity: 1; }
thead th.sorted-desc .sort-icon::after { content: '↓'; opacity: 1; }
.sort-icon:not(.has-sort)::after { content: '↕'; }

.th-tags { display: flex; flex-wrap: wrap; gap: 2px; padding: 0 4px 4px; }
.th-tags:empty { display: none; }

.tag-pill {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 1px 4px; font-size: 9px; border: 1px solid #ccc;
  background: #eee; cursor: default;
}
.tag-remove { cursor: pointer; font-size: 10px; }
.tag-remove:hover { color: red; }

.th-tag-btn {
  padding: 1px 5px; font-size: 9px; cursor: pointer;
  border: 1px dashed #aaa; background: transparent;
  font-family: monospace;
}
.th-tag-btn:hover { border-color: #333; }

tbody tr { border-bottom: 1px solid #eee; }
tbody tr:hover { background: #f9f9f9; }

tbody td {
  padding: 0; height: 36px;
  border-right: 1px solid #eee;
  vertical-align: middle; position: relative; min-width: 110px;
}
tbody td:last-child { border-right: none; }

.cell-inner {
  display: block; width: 100%; height: 100%;
  padding: 0 8px; line-height: 36px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: text;
}
.cell-inner:hover { background: #f0f0f0; }
.cell-inner.link-cell { color: blue; text-decoration: underline; cursor: pointer; }
.cell-inner.image-cell { color: #555; cursor: pointer; }

.cell-edit {
  display: none; position: absolute; inset: 0; width: 100%; height: 100%;
  padding: 0 8px; border: 2px solid #333;
  background: #fff; color: #000; font-family: monospace; font-size: 12px; outline: none; z-index: 10;
}
td.editing .cell-inner, td.editing .access-cell, td.editing .access-status-cell { display: none; }
td.editing .cell-edit { display: block; }
td.saving .cell-inner { opacity: 0.5; }

/* ACCESS */
.access-cell { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; cursor: pointer; }
.access-checkbox {
  width: 16px; height: 16px; border: 1px solid #aaa;
  display: flex; align-items: center; justify-content: center;
}
.access-checkbox.checked { background: #aaa; }
.access-checkbox.checked::after {
  content: ''; display: block; width: 4px; height: 8px;
  border-right: 2px solid #fff; border-bottom: 2px solid #fff;
  transform: rotate(45deg) translate(-1px, -1px);
}

.access-status-cell { display: flex; align-items: center; gap: 4px; padding: 0 6px; height: 100%; }
.access-status-value { flex: 1; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: text; }
.timespan-badge { padding: 1px 5px; font-size: 9px; border: 1px solid #aaa; background: #eee; white-space: nowrap; }
.timespan-badge.active { background: #d4ffd4; border-color: green; }
.timespan-badge.inactive { background: #ffd4d4; border-color: red; }

/* ID / BARCODE */
.id-cell { display: flex; align-items: center; gap: 6px; padding: 0 8px; height: 100%; }
.id-value { font-weight: bold; }
.id-gen-btn { padding: 1px 6px; font-size: 10px; cursor: pointer; border: 1px solid #aaa; background: #f5f5f5; font-family: monospace; }

.barcode-cell { display: flex; align-items: center; gap: 4px; padding: 0 6px; height: 100%; cursor: pointer; }
.barcode-canvas-wrap { display: flex; align-items: center; }
.barcode-canvas-wrap canvas { display: block; image-rendering: pixelated; }
.barcode-print-btn { padding: 1px 5px; font-size: 10px; cursor: pointer; border: 1px solid #aaa; background: #f5f5f5; }
.barcode-no-id { font-size: 11px; color: #aaa; }

/* ROW ACTIONS */
.row-actions { display: none; position: absolute; right: 2px; top: 50%; transform: translateY(-50%); z-index: 5; }
tbody tr:hover .row-actions { display: flex; gap: 2px; }
.row-del-btn {
  background: #fdd; border: 1px solid #f88; color: #c00;
  width: 20px; height: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 14px;
}

.row-card-btn {
  background: #e8f4ff;
  border: 1px solid #7bb3e0;
  color: #1a5fa0;
  width: 24px;
  height: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  padding: 0;
}
.row-card-btn:hover { background: #c8e0f8; }

/* EMPTY STATE */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 60px 20px; gap: 8px; color: #aaa; }
.empty-state svg { display: none; }
.empty-state h3 { font-size: 14px; color: #666; }
.empty-state p { font-size: 12px; text-align: center; }

/* LOADING */
.loading-overlay { position: absolute; inset: 0; background: #fff; opacity: 0.7; z-index: 50; display: none; align-items: center; justify-content: center; }
.loading-overlay.show { display: flex; }
.spinner { width: 24px; height: 24px; border: 2px solid #ccc; border-top-color: #333; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg) } }

/* MODALS */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 100; display: none; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal {
  background: #fff; border: 1px solid #aaa;
  padding: 16px; width: 400px; max-width: 95vw;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.modal h2 { font-size: 13px; margin-bottom: 12px; font-family: monospace; }
.modal-body { display: flex; flex-direction: column; gap: 10px; }
.field-group { display: flex; flex-direction: column; gap: 3px; }
.field-label { font-size: 10px; color: #666; }
.field-input, .field-select {
  border: 1px solid #aaa; padding: 5px 8px; font-size: 12px;
  font-family: monospace; width: 100%; background: #fff; color: #000;
}
.field-input:focus, .field-select:focus { outline: 1px solid #333; }

.modal-row-inputs { display: flex; flex-direction: column; gap: 6px; max-height: 40vh; overflow-y: auto; }
.modal-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 4px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* TAG MODAL */
.tag-modal { width: 460px; }
.tag-col-name { font-size: 12px; font-weight: bold; }
.section-label { font-size: 10px; color: #666; margin-bottom: 3px; }
.predefined-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.pred-tag-btn {
  padding: 3px 8px; font-size: 11px; cursor: pointer;
  border: 1px solid #aaa; background: #f5f5f5; font-family: monospace;
}
.pred-tag-btn:hover { background: #e0e0e0; }
.pred-tag-btn.selected { background: #ccc; font-weight: bold; border-color: #555; }

.custom-tag-row { display: flex; gap: 6px; }
.tag-desc-box { background: #f5f5f5; border: 1px solid #ddd; padding: 8px; font-size: 11px; line-height: 1.5; min-height: 36px; }

/* ACCESS STATUS CONFIG */
.access-status-config { display: none; flex-direction: column; gap: 8px; padding: 10px; border: 1px solid #ddd; background: #f9f9f9; }
.access-status-config.visible { display: flex; }
.time-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.time-input, .linked-col-select { border: 1px solid #aaa; padding: 5px 8px; font-size: 12px; font-family: monospace; width: 100%; background: #fff; }
.config-note { font-size: 10px; color: #666; line-height: 1.4; }

/* ID CONFIG */
.id-config { display: none; flex-direction: column; gap: 8px; padding: 10px; border: 1px solid #ddd; background: #f9f9f9; }
.id-config.visible { display: flex; }

/* TOAST */
.toast-container { position: fixed; bottom: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 4px; }
.toast { padding: 6px 12px; background: #f5f5f5; border: 1px solid #aaa; font-size: 11px; font-family: monospace; }
.toast.success { border-color: green; }
.toast.error { border-color: red; }
.toast.info { border-color: #555; }
.toast.fade-out { opacity: 0; transition: opacity 0.2s; }

/* IMAGE PREVIEW */
.img-preview-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 300; display: none; align-items: center; justify-content: center; cursor: zoom-out; }
.img-preview-overlay.open { display: flex; }
.img-preview-overlay img { max-width: 90vw; max-height: 90vh; }

/* SCHEDULE */
.schedule-modal { width: 500px; max-height: 85vh; overflow-y: auto; }
.schedule-sheet-row { display: grid; grid-template-columns: 1fr 60px 80px; gap: 6px; align-items: center; padding: 6px 10px; border: 1px solid #ddd; }
.sched-name { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sched-day-input, .sched-prefix-input { border: 1px solid #aaa; padding: 3px 5px; font-size: 11px; font-family: monospace; width: 100%; text-align: center; background: #fff; }
.sched-enabled-toggle { display: flex; align-items: center; gap: 4px; font-size: 11px; cursor: pointer; }

/* CORNER */
.corner-cell { position: sticky; left: 0; top: 0; z-index: 5; background: #f0f0f0; border-right: 1px solid #ddd; border-bottom: 2px solid #aaa; }

/* HIGHLIGHT */
tbody tr.highlight { background: #ffffcc; }

.user-id-config { display: none; flex-direction: column; gap: 8px; padding: 10px; border: 1px solid #ddd; background: #f9f9f9; }
.user-id-config.visible { display: flex; }

