:root {
  color-scheme: dark;
  --bg: #111315;
  --panel: #1d2024;
  --panel-soft: #262b31;
  --line: #343a42;
  --text: #e5e9ef;
  --muted: #9aa5b1;
  --accent: #35a6d9;
  --accent-strong: #4ebbe9;
  --good: #55b37a;
  --warn: #d8a33f;
  --danger: #d95f59;
  --shadow: rgba(0, 0, 0, 0.28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

.is-hidden {
  display: none !important;
}

button,
input {
  font: inherit;
}

select {
  font: inherit;
  color: var(--text);
}

button {
  color: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100vh;
  background: var(--bg);
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 0%, #152230 0, var(--bg) 42%);
}

.login-panel {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 44px var(--shadow);
}

.login-brand {
  padding: 0;
}

.login-panel h1 {
  margin: 4px 0 0;
  font-size: 24px;
  line-height: 1.2;
}

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

.login-panel label {
  display: grid;
  gap: 7px;
}

.login-panel label span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.login-panel input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0f151d;
  color: var(--text);
  padding: 0 10px;
  outline: 0;
}

.login-panel.external-login label,
.login-panel.external-login .primary-button {
  display: none;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #181b1f;
  padding: 14px 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 42px;
  padding: 0 8px;
  font-weight: 700;
  letter-spacing: 0;
}

.brand-logo,
.brand-mark {
  display: grid;
  width: 30px;
  height: 30px;
  border-radius: 3px;
}

.brand-logo {
  display: block;
}

.nav-list {
  display: grid;
  gap: 2px;
  margin-top: 18px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 2px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.nav-item.active,
.nav-item:hover {
  background: var(--panel-soft);
  border-left-color: var(--accent);
  color: var(--text);
}

.main {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  background: #1b1f23;
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1.2;
  letter-spacing: 0;
}

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

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

.view {
  display: none;
  padding: 18px 22px 34px;
}

.active-view {
  display: block;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.scan-progress-panel {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--panel);
}

.scan-progress-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.scan-progress-header span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.scan-progress-track {
  height: 8px;
  overflow: hidden;
  border: 1px solid #1b2026;
  border-radius: 3px;
  background: #0f151d;
}

.scan-progress-fill {
  width: 0%;
  height: 100%;
  background: var(--accent);
  transition: width 180ms ease;
}

.library-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 38px;
  align-items: center;
}

.library-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
}

.library-chip input {
  accent-color: var(--accent);
}

.library-chip:has(input:checked) {
  border-color: rgba(72, 184, 232, 0.72);
  color: var(--text);
}

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  width: min(280px, 42vw);
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--panel);
  padding: 0 10px;
  color: var(--muted);
}

.mode-field {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.mode-field select {
  height: 38px;
  min-width: 112px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--panel);
  color: var(--text);
  padding: 0 9px;
}

.search-field input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat {
  min-height: 66px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--panel);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  margin-top: 7px;
  font-size: 24px;
  line-height: 1;
}

.duplicates-list {
  display: grid;
  gap: 12px;
}

.duplicate-group {
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--panel);
  box-shadow: none;
  overflow: hidden;
}

.group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #23282e;
}

.group-title {
  min-width: 0;
}

.group-title h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
  letter-spacing: 0;
}

.group-title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.group-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pill,
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 3px;
  border: 1px solid var(--line);
  background: #111923;
  color: var(--muted);
  font-size: 12px;
}

.status-badge.online {
  color: #dff7e8;
  border-color: rgba(85, 179, 122, 0.55);
  background: rgba(85, 179, 122, 0.14);
}

.status-badge.muted {
  color: var(--muted);
}

.file-row {
  display: grid;
  grid-template-columns: 78px minmax(220px, 1.6fr) minmax(150px, 0.9fr) minmax(150px, 0.9fr) 106px 92px;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(44, 54, 68, 0.7);
}

.subtitle-row {
  grid-template-columns: 78px minmax(220px, 1.8fr) minmax(150px, 0.8fr) minmax(180px, 1fr) 92px;
}

.file-row.selected-keep {
  background: rgba(85, 179, 122, 0.08);
}

.file-row.suggested-file:not(.selected-keep) {
  background: rgba(47, 155, 204, 0.06);
}

.file-row:last-child {
  border-bottom: 0;
}

.score {
  display: grid;
  place-items: center;
  width: 56px;
  height: 38px;
  border-radius: 3px;
  background: rgba(47, 155, 204, 0.16);
  color: #d8f3ff;
  border: 1px solid rgba(72, 184, 232, 0.42);
  font-weight: 700;
}

.score.suggested,
.score.best {
  background: rgba(85, 179, 122, 0.16);
  border-color: rgba(85, 179, 122, 0.58);
  color: #e6ffee;
}

.file-main {
  min-width: 0;
}

.file-name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 600;
}

.file-name span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.keep-badge,
.suggested-badge {
  color: #dff7e8;
  background: rgba(85, 179, 122, 0.16);
  border: 1px solid rgba(85, 179, 122, 0.5);
  border-radius: 3px;
  padding: 2px 6px;
  font-size: 11px;
}

.suggested-badge {
  color: #d8f3ff;
  background: rgba(47, 155, 204, 0.16);
  border-color: rgba(72, 184, 232, 0.48);
}

.file-path {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-detail {
  min-width: 0;
}

.file-detail strong {
  display: block;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-detail span,
.file-size {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

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

.keep-file-button.selected {
  border-color: rgba(85, 179, 122, 0.6);
  background: rgba(85, 179, 122, 0.14);
  color: #dff7e8;
}

.keep-subtitle-button.selected {
  border-color: rgba(85, 179, 122, 0.6);
  background: rgba(85, 179, 122, 0.14);
  color: #dff7e8;
}

.message-area {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.message {
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 12px;
  background: var(--panel);
  color: var(--muted);
}

.message.success {
  color: #dff7e8;
  border-color: rgba(85, 179, 122, 0.45);
  background: rgba(85, 179, 122, 0.1);
}

.message.error {
  color: #ffd9d7;
  border-color: rgba(217, 95, 89, 0.55);
  background: rgba(217, 95, 89, 0.11);
}

.settings-panel {
  display: grid;
  gap: 14px;
  max-width: 1120px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--panel);
}

.settings-section {
  display: grid;
  gap: 14px;
  padding: 14px;
  border-top: 1px solid var(--line);
}

.settings-section.first-section {
  border-top: 0;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
  margin: -14px -14px 0;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: #23282e;
}

.settings-section h2,
.section-heading h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
}

.section-status {
  color: var(--muted);
  font-size: 12px;
}

.field-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(240px, 1fr) 140px;
  gap: 14px;
}

.field-grid label:not(.multi-select-option),
.field-grid .preference-field,
.settings-panel label:not(.toggle-row):not(.multi-select-option),
.delete-dialog label {
  display: grid;
  gap: 7px;
}

.field-grid label:not(.multi-select-option) > span,
.field-grid .preference-field > span,
.settings-panel label:not(.toggle-row):not(.multi-select-option) > span,
.delete-dialog label > span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.field-grid input,
.field-grid select,
.delete-dialog input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #0f151d;
  color: var(--text);
  padding: 0 10px;
  outline: 0;
}

.preference-field {
  min-width: 0;
}

.multi-select {
  position: relative;
  min-width: 0;
}

.multi-select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #0f151d;
  color: var(--text);
  padding: 0 10px;
  cursor: pointer;
}

.multi-select-trigger:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.multi-select-summary {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.multi-select-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  display: none;
  max-height: 220px;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #0f151d;
  box-shadow: 0 12px 28px var(--shadow);
}

.multi-select.open .multi-select-menu {
  display: grid;
  gap: 2px;
}

.field-grid .multi-select-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 8px;
  border-radius: 3px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.multi-select-option:hover {
  background: var(--panel-soft);
}

.field-grid .multi-select-option input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}

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

.auth-grid {
  grid-template-columns: minmax(150px, 0.45fr) minmax(180px, 0.55fr) minmax(260px, 1fr);
}

.preferences-grid {
  grid-template-columns: minmax(150px, 0.5fr) repeat(3, minmax(180px, 1fr));
}

.subtitle-preferences-grid {
  grid-template-columns: repeat(3, minmax(180px, 1fr));
}

.password-grid {
  grid-template-columns: repeat(3, minmax(180px, 1fr));
}

.settings-panel > .message-area {
  margin: 0;
  padding: 0 14px;
}

.settings-panel > .message-area:empty {
  display: none;
}

.settings-panel > .form-actions {
  padding: 0 14px 14px;
}

.toggle-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  border-radius: 3px;
  border: 1px solid transparent;
  cursor: pointer;
}

.primary-button {
  padding: 0 14px;
  background: var(--accent);
  color: #06131b;
  font-weight: 700;
}

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

.secondary-button {
  padding: 0 14px;
  border-color: var(--line);
  background: var(--panel-soft);
}

.danger-button {
  padding: 0 14px;
  background: var(--danger);
  color: #fff7f7;
}

.icon-button {
  width: 38px;
  border-color: var(--line);
  background: var(--panel);
}

.icon-button.ghost {
  background: transparent;
}

.icon-button:disabled,
.primary-button:disabled,
.secondary-button:disabled,
.danger-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.delete-dialog {
  width: min(560px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
}

.delete-dialog::backdrop {
  background: rgba(0, 0, 0, 0.64);
}

.delete-dialog form {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.delete-dialog header,
.delete-dialog menu {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0;
  padding: 0;
}

.delete-dialog h2 {
  margin: 0;
  font-size: 18px;
}

.delete-file-name {
  margin: 0;
  font-weight: 700;
}

.delete-dialog code {
  display: block;
  max-height: 86px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: #cfe0ef;
  background: #0f151d;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 8;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-list {
    display: flex;
    margin-top: 0;
  }

  .nav-item {
    width: auto;
  }

  .toolbar,
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions,
  .topbar-actions {
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .search-field {
    width: 100%;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .file-row {
    grid-template-columns: 64px minmax(0, 1fr) 92px;
    align-items: start;
  }

  .subtitle-row {
    grid-template-columns: 64px minmax(0, 1fr) 92px;
  }

  .file-detail,
  .file-size {
    grid-column: 2 / 3;
  }

  .row-actions {
    grid-column: 3 / 4;
    grid-row: 1;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .view {
    padding: 16px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .group-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .file-row {
    padding: 12px;
  }
}
