:root {
  color-scheme: light;
  --bg: #f4f1ec;
  --surface: #ffffff;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --border: #e5e0d8;
  --primary: #2d2a4a;
  --primary-contrast: #ffffff;
  --accent: #6d5bd0;
  --success: #15803d;
  --success-bg: #dcfce7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --code-bg: #f1f0fb;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #14121f;
    --surface: #1e1b2e;
    --text: #f1f2f4;
    --text-muted: #a7a2bd;
    --border: #33304a;
    --primary: #f1f2f4;
    --primary-contrast: #14121f;
    --accent: #a996ff;
    --success: #4ade80;
    --success-bg: #14301f;
    --danger: #f87171;
    --danger-bg: #3a1414;
    --code-bg: #262238;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

code {
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
}

.app-header-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-header h1 {
  font-size: 18px;
  margin: 0;
}

.badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-on { background: var(--success-bg); color: var(--success); }
.badge-off { background: var(--danger-bg); color: var(--danger); }

#app {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card h2 { margin-top: 0; font-size: 16px; }
.card h3 { font-size: 14px; color: var(--text-muted); margin-bottom: 6px; }

.hint {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

.settings-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.field input, .sql-input {
  font: inherit;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

.settings-actions {
  grid-column: 1 / -1;
}

.btn {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: 999px;
  padding: 9px 18px;
  cursor: pointer;
}

.btn-primary { background: var(--primary); color: var(--primary-contrast); }
.btn-secondary { background: var(--accent); color: #fff; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.log-panel {
  margin-top: 14px;
  background: var(--code-bg);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  max-height: 160px;
  overflow-y: auto;
  white-space: pre-wrap;
}

.timing {
  font-size: 12px;
  color: var(--text-muted);
  margin: 10px 0 4px;
}

.result-table {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

th, td {
  border-bottom: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
}

th { color: var(--text-muted); font-weight: 600; }

.error { color: var(--danger); font-size: 13px; }

.sql-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sql-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  resize: vertical;
}

@media (max-width: 600px) {
  .settings-form { grid-template-columns: 1fr; }
}
