/* SQLQLtter - ダークテーマ */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-input: #0f3460;
  --accent: #00d4ff;
  --accent-hover: #00b4d8;
  --text-primary: #e0e0e0;
  --text-secondary: #aaa;
  --text-muted: #888;
  --danger: #e74c3c;
  --success: #2ecc71;
  --warning: #f39c12;
  --border-radius: 6px;
}

body {
  font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── ヘッダー ─── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid #2a2a4e;
  flex-shrink: 0;
}

.header h1 {
  color: var(--accent);
  font-size: 20px;
  letter-spacing: 2px;
}

.header .auth-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header .user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.header .user-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--bg-primary);
  font-weight: bold;
}

/* ─── ボタン共通 ─── */
button, .btn {
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  padding: 6px 14px;
  border-radius: var(--border-radius);
  cursor: pointer;
  font-family: inherit;
  font-weight: bold;
  font-size: 12px;
  transition: background 0.2s;
}

button:hover { background: var(--accent-hover); }
button.danger { background: var(--danger); color: white; }
button.danger:hover { background: #c0392b; }
button.small { padding: 3px 8px; font-size: 11px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── メインレイアウト ─── */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── TL パネル（左） ─── */
.tl-panel {
  width: 360px;
  min-width: 300px;
  background: var(--bg-secondary);
  border-right: 1px solid #2a2a4e;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tl-header {
  padding: 10px 12px;
  border-bottom: 1px solid #2a2a4e;
  font-size: 14px;
  color: var(--accent);
  font-weight: bold;
  flex-shrink: 0;
}

/* ─── 投稿フォーム ─── */
.post-form {
  padding: 10px 12px;
  border-bottom: 1px solid #2a2a4e;
  flex-shrink: 0;
}

.post-form textarea {
  width: 100%;
  height: 56px;
  background: var(--bg-input);
  border: 1px solid #2a2a4e;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  padding: 8px;
  border-radius: var(--border-radius);
  resize: none;
}

.post-form textarea:focus {
  border-color: var(--accent);
  outline: none;
}

.post-form .form-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
}

.post-form .char-count {
  font-size: 11px;
  color: var(--text-muted);
}

.post-form .char-count.over { color: var(--danger); }

/* ─── TL 投稿一覧 ─── */
.tl-posts {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.post-card {
  padding: 10px 12px;
  border-bottom: 1px solid #1a1a2e;
  animation: fadeIn 0.3s ease;
}

.post-card.fading {
  animation: fadeOut 2s ease forwards;
}

.post-card .post-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.post-card .post-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--bg-primary);
  font-weight: bold;
  flex-shrink: 0;
}

.post-card .post-name {
  font-weight: bold;
  font-size: 12px;
  color: var(--accent);
}

.post-card .post-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-left: auto;
}

.post-card .post-content {
  font-size: 13px;
  line-height: 1.5;
  margin: 4px 0;
  word-break: break-word;
}

.post-card .post-actions {
  display: flex;
  gap: 16px;
  margin-top: 6px;
}

.post-card .post-actions button {
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  padding: 2px 6px;
  font-weight: normal;
}

.post-card .post-actions button:hover { color: var(--accent); background: transparent; }
.post-card .post-actions button.faved { color: var(--danger); }
.post-card .post-actions button.reposted { color: var(--success); }

/* ─── SQL パネルエリア（右） ─── */
.sql-area {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  overflow: hidden;
}

.sql-panel {
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sql-panel .panel-toolbar {
  display: flex;
  gap: 4px;
  padding: 6px 8px;
  flex-shrink: 0;
  align-items: center;
}

.sql-panel .panel-toolbar .panel-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-right: auto;
}

.sql-panel textarea {
  width: 100%;
  flex: 0 0 auto;
  min-height: 60px;
  max-height: 120px;
  background: var(--bg-input);
  border: none;
  border-top: 1px solid #2a2a4e;
  border-bottom: 1px solid #2a2a4e;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12px;
  padding: 6px 8px;
  resize: vertical;
}

.sql-panel textarea:focus { outline: 1px solid var(--accent); }

.sql-panel .result-area {
  flex: 1;
  overflow: auto;
  padding: 6px 8px;
  font-size: 11px;
}

/* ─── 結果テーブル ─── */
.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.result-table th {
  background: var(--bg-input);
  color: var(--accent);
  padding: 4px 8px;
  text-align: left;
  position: sticky;
  top: 0;
  font-weight: bold;
}

.result-table td {
  padding: 3px 8px;
  border-bottom: 1px solid #1a1a2e;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-table tr:hover td {
  background: rgba(0, 212, 255, 0.05);
}

/* ─── SSE イベント表示 ─── */
.sse-event {
  background: var(--bg-input);
  border-left: 3px solid var(--accent);
  padding: 4px 8px;
  margin-bottom: 4px;
  border-radius: 0 var(--border-radius) var(--border-radius) 0;
  font-size: 11px;
}

.sse-event.INSERT { border-left-color: var(--success); }
.sse-event.UPDATE { border-left-color: var(--warning); }
.sse-event.DELETE { border-left-color: var(--danger); }

.sse-event .op { font-weight: bold; }
.sse-event .op.INSERT { color: var(--success); }
.sse-event .op.UPDATE { color: var(--warning); }
.sse-event .op.DELETE { color: var(--danger); }

/* ─── エラー表示 ─── */
.error-msg {
  color: var(--danger);
  font-size: 12px;
  padding: 8px;
}

/* ─── 認証モーダル ─── */
.auth-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.auth-overlay.show { display: flex; }

.auth-modal {
  background: var(--bg-secondary);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 32px;
  width: 360px;
  text-align: center;
}

.auth-modal h2 {
  color: var(--accent);
  font-size: 24px;
  margin-bottom: 8px;
}

.auth-modal p {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 20px;
}

.auth-modal input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid #2a2a4e;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  padding: 10px;
  border-radius: var(--border-radius);
  margin-bottom: 12px;
}

.auth-modal input:focus {
  border-color: var(--accent);
  outline: none;
}

.auth-modal .auth-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.auth-modal .auth-buttons button {
  width: 100%;
  padding: 10px;
  font-size: 14px;
}

.auth-modal .auth-buttons .passkey-btn {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
}

.auth-modal .divider {
  color: var(--text-muted);
  font-size: 11px;
  margin: 8px 0;
}

/* ─── SSE ステータス ─── */
.sse-status {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  display: inline-block;
}

.sse-status.active { background: var(--success); color: var(--bg-primary); }
.sse-status.inactive { background: var(--text-muted); color: var(--bg-primary); }

/* ─── アニメーション ─── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; height: 0; padding: 0; overflow: hidden; }
}

/* ─── スクロールバー ─── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: #2a2a4e; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ─── レスポンシブ（スマホ縦） ─── */
@media (max-width: 768px) {
  .main {
    flex-direction: column;
  }

  .tl-panel {
    width: 100%;
    min-width: 0;
    max-height: 50vh;
    border-right: none;
    border-bottom: 1px solid #2a2a4e;
  }

  .sql-area {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(4, 1fr);
  }
}
