:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #d8e0ea;
  --brand: #2563eb;
  --brand-weak: #dbeafe;
  --ok: #16a34a;
  --warn: #d97706;
  --shadow: 0 8px 30px rgba(15, 23, 42, 0.08);
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

input, select, button, textarea { font: inherit; }

input, select, textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

button {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
}

button.secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}

button:disabled { opacity: 0.6; cursor: not-allowed; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.subtle { color: var(--muted); font-size: 13px; }
.full-width { width: 100%; }
.error-text { color: #dc2626; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.auth-brand {
  font-size: 13px;
  color: var(--brand);
  font-weight: 700;
  margin-bottom: 10px;
}

.auth-title {
  margin: 0 0 8px;
  font-size: 28px;
}

.auth-subtitle {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 14px;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.field-label {
  font-size: 13px;
  color: #475569;
  font-weight: 600;
}

.form-message {
  font-size: 12px;
}

.admin-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  background: var(--panel);
  color: var(--text);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid var(--line);
}

.sidebar-brand {
  padding: 8px 10px 14px;
  border-bottom: 1px solid var(--line);
}

.sidebar-title {
  font-size: 22px;
  font-weight: 700;
}

.sidebar-subtitle {
  margin-top: 6px;
  font-size: 12px;
  color: #64748b;
}

.sidebar-nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  color: #334155;
  padding: 12px 14px;
}

.nav-item:hover {
  background: #dbeafe;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.nav-item.active {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

.sidebar-footer {
  margin-top: auto;
}

.main-layout {
  min-width: 0;
}

.topbar {
  padding: 14px 20px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
}

.topbar-heading {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.page-title {
  margin: 0;
  font-size: 22px;
}

.topbar .subtle {
  line-height: 1.5;
}

.container {
  padding: 12px 16px 16px;
  max-width: 1500px;
  margin: 0 auto;
}

.admin-container {
  max-width: none;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 12px;
}

.toolbar.compact {
  margin-bottom: 0;
  gap: 8px;
  justify-content: flex-end;
  flex-shrink: 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 14px;
}

.dashboard-kpi-grid {
  margin-top: 14px;
  margin-bottom: 14px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.dashboard-main-grid,
.dashboard-analysis-grid,
.dashboard-footer-grid {
  margin-top: 10px;
}

.dashboard-span-8 { grid-column: span 8; }
.dashboard-span-6 { grid-column: span 6; }
.dashboard-span-4 { grid-column: span 4; }
.dashboard-span-3 { grid-column: span 3; }

.dashboard-card {
  padding: 14px;
  overflow: hidden;
}

.dashboard-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.dashboard-card-head h3 {
  margin: 0;
  font-size: 15px;
}

.chart-box {
  width: 100%;
  height: 280px;
}

.chart-box-tall {
  height: 330px;
}

.stat.operational {
  padding: 14px 16px;
}

.stat-hero {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 96px;
  border-radius: 16px;
}

.stat-hero-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  flex-shrink: 0;
}

.stat-hero-icon svg {
  width: 44px;
  height: 44px;
  display: block;
}

.stat-hero-icon.teal {
  background: #ffffff;
  color: #059669;
}

.stat-hero-icon.blue {
  background: #ffffff;
  color: #2563eb;
}

.stat-hero-icon.green {
  background: #ffffff;
  color: #16a34a;
}

.stat-hero-icon.orange {
  background: #ffffff;
  color: #ea580c;
}

.stat-hero-icon.purple {
  background: #ffffff;
  color: #9333ea;
}

.stat-hero-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat.operational .value {
  font-size: 20px;
  font-weight: 800;
  color: #0f172a;
}

.stat-hero-total {
  margin-top: 2px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

@media (max-height: 1080px) {
  .container {
    padding-top: 16px;
    padding-bottom: 20px;
  }

  .dashboard-grid {
    gap: 12px;
  }

  .dashboard-kpi-grid {
    margin-top: 12px;
    margin-bottom: 12px;
  }

  .dashboard-main-grid,
  .dashboard-analysis-grid,
  .dashboard-footer-grid {
    margin-top: 8px;
  }

  .dashboard-card {
    padding: 12px;
  }

  .dashboard-card-head {
    margin-bottom: 8px;
  }

  .dashboard-card-head h3 {
    font-size: 14px;
  }

  .dashboard-card-head .muted {
    font-size: 12px;
  }

  .chart-box {
    height: 240px;
  }

  .chart-box-tall {
    height: 280px;
  }

  .stat.operational {
    padding: 12px 14px;
  }

  .stat-hero {
    min-height: 84px;
    gap: 10px;
  }

  .stat-hero-icon {
    width: 40px;
    height: 40px;
  }

  .stat-hero-icon svg {
    width: 40px;
    height: 40px;
  }

  .stat.operational .label {
    font-size: 12px;
  }

  .stat.operational .value {
    font-size: 18px;
  }

  .stat-hero-total {
    font-size: 11px;
  }
}

.stat.operational .hint {
  min-height: 18px;
}

.stat-hero .label {
  margin-bottom: 6px;
  font-size: 13px;
  color: #64748b;
  font-weight: 600;
}

.stat-hero .hint {
  margin-top: 0;
  font-size: 12px;
  color: #94a3b8;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.stat { padding: 16px; }
.stat .label { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.stat .value { font-size: 28px; font-weight: 700; line-height: 1.1; }
.stat .hint { margin-top: 6px; color: var(--muted); font-size: 12px; }

.list-shell { display: grid; gap: 10px; }
.panel { padding: 12px; }

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.panel-title { margin: 0; font-size: 16px; }

.panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.devices-panel {
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
}

.devices-panel .panel-head {
  margin-bottom: 12px;
}

.devices-panel .panel-title {
  font-size: 18px;
}

.device-toolbar {
  padding: 10px;
  margin-bottom: 12px;
  border: 1px solid #dbe7f5;
  border-radius: 12px;
  background: linear-gradient(180deg, #f8fbff 0%, #fdfefe 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.device-toolbar input,
.device-toolbar select {
  min-width: 180px;
}

.device-toolbar button {
  min-width: 86px;
}

.device-modal .modal-card {
  width: min(820px, 100%);
}

.exhibit-modal .modal-card {
  width: min(900px, 100%);
}

.exhibit-html-editor-field {
  min-width: 0;
}

.exhibit-html-editor-toolbar {
  border: 1px solid #d1d5db;
  border-bottom: 0;
}

.exhibit-html-editor-content,
.exhibit-html-editor-content .w-e-text-container {
  min-height: 260px;
  border: 1px solid #d1d5db;
  background: #fff;
}

.device-form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.device-form-grid textarea {
  min-height: 108px;
}

.device-status-badge {
  min-width: 64px;
  justify-content: center;
  font-weight: 700;
}

.device-status-badge.ok {
  box-shadow: inset 0 0 0 1px rgba(22, 163, 74, 0.12);
}

.device-status-badge.gray {
  box-shadow: inset 0 0 0 1px rgba(55, 65, 81, 0.08);
}

.device-status-badge.warn {
  box-shadow: inset 0 0 0 1px rgba(217, 119, 6, 0.12);
}

.device-online-badge {
  min-width: 64px;
  justify-content: center;
  font-weight: 700;
}

.panel-refresh-button {
  background: var(--brand) !important;
  color: #fff !important;
  border-color: var(--brand) !important;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.16);
  transition: background-color 0.14s ease, color 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease, transform 0.14s ease;
}

.panel-refresh-button.is-active {
  background: #eaf2ff !important;
  color: #1d4ed8 !important;
  border-color: #93c5fd !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
  transform: translateY(1px);
}

.table-shell {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.table-shell.empty {
  min-height: 120px;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.table-head-wrap {
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}

.table-body-wrap {
  max-height: 500px;
  overflow: auto;
}

table,
.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th, td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

.table-shell-wide .table-head-wrap {
  overflow-x: auto;
  overflow-y: hidden;
}

.table-shell-wide .data-table {
  width: 100%;
  min-width: 100%;
  table-layout: fixed;
}

.table-shell-wide .data-table col {
  width: auto !important;
}

.table-shell-wide thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.table-shell-wide th,
.table-shell-wide td {
  white-space: nowrap;
}

th {
  background: #f8fafc;
  color: #475569;
  font-weight: 700;
}

tbody tr:hover { background: #f8fbff; }

.table-pagination {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.pagination-summary {
  font-size: 13px;
  color: var(--muted);
}

.pagination-actions {
  display: flex;
  gap: 8px;
}

.pagination-button {
  min-width: 88px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--brand-weak);
  color: var(--brand);
}

.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.warn { background: #fef3c7; color: var(--warn); }
.badge.gray { background: #e5e7eb; color: #374151; }

.cell-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.cell-actions button {
  padding: 6px 10px;
  font-size: 12px;
}

.ticket-cell-actions {
  flex-wrap: nowrap;
  align-items: center;
}

.ticket-cell-actions button {
  white-space: nowrap;
}

.refund-summary {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
  font-size: 13px;
}

.refund-form-grid {
  grid-template-columns: 1fr;
}

.mono {
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  color: #334155;
  word-break: break-all;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.38);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-card {
  width: min(760px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.18);
}

.modal-card-sm {
  width: min(420px, 100%);
}

.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
}

.modal-head {
  border-bottom: 1px solid var(--line);
}

.modal-actions {
  border-top: 1px solid var(--line);
  justify-content: flex-end;
}

.modal-title {
  margin: 0;
  font-size: 18px;
}

.modal-body {
  padding: 14px 16px;
}

.confirm-message {
  font-size: 14px;
  line-height: 1.7;
  color: #334155;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.form-grid label {
  display: grid;
  gap: 8px;
}

.form-grid .span-2 {
  grid-column: span 2;
}

.form-message {
  min-height: 18px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.form-message.error-text {
  color: #dc2626;
}

.log-content-pre {
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 55vh;
  overflow: auto;
}

.footer-note {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 1200px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .dashboard-span-8,
  .dashboard-span-6,
  .dashboard-span-4,
  .dashboard-span-3 { grid-column: span 6; }
}

@media (max-width: 760px) {
  .admin-shell { grid-template-columns: 1fr; }
  .sidebar { padding: 16px; }
  .topbar { padding: 12px; flex-direction: column; align-items: stretch; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .dashboard-span-8,
  .dashboard-span-6,
  .dashboard-span-4,
  .dashboard-span-3 { grid-column: span 1; }
  .panel-head, .toolbar { align-items: stretch; }
  .panel-head { flex-direction: column; }
  .dashboard-card-head { flex-direction: column; align-items: flex-start; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
  table { display: block; overflow-x: auto; white-space: nowrap; }
}