:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, #0b1017 0%, var(--bg) 100%);
  color: var(--text);
}

code {
  background: rgba(255, 255, 255, 0.08);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.9em;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(26, 35, 50, 0.95);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
}

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

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.header-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.sidebar-search {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-search input,
.sidebar-footer input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.category-nav {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 0.5rem;
}

.nav-group-label {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0.75rem 0.75rem 0.35rem;
}

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.92rem;
}

.nav-item-content {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  min-width: 0;
  width: 100%;
}

.nav-item-label {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-item-match {
  display: block;
  width: 100%;
  font-size: 0.74rem;
  line-height: 1.25;
  color: #93c5fd;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-item-has-match:not(.active) {
  border-left: 3px solid rgba(59, 130, 246, 0.55);
  padding-left: calc(0.75rem - 3px);
}

.nav-item.active .nav-item-match {
  color: #dbeafe;
}

.search-filter-banner {
  margin-bottom: 1rem;
  padding: 0.65rem 0.85rem;
  border: 1px solid rgba(59, 130, 246, 0.35);
  border-radius: var(--radius);
  background: rgba(59, 130, 246, 0.12);
  color: #bfdbfe;
  font-size: 0.88rem;
}

.section-card.search-section-match h3 {
  color: #93c5fd;
}

.field.search-match {
  padding: 0.65rem;
  border: 1px solid rgba(59, 130, 246, 0.45);
  border-radius: var(--radius);
  background: rgba(59, 130, 246, 0.1);
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.25);
}

.connection-card.search-match {
  border-color: rgba(59, 130, 246, 0.45);
  background: rgba(59, 130, 246, 0.1);
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.25);
}

.field.search-match label {
  color: #dbeafe;
}

.nav-item:hover {
  background: var(--surface-2);
}

.nav-item.active {
  background: rgba(59, 130, 246, 0.18);
  color: #bfdbfe;
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
}

.sidebar-footer label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0.5rem 0 0.25rem;
}

.sidebar-footer label:first-child {
  margin-top: 0;
}

.sidebar-footer .sidebar-btn {
  display: block;
  width: 100%;
  text-align: center;
  margin: 0 0 0.75rem;
  cursor: pointer;
}

.nav-item-row {
  display: flex;
  align-items: stretch;
  gap: 0.25rem;
  margin-bottom: 0.15rem;
}

.nav-item-row .nav-item {
  flex: 1;
  min-width: 0;
  width: auto;
}

.nav-item-row.active .nav-item,
.nav-item-row.active .nav-delete-btn {
  background: rgba(59, 130, 246, 0.18);
}

.nav-delete-btn {
  flex-shrink: 0;
  width: 2rem;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.nav-delete-btn:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
}

.nav-item.plugin-nav-item {
  color: #c4b5fd;
  font-size: 0.88rem;
}

.plugin-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(59, 130, 246, 0.08);
  font-size: 0.9rem;
}

.plugin-remove-btn {
  flex-shrink: 0;
}

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

.content {
  padding: 1.5rem 2rem 3rem;
  overflow-y: auto;
  min-height: 0;
}

.panel-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.panel-description {
  color: var(--muted);
  margin-bottom: 1.5rem;
  max-width: 70ch;
}

.settings-form {
  max-width: 900px;
}

.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.section-card h3 {
  margin: 0 0 1rem;
  font-size: 1rem;
  color: #cbd5e1;
}

.section-search {
  margin-bottom: 0.75rem;
}

.section-search input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.section-search-count {
  margin: 0 0 0.75rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field label {
  font-size: 0.85rem;
  font-weight: 600;
}

.field label.required::after {
  content: " *";
  color: #c0392b;
}

.field .help,
.field .summary {
  font-size: 0.78rem;
  color: var(--muted);
}

.field input[type="text"],
.field input[type="number"],
.field input[type="password"],
.field select,
.field textarea,
.color-value-input {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.field textarea {
  min-height: 80px;
  resize: vertical;
}

.field-wide {
  grid-column: 1 / -1;
}

.multiselect-box {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  max-height: 220px;
  overflow-y: auto;
}

.multiselect-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
}

.custom-option-input {
  margin-top: 0.45rem;
}

.custom-option-input[hidden] {
  display: none;
}

.checkbox-row {
  flex-direction: row;
  align-items: center;
  gap: 0.6rem;
}

.checkbox-row input {
  width: auto;
}

.connection-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  background: rgba(15, 20, 25, 0.55);
}

.connection-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.connection-header h4 {
  margin: 0;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1rem;
  font-size: 0.92rem;
  cursor: pointer;
  font-weight: 600;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

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

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: #2f3f56;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #fecaca;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.import-btn {
  display: inline-flex;
  align-items: center;
}

.empty-state {
  color: var(--muted);
  padding: 2rem 0;
}

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  width: min(900px, 92vw);
  max-height: 85vh;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

#preview-content {
  margin: 0;
  padding: 1rem 1.25rem;
  overflow: auto;
  max-height: calc(85vh - 130px);
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.import-xml-body {
  padding: 1rem 1.25rem;
}

.import-xml-hint {
  margin: 0 0 0.75rem;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.45;
}

.import-xml-textarea {
  width: 100%;
  min-height: 280px;
  max-height: calc(85vh - 220px);
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  resize: vertical;
  box-sizing: border-box;
}

.import-xml-textarea:focus {
  outline: 2px solid rgba(59, 130, 246, 0.45);
  outline-offset: 1px;
}

.import-xml-error {
  margin: 0.75rem 0 0;
  color: #fca5a5;
  font-size: 0.88rem;
  line-height: 1.4;
}

#import-xml-dialog {
  width: min(960px, 94vw);
}

.import-merge-body,
.import-summary-body {
  padding: 1rem 1.25rem;
}

.import-merge-hint {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.45;
}

.import-merge-options {
  border: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.import-merge-option {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  background: var(--bg);
}

.import-merge-option:has(input:checked) {
  border-color: rgba(59, 130, 246, 0.65);
  background: rgba(59, 130, 246, 0.08);
}

.import-merge-option input {
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.import-merge-option-text {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.4;
}

.import-merge-option-text strong {
  color: var(--text);
  font-size: 0.95rem;
}

.import-summary-message {
  margin: 0 0 1rem;
  line-height: 1.5;
}

.import-summary-reconcile {
  margin: 1rem 0 0;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.45;
}

.import-merge-clean {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  margin-top: 1rem;
  font-size: 0.88rem;
  line-height: 1.4;
  cursor: pointer;
}

.import-merge-clean input {
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.import-merge-radial-hint {
  margin: 0.65rem 0 0;
  font-size: 0.85rem;
  color: #fcd34d;
  line-height: 1.45;
}

.import-summary-fixed {
  margin: 1rem 0 0;
  font-size: 0.88rem;
  color: #86efac;
  line-height: 1.45;
}

.import-summary-warnings {
  margin: 1rem 0 0;
  padding-left: 1.2rem;
  color: #fcd34d;
  font-size: 0.88rem;
  line-height: 1.45;
}

.import-summary-warnings li + li {
  margin-top: 0.35rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#import-merge-dialog {
  width: min(560px, 94vw);
}

#import-summary-dialog {
  width: min(520px, 94vw);
}

#import-summary-dialog .apk-scan-details {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 1rem;
  margin: 0;
}

#import-summary-dialog .apk-scan-details dt {
  color: var(--muted);
  font-size: 0.85rem;
}

#import-summary-dialog .apk-scan-details dd {
  margin: 0;
  font-size: 0.92rem;
}

.apk-scan-body {
  padding: 1.25rem;
}

.apk-scan-status {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
}

.apk-scan-message {
  margin: 0;
  line-height: 1.5;
}

.apk-scan-message.is-scanning {
  color: var(--muted);
}

.apk-scan-message.is-success {
  color: #86efac;
}

.apk-scan-message.is-warning {
  color: #fcd34d;
}

.apk-scan-message.is-error {
  color: #fca5a5;
}

.apk-scan-spinner {
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: #60a5fa;
  border-radius: 50%;
  animation: apk-scan-spin 0.8s linear infinite;
  flex-shrink: 0;
  margin-top: 0.15rem;
}

@keyframes apk-scan-spin {
  to {
    transform: rotate(360deg);
  }
}

.apk-scan-details {
  margin: 1rem 0 0;
  display: grid;
  grid-template-columns: minmax(8rem, 34%) 1fr;
  gap: 0.35rem 1rem;
  font-size: 0.9rem;
}

.apk-scan-details dt {
  margin: 0;
  color: var(--muted);
}

.apk-scan-details dd {
  margin: 0;
  word-break: break-word;
}

.apk-scan-warnings {
  margin: 1rem 0 0;
  padding-left: 1.15rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.apk-scan-warnings li + li {
  margin-top: 0.35rem;
}

#apk-scan-dialog {
  width: min(560px, 92vw);
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: #14532d;
  color: #dcfce7;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  opacity: 0;
  transform: translateY(12px);
  transition: 0.2s ease;
  pointer-events: none;
  z-index: 100;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  background: #7f1d1d;
  color: #fee2e2;
}

.color-input-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.color-picker {
  width: 3rem;
  height: 2.5rem;
  padding: 0.15rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  flex-shrink: 0;
}

.color-value-input {
  flex: 1;
  min-width: 0;
}

.palette-color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.palette-swatch {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 8px;
  border: 2px solid var(--border);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.palette-swatch.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.35);
}

.palette-swatch-unset {
  width: auto;
  min-width: 2.5rem;
  height: 2.5rem;
  padding: 0 0.65rem;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.78rem;
}

.palette-option-btn {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  font-size: 0.82rem;
}

.palette-option-btn.selected {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.18);
  color: #bfdbfe;
}

@media (max-width: 900px) {
  html,
  body {
    height: auto;
  }

  body {
    display: block;
    overflow: visible;
  }

  .layout {
    grid-template-columns: 1fr;
    flex: none;
    min-height: auto;
    overflow: visible;
  }

  .sidebar {
    max-height: 280px;
    min-height: 0;
    overflow: hidden;
  }

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