:root {
  --bg-base: #0b1120;
  --bg-panel: #111827;
  --bg-card: #1e293b;
  --bg-hover: #263449;
  --bg-input: #0f172a;
  --border: #334155;
  --border-focus: #3b82f6;
  --text-main: #f8fafc;
  --text-sub: #94a3b8;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.14);
  --warn: #f59e0b;
  --warn-bg: rgba(245, 158, 11, 0.15);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.15);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-base);
  color: var(--text-main);
  line-height: 1.5;
}

.app-shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px 24px 48px;
}

/* Header & Nav */
.top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-status-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.nav-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.nav-btn {
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-sub);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-btn:hover {
  background: var(--bg-card);
  color: var(--text-main);
}

.nav-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.28);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
}

.badge-active {
  background: var(--success-bg);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.35);
}

.badge-paused {
  background: var(--warn-bg);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.35);
}

.badge-danger {
  background: var(--danger-bg);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.35);
}

.badge-neutral {
  background: var(--bg-card);
  color: var(--text-sub);
  border-color: var(--border);
}

/* Session Banner */
.session-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 18px;
  font-size: 13px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
}

.session-banner.warn {
  background: var(--danger-bg);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}

.session-banner.ok {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.3);
  color: #a7f3d0;
}

/* Views & Panels */
.view-section { display: none; }
.view-section.active { display: block; }

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  margin-bottom: 18px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.panel-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.panel-sub {
  font-size: 12px;
  color: var(--text-sub);
  margin-top: 2px;
}

/* Controls & Buttons */
input, select {
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  outline: none;
}

input:focus, select:focus {
  border-color: var(--border-focus);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.14s ease;
  white-space: nowrap;
}

.btn:hover:not(:disabled) { background: var(--bg-hover); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-success { background: #059669; border-color: #059669; color: #fff; }
.btn-success:hover:not(:disabled) { background: #047857; }

.btn-warn { background: #d97706; border-color: #d97706; color: #fff; }
.btn-warn:hover:not(:disabled) { background: #b45309; }

.btn-danger { background: rgba(239, 68, 68, 0.16); border-color: rgba(239, 68, 68, 0.45); color: #fca5a5; }
.btn-danger:hover:not(:disabled) { background: #dc2626; border-color: #dc2626; color: #fff; }

.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 6px; }

/* Dashboard Toolbar & Stats */
.dash-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 16px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

.stat-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-focus);
}

.stat-card.selected {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.1);
}

.stat-label {
  font-size: 12px;
  color: var(--text-sub);
  font-weight: 600;
}

.stat-value {
  font-size: 28px;
  font-weight: 800;
  margin-top: 6px;
}

.stat-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Live Monitor */
.monitor-meta-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

@media (max-width: 820px) {
  .monitor-meta-grid { grid-template-columns: 1fr; }
}

.meta-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.meta-label { font-size: 11px; color: var(--text-sub); }
.meta-val { font-size: 14px; font-weight: 700; margin-top: 4px; }

.log-terminal {
  margin: 0;
  padding: 14px;
  border-radius: 10px;
  background: #050811;
  border: 1px solid #1e293b;
  color: #cbd5e1;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.55;
  max-height: 290px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Detail Item List */
.item-list { display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow-y: auto; }
.item-card {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
}
.item-title { font-size: 14px; font-weight: 600; color: var(--text-main); }
.item-sub { font-size: 12px; color: var(--text-sub); margin-top: 4px; }

/* View 1: Cafe Management Layout */
.cafe-mgmt-grid {
  display: grid;
  grid-template-columns: 1.45fr 1fr;
  gap: 18px;
  align-items: start;
}

@media (max-width: 980px) {
  .cafe-mgmt-grid { grid-template-columns: 1fr; }
}

.cafe-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cafe-row-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 15px 16px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.cafe-row-card:hover {
  border-color: #475569;
}

.cafe-row-card.editing {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.cafe-click-area {
  cursor: pointer;
  display: block;
}

.cafe-click-area:hover .cafe-name-link {
  color: #60a5fa;
  text-decoration: underline;
}

.cafe-row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.cafe-name-link {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
}

.cafe-url-text {
  font-size: 12px;
  color: var(--text-sub);
  margin-top: 3px;
}

.cafe-metrics-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-sub);
}

.cafe-actions-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(51, 65, 85, 0.55);
}

.form-field { margin-bottom: 12px; }
.form-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 5px;
}
.form-field input, .form-field select { width: 100%; }

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* View 2: 3-Section Shuttle Board UI */
.shuttle-layout {
  display: grid;
  grid-template-columns: 0.85fr 58px 0.95fr 1.48fr;
  gap: 14px;
  align-items: stretch;
}

@media (max-width: 1100px) {
  .shuttle-layout {
    grid-template-columns: 1fr;
  }
}

.shuttle-col {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-height: 510px;
}

.shuttle-controls-col {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
}

@media (max-width: 1100px) {
  .shuttle-controls-col {
    flex-direction: row;
    padding: 6px 0;
  }
}

.shuttle-arrow-btn {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 20px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.shuttle-arrow-btn:hover:not(:disabled) {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  transform: scale(1.05);
}

.shuttle-arrow-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.board-list-box {
  flex: 1;
  margin-top: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  overflow-y: auto;
  max-height: 410px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.board-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: rgba(30, 41, 59, 0.45);
  cursor: pointer;
  user-select: none;
  transition: all 0.12s ease;
}

.board-item:hover {
  background: var(--bg-card);
  border-color: #475569;
}

.board-item.selected {
  background: rgba(37, 99, 235, 0.22);
  border-color: var(--primary);
}

.board-item.active-option {
  box-shadow: inset 3px 0 0 #38bdf8;
}

.board-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
}

.board-item-meta {
  font-size: 11px;
  color: var(--text-sub);
  margin-top: 2px;
}

.empty-placeholder {
  margin: auto;
  text-align: center;
  padding: 28px 14px;
  color: var(--text-muted);
  font-size: 13px;
}

.toast-msg {
  position: fixed;
  right: 24px;
  bottom: 24px;
  padding: 12px 18px;
  border-radius: 10px;
  background: #1e293b;
  border: 1px solid #475569;
  color: #f8fafc;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: all 0.2s ease;
}

.toast-msg.show {
  opacity: 1;
  transform: translateY(0);
}

/* 2-Mode Option Cards & Toggle Switch */
.mode-option-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 13px 14px;
  margin-bottom: 12px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.mode-option-card.enabled {
  border-color: rgba(59, 130, 246, 0.55);
  background: rgba(30, 41, 59, 0.55);
}

.mode-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.mode-card-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-main);
}

.mode-card-desc {
  font-size: 11.5px;
  color: var(--text-sub);
  margin-top: 3px;
}

.mode-card-body {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(51, 65, 85, 0.65);
}

.switch-toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #334155;
  border-radius: 999px;
  transition: 0.18s;
}

.switch-slider::before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: #f8fafc;
  border-radius: 50%;
  transition: 0.18s;
}

.switch-toggle input:checked + .switch-slider {
  background-color: var(--primary);
}

.switch-toggle input:checked + .switch-slider::before {
  transform: translateX(20px);
}

textarea.script-textarea {
  width: 100%;
  min-height: 128px;
  resize: vertical;
  background: #090e1a;
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 12.5px;
  line-height: 1.5;
  outline: none;
}

textarea.script-textarea:focus {
  border-color: var(--border-focus);
}

.badge-info {
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  border-color: rgba(56, 189, 248, 0.35);
}

.board-script-snippet {
  font-size: 11px;
  color: #93c5fd;
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 250px;
}
.dirty-indicator {
  display: none;
  font-size: 11px;
  font-weight: 700;
  color: #fbbf24;
  background: rgba(245, 158, 11, 0.16);
  border: 1px solid rgba(245, 158, 11, 0.4);
  padding: 3px 9px;
  border-radius: 999px;
}
.dirty-indicator.show {
  display: inline-flex;
}
details.test-box {
  margin-top: 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
details.test-box summary {
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 700;
  color: #93c5fd;
  user-select: none;
}

/* Separated Monitoring Zones (Infiltration vs Realtime AI) */
.dedicated-watch-zone {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  margin-bottom: 20px;
}

.zone-infiltration {
  border-top: 3px solid #f59e0b;
}

.zone-realtime {
  border-top: 3px solid #38bdf8;
}

.zone-stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}

@media (max-width: 820px) {
  .zone-stats-row {
    grid-template-columns: 1fr;
  }
}

.zone-stat-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px 16px;
  cursor: pointer;
  transition: all 0.14s ease;
}

.zone-stat-card:hover {
  border-color: var(--border-focus);
  transform: translateY(-1px);
}

.zone-stat-card.selected {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.14);
}

.zone-stat-card.static-card {
  cursor: default;
}

.zone-stat-card.static-card:hover {
  border-color: var(--border);
  transform: none;
}

.board-status-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-input);
}

.board-status-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.board-status-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-sub);
  background: rgba(15, 23, 42, 0.9);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.board-status-table td {
  padding: 11px 14px;
  border-bottom: 1px solid rgba(51, 65, 85, 0.5);
  vertical-align: middle;
}

.board-status-table tr:last-child td {
  border-bottom: none;
}

.board-status-table tr:hover td {
  background: rgba(30, 41, 59, 0.42);
}

.script-pill-preview {
  font-size: 11.5px;
  color: #93c5fd;
  max-width: 320px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.zone-stat-card:not(.static-card) { cursor: pointer; user-select: none; }
.zone-stat-card:not(.static-card):hover .stat-value { text-decoration: underline; text-underline-offset: 4px; }
