:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-strong: #eef1f5;
  --line: #d8dee7;
  --line-strong: #b8c0cc;
  --text: #151923;
  --muted: #667085;
  --accent: #1268b3;
  --accent-strong: #0f5797;
  --fatal: #8b3d9b;
  --error: #c92a2a;
  --warn: #b65c00;
  --info: #1f2937;
  --debug: #667085;
  --heavy: #828a97;
  --trace: #2f7d68;
  --unknown: #77808c;
  --row-height: 34px;
  font-family: Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 32px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
.virtual-list:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) 28px;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 62px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: 0;
}

.brand p {
  max-width: min(62vw, 780px);
  margin: 2px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
}

.file-input {
  display: none;
}

.primary-button {
  border-color: var(--accent-strong);
  background: var(--accent);
  color: #ffffff;
  font-weight: 650;
  padding: 0 14px;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.ghost-button {
  padding: 0 12px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 50px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-strong);
}

.mobile-panel-toggles {
  display: none;
}

.mobile-toggle {
  min-width: 88px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 650;
}

.mobile-toggle[aria-expanded="true"] {
  background: #1f2937;
  color: #ffffff;
}

.toolbar-content {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.filter-box,
.search-box,
.highlight-box,
.goto-box {
  display: grid;
  grid-template-columns: auto minmax(160px, 320px);
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.filter-box input,
.search-box input,
.highlight-box input,
.goto-box input {
  width: 100%;
  height: 32px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--text);
  background: var(--surface);
}

.goto-box {
  grid-template-columns: auto 72px;
}

.search-actions {
  display: inline-flex;
  gap: 4px;
}

.small-button {
  min-width: 48px;
  padding: 0 8px;
  font-size: 12px;
}

.level-select {
  display: grid;
  grid-template-columns: auto minmax(150px, 210px);
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.level-select select {
  width: 100%;
  height: 32px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0 28px 0 10px;
  background: var(--surface);
  color: var(--text);
}

.level-select select:disabled {
  opacity: 0.65;
}

.view-toggle {
  display: inline-flex;
  flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  overflow: hidden;
}

.mode-button {
  min-width: 64px;
  border: 0;
  border-radius: 0;
  background: var(--surface);
}

.mode-button + .mode-button {
  border-left: 1px solid var(--line-strong);
}

.mode-button.is-active {
  background: #1f2937;
  color: #ffffff;
}

.workspace {
  min-height: 0;
  overflow: hidden;
}

.drop-stage {
  display: grid;
  height: 100%;
  padding: 20px;
  place-items: center;
}

.drop-target {
  display: grid;
  width: min(520px, 100%);
  min-height: 260px;
  place-items: center;
  align-content: center;
  gap: 10px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
}

.drop-target.is-over {
  border-color: var(--accent);
  background: #eaf4ff;
}

.drop-target img {
  width: 48px;
  height: 48px;
}

.drop-target h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.drop-target p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.viewer {
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(164px, 30vh);
  height: 100%;
  min-height: 0;
}

.is-hidden {
  display: none;
}

.log-area {
  display: grid;
  grid-template-rows: 34px minmax(0, 1fr);
  min-height: 0;
  background: var(--surface);
}

.log-header,
.log-row {
  display: grid;
  grid-template-columns: 72px 164px 78px 150px minmax(280px, 1fr);
  align-items: center;
}

.log-header {
  padding-right: 14px;
  border-bottom: 1px solid var(--line);
  background: #f9fafb;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.log-header span,
.log-cell {
  min-width: 0;
  overflow: hidden;
  padding: 0 8px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.virtual-list {
  position: relative;
  min-height: 0;
  overflow: auto;
  background: var(--surface);
}

.virtual-spacer {
  width: 1px;
}

.visible-rows {
  position: absolute;
  inset: 0 0 auto 0;
}

.log-row {
  position: absolute;
  right: 0;
  left: 0;
  height: var(--row-height);
  border-bottom: 1px solid #edf0f4;
  border-left: 4px solid transparent;
  color: #202633;
  font-size: 12px;
  line-height: 1;
}

.log-row:hover {
  background: #f5f9fc;
}

.log-row.is-selected {
  background: #e8f2fb;
}

.log-row.level-fatal { border-left-color: var(--fatal); }
.log-row.level-error { border-left-color: var(--error); }
.log-row.level-warn { border-left-color: var(--warn); }
.log-row.level-info { border-left-color: var(--info); }
.log-row.level-debug { border-left-color: var(--debug); }
.log-row.level-heavy { border-left-color: var(--heavy); }
.log-row.level-trace { border-left-color: var(--trace); }
.log-row.level-unknown { border-left-color: var(--unknown); }

.raw-row {
  grid-template-columns: 72px minmax(420px, 1fr);
}

.level-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  height: 22px;
  border-radius: 5px;
  padding: 0 7px;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.level-badge.fatal { background: var(--fatal); }
.level-badge.error { background: var(--error); }
.level-badge.warn { background: var(--warn); }
.level-badge.info { background: var(--info); }
.level-badge.debug { background: var(--debug); }
.level-badge.heavy { background: var(--heavy); }
.level-badge.trace { background: var(--trace); }
.level-badge.unknown { background: var(--unknown); }

.message-cell {
  font-family: Consolas, monospace;
}

.detail-panel {
  min-height: 0;
  overflow: auto;
  border-top: 1px solid var(--line);
  background: #fbfcfd;
  padding: 10px 14px 12px;
}

.detail-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.detail-heading h2 {
  margin: 0;
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-message {
  min-height: 80px;
  margin: 10px 0 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: #111827;
  font-family: Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  padding: 10px;
  white-space: pre-wrap;
  word-break: break-word;
}

.highlight-hit {
  border-radius: 2px;
  background: #ffe66d;
  color: #111827;
  padding: 0 1px;
}

.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  overflow: hidden;
  padding: 0 10px;
  border-top: 1px solid var(--line);
  background: #28313d;
  color: #ffffff;
  font-size: 12px;
}

.statusbar span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar {
    display: block;
    min-height: 0;
    padding: 6px 10px;
  }

  .mobile-panel-toggles {
    display: flex;
    gap: 6px;
  }

  .mobile-panel-toggles button {
    flex: 1 1 0;
  }

  .toolbar-content {
    display: none;
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
  }

  .toolbar-content.is-open {
    display: flex;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions button {
    flex: 1 1 0;
  }

  .filter-box,
  .search-box,
  .highlight-box,
  .goto-box {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .filter-box input,
  .search-box input,
  .highlight-box input,
  .goto-box input {
    max-width: none;
  }

  .search-actions {
    width: 100%;
  }

  .search-actions button,
  #gotoButton {
    flex: 1 1 0;
  }

  .level-select {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .view-toggle {
    width: 100%;
  }

  .mode-button {
    flex: 1 1 0;
  }

  .log-header,
  .log-row {
    grid-template-columns: 58px 130px 74px minmax(220px, 1fr);
  }

  .log-header span:nth-child(4),
  .log-row .log-cell:nth-child(4) {
    display: none;
  }

  .raw-row {
    grid-template-columns: 58px minmax(260px, 1fr);
  }

  .viewer {
    grid-template-rows: minmax(0, 1fr);
  }

  .viewer.detail-open {
    grid-template-rows: minmax(0, 1fr) minmax(190px, 34vh);
  }

  .viewer.detail-collapsed .detail-panel {
    display: none;
  }
}

@media (max-width: 520px) {
  .brand-icon {
    width: 30px;
    height: 30px;
  }

  .brand h1 {
    font-size: 16px;
  }

  .viewer.detail-open {
    grid-template-rows: minmax(0, 1fr) minmax(190px, 34vh);
  }
}
