﻿/* ═══════════════════════════════════════════════════════
   M4 Log Visualizer — Carbon Split design
   ═══════════════════════════════════════════════════════ */

/* ── Design tokens ──────────────────────────────────── */
:root {
  color-scheme: light;
  --bg:            #f6f8fa;
  --panel:         #ffffff;
  --panel-soft:    #f0f3f6;
  --sidebar:       #f6f8fa;
  --control:       #ffffff;
  --control-hover: #f0f3f6;
  --table-head:    #f6f8fa;
  --raw-bg:        #f8f9fa;
  --raw-text:      #3b4649;
  --text:          #1f2328;
  --muted:         #656d76;
  --line:          #d0d7de;
  --accent:        #0969da;
  --accent-strong: #0550ae;
  --orange:        #bc4c00;
  --shadow:        0 1px 3px rgba(31,35,40,.12), 0 4px 12px rgba(31,35,40,.06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg:            #0d1117;
  --panel:         #161b22;
  --panel-soft:    #1c2128;
  --sidebar:       #0d1117;
  --control:       #21262d;
  --control-hover: #30363d;
  --table-head:    #1c2128;
  --raw-bg:        #0d1117;
  --raw-text:      #c9d1d9;
  --text:          #e6edf3;
  --muted:         #8b949e;
  --line:          #30363d;
  --accent:        #58a6ff;
  --accent-strong: #79c0ff;
  --orange:        #e3b341;
  --shadow:        0 1px 3px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
}

/* ── Reset ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body  { margin: 0; }
h1, h2, h3, h4, p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
button, input { font: inherit; }

/* ── Global button base ─────────────────────────────── */
button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--control);
  color: var(--text);
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
button:hover { border-color: var(--accent); }

/* ── Layout ─────────────────────────────────────────── */
body {
  height: 100vh;
  display: grid;
  grid-template-rows: 52px 1fr;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.app-body {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  min-height: 0;
  overflow: hidden;
}

/* ── Top bar ────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 0;
  background: #24292f;
  border-bottom: 1px solid #30363d;
  overflow: hidden;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
  padding-right: 16px;
  margin-right: 4px;
  border-right: 1px solid rgba(255,255,255,.12);
}

.brand-mark {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 12px;
  flex-shrink: 0;
}

.brand-name {
  font-size: 14px;
  font-weight: 600;
  color: #e6edf3;
  white-space: nowrap;
}

.app-version {
  font-size: 11px;
  color: #8b949e;
  background: rgba(255,255,255,.07);
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.12);
  white-space: nowrap;
}

.topbar-title {
  flex: 1;
  min-width: 0;
  padding: 0 14px;
  overflow: hidden;
}

.topbar-title .eyebrow {
  font-size: 11px;
  color: #8b949e;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-title h2 {
  font-size: 14px;
  font-weight: 600;
  color: #e6edf3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
  padding-left: 14px;
  border-left: 1px solid rgba(255,255,255,.12);
}

/* Override generic button for topbar */
.topbar-actions button {
  height: 30px;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 6px;
  background: rgba(255,255,255,.06);
  color: #e6edf3;
  font-size: 12px;
}
.topbar-actions button:hover {
  background: rgba(255,255,255,.14);
  border-color: rgba(255,255,255,.3);
}

.topbar-actions .icon-button {
  width: 32px;
  min-width: 32px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 18px;
}

.theme-icon {
  width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  font-size: 18px;
  line-height: 1;
}

/* ── Sidebar ────────────────────────────────────────── */
.sidebar {
  height: 100%;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-top {
  flex-shrink: 0;
  padding: 10px 10px 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.file-loader {
  padding: 9px 10px;
  border: 1px dashed var(--line);
  border-radius: 7px;
  background: var(--control-hover);
}

.file-loader.dragging {
  border-color: var(--accent);
  background: var(--panel-soft);
}

.file-loader label {
  display: block;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}

.file-loader input {
  width: 100%;
  font-size: 12px;
}

.file-loader input[type="file"] {
  display: block;
  padding: 5px 0;
  color: var(--muted);
}

.file-loader input[type="file"]::file-selector-button {
  margin-right: 10px;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: linear-gradient(180deg, var(--control) 0%, var(--control-hover) 100%);
  color: var(--text);
  cursor: pointer;
  transition: border-color .12s, background .12s, transform .12s;
}

.file-loader input[type="file"]::file-selector-button:hover {
  border-color: var(--accent);
  background: var(--panel-soft);
}

.file-loader input[type="file"]::file-selector-button:active {
  transform: translateY(1px);
}

.file-loader p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  font-family: Consolas, "Courier New", monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-box input {
  width: 100%;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  outline: none;
  background: var(--control);
  color: var(--text);
  font-size: 13px;
}
.search-box input::placeholder { color: var(--muted); }
.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(9, 105, 218, .18);
}
[data-theme="dark"] .search-box input:focus {
  box-shadow: 0 0 0 3px rgba(88, 166, 255, .18);
}

.filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(72px, 1fr)) 34px;
  gap: 5px;
}

.filters button {
  height: 30px;
  min-height: 30px;
  padding: 0;
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--control);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.filter.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.sort-button {
  width: 34px;
  min-width: 34px;
  font-size: 16px;
}

.sort-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.system-filter {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  padding-bottom: 2px;
}

.system-filter input {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
}

.summary {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.entry-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overflow-x: hidden;
  padding: 6px 6px 16px;
}

.entry-item {
  width: 100%;
  margin-bottom: 2px;
  padding: 7px 9px;
  display: block;
  text-align: left;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  min-height: unset;
  overflow: hidden;
}

.entry-item:hover {
  background: var(--control-hover);
  border-color: var(--line);
}

.entry-item.active {
  background: var(--panel-soft);
  border-color: var(--accent);
}

.entry-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
  line-height: 1.3;
}

.entry-title > span:last-child {
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.entry-meta,
.entry-sql {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.entry-sql {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: Consolas, "Courier New", monospace;
}

/* ── Viewer ─────────────────────────────────────────── */
.viewer {
  height: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.viewer-meta {
  flex-shrink: 0;
  padding: 10px 14px 0;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.viewer-meta-file {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}

.viewer-meta-title {
  font-size: 20px;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: .01em;
  margin-bottom: 8px;
}

.viewer-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 14px;
}

/* ── Panels ─────────────────────────────────────────── */
.panel {
  margin-bottom: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-header {
  min-height: 42px;
  padding: 7px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.panel h3 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}

.panel-action {
  height: 28px;
  min-height: 28px;
  padding: 0 11px;
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--control);
  color: var(--text);
}
.panel-action:hover { border-color: var(--accent); }

#formatSqlButton {
  background: #0f766e;
  border-color: #0f766e;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 1px 0 rgba(31, 35, 40, .08);
}

#formatSqlButton:hover {
  background: #0b5f59;
  border-color: #0b5f59;
}

#formatSqlButton:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(9, 105, 218, .25);
}

[data-theme="dark"] #formatSqlButton:focus-visible {
  box-shadow: 0 0 0 3px rgba(88, 166, 255, .25);
}

[data-theme="dark"] #formatSqlButton {
  background: #1b9a8b;
  border-color: #1b9a8b;
  color: #f0fffb;
}

[data-theme="dark"] #formatSqlButton:hover {
  background: #147e72;
  border-color: #147e72;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

pre {
  margin: 0;
  padding: 14px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: Consolas, "Cascadia Code", "Courier New", monospace;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
}

.sql-panel pre {
  max-height: min(56vh, 520px);
  overflow-wrap: anywhere;
}

/* ── SQL syntax highlighting ────────────────────────── */
.sql-keyword  { color: #cf222e; font-weight: 700; }
.sql-function { color: #8250df; font-weight: 600; }
.sql-string   { color: #0a3069; }
.sql-identifier { color: #953800; font-weight: 600; }
.sql-number   { color: #0550ae; }
.sql-comment  { color: #57606a; font-style: italic; }
.sql-operator { color: #6e7781; font-weight: 600; }

[data-theme="dark"] .sql-keyword  { color: #ff7b72; font-weight: 700; }
[data-theme="dark"] .sql-function { color: #d2a8ff; font-weight: 600; }
[data-theme="dark"] .sql-string   { color: #a5d6ff; }
[data-theme="dark"] .sql-identifier { color: #ffa657; font-weight: 600; }
[data-theme="dark"] .sql-number   { color: #79c0ff; }
[data-theme="dark"] .sql-comment  { color: #8b949e; font-style: italic; }
[data-theme="dark"] .sql-operator { color: #8b949e; font-weight: 600; }

/* ── Raw output ─────────────────────────────────────── */
.raw-panel pre {
  max-height: 240px;
  color: var(--raw-text);
  background: var(--raw-bg);
  font-size: 12px;
}

/* ── Result table ───────────────────────────────────── */
.table-wrap { width: 100%; overflow: auto; }

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

th, td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--panel-soft) 65%, transparent);
}

th {
  position: sticky;
  top: 0;
  background: var(--table-head);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}

td { font-family: Consolas, "Courier New", monospace; }

.empty { padding: 16px; color: var(--muted); font-size: 13px; }

/* ── Status bar ─────────────────────────────────────── */
.status-bar {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  padding: 0 0 8px;
}

.status-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 6px 10px;
  min-height: 50px;
}

.status-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}

.status-item strong {
  display: block;
  width: 100%;
  font-weight: 700;
  font-size: 13px;
  line-height: 1.05;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.status-item-primary {
  background: #f4f8ff;
  border-color: #b8cceb;
  box-shadow: inset 0 0 0 1px rgba(9, 105, 218, .06);
  transition: box-shadow .18s ease, border-color .18s ease, background-color .18s ease;
}

.status-item-primary strong {
  font-size: 14px;
}

.status-object-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
}

.status-object-row strong {
  flex: 1;
  min-width: 0;
}

.status-ignore-link {
  display: none;
  flex: 0 0 auto;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-size: 12px;
  line-height: 1;
}

.status-ignore-link.is-visible {
  display: inline;
}

.status-ignore-link.is-disabled {
  color: var(--muted);
  cursor: default;
  pointer-events: none;
  text-decoration: none;
}

.status-item-feedback-added {
  border-color: #3ca66b;
  box-shadow: inset 0 0 0 1px rgba(60, 166, 107, .25), 0 0 0 3px rgba(60, 166, 107, .12);
  background: #eefbf3;
}

.status-item-feedback-existing {
  border-color: #ca7b1b;
  box-shadow: inset 0 0 0 1px rgba(202, 123, 27, .2), 0 0 0 3px rgba(202, 123, 27, .1);
  background: #fff7ea;
}

[data-theme="dark"] .status-item-feedback-added {
  border-color: #3ca66b;
  box-shadow: inset 0 0 0 1px rgba(60, 166, 107, .35), 0 0 0 3px rgba(60, 166, 107, .15);
  background: #173226;
}

[data-theme="dark"] .status-item-feedback-existing {
  border-color: #ca7b1b;
  box-shadow: inset 0 0 0 1px rgba(202, 123, 27, .3), 0 0 0 3px rgba(202, 123, 27, .12);
  background: #352712;
}

.status-item-compact {
  padding-right: 8px;
}

.status-item-compact strong {
  font-size: 12px;
}

[data-theme="dark"] .status-item-primary {
  background: #1b2535;
  border-color: #2f4f75;
  box-shadow: inset 0 0 0 1px rgba(88, 166, 255, .18);
}

.status-hidden {
  display: none;
}

/* ── Settings drawer ────────────────────────────────── */
.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 400px;
  max-width: 100%;
  height: 100vh;
  z-index: 80;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 32px rgba(0,0,0,.22);
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform .2s ease, visibility .2s;
  visibility: visible;
}

.settings-panel.hidden {
  transform: translateX(100%);
  visibility: hidden;
  pointer-events: none;
}

.settings-panel .panel-header {
  flex-shrink: 0;
}

.settings-content {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-content > label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}

.add-row {
  display: flex;
  gap: 8px;
}

.add-row input {
  flex: 1;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--control);
  color: var(--text);
  font-size: 13px;
}
.add-row input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(9, 105, 218, .18);
}
[data-theme="dark"] .add-row input:focus {
  box-shadow: 0 0 0 3px rgba(88, 166, 255, .18);
}

.add-row button {
  height: 34px;
  min-height: 34px;
  padding: 0 12px;
}

.ignored-list-wrap {
  flex: 1;
  min-height: 100px;
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  padding: 8px;
}

.ignored-list-wrap h4 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin: 0 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.ignored-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ignored-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 5px;
  background: var(--control);
  border: 1px solid var(--line);
  font-size: 12px;
  font-family: Consolas, "Courier New", monospace;
}

.ignored-list .remove-ignored {
  min-width: 26px;
  height: 26px;
  min-height: 26px;
  padding: 0 5px;
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--control);
  color: var(--muted);
  flex-shrink: 0;
}
.ignored-list .remove-ignored:hover {
  border-color: #cf222e;
  color: #cf222e;
  background: var(--control);
}

.settings-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.settings-actions button {
  height: 34px;
  min-height: 34px;
  padding: 0 14px;
  font-size: 13px;
}

/* ── Backdrop ───────────────────────────────────────── */
#settingsBackdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 70;
}
#settingsBackdrop.hidden { display: none; }

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 980px) {
  body {
    grid-template-rows: 52px auto;
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .app-body {
    grid-template-columns: 1fr;
    overflow: visible;
    height: auto;
  }

  .sidebar {
    height: auto;
    overflow: visible;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .viewer {
    height: auto;
    overflow: visible;
  }

  .viewer-scroll {
    overflow: visible;
    height: auto;
    flex: unset;
  }

  .entry-list { max-height: 360px; }
  .viewer-meta-title { font-size: 20px; }
  .status-bar { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
  .brand-name   { display: none; }
  .filters { grid-template-columns: 1fr 1fr 34px; }
  .viewer-scroll { padding: 10px; }
  .viewer-meta { padding: 8px 10px 0; }
  .viewer-meta-file { font-size: 12px; }
  .viewer-meta-title { font-size: 17px; margin-bottom: 8px; }
  .status-item { min-height: 48px; padding: 6px 9px; }
  .status-label { font-size: 10px; }
  .status-item strong { font-size: 13px; }
  .status-item-primary strong { font-size: 14px; }
}
