/* css/style.css */
/* 応用情報 SQL練習サイト - ダークテーマ 2カラムレイアウト */

/* ===== リセット・基本 ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-base:       #1e1e2e;
  --bg-panel:      #181825;
  --bg-surface:    #24273a;
  --bg-hover:      #313244;
  --text-main:     #cdd6f4;
  --text-muted:    #6c7086;
  --text-heading:  #89b4fa;
  --accent:        #89b4fa;
  --accent-green:  #a6e3a1;
  --accent-red:    #f38ba8;
  --accent-yellow: #f9e2af;
  --border:        #313244;
  --header-h:      52px;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', 'Noto Sans JP', sans-serif;
  font-size: 14px;
  color: var(--text-main);
  background: var(--bg-base);
  overflow: hidden;
}

/* ===== ヘッダー ===== */
#topbar {
  height: var(--header-h);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  flex-shrink: 0;
}

#topbar h1 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-heading);
  white-space: nowrap;
  flex-shrink: 0;
}

#problem-selector {
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 13px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

#problem-selector:focus {
  outline: none;
  border-color: var(--accent);
}

.db-status {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}

.db-status.loading  { color: var(--accent-yellow); }
.db-status.ready    { color: var(--accent-green); }
.db-status.error    { color: var(--accent-red); }

/* ===== メインレイアウト ===== */
#workspace {
  display: grid;
  grid-template-columns: 38% 1fr;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
  position: relative;
}

/* ===== 問題パネル（左） ===== */
#problem-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

/* 設問タブ */
#question-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 6px 8px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.q-tab {
  background: var(--bg-hover);
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, background 0.15s;
}

.q-tab:hover {
  color: var(--text-main);
  background: var(--bg-base);
}

.q-tab.active {
  color: var(--accent);
  background: var(--bg-base);
  border-color: var(--accent);
}

/* 設問コンテンツ */
#question-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
}

#question-description {
  line-height: 1.6;
}

#question-description h3 {
  color: var(--text-heading);
  font-size: 14px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

#question-description h4 {
  color: var(--accent-yellow);
  font-size: 13px;
  margin: 10px 0 4px;
}

#question-description p {
  margin: 6px 0;
  font-size: 13px;
}

#question-description ul, #question-description ol {
  padding-left: 18px;
  margin: 6px 0;
  font-size: 13px;
}

#question-description li {
  margin: 2px 0;
}

#question-description blockquote {
  border-left: 3px solid var(--accent);
  padding: 6px 10px;
  margin: 8px 0;
  background: var(--bg-surface);
  border-radius: 0 4px 4px 0;
  font-size: 13px;
}

#question-description table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 12px;
  width: 100%;
}

#question-description table th,
#question-description table td {
  border: 1px solid var(--border);
  padding: 4px 8px;
  text-align: left;
}

#question-description table th {
  background: var(--bg-surface);
  color: var(--text-heading);
}

#question-description pre {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
  font-family: 'Consolas', 'Noto Sans Mono', monospace;
  font-size: 12px;
  overflow-x: auto;
  white-space: pre;
  margin: 8px 0;
}

#question-description code {
  background: var(--bg-surface);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: 'Consolas', 'Noto Sans Mono', monospace;
  font-size: 12px;
}

/* ヒント・解答ボックス */
#hint-box, #answer-box {
  margin: 0 0 8px;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.6;
}

#hint-box {
  background: #1e2a1e;
  border: 1px solid #4a7c59;
}

#hint-box h4 {
  color: var(--accent-green);
  margin-bottom: 6px;
  font-size: 13px;
}

#answer-box {
  background: #1e1e2a;
  border: 1px solid var(--accent);
}

#answer-box h4 {
  color: var(--accent);
  margin-bottom: 6px;
  font-size: 13px;
}

#answer-box p, #answer-box ul, #answer-box pre {
  font-size: 13px;
  margin: 4px 0;
}

#answer-box pre {
  background: var(--bg-surface);
  padding: 8px;
  border-radius: 4px;
  overflow-x: auto;
  font-family: 'Consolas', monospace;
  font-size: 12px;
}

/* パネルコントロールボタン */
#panel-controls {
  padding: 8px 14px;
  display: flex;
  gap: 8px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#panel-controls button {
  flex: 1;
  padding: 6px 4px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-muted);
  transition: color 0.15s, background 0.15s;
}

#panel-controls button:hover {
  color: var(--text-main);
  background: var(--bg-hover);
}

/* ===== エディタパネル（右） ===== */
#editor-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-base);
  overflow: hidden;
}

/* エディタツールバー */
#editor-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#btn-run {
  padding: 5px 16px;
  background: var(--accent);
  color: #1e1e2e;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

#btn-run:hover { opacity: 0.85; }
#btn-run:disabled { opacity: 0.5; cursor: default; }

#run-status {
  font-size: 12px;
  color: var(--text-muted);
}

/* CodeMirrorエリア */
.CodeMirror {
  height: 42vh;
  font-family: 'Consolas', 'Noto Sans Mono', monospace !important;
  font-size: 13px !important;
  line-height: 1.5;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.CodeMirror-scroll {
  overflow-y: auto !important;
}

/* 結果エリア */
#results-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#error-display {
  margin: 8px 12px;
  padding: 8px 12px;
  background: #2d1b1b;
  border-left: 3px solid var(--accent-red);
  color: var(--accent-red);
  font-family: 'Consolas', monospace;
  font-size: 12px;
  border-radius: 0 4px 4px 0;
  line-height: 1.5;
  flex-shrink: 0;
}

#results-meta {
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

#results-table-wrapper {
  flex: 1;
  overflow: auto;
  padding: 0 12px 12px;
}

#results-table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  font-size: 13px;
}

#results-table th {
  background: var(--bg-surface);
  color: var(--text-heading);
  border: 1px solid var(--border);
  padding: 5px 10px;
  text-align: left;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}

#results-table td {
  border: 1px solid var(--border);
  padding: 4px 10px;
  white-space: nowrap;
  color: var(--text-main);
}

#results-table tbody tr:hover td {
  background: var(--bg-surface);
}

#results-table .null-cell {
  color: var(--text-muted);
  font-style: italic;
}

#results-table .no-results {
  color: var(--text-muted);
  text-align: center;
  padding: 16px;
}

/* ===== スキーマサイドバー ===== */
#schema-sidebar {
  position: absolute;
  right: 0;
  top: 0;
  width: 240px;
  height: 100%;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  box-shadow: -4px 0 12px rgba(0,0,0,0.4);
}

#schema-sidebar h3 {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-heading);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

#schema-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

#schema-close:hover { color: var(--text-main); }

#schema-tree {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.schema-item {
  border-bottom: 1px solid var(--border);
}

.schema-table-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  cursor: pointer;
  user-select: none;
}

.schema-table-header:hover {
  background: var(--bg-hover);
}

.schema-table-icon {
  font-size: 10px;
  color: var(--text-muted);
  width: 10px;
  flex-shrink: 0;
}

.schema-table-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--accent-yellow);
  cursor: pointer;
}

.schema-table-name:hover {
  text-decoration: underline;
}

.schema-columns {
  list-style: none;
  padding: 2px 0 4px 28px;
  background: var(--bg-surface);
}

.schema-columns li {
  font-size: 12px;
  color: var(--text-muted);
  padding: 2px 0;
  font-family: 'Consolas', monospace;
}

/* ユーティリティ */
.hidden {
  display: none !important;
}

/* ===== スクロールバー ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== タブレット以下 ===== */
@media (max-width: 900px) {
  #workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 45vh 1fr;
  }

  #problem-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .CodeMirror {
    height: 28vh;
  }
}
