/* W3Schools-style full-page SQL exercise layout */

html.tds-exercise-html,
html.tds-exercise-html body.tds-exercise-page {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body.tds-exercise-page {
  display: flex;
  flex-direction: column;
  background: var(--tds-surface-workspace, #f3f7fb);
  font-family: inherit;
  color: var(--tds-text-heading, #2d2a33);
}

/* --- Header --- */
.tds-exercise-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  min-height: 52px;
  padding: 8px 16px;
  background: var(--tds-brand);
  border-bottom: none;
  flex-shrink: 0;
  color: var(--tds-text-on-brand);
}

.tds-exercise-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.tds-exercise-brand img {
  max-height: 50px;
  width: auto;
}

.tds-exercise-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--tds-text-on-brand);
  text-decoration: none;
  background: var(--tds-brand-light);
  border: none;
  border-radius: 6px;
  white-space: nowrap;
  transition: background-color 0.2s ease;
}

.tds-exercise-back:hover {
  background: var(--tds-brand-dark);
  color: var(--tds-text-on-brand);
}

.tds-exercise-heading {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--tds-text-on-brand);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Workspace --- */
.tds-exercise-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--tds-surface-workspace, #f3f7fb);
}

.tds-exercise-page .tds-playground {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin: 0;
  min-height: 0;
  background: var(--tds-surface-workspace, #f3f7fb);
  border: none;
  box-shadow: none;
}

.tds-exercise-page .tds-playground-inner--exercise {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.tds-playground-workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 12px;
  height: 100%;
  padding: 12px 14px;
  background: var(--tds-surface-workspace, #f3f7fb);
  box-sizing: border-box;
}

.tds-playground-inner--exercise-python .tds-playground-workspace {
  grid-template-columns: minmax(0, 1fr);
  display: flex;
  flex-direction: column;
}

.tds-playground-inner--exercise-python .tds-playground-sidebar {
  display: none;
}

/* Python exercise: W3Schools split — editor left, black terminal right */
.tds-playground-python-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex: 1;
  min-height: 0;
  height: 100%;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--tds-code-shadow, 0 2px 12px rgba(46, 95, 151, 0.08));
}

.tds-playground-python-code {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  padding: 14px 16px 16px;
  background: var(--tds-surface-card, #fff);
  border-right: 1px solid var(--tds-border, #d4e0ed);
}

.tds-playground-python-result {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--tds-code-terminal-header, #1a3a5c);
}

.tds-playground-inner--exercise-python .tds-playground-python-code .tds-exercise-section-title {
  margin: 0 0 10px;
  flex-shrink: 0;
}

.tds-playground-inner--exercise-python .tds-exercise-section-title--result {
  margin: 0;
  padding: 12px 16px;
  font-size: 17px;
  font-weight: 700;
  color: var(--tds-text-on-brand, #fff);
  background: var(--tds-code-terminal-header, #1a3a5c);
  border-bottom: 1px solid var(--tds-brand-dark, #234a75);
  flex-shrink: 0;
}

.tds-playground-inner--exercise-python .tds-playground-editor-host {
  flex: 1;
  min-height: 160px;
  flex-basis: auto;
}

.tds-playground-inner--exercise-python .tds-playground-exercise-hint {
  margin: 10px 0 0;
  flex-shrink: 0;
}

.tds-playground-inner--exercise-python .tds-playground-output {
  flex: 1;
  min-height: 0;
  background: var(--tds-code-terminal-bg, #000);
  color: var(--tds-code-terminal-text, #f1f1f1);
  border-radius: 0;
  box-shadow: none;
  font-family: Consolas, Menlo, "Courier New", monospace;
}

.tds-playground-inner--exercise-python .tds-playground-output.is-empty {
  color: #888;
  font-style: italic;
  font-family: Consolas, Menlo, "Courier New", monospace;
}

.tds-playground-inner--exercise-python .tds-playground-output.is-error {
  color: #ff8a8a;
  background: #1a0000;
}

.tds-playground-inner--exercise-python .tds-playground-output.is-success:not(.has-table) {
  color: #f1f1f1;
}

.tds-playground-inner--exercise-python .tds-playground-output .tds-playground-loading {
  color: #aaa;
}

.tds-playground-inner--exercise-python .tds-playground-output .tds-playground-spinner {
  border-color: #555;
  border-top-color: #2e5f97;
}

.tds-playground-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.tds-exercise-section-title {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 700;
  color: var(--tds-text-heading, #2d2a33);
}

.tds-playground-main .tds-exercise-section-title:last-of-type {
  margin-top: 2px;
}

/* White cards — no visible borders */
.tds-exercise-page .tds-playground-editor-host {
  flex: 0 0 200px;
  min-height: 165px;
  border: none;
  border-radius: 10px;
  background: var(--tds-surface-card, #fff);
  overflow: hidden;
  box-shadow: var(--tds-code-shadow, 0 2px 12px rgba(46, 95, 151, 0.08));
}

.tds-exercise-page .tds-playground-editor-host .CodeMirror {
  height: 100% !important;
  min-height: 165px;
  font-size: 13px;
  line-height: 1.45;
}

.tds-playground-editor-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.tds-playground-editor-actions .tds-btn-run,
.tds-playground-editor-actions .tds-btn-reset,
.tds-playground-editor-actions [data-playground-run],
.tds-playground-editor-actions [data-playground-reset] {
  min-width: 120px;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 600;
  color: var(--tds-text-on-brand);
  background-color: var(--tds-brand);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.tds-playground-editor-actions .tds-btn-run:hover:not(:disabled),
.tds-playground-editor-actions .tds-btn-reset:hover:not(:disabled),
.tds-playground-editor-actions [data-playground-run]:hover:not(:disabled),
.tds-playground-editor-actions [data-playground-reset]:hover:not(:disabled) {
  background-color: var(--tds-brand-dark);
  color: var(--tds-text-on-brand);
}

.tds-playground-editor-actions .tds-btn-run {
  min-width: 140px;
}

.tds-playground-exercise-hint {
  margin: 10px 0 14px;
  font-size: 14px;
  color: var(--tds-text, #5c5962);
}

.tds-exercise-page .tds-playground-output {
  flex: 1;
  min-height: 110px;
  margin: 0;
  padding: 14px 16px;
  overflow: auto;
  border: none;
  border-radius: 10px;
  background: var(--tds-surface-card, #fff);
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: var(--tds-code-shadow, 0 2px 12px rgba(46, 95, 151, 0.08));
}

.tds-exercise-page .tds-playground-output.has-table {
  padding: 0;
  white-space: normal;
}

.tds-exercise-page .tds-playground-output.is-empty {
  color: var(--tds-text, #5c5962);
  font-style: italic;
  font-family: inherit;
}

.tds-exercise-page .tds-playground-output.is-error {
  color: var(--tds-code-error-border, #c62828);
  background: var(--tds-code-error-bg, #fdf0f0);
}

.tds-exercise-page .tds-playground-output.is-success:not(.has-table) {
  font-family: Consolas, Menlo, "Courier New", monospace;
}

/* Python split layout — overrides after general exercise output rules */
.tds-exercise-page .tds-playground-inner--exercise-python .tds-playground-editor-host {
  flex: 1;
  min-height: 160px;
  flex-basis: auto;
}

.tds-exercise-page .tds-playground-inner--exercise-python .tds-playground-output {
  background: var(--tds-code-terminal-bg, #000);
  color: var(--tds-code-terminal-text, #f1f1f1);
  font-family: Consolas, Menlo, "Courier New", monospace;
}

.tds-exercise-page .tds-playground-inner--exercise-python .tds-playground-output.is-empty {
  color: #888;
  font-style: italic;
  font-family: Consolas, Menlo, "Courier New", monospace;
}

.tds-exercise-page .tds-playground-inner--exercise-python .tds-playground-output.is-error {
  color: #ff8a8a;
  background: #1a0000;
}

.tds-exercise-page .tds-playground-inner--exercise-python .tds-playground-output.is-success:not(.has-table) {
  color: #f1f1f1;
}

.tds-playground-output.has-plot {
  overflow: auto;
}

.tds-playground-text-output {
  margin: 0 0 12px;
  padding: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: Consolas, Menlo, "Courier New", monospace;
  font-size: 14px;
  line-height: 1.5;
  color: inherit;
  background: transparent;
  border: 0;
}

.tds-playground-plot-wrap {
  margin: 10px 0 0;
  padding: 0;
}

.tds-playground-plot {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

/* --- Sidebar --- */
.tds-playground-sidebar {
  min-height: 0;
  overflow: auto;
}

.tds-db-browser-host {
  background: var(--tds-surface-card, #fff);
  border: none;
  border-radius: 10px;
  padding: 14px;
  box-shadow: var(--tds-code-shadow, 0 2px 12px rgba(46, 95, 151, 0.08));
}

.tds-db-browser-host[hidden] {
  display: none;
}

.tds-db-browser-title {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 700;
  color: var(--tds-text-heading, #2d2a33);
}

.tds-db-browser-empty {
  margin: 0;
  font-size: 13px;
  color: var(--tds-text, #5c5962);
}

.tds-db-browser-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-family: inherit;
}

.tds-db-browser-table th {
  padding: 8px 10px;
  background: var(--tds-brand-pale, #e8f0f8);
  font-weight: 600;
  text-align: left;
  color: var(--tds-text-heading, #2d2a33);
}

.tds-db-browser-table td {
  padding: 7px 10px;
  text-align: left;
  border-top: 1px solid var(--tds-border-light, #e8f0f8);
}

.tds-db-browser-table tr:hover td {
  background: var(--tds-brand-pale-2, #f3f7fb);
}

.tds-db-table-link {
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  font-size: 13px;
  color: var(--tds-brand, #2e5f97);
  text-decoration: none;
  cursor: pointer;
}

.tds-db-table-link:hover,
.tds-db-table-link.is-active {
  color: var(--tds-brand-dark, #234a75);
  font-weight: 600;
  text-decoration: underline;
}

/* --- Footer --- */
.tds-exercise-footer {
  padding: 8px 16px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--tds-text, #5c5962);
  background: var(--tds-surface-card, #fff);
  border-top: 1px solid var(--tds-border, #d4e0ed);
  flex-shrink: 0;
}

.tds-exercise-footer kbd {
  padding: 1px 5px;
  font-size: 11px;
  border-radius: 3px;
  background: var(--tds-brand-pale, #e8f0f8);
}

/* --- CodeMirror SQL syntax --- */
.cm-s-tds-exercise.CodeMirror,
.cm-s-tds-python.CodeMirror {
  background: #fff;
  color: #000;
  font-size: 13px;
  line-height: 1.45;
}

.cm-s-tds-exercise .CodeMirror-gutters {
  background: #fafafa;
  border-right: none;
}

.cm-s-tds-exercise .CodeMirror-linenumber {
  color: #aaa;
}

.cm-s-tds-exercise .cm-keyword {
  color: var(--tds-sql-keyword, #2e5f97);
  font-weight: 700;
}

.cm-s-tds-exercise .cm-operator {
  color: #666;
}

.cm-s-tds-exercise .cm-string,
.cm-s-tds-exercise .cm-string-2 {
  color: #a31515;
}

.cm-s-tds-exercise .cm-number,
.cm-s-tds-exercise .cm-atom {
  color: #098658;
}

.cm-s-tds-exercise .cm-comment {
  color: #008000;
  font-style: italic;
}

.cm-s-tds-exercise .cm-variable,
.cm-s-tds-exercise .cm-variable-2,
.cm-s-tds-exercise .cm-qualifier {
  color: #001080;
}

.cm-s-tds-exercise .cm-builtin {
  color: #795e26;
}

.cm-s-tds-exercise .cm-type {
  color: #267f99;
}

/* --- Result tables (W3Schools style) --- */
.tds-exercise-page .tds-result-block {
  margin: 0;
}

.tds-exercise-page .tds-playground-meta {
  margin: 0;
  padding: 8px 12px;
  background: var(--tds-brand-pale, #e8f0f8);
  font-family: inherit;
  font-size: 13px;
  font-weight: 400;
  font-style: normal;
  color: var(--tds-text-heading, #2d2a33);
  border-bottom: 1px solid var(--tds-border, #d4e0ed);
}

.tds-exercise-page .tds-playground-output.has-table .tds-playground-table-wrap {
  overflow: auto;
}

.tds-exercise-page .tds-playground-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-family: inherit;
  background: var(--tds-surface-card, #fff);
  margin: 0;
}

.tds-exercise-page .tds-playground-table th,
.tds-exercise-page .tds-playground-table td {
  padding: 8px 12px;
  text-align: left;
  border: 1px solid var(--tds-border, #d4e0ed);
  color: var(--tds-text-heading, #2d2a33);
}

.tds-exercise-page .tds-playground-table th {
  background: var(--tds-brand-pale, #e8f0f8);
  font-weight: 700;
  white-space: nowrap;
}

.tds-exercise-page .tds-playground-table td {
  background: var(--tds-surface-card, #fff);
  font-weight: 400;
}

.tds-exercise-page .tds-playground-table tbody tr:hover td {
  background: var(--tds-brand-pale-2, #f3f7fb);
}

@media (max-width: 900px) {
  .tds-playground-workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .tds-playground-python-panels {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }

  .tds-playground-python-code {
    border-right: none;
    border-bottom: 1px solid var(--tds-border, #d4e0ed);
  }

  .tds-playground-sidebar {
    max-height: 240px;
  }

  .tds-exercise-heading {
    display: none;
  }
}

@media (max-width: 600px) {
  .tds-exercise-header {
    padding: 8px 10px;
  }

  .tds-exercise-back span {
    display: none;
  }

  .tds-playground-workspace {
    padding: 8px 10px;
  }

  .tds-exercise-page .tds-playground-editor-host {
    flex-basis: 155px;
    min-height: 145px;
  }

  .tds-exercise-page .tds-playground-editor-host .CodeMirror {
    min-height: 145px;
    font-size: 12px;
  }
}
