:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --text: #17212b;
  --muted: #667481;
  --line: #d8e0e7;
  --line-strong: #b9c6d1;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #d9f2ee;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --red: #b42318;
  --red-soft: #fee4e2;
  --green: #027a48;
  --green-soft: #dcfae6;
  --shadow: 0 18px 48px rgba(22, 34, 51, 0.12);
  --radius: 8px;
  --sidebar: 210px;
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-width: 320px;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
}

.sidebar {
  background: #17252f;
  color: #dbe7ef;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  min-height: 0;
  padding: 4px 6px 16px;
  border-bottom: 1px solid rgba(255,255,255,.12);
}

.brand-logo {
  width: 120px;
  height: auto;
  max-height: 78px;
  object-fit: contain;
  border-radius: 6px;
}

.brand strong { display: block; font-size: 17px; }
.brand span { display: block; color: #9fb1bf; font-size: 12px; margin-top: 2px; }

.nav { display: grid; gap: 4px; }
.nav button {
  border: 0;
  background: transparent;
  color: #c8d7e2;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 8px 9px;
  border-radius: 6px;
  text-align: left;
}
.nav button:hover, .nav button.active { background: rgba(255,255,255,.1); color: white; }
.nav .nav-icon { width: 20px; text-align: center; }

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #aabac7;
  font-size: 13px;
  padding: 10px 8px;
}
.status-dot {
  width: 9px;
  height: 9px;
  background: #22c55e;
  border-radius: 999px;
  box-shadow: 0 0 0 3px rgba(34,197,94,.16);
}

.main { min-width: 0; }
.topbar {
  min-height: 84px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar h1 { margin: 0; font-size: 24px; line-height: 1.2; letter-spacing: 0; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.role-switcher { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.role-switcher select, .field select, .field input, .field textarea, .filter-row input, .filter-row select {
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  min-height: 38px;
  padding: 8px 10px;
  background: white;
  color: var(--text);
  width: 100%;
}

.content { padding: 22px 24px 36px; }

.icon-button, .ghost-button, .primary-button, .danger-button, .small-button {
  border-radius: 6px;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  background: white;
  color: var(--text);
  padding: 8px 12px;
}
.icon-button { width: 38px; padding: 0; display: grid; place-items: center; font-size: 20px; }
.menu-toggle { display: none; }
.primary-button { background: var(--accent); border-color: var(--accent); color: white; }
.primary-button:hover { background: var(--accent-strong); }
.ghost-button:hover, .small-button:hover, .icon-button:hover { background: var(--surface-2); }
.danger-button { background: var(--red); border-color: var(--red); color: white; }
.small-button { min-height: 32px; padding: 5px 9px; font-size: 13px; }

.grid { display: grid; gap: 16px; }
.metrics { grid-template-columns: repeat(4, minmax(150px, 1fr)); }
.two-col { grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr); align-items: start; }

.card, .panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card { padding: 16px; }
.metric-value { font-size: 28px; font-weight: 800; margin-top: 8px; }
.metric-label { color: var(--muted); font-size: 13px; }
.metric-note { color: var(--muted); font-size: 12px; margin-top: 8px; }
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
}
.panel-header h2 { margin: 0; font-size: 17px; }
.panel-header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.panel-body { padding: 16px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 780px; }
th, td { padding: 11px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: 14px; }
th { color: #26516f; background: #f7fafc; font-weight: 700; }
tbody tr:hover { background: #fbfcfd; }
.actions-cell { white-space: nowrap; display: flex; gap: 6px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid transparent;
}
.badge.created, .badge.backend-ready { color: var(--blue); background: var(--blue-soft); }
.badge.cancelled { color: var(--red); background: var(--red-soft); }
.badge.completed, .badge.sent, .badge.yes { color: var(--green); background: var(--green-soft); }
.badge.pending, .badge.no { color: var(--amber); background: var(--amber-soft); }
.badge.neutral { color: #475467; background: #eef2f6; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field { display: grid; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-weight: 700; font-size: 13px; color: #344054; }
.field small { color: var(--muted); }
textarea { min-height: 88px; resize: vertical; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.filter-row { display: grid; grid-template-columns: 1fr 180px 180px auto; gap: 10px; margin-bottom: 14px; align-items: end; }

.timeline { display: grid; gap: 12px; }
.timeline-item { border-left: 3px solid var(--accent); padding-left: 12px; }
.timeline-item strong { display: block; }
.timeline-item span { color: var(--muted); font-size: 13px; }

.empty-state { padding: 30px; text-align: center; color: var(--muted); }
.permission-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.permission-grid div { padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: #fbfcfd; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(12, 23, 34, .54);
  display: grid;
  place-items: center;
  padding: 22px;
  z-index: 20;
}
.modal.hidden { display: none; }
.modal-panel {
  width: min(880px, 100%);
  max-height: min(860px, 92vh);
  overflow: auto;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 0; font-size: 20px; }
#modalBody { padding: 16px; }

.notice { padding: 12px; border-radius: 6px; background: var(--amber-soft); color: #7a4b00; border: 1px solid #f2d68c; margin-bottom: 14px; }
.success { background: var(--green-soft); border-color: #a7f3c2; color: var(--green); }
.error { background: var(--red-soft); border-color: #fda29b; color: var(--red); }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 30; transform: translateX(-100%); transition: transform .2s ease; width: var(--sidebar); }
  body.nav-open .sidebar { transform: translateX(0); }
  .menu-toggle { display: grid; }
  .metrics, .two-col { grid-template-columns: 1fr; }
  .filter-row { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; }
}

@media (max-width: 680px) {
  .content, .topbar { padding-left: 14px; padding-right: 14px; }
  .topbar { flex-wrap: wrap; }
  .topbar-actions { width: 100%; justify-content: flex-start; }
  .form-grid { grid-template-columns: 1fr; }
  .permission-grid { grid-template-columns: 1fr; }
}

.session-table {
  min-width: 1080px;
}

.session-table .date-cell,
.session-table .count-cell,
.session-table .actions-cell {
  white-space: nowrap;
}

.session-table th:nth-child(1) { width: 28%; }
.session-table th:nth-child(2) { width: 13%; }
.session-table th:nth-child(3) { width: 18%; }
.session-table th:nth-child(4) { width: 17%; }
.session-table th:nth-child(5) { width: 10%; }

@media (min-width: 1280px) {
  .session-table {
    min-width: 100%;
  }
}

.games-table {
  min-width: 100%;
}

.games-table th:nth-child(1) { width: 30%; }
.games-table th:nth-child(5) { width: 30%; }
.games-table td:nth-child(5),
.games-table td:nth-child(6) {
  white-space: normal;
}

.route-stack {
  display: grid;
  gap: 4px;
  line-height: 1.35;
}

.route-stack span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-right: 4px;
}



.workflow-flow {
  display: grid;
  grid-template-columns: minmax(145px, 1fr) 34px minmax(145px, 1fr) 34px minmax(145px, 1fr) 34px minmax(145px, 1fr) 34px minmax(145px, 1fr);
  align-items: stretch;
  gap: 10px;
}
.flow-step {
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 14px;
  min-height: 150px;
}
.flow-owner {
  display: inline-flex;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 12px;
}
.flow-step strong { display: block; font-size: 18px; margin-bottom: 8px; }
.flow-step p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.flow-arrow {
  display: grid;
  place-items: center;
  color: var(--accent-strong);
  font-size: 28px;
  font-weight: 800;
}
.certificate-workspace { display: grid; gap: 16px; }
.certificate-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr); gap: 16px; align-items: start; }
.certificate-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 14px;
}
.certificate-section h3 { margin: 0 0 12px; font-size: 16px; }
.template-list { display: grid; gap: 10px; }
.template-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
}
.template-row span { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
.upload-box {
  display: grid;
  gap: 8px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  padding: 18px;
  margin: 12px 0;
  color: var(--muted);
}
.upload-box strong { color: var(--text); }
.upload-box input, .mini-upload input { width: 100%; }
.mini-upload {
  display: inline-grid;
  gap: 4px;
  color: var(--accent-strong);
  font-weight: 700;
  font-size: 13px;
}
.danger-button { background: var(--red); border-color: var(--red); color: white; }
.danger-button:hover { background: #8f1d14; border-color: #8f1d14; }
.certificate-metrics { margin-top: 0; }
@media (max-width: 1180px) {
  .workflow-flow { grid-template-columns: 1fr; }
  .flow-arrow { transform: rotate(90deg); min-height: 26px; }
  .certificate-grid { grid-template-columns: 1fr; }
}
.system-map { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px; margin-top: 16px; }
.system-map .card { height: 100%; }
@media (max-width: 1180px) { .system-map { grid-template-columns: 1fr 1fr; } }
@media (max-width: 680px) { .system-map { grid-template-columns: 1fr; } }
