:root {
  color-scheme: light;
  --bg: #eef3f7;
  --surface: #ffffff;
  --surface-soft: #f7fafc;
  --ink: #1a2633;
  --muted: #667789;
  --line: #d8e1ea;
  --brand: #1b3a57;
  --brand-2: #285a80;
  --accent: #d4a72c;
  --risk: #b42318;
  --ok: #147a4d;
  --shadow: 0 18px 45px rgba(21, 39, 57, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 16px;
}

button,
textarea {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  background: var(--brand);
  color: #fff;
  border-radius: 12px 12px 0 0;
}

.topbar h1,
.panel-header h2,
.case-head h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 22px;
}

.eyebrow {
  margin: 0 0 5px;
  color: inherit;
  opacity: 0.78;
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-badge {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: 235px 310px minmax(0, 1fr);
  min-height: calc(100vh - 112px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 0;
  box-shadow: var(--shadow);
}

.sidebar,
.case-list-panel,
.practice-panel {
  min-width: 0;
  padding: 18px;
}

.sidebar {
  background: #f1f6fa;
  border-right: 1px solid var(--line);
}

.sidebar-title {
  margin-bottom: 12px;
  color: var(--muted);
  font-weight: 700;
}

.chapter-nav,
.case-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chapter-btn,
.case-btn {
  width: 100%;
  padding: 12px;
  text-align: left;
  background: transparent;
  color: var(--ink);
  border: 1px solid transparent;
}

.chapter-btn:hover,
.case-btn:hover {
  background: #fff;
  border-color: var(--line);
}

.chapter-btn.active,
.case-btn.active {
  background: var(--brand);
  color: #fff;
}

.chapter-btn span,
.case-btn span {
  display: block;
  color: inherit;
  opacity: 0.76;
  font-size: 13px;
  margin-top: 4px;
}

.case-list-panel {
  border-right: 1px solid var(--line);
  background: var(--surface-soft);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.chapter-goal {
  color: var(--muted);
  line-height: 1.55;
}

.case-btn.done {
  border-color: rgba(20, 122, 77, 0.28);
}

.case-btn.done::after {
  content: "已完成";
  display: inline-block;
  margin-top: 8px;
  color: var(--ok);
  font-size: 13px;
  font-weight: 700;
}

.practice-panel {
  overflow: auto;
}

.case-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.case-summary {
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  gap: 14px;
  padding: 14px;
  background: #f8fbfd;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.case-summary p {
  margin: 0;
  line-height: 1.65;
}

.case-summary ul {
  margin: 0;
  padding-left: 20px;
  line-height: 1.65;
}

.primary-btn {
  padding: 0 16px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
}

.primary-btn:hover {
  background: var(--brand-2);
}

.ghost-btn {
  padding: 0 14px;
  background: #fff;
  color: var(--brand);
  border: 1px solid var(--line);
  font-weight: 700;
}

.topbar .ghost-btn {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.28);
}

.tabs,
.sql-area,
.result-card {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.table-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.table-tab {
  white-space: nowrap;
  padding: 0 12px;
  background: #f3f7fa;
  color: var(--brand);
}

.table-tab.active {
  background: var(--brand);
  color: #fff;
}

.table-wrap {
  overflow: auto;
  max-height: 310px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 10px 11px;
  border-bottom: 1px solid #e8eef3;
  text-align: left;
  white-space: nowrap;
  font-size: 14px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
}

.sql-area {
  padding: 14px;
}

.sql-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.sql-toolbar h3,
.result-card h3 {
  margin: 0;
  font-size: 16px;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#sqlEditor {
  width: 100%;
  min-height: 190px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #0f1720;
  background: #f9fbfd;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px;
  line-height: 1.55;
  resize: vertical;
}

.sql-status {
  min-height: 24px;
  margin: 10px 0 0;
  color: var(--muted);
}

.sql-status.error {
  color: var(--risk);
}

.sql-status.pass {
  color: var(--ok);
  font-weight: 700;
}

.result-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  gap: 14px;
  margin-top: 16px;
}

.result-card {
  padding: 14px;
}

.result-wrap {
  max-height: 270px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.explain-box {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.65;
}

.explain-box pre {
  overflow: auto;
  padding: 12px;
  border-radius: 8px;
  background: #f3f7fa;
  color: #102334;
  font-size: 13px;
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .case-list-panel {
    display: none;
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 0;
  }

  .topbar {
    border-radius: 0;
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace {
    display: block;
    min-height: auto;
    border-left: 0;
    border-right: 0;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chapter-nav {
    flex-direction: row;
    overflow-x: auto;
  }

  .chapter-btn {
    min-width: 170px;
  }

  .case-list-panel {
    display: block;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .case-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(190px, 1fr));
    overflow-x: auto;
  }

  .case-summary,
  .result-grid {
    grid-template-columns: 1fr;
  }
}
