: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;
}

body {
  margin: 0;
  min-height: 100vh;
  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;
}

.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;
  min-height: calc(100vh - 78px);
}

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

.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;
  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: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;
}

.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;
}

.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 {
  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 1.25rem;
  overflow: auto;
  max-height: calc(85vh - 70px);
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

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

.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;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    max-height: 280px;
  }

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