:root {
  color-scheme: dark;
  --bg-0: #0b0f14;
  --bg-1: #111822;
  --bg-2: #172030;
  --bg-3: #1f2a3d;
  --border: #2a3548;
  --text: #e8edf5;
  --text-muted: #8b97ab;
  --accent: #4da3ff;
  --accent-soft: rgba(77, 163, 255, 0.15);
  --danger: #ff6b6b;
  --warn: #ffb020;
  --info: #4da3ff;
  --debug: #8b97ab;
  --trace: #6b7280;
  --fatal: #ff4757;
  --success: #3ddc97;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--sans);
  background:
    radial-gradient(circle at top left, rgba(77, 163, 255, 0.08), transparent 40%),
    radial-gradient(circle at bottom right, rgba(61, 220, 151, 0.06), transparent 35%),
    var(--bg-0);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 24, 34, 0.85);
  backdrop-filter: blur(10px);
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.topbar-user {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 0 4px;
}

.auth-loading {
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--text-muted);
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  padding: 32px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(17, 24, 34, 0.92);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.35);
}

.login-brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 28px;
}

.login-brand h1 {
  margin: 0;
  font-size: 1.2rem;
}

.login-brand p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-form .field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.login-form .field span {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.login-form input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
}

.login-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-error {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 107, 107, 0.12);
  border: 1px solid rgba(255, 107, 107, 0.35);
  color: #ffb4b4;
  font-size: 0.9rem;
}

.login-submit {
  width: 100%;
  margin-top: 4px;
}

a.btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #3ddc97);
  color: #041018;
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
}

.brand p {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.toolbar {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
}

.toolbar-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.search-input,
.view-select,
.level-select,
.page-size-select {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
}

.view-select {
  min-width: 200px;
  max-width: 280px;
  font-weight: 500;
}

#view-select-slot {
  display: contents;
}

.search-input {
  flex: 1;
  min-width: 220px;
}

.btn {
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #041018;
  font-weight: 600;
}

.btn.ghost {
  background: transparent;
}

.btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.stats-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.time-range-bar {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed rgba(42, 53, 72, 0.8);
}

.time-range-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.time-mode-select,
.recent-select,
.datetime-input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
}

.time-mode-select {
  min-width: 160px;
}

.recent-select {
  min-width: 150px;
}

.datetime-input {
  min-width: 210px;
}

.time-separator {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.time-range-label {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 0.82rem;
}

#custom-time-fields {
  display: inline-flex;
  gap: 10px;
  align-items: center;
}

.stat-chip {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.error-banner {
  margin: 12px 20px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 107, 107, 0.12);
  border: 1px solid rgba(255, 107, 107, 0.35);
  color: #ffc9c9;
}

.error-banner.compact {
  margin: 12px 0 0;
}

.success-banner {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(61, 220, 151, 0.12);
  border: 1px solid rgba(61, 220, 151, 0.35);
  color: #b8f5d8;
}

.success-banner.compact {
  margin: 0;
}

.stats-panel {
  margin: 16px 20px 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(17, 24, 34, 0.75);
}

.stats-panel-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.stats-panel-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.stats-panel-subtitle {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.stats-loading {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.level-summary {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.level-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: inherit;
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.82rem;
}

.level-pill.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.histogram {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  min-height: 120px;
  padding-top: 8px;
  overflow-x: auto;
  width: 100%;
}

.histogram-bar-wrap {
  flex: 1;
  min-width: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 120px;
  position: relative;
  cursor: pointer;
}

.histogram-tooltip {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(12, 18, 28, 0.96);
  border: 1px solid rgba(77, 163, 255, 0.45);
  color: var(--text);
  font-size: 0.72rem;
  line-height: 1.2;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.12s ease, visibility 0.12s ease;
  z-index: 2;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.histogram-bar-wrap:hover .histogram-tooltip {
  opacity: 1;
  visibility: visible;
}

.histogram-bar {
  width: 100%;
  margin-top: auto;
  border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, #7cc0ff, var(--accent));
  min-height: 4px;
  transition: height 0.2s ease, filter 0.15s ease;
}

.histogram-bar-empty {
  min-height: 0;
  background: transparent;
}

.histogram-bar-wrap:hover .histogram-bar:not(.histogram-bar-empty) {
  filter: brightness(1.12);
}

.histogram-bar-wrap:hover .histogram-bar-empty {
  min-height: 4px;
  background: rgba(77, 163, 255, 0.18);
}

.histogram-bar-wrap:hover .histogram-label {
  color: var(--accent);
}

.histogram-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.histogram-empty {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 24px 0;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 14, 0.72);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 1000;
}

.page-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(11, 15, 20, 0.58);
  backdrop-filter: blur(2px);
  pointer-events: all;
}

.page-loading-overlay.is-active {
  display: flex;
}

.page-loading-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 22px 28px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(17, 24, 34, 0.96);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}

.page-loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(77, 163, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: page-loading-spin 0.75s linear infinite;
}

.page-loading-text {
  color: var(--text-muted);
  font-size: 0.9rem;
  letter-spacing: 0.02em;
}

body.is-loading {
  overflow: hidden;
}

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

.modal-card {
  width: min(640px, 100%);
  max-height: 90vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg-1);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.modal-header,
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-footer {
  border-bottom: none;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-body {
  padding: 20px 20px 24px;
}

.modal-body > * + * {
  margin-top: 14px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field span {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.form-field input,
.form-field select {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
}

.form-row-between {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.form-row-between .form-field {
  flex: 1;
}

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

.nested-panel {
  padding: 14px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: rgba(23, 32, 48, 0.55);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-card.wide {
  width: min(760px, 100%);
}

.modal-hint {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.section-block {
  display: flex;
  flex-direction: column;
}

.section-block > * + * {
  margin-top: 12px;
}

.modal-form {
  display: block;
}

.modal-form > * + * {
  margin-top: 12px;
}

.modal-form > .form-actions {
  margin-top: 16px;
}

.section-title {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.datasource-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: min(280px, 40vh);
  overflow-y: auto;
  padding-right: 4px;
}

.datasource-list::-webkit-scrollbar {
  width: 8px;
}

.datasource-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

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

.datasource-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-2);
}

.datasource-item.active {
  border-color: rgba(77, 163, 255, 0.45);
  background: var(--bg-3);
}

.datasource-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.datasource-name {
  font-weight: 600;
}

.datasource-meta {
  margin-top: 4px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.info-panel {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.danger-text {
  color: #ff9b9b;
}

.line-no,
.line-ts {
  color: var(--text-muted);
}

.line-level {
  font-weight: 600;
}

.log-viewport {
  position: relative;
  flex: 1;
  overflow: auto;
  padding: 0 20px 20px;
}

.loading-overlay,
.empty-state,
.empty-hint {
  color: var(--text-muted);
  padding: 24px;
}

.log-table {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: rgba(17, 24, 34, 0.65);
}

.log-header,
.log-row {
  display: grid;
  grid-template-columns: 64px 160px 88px 1fr;
  gap: 12px;
  align-items: start;
  padding: 10px 14px;
}

.log-header {
  position: sticky;
  top: 0;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.log-header-sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  cursor: pointer;
}

.log-header-sort:hover {
  color: var(--accent);
}

.log-header-sort .sort-indicator {
  color: var(--accent);
  font-size: 0.95em;
  line-height: 1;
}

.log-row {
  border-bottom: 1px solid rgba(42, 53, 72, 0.65);
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.55;
}

.log-row.exception {
  background: rgba(255, 107, 107, 0.04);
  border-left: 3px solid rgba(255, 107, 107, 0.55);
}

.log-row:hover {
  background: rgba(77, 163, 255, 0.04);
}

.log-row.exception:hover {
  background: rgba(255, 107, 107, 0.07);
}

.line-body {
  min-width: 0;
}

.line-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-bottom: 6px;
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--text-muted);
}

.line-field {
  white-space: nowrap;
}

.line-field-key {
  color: #9db0cc;
}

.line-content {
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  display: block;
}

.stack-trace {
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(8, 12, 18, 0.85);
  border: 1px solid rgba(255, 107, 107, 0.22);
  color: #ffb4b4;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.5;
  overflow-x: auto;
}

.keyword-hit {
  background: rgba(255, 176, 32, 0.25);
  color: #ffe6b3;
  padding: 0 2px;
  border-radius: 3px;
}

.level-trace,
.level-default {
  color: var(--trace);
}

.level-debug {
  color: var(--debug);
}

.level-info {
  color: var(--info);
}

.level-warn {
  color: var(--warn);
}

.level-error {
  color: var(--danger);
}

.level-fatal {
  color: var(--fatal);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg-1);
}

@media (max-width: 960px) {
  .view-select {
    min-width: 100%;
    max-width: none;
  }

  .log-header,
  .log-row {
    grid-template-columns: 48px 1fr;
  }

  .log-header :nth-child(2),
  .log-header :nth-child(3),
  .line-ts,
  .line-level {
    display: none;
  }
}

.empty-hint, .query-results .empty-hint {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
}

.modal-body .empty-hint {
  padding: 24px;
  text-align: center;
}

.stats-applied-time {
  color: var(--text-muted);
}

.stats-applied-time strong {
  color: var(--text);
  font-weight: 600;
}

.small { font-size: 0.85rem; }

.pagination {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

.log-meta {
  padding: 10px 20px;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}
