/* ===== RESET & VARIABLES ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:       #0f0f1a;
  --bg2:      #1a1a2e;
  --bg3:      #252545;
  --accent:   #6c63ff;
  --accent-d: #5a52e0;
  --text:     #e8e8f0;
  --muted:    #8888aa;
  --success:  #4ade80;
  --error:    #f87171;
  --warn:     #fbbf24;
  --radius:   12px;
  --hdr:      56px;
}

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { display: block; }
button { font-family: inherit; cursor: pointer; }

/* ===== iOS SAFE AREA ===== */
body {
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ===== IOS INSTALL BANNER ===== */
.ios-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--accent);
  color: #fff;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 300;
  font-size: 0.85rem;
  line-height: 1.4;
}
.ios-banner span { flex: 1; }
.ios-banner.hidden { display: none; }
.ios-banner-close {
  background: rgba(255,255,255,0.25);
  border: none;
  color: #fff;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-size: 0.75rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== HEADER ===== */
.app-header {
  position: fixed;
  top: env(safe-area-inset-top, 0px);
  left: 0;
  right: 0;
  height: var(--hdr);
  background: var(--bg);
  border-bottom: 1px solid var(--bg3);
  display: flex;
  align-items: center;
  padding: 0 12px 0 16px;
  z-index: 100;
}
.app-title {
  flex: 1;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* ===== VIEWS ===== */
.view {
  display: none;
  padding-top: calc(var(--hdr) + env(safe-area-inset-top, 0px) + 20px);
  padding-left: 16px;
  padding-right: 16px;
  padding-bottom: calc(32px + env(safe-area-inset-bottom, 0px));
  min-height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
}

body[data-view="onboarding"] #view-onboarding { display: block; }
body[data-view="search"]     #view-search     { display: block; }
body[data-view="detail"]     #view-detail     { display: block; }

/* Hide settings gear when already in settings */
body[data-view="onboarding"] #btn-settings { visibility: hidden; }

/* ===== BUTTONS ===== */
.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.25rem;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { background: var(--bg3); }

.btn-primary {
  display: block;
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 14px 20px;
  font-size: 1rem;
  font-weight: 600;
  margin-top: 6px;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.btn-primary:active  { background: var(--accent-d); }
.btn-primary:disabled { opacity: 0.55; cursor: default; }

.back-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.9rem;
  padding: 0;
  margin-bottom: 20px;
  -webkit-tap-highlight-color: transparent;
}
.back-btn:active { opacity: 0.7; }

/* ===== FORM ELEMENTS ===== */
.form-group {
  margin-bottom: 22px;
}
.form-group > label {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.input-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.input-row input { flex: 1; }

input[type="password"],
input[type="text"],
input[type="search"],
select {
  background: var(--bg2);
  border: 1.5px solid var(--bg3);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  padding: 12px 14px;
  width: 100%;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
input::placeholder { color: var(--muted); }
input:focus, select:focus { border-color: var(--accent); }

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238888aa' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.help-link {
  display: inline-block;
  margin-top: 7px;
  color: var(--accent);
  font-size: 0.82rem;
}
.hint {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 10px;
  line-height: 1.5;
}

/* ===== ONBOARDING ===== */
.onboarding-content {
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: 40px;
}
.setup-icon {
  font-size: 3rem;
  text-align: center;
  margin-bottom: 10px;
}
.onboarding-content h2 {
  text-align: center;
  font-size: 1.45rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.subtitle {
  text-align: center;
  color: var(--muted);
  margin-bottom: 28px;
  font-size: 0.95rem;
}

/* ===== SETTINGS STATUS ===== */
.settings-status {
  margin-top: 12px;
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 0.9rem;
  line-height: 1.4;
}
.settings-status.hidden { display: none; }
.settings-status.error {
  background: rgba(248,113,113,0.12);
  border: 1px solid var(--error);
  color: var(--error);
}
.settings-status.success {
  background: rgba(74,222,128,0.12);
  border: 1px solid var(--success);
  color: var(--success);
}

/* ===== PROVIDER CHECKLIST ===== */
.provider-checklist {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.provider-check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  background: var(--bg2);
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}
.provider-check:active { background: var(--bg3); }

.provider-check input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  flex-shrink: 0;
  padding: 0;
  border: none;
  margin: 0;
  cursor: pointer;
}
.provider-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.provider-check-name {
  font-size: 0.95rem;
  flex: 1;
}

/* ===== SEARCH VIEW ===== */
.search-bar-wrap {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.search-bar-wrap input { flex: 1; }

input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }

.btn-search-go {
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  padding: 0 16px;
  font-size: 1.1rem;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.btn-search-go:active { background: var(--accent-d); }

.search-hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 40px 20px;
}

/* ===== LOADING / STATES ===== */
.loading-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  font-size: 0.9rem;
}
.loading-state::after {
  content: '';
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--bg3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-left: 8px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state, .error-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  font-size: 0.9rem;
  line-height: 1.6;
}
.error-state { color: var(--error); }

/* ===== RESULT CARDS ===== */
.search-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.result-card {
  display: flex;
  gap: 12px;
  background: var(--bg2);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 10px;
  text-align: left;
  color: var(--text);
  width: 100%;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s;
}
.result-card:active {
  border-color: var(--accent);
  background: var(--bg3);
}

.card-poster {
  width: 54px;
  flex-shrink: 0;
  align-self: flex-start;
}
.card-poster img {
  width: 54px;
  height: 81px;
  object-fit: cover;
  border-radius: 7px;
}
.no-poster {
  width: 54px;
  height: 81px;
  background: var(--bg3);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.card-info { flex: 1; min-width: 0; }
.card-title {
  font-weight: 600;
  font-size: 0.98rem;
  line-height: 1.35;
  margin-bottom: 5px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.card-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 5px;
}
.card-year {
  font-size: 0.82rem;
  color: var(--muted);
}
.card-overview {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* ===== BADGES ===== */
.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}
.badge-movie { background: rgba(108,99,255,0.2); color: #a89fff; }
.badge-tv    { background: rgba(74,222,128,0.2); color: #6ee7a0; }

/* ===== DETAIL VIEW ===== */
.detail-header {
  display: flex;
  gap: 14px;
  margin-bottom: 16px;
  align-items: flex-start;
}
.detail-poster {
  width: 105px;
  height: 157px;
  object-fit: cover;
  border-radius: 10px;
  flex-shrink: 0;
}
.detail-meta-wrap {
  flex: 1;
  min-width: 0;
  padding-top: 2px;
}
.detail-title {
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 8px;
}
.detail-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  flex-wrap: wrap;
}

.detail-overview {
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.65;
  margin-bottom: 24px;
}

/* ===== PROVIDER SECTION ===== */
.provider-group {
  margin-bottom: 22px;
}
.provider-group-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 10px;
}
.provider-group--yours .provider-group-label {
  color: var(--success);
}

.provider-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.provider-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--bg2);
  border: 1.5px solid var(--bg3);
  border-radius: 9px;
  padding: 6px 11px 6px 7px;
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
}
.chip-text-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.chip-languages {
  font-size: 0.65rem;
  color: var(--muted);
  line-height: 1.4;
  white-space: normal;
  word-break: break-word;
}
.provider-chip--langs {
  white-space: normal;
  max-width: 280px;
  align-items: flex-start;
}
.provider-chip img {
  width: 26px;
  height: 26px;
  border-radius: 5px;
  object-fit: cover;
  flex-shrink: 0;
}
.provider-chip-fallback {
  width: 26px;
  height: 26px;
  border-radius: 5px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 800;
  color: #fff;
  line-height: 1;
  text-align: center;
}

.providers-empty {
  text-align: center;
  padding: 30px 20px;
  color: var(--muted);
}
.providers-empty-icon {
  font-size: 2.5rem;
  margin-bottom: 10px;
}

.btn-justwatch {
  display: block;
  text-align: center;
  background: var(--bg2);
  border: 1px solid var(--bg3);
  color: var(--accent);
  border-radius: var(--radius);
  padding: 13px;
  font-size: 0.9rem;
  font-family: inherit;
  margin-top: 20px;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  width: 100%;
}
.btn-justwatch:active { background: var(--bg3); }
