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

:root {
  --bg: #0f1117;
  --bg2: #1a1d2e;
  --bg3: #242740;
  --accent: #6c63ff;
  --accent2: #4dabf7;
  --text: #e0e0e0;
  --text2: #a0a0b0;
  --success: #40c057;
  --error: #e03131;
  --border: #2a2d3e;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0,0,0,0.3);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

#app {
  display: flex;
  height: 100vh;
}

#sidebar {
  width: 220px;
  background: var(--bg2);
  padding: 24px 12px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-header h1 {
  font-size: 1.35rem;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  padding-left: 4px;
}

.tagline {
  font-size: 0.7rem;
  color: var(--text2);
  margin-top: 2px;
  margin-bottom: 20px;
  padding-left: 4px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  background: none;
  border: none;
  color: var(--text2);
  font-size: 0.9rem;
  cursor: pointer;
  border-radius: 8px;
  margin-bottom: 4px;
  transition: all 0.2s;
}
.nav-btn:hover { background: var(--bg3); color: var(--text); }
.nav-btn.active { background: var(--accent); color: white; }

.nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

#main-content {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
  padding-bottom: 80px;
}

.view { display: none; }
.view.active { display: block; }

.search-container {
  display: flex;
  gap: 10px;
  max-width: 700px;
  margin-bottom: 28px;
}

#searchInput {
  flex: 1;
  padding: 14px 18px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg2);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}
#searchInput:focus { border-color: var(--accent); }

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn-primary:hover { background: #5a52e0; transform: translateY(-1px); }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-secondary:hover { background: var(--border); }

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--accent2);
  font-size: 1rem;
  cursor: pointer;
  padding: 8px 0;
  margin-bottom: 16px;
}
.btn-back:hover { text-decoration: underline; }

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 16px;
}

.result-card {
  background: var(--bg2);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s;
  border: 1px solid var(--border);
}
.result-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: var(--accent); }

.result-card .poster {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  background: var(--bg3);
  display: flex;
  align-items: center;
  justify-content: center;
}

.result-card .poster svg {
  width: 48px;
  height: 48px;
  color: var(--text2);
  opacity: 0.5;
}

.result-card .info {
  padding: 10px;
}

.result-card .info h3 {
  font-size: 0.85rem;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-card .info .meta {
  font-size: 0.75rem;
  color: var(--text2);
  display: flex;
  gap: 8px;
  align-items: center;
}

.badge {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-movie { background: #4dabf733; color: #4dabf7; }
.badge-tv { background: #6c63ff33; color: #6c63ff; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text2);
}
.empty-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  color: var(--text2);
  opacity: 0.4;
  display: block;
}
.empty-state h2 { color: var(--text); margin-bottom: 8px; font-size: 1.3rem; }
.empty-state p { font-size: 0.9rem; max-width: 400px; margin: 0 auto; }

.detail-backdrop {
  width: 100%;
  height: 280px;
  object-fit: cover;
  background: var(--bg3);
}

.detail-body {
  padding: 28px;
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 28px;
}

.detail-poster {
  width: 100%;
  border-radius: 8px;
}

.detail-poster-placeholder svg {
  width: 64px;
  height: 64px;
  color: var(--text2);
  opacity: 0.5;
}

.detail-info h2 { font-size: 1.8rem; margin-bottom: 8px; }
.detail-meta { color: var(--text2); margin-bottom: 14px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.detail-meta .star-icon { width: 16px; height: 16px; color: #fcc419; vertical-align: middle; margin-right: 2px; }
.detail-overview { color: var(--text2); line-height: 1.8; margin-bottom: 24px; font-size: 0.95rem; }

.request-form {
  background: var(--bg3);
  padding: 24px;
  border-radius: var(--radius);
  margin-top: 24px;
}

.request-form h3 { margin-bottom: 16px; font-size: 1.1rem; }
.form-row { margin-bottom: 14px; }
.form-row label { display: block; margin-bottom: 6px; color: var(--text2); font-size: 0.85rem; }
.form-row select {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg2);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a0a0b0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
.form-row select:focus { border-color: var(--accent); }

.settings-section {
  background: var(--bg2);
  padding: 24px;
  border-radius: var(--radius);
  margin-bottom: 20px;
}

.settings-section h3 { margin-bottom: 12px; font-size: 1.05rem; }
.help-text { font-size: 0.85rem; color: var(--text2); margin-bottom: 12px; }
.help-text a { color: var(--accent2); }

.settings-section input[type="text"],
.settings-section input[type="number"] {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg3);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  margin-bottom: 8px;
}
.settings-section input:focus { border-color: var(--accent); }

.instance-card {
  background: var(--bg3);
  padding: 16px;
  border-radius: 8px;
  margin-bottom: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.instance-card input { margin-bottom: 0; }
.instance-card .full-width { grid-column: 1 / -1; }

.instance-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.btn-test {
  padding: 8px 14px;
  background: #2b8a3e;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}
.btn-remove {
  padding: 8px 14px;
  background: #c92a2a;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}
.status-success { color: var(--success); font-size: 0.85rem; margin-top: 4px; }
.status-error { color: var(--error); font-size: 0.85rem; margin-top: 4px; }

.status-msg { margin-top: 16px; padding: 12px; border-radius: 8px; display: none; }
.status-msg.success { display: block; background: #2b8a3e33; color: var(--success); }
.status-msg.error { display: block; background: #c92a2a33; color: var(--error); }

.modal {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 32px 28px;
  max-width: 460px;
  width: 100%;
  position: relative;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text2);
  padding: 4px;
  line-height: 0;
}
.modal-close:hover { color: var(--text); }
.modal-close svg { width: 22px; height: 22px; }

.result-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  display: block;
  color: var(--success);
}
.result-icon.error { color: var(--error); }

.loading-spinner {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 20px;
  color: var(--text2);
}

@media (max-width: 768px) {
  #app {
    flex-direction: column;
  }

  #sidebar {
    width: 100%;
    padding: 10px 12px;
    flex-direction: row;
    align-items: center;
    border-right: none;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg2);
  }

  .sidebar-header h1 {
    font-size: 1.1rem;
  }

  .tagline {
    display: none;
  }

  #sidebar nav {
    display: flex;
    gap: 4px;
    margin-left: auto;
  }

  .nav-btn {
    padding: 8px 10px;
    font-size: 0;
    gap: 0;
    width: auto;
    margin-bottom: 0;
    border-radius: 6px;
  }
  .nav-btn .nav-icon {
    width: 22px;
    height: 22px;
  }

  #main-content {
    padding: 16px;
    padding-bottom: 24px;
  }

  .search-container {
    flex-direction: row;
    max-width: 100%;
    margin-bottom: 20px;
  }

  #searchInput {
    font-size: 0.9rem;
    padding: 12px 14px;
  }

  .btn-primary {
    padding: 12px 16px;
    font-size: 0.9rem;
  }

  .results-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 12px;
  }

  .result-card .info {
    padding: 8px;
  }
  .result-card .info h3 {
    font-size: 0.8rem;
  }

  .detail-backdrop {
    height: 160px;
  }

  .detail-body {
    grid-template-columns: 1fr;
    padding: 16px;
    gap: 16px;
  }

  .detail-poster {
    max-width: 180px;
    margin: 0 auto;
  }

  .detail-info h2 {
    font-size: 1.4rem;
  }

  .request-form {
    padding: 16px;
  }

  .instance-card {
    grid-template-columns: 1fr;
  }

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

  .empty-state {
    padding: 40px 16px;
  }
  .empty-icon {
    width: 48px;
    height: 48px;
  }
}

@media (max-width: 480px) {
  #main-content {
    padding: 12px;
  }

  .results-grid {
    grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
    gap: 8px;
  }

  .result-card .info h3 {
    font-size: 0.75rem;
  }
  .result-card .info .meta {
    font-size: 0.65rem;
  }

  .detail-backdrop {
    height: 120px;
  }

  .detail-body {
    padding: 12px;
  }
}
