:root {
  --bg: #0f0f0f; --surface: #1c1c1c; --surface-2: #272727;
  --text: #f1f1f1; --muted: #aaaaaa; --accent: #2E7D32;
  --accent-bright: #4caf50; --border: #333; --red: #ff5252; --gold: #ffb300;
}
* { box-sizing: border-box; }
.hidden { display: none !important; }

body {
  margin: 0; font-family: "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5; padding: 0 16px 64px;
}
.app-header { text-align: center; padding: 24px 0 8px; }
.app-header h1 { margin: 0; font-size: 1.6rem; }
.subtitle { color: var(--muted); margin: 6px 0 0; }
.subtitle strong { color: var(--accent-bright); }
.req { color: var(--red); }
.optional { color: var(--muted); font-weight: 400; font-size: .82rem; }

.quota {
  margin: 10px auto 0; display: inline-block; font-size: .8rem; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 4px 14px;
}
.quota.warn { color: #fff; border-color: var(--red); background: rgba(255,82,82,.15); }

/* Tabs */
.tabs { max-width: 900px; margin: 18px auto 0; display: flex; gap: 8px; border-bottom: 1px solid var(--border); }
.tab-btn {
  background: transparent; border: none; border-bottom: 2px solid transparent; border-radius: 0;
  color: var(--muted); padding: 10px 16px; font-size: .95rem; font-weight: 600;
}
.tab-btn:hover:not(:disabled) { color: var(--text); filter: none; }
.tab-btn.active { color: var(--accent-bright); border-bottom-color: var(--accent-bright); }
.tab-panel { margin-top: 18px; }

/* Config */
.config-box { max-width: 760px; margin: 0 auto; display: grid; gap: 12px; }
.config-field { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.config-field label { font-weight: 600; font-size: .9rem; }
.config-field .row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.config-field input { flex: 1; min-width: 0; }
.hint { color: var(--muted); display: block; margin-top: 8px; font-size: .82rem; }
.hint.ok { color: var(--accent-bright); }
.hint.err { color: var(--red); }

.saved-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; }
.saved-badge {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(46,125,50,.14); border: 1px solid var(--accent); border-radius: 8px;
  padding: 8px 12px; font-family: ui-monospace, Menlo, monospace; font-size: .9rem;
  letter-spacing: 1px; color: var(--text); flex: 1; overflow: hidden; text-overflow: ellipsis;
}
.saved-badge .check {
  background: var(--accent-bright); color: #08210b; border-radius: 50%;
  width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 800; letter-spacing: 0;
}
.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.ghost.danger { border-color: var(--red); color: var(--red); }
.settings-note { max-width: 760px; margin: 4px auto 0; color: var(--muted); font-size: .82rem; }
.auth-forms { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; margin-top: 12px; }
.auth-box {
  border: 1px solid var(--border); border-radius: 8px; padding: 12px;
  display: grid; gap: 8px; background: rgba(255,255,255,.02);
}
.auth-box h3 { margin: 0 0 2px; font-size: .95rem; }
.auth-box input, .auth-box button { width: 100%; }

/* Form */
.search-form { max-width: 900px; margin: 0 auto; }
.search-bar { display: flex; gap: 8px; margin-bottom: 14px; }
.search-bar input { flex: 1; font-size: 1rem; }
input, select, button {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; font-size: .95rem;
}
input:focus, select:focus { outline: 2px solid var(--accent); }
input:disabled, select:disabled { opacity: .45; cursor: not-allowed; }
button { cursor: pointer; background: var(--accent); border-color: var(--accent); font-weight: 600; transition: filter .15s ease; }
button:hover:not(:disabled) { filter: brightness(1.1); }
button:disabled { opacity: .5; cursor: not-allowed; }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.filter { display: flex; flex-direction: column; gap: 4px; }
.filter label { font-size: .82rem; color: var(--muted); }

/* Idiomas */
.lang-box { margin-top: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; }
.lang-box summary { cursor: pointer; font-size: .88rem; color: var(--text); }
.lang-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-top: 12px; }
.lang-groups fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px 12px; }
.lang-groups legend { font-size: .78rem; color: var(--accent-bright); padding: 0 6px; }
.lang-groups label { display: flex; align-items: center; gap: 6px; font-size: .85rem; padding: 2px 0; }
.lang-groups input { width: auto; padding: 0; }

/* Results header */
.results-header { max-width: 1100px; margin: 20px auto 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.results-count { color: var(--muted); font-size: .9rem; }
.sort-control { display: flex; align-items: center; gap: 8px; }
.sort-control label { color: var(--muted); font-size: .85rem; }
.sort-control select { padding: 6px 10px; }

/* Status */
.status { max-width: 1100px; margin: 14px auto 0; text-align: center; color: var(--muted); min-height: 20px; }
.status.error { color: var(--red); }

/* Results grid */
.results { max-width: 1100px; margin: 14px auto 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; transition: transform .12s ease, border-color .12s ease; }
.card:hover { transform: translateY(-3px); border-color: var(--accent); }
.thumb-wrap { position: relative; aspect-ratio: 16 / 9; background: #000; display: block; }
.thumb-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-duration { position: absolute; bottom: 6px; right: 6px; background: rgba(0,0,0,.8); color: #fff; font-size: .72rem; font-weight: 600; padding: 1px 6px; border-radius: 4px; }
.thumb-ratio { position: absolute; top: 6px; left: 6px; background: rgba(46,125,50,.92); color: #fff; font-size: .74rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.card-body { padding: 12px 14px 16px; display: flex; flex-direction: column; gap: 6px; }
.card-title { font-weight: 600; font-size: .98rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-title a { color: var(--text); text-decoration: none; }
.card-title a:hover { color: var(--accent-bright); }
.card-channel { color: var(--muted); font-size: .85rem; }
.card-stats { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .82rem; margin-top: 4px; }
.stat b { color: var(--accent-bright); font-weight: 700; }
.card-date { color: var(--muted); font-size: .78rem; }

/* Related */
.related { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.related-btn { width: 100%; background: transparent; color: var(--accent-bright); border: 1px dashed var(--accent); font-size: .82rem; }
.related-title { font-size: .8rem; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.related-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; max-height: 260px; overflow-y: auto; }
.related-list li { font-size: .82rem; line-height: 1.3; }
.related-list a { color: var(--text); text-decoration: none; }
.related-list a:hover { color: var(--accent-bright); }
.related-list .r-ratio { color: var(--gold); font-weight: 700; margin-right: 4px; }
.related-empty { font-size: .8rem; color: var(--muted); }

/* Historial */
.history-head { max-width: 900px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.history-head h2 { font-size: 1.1rem; margin: 0; }
.history-list { max-width: 900px; margin: 14px auto 0; display: flex; flex-direction: column; gap: 10px; }
.history-group { display: grid; gap: 10px; }
.history-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.history-main { min-width: 0; flex: 1; }
.history-query-btn {
  background: transparent; border: none; color: var(--text); padding: 0; text-align: left;
  font-size: .98rem; font-weight: 700; cursor: pointer; line-height: 1.3;
}
.history-query-btn:hover { color: var(--accent-bright); filter: none; }
.history-meta { color: var(--muted); font-size: .78rem; margin-top: 4px; }
.history-actions { display: flex; gap: 6px; flex-shrink: 0; }
.history-empty { max-width: 900px; margin: 14px auto 0; color: var(--muted); text-align: center; }
.history-versions {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px;
}
.history-versions summary { cursor: pointer; color: var(--accent-bright); font-size: .86rem; font-weight: 600; }
.history-version-list { margin-top: 10px; display: grid; gap: 8px; }
.history-version-item {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px; background: rgba(255,255,255,.02);
}
.history-version-head { background: rgba(46,125,50,.08); }
.history-version-main { min-width: 0; flex: 1; }
.history-version-title { font-weight: 700; font-size: .9rem; }
.history-version-meta { color: var(--muted); font-size: .78rem; margin-top: 4px; }

/* Show more */
.more-wrap { text-align: center; margin: 26px 0; }
.show-more { padding: 12px 28px; font-size: 1rem; }
.app-footer { text-align: center; color: var(--muted); margin-top: 30px; }

/* Spinner */
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--muted); border-top-color: var(--accent-bright); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
