:root {
  color-scheme: dark;
  --bg: #0f1117;
  --surface: #171a22;
  --surface-2: #1f2430;
  --border: #2a3140;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #5b8def;
  --accent-hover: #4a7de0;
  --green: #3ecf8e;
  --yellow: #f0c14b;
  --red: #ef6461;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  font-family:
    "SF Pro Text",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, #151927 0%, var(--bg) 45%);
  color: var(--text);
  overflow: hidden;
}

.hidden {
  display: none !important;
}

.login-screen {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
}

.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 1.75rem;
}

.login-card p {
  margin: 0 0 20px;
  color: var(--muted);
}

.login-card form {
  display: grid;
  gap: 12px;
}

input,
select,
button,
textarea {
  font: inherit;
  font-size: 16px; /* iOS Safari zooms focused fields under 16px */
}

input,
select,
textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
}

textarea {
  resize: vertical;
  min-height: 60px;
  line-height: 1.4;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(91, 141, 239, 0.45);
  border-color: var(--accent);
}

button {
  cursor: pointer;
}

.error {
  color: var(--red);
  margin-top: 12px;
  font-size: 0.9rem;
}

.app {
  max-width: 1280px;
  height: 100%;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-shrink: 0;
  position: relative;
}

.header h1 {
  margin: 0;
  font-size: 1.75rem;
  flex-shrink: 0;
}

.main-nav {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.nav-tab {
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.nav-tab:hover {
  color: var(--text);
}

.nav-tab.active {
  background: rgba(91, 141, 239, 0.15);
  border-color: rgba(91, 141, 239, 0.45);
  color: var(--text);
}

.header-menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  flex-shrink: 0;
}

.header-menu-icon,
.header-menu-icon::before,
.header-menu-icon::after {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  position: relative;
}

.header-menu-icon::before,
.header-menu-icon::after {
  content: "";
  position: absolute;
  left: 0;
}

.header-menu-icon::before {
  top: -6px;
}

.header-menu-icon::after {
  top: 6px;
}

.header-menu {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  min-width: 0;
}

.status-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  margin-left: auto;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
}

.pill.ok {
  color: var(--green);
  border-color: rgba(62, 207, 142, 0.35);
}

.pill.warn {
  color: var(--yellow);
  border-color: rgba(240, 193, 75, 0.35);
}

.layout {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.view-panel {
  flex: 1;
  min-height: 0;
}

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

.panel-header,
.add-search-form {
  flex-shrink: 0;
}

.panel-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

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

.listings-filters {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.listings-filters select {
  width: auto;
  min-width: 160px;
  flex-shrink: 0;
}

.status-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tab {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
}

.tab.active {
  background: rgba(91, 141, 239, 0.15);
  border-color: rgba(91, 141, 239, 0.45);
  color: var(--text);
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
}

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

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

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  color: var(--text);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.8rem;
  border-radius: 8px;
}

.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid rgba(239, 100, 97, 0.35);
}

.add-search-form {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: grid;
  gap: 10px;
}

.price-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.searches-list {
  padding: 12px;
  display: grid;
  gap: 10px;
  align-content: start;
}

.list-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.list-scroll-content.pull-release {
  transition: transform 0.25s ease;
}

.listings-list {
  padding: 12px;
  display: grid;
  gap: 10px;
  align-content: start;
}

.pull-refresh {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
  height: 40px;
  margin-top: -40px;
  padding-bottom: 4px;
  color: var(--muted);
  font-size: 0.8rem;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.pull-refresh.visible {
  opacity: 1;
}

.pull-refresh.ready {
  color: var(--accent);
}

.pull-refresh.refreshing .pull-refresh-icon {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.pull-refresh.refreshing .pull-refresh-icon::before {
  content: none;
}

.pull-refresh-icon {
  display: block;
  width: 18px;
  height: 18px;
  position: relative;
  flex-shrink: 0;
}

.pull-refresh-icon::before {
  content: "↓";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 14px;
  line-height: 1;
  transition: transform 0.2s ease;
}

.pull-refresh.ready .pull-refresh-icon::before {
  transform: rotate(180deg);
}

.search-item {
  padding: 14px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.search-item.inactive {
  opacity: 0.65;
}

.search-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.search-query {
  font-weight: 600;
  line-height: 1.3;
}

.search-meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 10px;
}

.search-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-blurb {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--muted);
}

.search-options {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.filter-blurb + .search-options {
  margin-top: 10px;
}

.search-options .checkbox-label.disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.search-item.editing {
  border-color: rgba(91, 141, 239, 0.45);
}

.search-edit-form {
  display: grid;
  gap: 12px;
}

.field-label {
  display: grid;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--muted);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--text);
  cursor: pointer;
}

.checkbox-label input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.search-edit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.listing-card {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 14px;
  padding: 14px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.listing-image {
  width: 96px;
  height: 96px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg);
}

.listing-image.placeholder {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.75rem;
}

.listing-title {
  margin: 0 0 6px;
  font-size: 1rem;
  line-height: 1.35;
}

.listing-title a {
  color: inherit;
  text-decoration: none;
}

.listing-title a:hover {
  color: var(--accent);
}

.listing-price {
  color: var(--green);
  font-weight: 600;
  margin-bottom: 6px;
}

.listing-meta {
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 8px;
}

.eval-block {
  font-size: 0.85rem;
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 10px;
  background: rgba(255, 255, 255, 0.03);
}

.eval-block.pass {
  border-left: 3px solid var(--green);
}

.eval-block.uncertain {
  border-left: 3px solid var(--yellow);
}

.eval-block.fail {
  border-left: 3px solid var(--red);
}

.listing-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.split-pill {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.split-pill-btn {
  border: none;
  background: transparent;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.split-pill-btn + .split-pill-btn {
  border-left: 1px solid var(--border);
}

.split-pill-btn:hover:not(:disabled) {
  color: var(--text);
}

.split-pill-btn.active[data-listing-action="consider"] {
  background: rgba(91, 201, 139, 0.15);
  color: var(--green);
}

.split-pill-btn.active[data-listing-action="ignore"] {
  background: rgba(239, 100, 97, 0.15);
  color: var(--red);
}

.split-pill-btn:disabled,
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.tooltip {
  position: fixed;
  z-index: 1000;
  max-width: 240px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.78rem;
  line-height: 1.35;
  pointer-events: none;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
  opacity: 0;
  transition: opacity 0.15s ease;
  transform: translate(-50%, -100%);
}

.tooltip.visible {
  opacity: 1;
}

.tooltip.hidden {
  display: none;
}

.empty-state {
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
}

.empty-hint {
  margin-top: 12px;
  font-size: 0.9rem;
  line-height: 1.5;
}

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

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

.status-pills.loading .pill {
  color: transparent;
  background: linear-gradient(
    90deg,
    var(--surface-2) 0%,
    var(--border) 50%,
    var(--surface-2) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
  min-width: 88px;
  min-height: 28px;
}

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-width: 360px;
}

@media (max-width: 900px) {
  .app {
    padding: 0;
    height: 100dvh;
  }

  .header {
    flex-wrap: nowrap;
    padding: 12px 16px;
    margin-bottom: 0;
    gap: 8px;
  }

  .header h1 {
    font-size: 1.25rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .panel {
    border-radius: 0;
    border-left: none;
    border-right: none;
    box-shadow: none;
  }

  .panel-header h2 {
    display: none;
  }

  .listings-filters {
    margin-top: 0;
  }

  .main-nav {
    flex: 1;
    min-width: 0;
    justify-content: flex-end;
    gap: 4px;
  }

  .nav-tab {
    padding: 6px 10px;
    font-size: 0.8rem;
    white-space: nowrap;
  }

  .header-menu-toggle {
    display: inline-flex;
    flex-shrink: 0;
  }

  .header-menu {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    left: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 100;
    flex: none;
  }

  .header.menu-open .header-menu {
    display: flex;
  }

  .header-actions {
    margin-left: 0;
    flex-direction: column;
  }

  .status-pills {
    flex: none;
  }
}

@media (max-width: 640px) {
  .panel-header {
    padding: 12px 14px;
  }

  .listings-filters {
    flex-wrap: nowrap;
    gap: 8px;
    margin-top: 0;
  }

  .listings-filters select {
    min-width: 0;
    flex: 0 1 38%;
    padding: 8px 10px;
    font-size: 16px;
  }

  .status-tabs {
    flex: 1;
    min-width: 0;
    flex-wrap: nowrap;
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .status-tabs::-webkit-scrollbar {
    display: none;
  }

  .status-tabs .tab {
    padding: 6px 9px;
    font-size: 0.75rem;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .listing-card {
    grid-template-columns: 72px 1fr;
    gap: 10px;
    padding: 10px;
  }

  .listing-image,
  .listing-image.placeholder {
    width: 72px;
    height: 72px;
  }

  .listing-title {
    font-size: 0.92rem;
  }
}
