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

:root {
  --bg: #f8f9fa;
  --surface: #fff;
  --border: #dee2e6;
  --text: #212529;
  --text-muted: #868e96;
  --accent: #228be6;
  --accent-hover: #1c7ed6;
  --hover: #e9ecef;
  --selected: #d0ebff;
  --radius: 6px;
}

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

#app {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* --- Header / Drop zone --- */

#header {
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 10px 20px;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.drop-zone.over {
  border-color: var(--accent);
  background: var(--selected);
}

.drop-zone.compact {
  padding: 6px 14px;
  flex: 0 auto;
}

.drop-label { color: var(--text-muted); font-size: 14px; }

#picker { font-size: 14px; cursor: pointer; }

#status { color: var(--text-muted); font-size: 13px; white-space: nowrap; }

.source-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: color 0.15s, background 0.15s;
}

.source-link:hover {
  color: var(--text);
  background: var(--hover);
}

/* --- Error banner --- */

#error-banner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 16px;
  background: #fff9ed;
  border-bottom: 1px solid #f0d9a8;
  color: #6e5a1f;
  font-size: 13px;
  line-height: 1.45;
  animation: error-slide-in 0.2s ease-out;
}

@keyframes error-slide-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

#error-banner::before {
  content: '\26A0';
  flex-shrink: 0;
  font-size: 14px;
  line-height: 1.45;
}

#error-banner .error-text { flex: 1; white-space: pre-line; }

#error-banner .error-dismiss {
  flex-shrink: 0;
  background: none;
  border: none;
  color: #a08a4a;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  border-radius: 3px;
}

#error-banner .error-dismiss:hover {
  color: #6e5a1f;
  background: rgba(0, 0, 0, 0.06);
}

/* --- Config toggle button --- */

.config-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
  font-size: 13px;
  white-space: nowrap;
  padding: 4px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.config-toggle:hover {
  color: var(--text);
  background: var(--hover);
}

.config-toggle.active {
  color: var(--accent);
  border-color: var(--accent);
  background: #e7f5ff;
}

.config-toggle.has-config {
  color: var(--accent);
  border-color: var(--accent);
}

.config-toggle.has-config::after {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  margin-left: 2px;
}

/* --- Config panel --- */

.config-panel {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
}

.config-panel.hidden {
  display: none;
}

.config-body {
  display: flex;
  gap: 16px;
  padding: 12px 16px;
  max-height: 260px;
}

.config-left {
  flex: 1;
  min-width: 0;
}

.config-left textarea {
  width: 100%;
  height: 100%;
  min-height: 140px;
  resize: vertical;
  font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  outline: none;
  tab-size: 4;
  transition: border-color 0.15s;
}

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

.config-left textarea.dragover {
  border-color: var(--accent);
  background: var(--selected);
}

.config-left textarea::placeholder {
  color: #adb5bd;
  font-style: italic;
}

.config-right {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.config-info {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.config-info.custom {
  color: var(--accent);
}

.config-error {
  font-size: 12px;
  color: #c92a2a;
  line-height: 1.4;
  background: #fff5f5;
  border: 1px solid #ffc9c9;
  border-radius: var(--radius);
  padding: 6px 10px;
  word-break: break-word;
  white-space: pre-line;
}

.config-error.hidden {
  display: none;
}

.config-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
}

.btn {
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn-apply {
  background: var(--accent);
  color: #fff;
}

.btn-apply:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-clear,
.btn-file {
  background: var(--surface);
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-clear:hover:not(:disabled),
.btn-file:hover {
  background: var(--hover);
  color: var(--text);
}

.btn-file {
  text-align: center;
}

/* --- Explorer layout --- */

#explorer {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* --- Panels --- */

#lists-panel {
  width: 280px;
  min-width: 180px;
  max-width: 40vw;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

#entries-panel {
  width: 260px;
  min-width: 160px;
  max-width: 40vw;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

#detail-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.panel-header {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  flex-shrink: 0;
  background: var(--surface);
}

.panel-header input[type="text"] {
  flex: 1 1 100%;
  padding: 4px 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
}

.panel-header input[type="text"]:focus {
  border-color: var(--accent);
}

.panel-header span {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#lists-content,
#entries-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

#detail-content {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

/* --- Dividers --- */

.divider {
  width: 4px;
  cursor: col-resize;
  background: transparent;
  flex-shrink: 0;
  position: relative;
  margin-left: -2px;
  margin-right: -2px;
  z-index: 10;
}

.divider:hover, .divider.dragging {
  background: var(--accent);
  opacity: 0.4;
}

/* --- List items --- */

.list-item,
.entry-item {
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
}

.list-item:hover,
.entry-item:hover {
  background: var(--hover);
}

.list-item.selected,
.entry-item.selected {
  background: var(--selected);
  font-weight: 500;
}

.list-item .badge {
  float: right;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: normal;
}

.entry-item .entry-id {
  color: var(--text-muted);
  font-size: 11px;
  margin-right: 6px;
  font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
}

/* --- Detail view --- */

.placeholder {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  margin-top: 80px;
}

.detail-table {
  width: 100%;
  border-collapse: collapse;
}

.detail-table tr {
  border-bottom: 1px solid var(--border);
}

.detail-table tr:hover {
  background: var(--hover);
}

.detail-table td {
  padding: 4px 12px;
  font-size: 13px;
  vertical-align: top;
}

.detail-table .field-name {
  width: 200px;
  min-width: 140px;
  color: var(--text-muted);
  font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
  font-size: 12px;
  white-space: nowrap;
  user-select: all;
}

.detail-table .field-value {
  word-break: break-all;
  font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
  font-size: 12px;
}

.field-value.string-value { color: #2b8a3e; }
.field-value.number-value { color: #1864ab; }
.field-value.bytes-value { color: var(--text-muted); font-size: 11px; }

.bytes-toggle {
  color: var(--accent);
  cursor: pointer;
  font-size: 11px;
}

.bytes-toggle:hover { text-decoration: underline; }

.bytes-hex {
  display: none;
  margin-top: 4px;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre;
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg);
  padding: 8px;
  border-radius: var(--radius);
}

.bytes-hex.expanded { display: block; }

/* --- Status bar --- */

#statusbar {
  padding: 4px 16px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 16px;
  flex-shrink: 0;
}

/* --- Utilities --- */

.hidden { display: none !important; }

/* --- Scrollbar styling --- */

#lists-content::-webkit-scrollbar,
#entries-content::-webkit-scrollbar,
#detail-content::-webkit-scrollbar {
  width: 8px;
}

#lists-content::-webkit-scrollbar-thumb,
#entries-content::-webkit-scrollbar-thumb,
#detail-content::-webkit-scrollbar-thumb {
  background: #ced4da;
  border-radius: 4px;
}

#lists-content::-webkit-scrollbar-thumb:hover,
#entries-content::-webkit-scrollbar-thumb:hover,
#detail-content::-webkit-scrollbar-thumb:hover {
  background: #adb5bd;
}
