:root {
  --ui-scale: 1;
  --content-width-ratio: 0.7;
  --content-gutter: 24px;
  --toolbar-control-height: 30px;
  --toolbar-chevron-dark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23e0e0e0' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --toolbar-chevron-light: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23000000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --layout-base-width: calc(100vw / var(--ui-scale));
  --content-width: min(
    calc(var(--layout-base-width) - (var(--content-gutter) * 2)),
    calc(var(--layout-base-width) * var(--content-width-ratio))
  );
}

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

html,
body {
  width: 100%;
  height: 100%;
}

body {
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 13px;
  background: #1a1a2e;
  color: #e0e0e0;
  width: calc(100vw / var(--ui-scale));
  height: calc(100vh / var(--ui-scale));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  zoom: var(--ui-scale);
  transform-origin: top left;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: #16213e;
}

::-webkit-scrollbar-thumb {
  background: #0f3460;
  border-radius: 3px;
}

.toolbar {
  width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
  background: #16213e;
  border-bottom: 1px solid #0f3460;
  flex-shrink: 0;
}

.toolbar-inner {
  width: var(--content-width);
  margin: 0 auto;
  padding: 6px 12px 8px;
  display: flex;
  flex-wrap: wrap;
  row-gap: 6px;
}

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

.toolbar-row--top {
  justify-content: space-between;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #80c0ff;
  font-size: 17px;
  font-weight: 700;
  text-decoration: none;
}

.logo-area:hover {
  color: #a0d8ff;
}

.logo-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #0f3460;
  color: #ffffff;
  font-size: 11px;
  letter-spacing: 0.08em;
}

.toolbar label {
  font-size: 13px;
  color: #a0a0c0;
}

.toolbar select,
.toolbar input[type="search"] {
  background: #0a0a1a;
  color: #e0e0e0;
  border: 1px solid #0f3460;
  border-radius: 4px;
  height: var(--toolbar-control-height);
  padding: 5px 8px;
  font-size: 13px;
}

.toolbar select {
  min-width: 128px;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 28px;
  background-image: var(--toolbar-chevron-dark);
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 10px 6px;
}

#comparison-select {
  min-width: 188px;
}

.toolbar-row--meta {
  align-items: flex-start;
}

.toolbar-meta-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 11px;
  color: #8ea7c7;
  line-height: 1.35;
}

.toolbar-meta-item {
  white-space: nowrap;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.author-prefix {
  font-size: 12px;
  color: #8ea7c7;
  white-space: nowrap;
}

.author-links {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.author-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  text-decoration: none;
  color: #c8d8f0;
  font-size: 12px;
  white-space: nowrap;
}

.author-link:hover {
  color: #ffffff;
}

.author-name {
  font-size: 12px;
  color: #c8d8f0;
  white-space: nowrap;
}

.author-sep {
  font-size: 12px;
  color: #a9b6cf;
  white-space: nowrap;
}

.author-text-link {
  color: #80c0ff;
  text-decoration: none;
  font-size: 12px;
  white-space: nowrap;
}

.author-text-link:hover {
  color: #a8d6ff;
  text-decoration: underline;
}

.author-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid #2e557f;
  object-fit: cover;
  flex-shrink: 0;
}

.theme-toggle-button {
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: #243b5c;
  color: #cfe6ff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.theme-toggle-button:hover {
  background: #2f527f;
}

.theme-icon {
  position: absolute;
  inset: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.18s ease;
}

.theme-icon svg {
  width: 16px;
  height: 16px;
  display: block;
  stroke: currentColor;
  vector-effect: non-scaling-stroke;
}

.theme-icon-sun {
  opacity: 1;
}

.theme-icon-moon {
  opacity: 0;
}

body.light-theme .theme-icon-sun {
  opacity: 0;
}

body.light-theme .theme-icon-moon {
  opacity: 1;
}

.menu-wrap {
  position: relative;
}

.menu-trigger {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 6px;
  border: none;
  background: #243b5c;
  color: #cfe6ff;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

.menu-trigger:hover {
  background: #2f527f;
}

.menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 160px;
  background: #0d1730;
  border: 1px solid #21456f;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  padding: 6px;
  display: none;
  z-index: 20;
}

.menu-panel.open {
  display: block;
}

.menu-group-label {
  padding: 6px 10px 4px;
  font-size: 10px;
  color: #6f8fb6;
  letter-spacing: 0.4px;
  white-space: nowrap;
  user-select: none;
}

.menu-divider {
  height: 1px;
  margin: 4px 6px;
  background: rgba(42, 87, 138, 0.5);
}

.menu-item {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: transparent;
  color: #d8e6ff;
  text-align: left;
  text-decoration: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}

.menu-item:hover {
  background: #183154;
}

.menu-item-with-icon {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.menu-item-glyph {
  width: 16px;
  min-width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: currentColor;
  line-height: 0;
  opacity: 0.92;
}

.menu-item-glyph svg {
  width: 16px;
  height: 16px;
  display: block;
  stroke: currentColor;
  vector-effect: non-scaling-stroke;
}

.menu-link-with-icon {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.menu-link-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #80c0ff;
  flex-shrink: 0;
}

.results-header-shell {
  width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
  background: #16213e;
  border-bottom: 1px solid #0f3460;
  flex-shrink: 0;
}

.results-header {
  width: var(--content-width);
  margin: 0 auto;
  padding: 6px 12px;
  font-size: 12px;
  color: #a0a0c0;
}

.page-shell {
  width: var(--content-width);
  margin: 0 auto;
  align-self: center;
  min-width: 0;
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main-layout {
  display: flex;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.sidebar-panel {
  width: 286px;
  min-width: 286px;
  background: #0a0a1a;
  border-right: 1px solid #0f3460;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-section {
  padding: 10px 12px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-section--files {
  overflow: hidden;
}

.sidebar-title {
  font-size: 12px;
  color: #80c0ff;
  margin-bottom: 8px;
  font-weight: 700;
}

.sidebar-search {
  margin-bottom: 10px;
  flex: 0 0 auto;
}

.sidebar-search input {
  width: 100%;
  background: #10172c;
  color: #e0e0e0;
  border: 1px solid #1b365a;
  border-radius: 4px;
  height: 30px;
  padding: 5px 8px;
}

.sidebar-file-groups {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  overflow: hidden;
}

.file-group {
  border: 1px solid #162c4a;
  border-radius: 6px;
  background: #10172c;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.file-group-title {
  padding: 8px 10px;
  font-size: 12px;
  color: #c9def8;
  background: #13213c;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.file-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.file-button {
  width: 100%;
  border: none;
  border-top: 1px solid rgba(15, 52, 96, 0.45);
  background: transparent;
  color: #dbe8f8;
  text-align: left;
  padding: 8px 10px;
  font-size: 14px;
  cursor: pointer;
  line-height: 1.45;
}

.file-button:hover {
  background: #163258;
}

.file-button.active {
  background: #205086;
  color: #ffffff;
}

.file-button small {
  color: #8ea7c7;
  margin-left: 6px;
}

.results-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  position: relative;
  background: #0c1020;
}

.results-table-wrap {
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  position: relative;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 15px;
}

.results-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #16213e;
  color: #80c0ff;
  border-bottom: 2px solid #0f3460;
  padding: 6px 10px;
  text-align: left;
  font-weight: 600;
}

.results-table td {
  padding: 6px 10px;
  border-bottom: 1px solid #0a0a2a;
  vertical-align: top;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.6;
}

.results-table tr:hover {
  background: #0f3460;
}

.col-no {
  width: 56px;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
  color: #ffa080;
}

.col-entry-meta {
  width: 172px;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
  overflow: hidden;
}

th.col-no,
th.col-entry-meta,
td.col-no,
td.col-entry-meta {
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

.col-text-half {
  width: calc((100% - 228px) / 2);
}

.entry-file,
.entry-id {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry-file {
  color: #d3e3ff;
}

.entry-id {
  margin-top: 2px;
  color: #f2d58b;
  font-size: 12px;
  line-height: 1.35;
}

.text-cell-old,
.text-cell-new,
.text-cell-added,
.text-cell-ref {
  display: block;
}

.results-table.tc-mode .col-text-half {
  width: calc((100% - 228px) / 3);
}

.text-cell-ref {
  color: #9fd0ff;
}

.diff-del {
  color: #ff8d92;
  background: rgba(214, 56, 73, 0.16);
  text-decoration: line-through;
}

.diff-add {
  color: #8be28e;
  background: rgba(31, 153, 63, 0.16);
}

.results-empty-state {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  color: #607090;
  font-size: 13px;
  pointer-events: none;
}

.results-empty-state.show {
  display: flex;
}

.results-loading-indicator {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 10px;
  font-size: 11px;
  color: #8ea7c7;
  border-top: 1px solid #0f3460;
  background: rgba(12, 16, 32, 0.96);
}

.results-loading-indicator.show {
  display: flex;
}

body.light-theme {
  background: #f6f7f9;
  color: #000000;
}

body.light-theme ::-webkit-scrollbar-track {
  background: #e7ebf0;
}

body.light-theme ::-webkit-scrollbar-thumb {
  background: #b8c4d1;
}

body.light-theme .toolbar,
body.light-theme .results-header-shell {
  background: #f8fafc;
  border-color: #d3d8de;
}

body.light-theme .toolbar label,
body.light-theme .toolbar-meta-summary,
body.light-theme .author-prefix,
body.light-theme .author-name,
body.light-theme .author-link,
body.light-theme .author-sep,
body.light-theme .author-text-link,
body.light-theme .results-header,
body.light-theme .sidebar-search input::placeholder,
body.light-theme .menu-group-label {
  color: #5f6b7c;
}

body.light-theme .logo-area,
body.light-theme .results-table th,
body.light-theme .sidebar-title {
  color: #2d6ecf;
}

body.light-theme .logo-area:hover {
  color: #215db0;
}

body.light-theme .author-link:hover,
body.light-theme .author-text-link:hover {
  color: #000000;
}

body.light-theme .toolbar select,
body.light-theme .toolbar input[type='search'],
body.light-theme .sidebar-search input,
body.light-theme .sidebar-panel,
body.light-theme .results-panel,
body.light-theme .file-group {
  background-color: #ffffff;
  color: #000000;
  border-color: #d3d8de;
}

body.light-theme .toolbar select {
  background-image: var(--toolbar-chevron-light);
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 10px 6px;
}

body.light-theme .logo-badge,
body.light-theme .file-group-title,
body.light-theme .results-table th {
  background: #f1f5fa;
  border-color: #d3d8de;
}

body.light-theme .file-group-title {
  color: #000000;
}

body.light-theme .file-button {
  color: #000000;
  border-top-color: rgba(95, 107, 124, 0.18);
}

body.light-theme .file-button:hover {
  background: #eef3f8;
}

body.light-theme .file-button.active {
  background: #2d6ecf;
  color: #ffffff;
}

body.light-theme .file-button small {
  color: #6b7280;
}

body.light-theme .results-panel {
  background: #ffffff;
}

body.light-theme .results-table td {
  border-bottom-color: #e3e8ee;
}

body.light-theme .results-table tr:hover {
  background: #eef3f8;
}

body.light-theme .col-no,
body.light-theme .text-cell-ref {
  color: #000000;
}

body.light-theme .entry-file {
  color: #000000;
}

body.light-theme .entry-id {
  color: #5b6472;
}

body.light-theme .diff-del {
  color: #9f3d3d;
  background: rgba(214, 56, 73, 0.1);
}

body.light-theme .diff-add {
  color: #2d7a42;
  background: rgba(31, 153, 63, 0.1);
}

body.light-theme .menu-trigger {
  background: #eef2f6;
  color: #111418;
}

body.light-theme .theme-toggle-button {
  background: #eef2f6;
  color: #111418;
}

body.light-theme .theme-toggle-button:hover {
  background: #e1e7ee;
}

body.light-theme .menu-trigger:hover {
  background: #e1e7ee;
}

body.light-theme .menu-panel {
  background: #ffffff;
  border-color: #d3d8de;
  box-shadow: 0 8px 24px rgba(17, 20, 24, 0.12);
}

body.light-theme .menu-item {
  color: #111418;
}

body.light-theme .menu-item:hover {
  background: #f0f3f6;
}

body.light-theme .menu-divider {
  background: rgba(95, 107, 124, 0.22);
}

body.light-theme .menu-link-dot {
  background: #2d6ecf;
}

@media (max-width: 1200px) {
  .page-shell {
    width: min(100vw, 100%);
    margin: 0;
  }

  .toolbar-inner,
  .results-header {
    width: 100%;
  }

  .toolbar-row--top {
    gap: 8px;
  }

  .toolbar-actions {
    width: 100%;
    margin-left: 0;
    justify-content: flex-start;
  }
}

@media (max-width: 960px) {
  body {
    overflow: auto;
    width: 100%;
    height: auto;
    display: block;
    zoom: 1;
  }

  .page-shell {
    height: auto;
  }

  .main-layout {
    flex-direction: column;
    overflow: visible;
  }

  .sidebar-panel {
    width: 100%;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid #0f3460;
  }

  .toolbar-meta-summary {
    gap: 4px 10px;
    font-size: 10px;
  }

  .results-panel {
    min-height: 70vh;
  }

  .file-group {
    flex: 0 0 auto;
    height: auto;
  }

  .sidebar-file-groups {
    display: flex;
    flex-direction: column;
    overflow: visible;
  }

  .file-list {
    max-height: 240px;
  }
}
