* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #1a1b26;
  --bg-surface: #24283b;
  --bg-input: #1e2030;
  --border: #3b4261;
  --text: #c0caf5;
  --text-muted: #565f89;
  --accent: #7aa2f7;
  --accent-hover: #89b4fa;
  --green: #9ece6a;
  --red: #f7768e;
  --orange: #ff9e64;
  --purple: #bb9af7;
  --radius: 6px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 32px;
}

h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

nav {
  display: flex;
  gap: 4px;
}

.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  transition: all .15s;
}

.tab:hover {
  color: var(--text);
  background: rgba(122, 162, 247, .1);
}

.tab.active {
  color: var(--accent);
  background: rgba(122, 162, 247, .15);
  border-color: var(--accent);
}

footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 10px 24px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  z-index: 10;
}

main {
  padding: 16px 24px;
  height: calc(100vh - 58px - 48px);
}

.tool {
  display: none;
  height: 100%;
  flex-direction: column;
  gap: 12px;
}

.tool.active {
  display: flex;
}

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar button {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: all .15s;
  position: relative;
  overflow: hidden;
}

.toolbar button:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.toolbar button:active {
  transform: scale(.96);
}

/* Primary action buttons */
.toolbar button.btn-primary {
  background: rgba(122, 162, 247, .15);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.toolbar button.btn-primary:hover {
  background: rgba(122, 162, 247, .25);
  border-color: var(--accent-hover);
  color: var(--accent-hover);
}

/* Danger / clear buttons */
.toolbar button.btn-danger {
  color: var(--text-muted);
}

.toolbar button.btn-danger:hover {
  border-color: var(--red);
  color: var(--red);
}

/* Flash feedback animation */
@keyframes btn-flash {
  0% { box-shadow: 0 0 0 0 rgba(122, 162, 247, .4); }
  100% { box-shadow: 0 0 0 8px rgba(122, 162, 247, 0); }
}

.toolbar button.flash {
  animation: btn-flash .4s ease-out;
}

.status {
  margin-left: auto;
  font-size: 13px;
  font-weight: 500;
}

.status.ok { color: var(--green); }
.status.err { color: var(--red); }

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

textarea {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 14px;
  font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 13px;
  line-height: 1.6;
  resize: none;
  outline: none;
  tab-size: 2;
}

textarea:focus {
  border-color: var(--accent);
}

textarea::placeholder {
  color: var(--text-muted);
}

/* JSON */
.json-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.json-container textarea {
  flex: 1;
}

.tree-view {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  overflow: auto;
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 13px;
  line-height: 1.7;
}

.hidden { display: none !important; }

.tree-key { color: var(--accent); }
.tree-string { color: var(--green); }
.tree-number { color: var(--orange); }
.tree-bool { color: var(--purple); }
.tree-null { color: var(--text-muted); }

.tree-toggle {
  cursor: pointer;
  user-select: none;
}

.tree-toggle::before {
  content: "▶ ";
  display: inline-block;
  transition: transform .15s;
  font-size: 10px;
  margin-right: 4px;
}

.tree-toggle.open::before {
  transform: rotate(90deg);
}

.tree-children {
  margin-left: 20px;
}

.tree-children.collapsed {
  display: none;
}

/* Diff */
.diff-input-row {
  display: flex;
  gap: 12px;
  flex: 1;
  min-height: 0;
}

.diff-input-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}

.diff-input-col label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.diff-input-col textarea {
  flex: 1;
}

.diff-output {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  overflow: auto;
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 13px;
  line-height: 1.7;
  max-height: 45vh;
}

.diff-output .diff-header {
  color: var(--text-muted);
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.diff-line {
  white-space: pre-wrap;
  word-break: break-all;
}

.diff-add {
  background: rgba(158, 206, 106, .15);
  color: var(--green);
}

.diff-remove {
  background: rgba(247, 118, 142, .15);
  color: var(--red);
}

.diff-context {
  color: var(--text-muted);
}

#sql-input {
  flex: 1;
}

/* CSV */
.csv-container {
  display: flex;
  gap: 12px;
  flex: 1;
  min-height: 0;
}

.csv-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}

.csv-col label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.csv-col textarea {
  flex: 1;
}

.toolbar-label {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-label select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: var(--radius);
  font-size: 13px;
}

#csvcheck-input {
  flex: 1;
  min-height: 80px;
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  transition: all .2s;
  cursor: pointer;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(122, 162, 247, .05);
}

.dropzone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 13px;
}

.dropzone-icon {
  font-size: 32px;
  line-height: 1;
}

.dropzone-or {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.dropzone-btn {
  background: rgba(122, 162, 247, .15);
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 8px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all .15s;
}

.dropzone-btn:hover {
  background: rgba(122, 162, 247, .25);
  color: var(--accent-hover);
  border-color: var(--accent-hover);
}

.dropzone-fileinfo {
  margin-top: 4px;
  color: var(--green);
  font-weight: 600;
}

.csv-report {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  overflow: auto;
  max-height: 40vh;
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 13px;
  line-height: 1.7;
}

.csv-report-ok {
  color: var(--green);
  font-weight: 600;
}

.csv-report-summary {
  color: var(--text-muted);
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.csv-report-error {
  color: var(--red);
  padding: 2px 0;
}

.csv-report-error span {
  color: var(--text-muted);
}

.csv-table-wrap {
  max-height: 40vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.csv-table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 12px;
}

.csv-table-wrap th {
  background: var(--bg-surface);
  color: var(--accent);
  position: sticky;
  top: 0;
  z-index: 1;
}

.csv-table-wrap th,
.csv-table-wrap td {
  padding: 6px 12px;
  border: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.csv-table-wrap tr:nth-child(even) {
  background: rgba(122, 162, 247, .04);
}

.csv-table-wrap tr:hover td {
  background: rgba(122, 162, 247, .1);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

@media (max-width: 768px) {
  header {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }
  .diff-input-row {
    flex-direction: column;
  }
  main {
    padding: 12px;
  }
}
