:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e4e9;
  --text: #1c1f26;
  --text-muted: #6b7280;
  --primary: #ff6e14;
  --primary-dark: #e05a00;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* --- Login --- */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-box {
  background: var(--surface);
  padding: 2.5rem;
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0,0,0,0.08);
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.login-box h1 { margin: 0; font-size: 1.5rem; }
.subtitle { margin: -0.5rem 0 0.5rem; color: var(--text-muted); font-size: 0.9rem; }

/* --- Layout --- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { margin: 0; font-size: 1.25rem; }
.topbar-actions { display: flex; align-items: center; gap: 0.6rem; }

main { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }
.toolbar { margin-bottom: 1rem; display: flex; justify-content: flex-end; }

/* --- Buttons --- */
.btn {
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
  font-weight: 600;
}
.btn.primary { background: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.secondary { background: #eef0f3; color: var(--text); }
.btn.secondary:hover { background: #e2e4e9; }
.btn.danger { background: #fde8e8; color: var(--danger); }
.btn.danger:hover { background: #fbd5d5; }
.btn.small { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

.pill {
  background: #eef0f3;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.pill.ok { background: #dcfce7; color: var(--success); }
.pill.warn { background: #fef3c7; color: #92400e; }

/* --- Search cards --- */
.searches-grid {
  display: grid;
  gap: 1rem;
}
.empty-hint { color: var(--text-muted); text-align: center; padding: 3rem 0; }

.search-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.search-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}
.search-card-title { font-size: 1.1rem; font-weight: 700; margin: 0 0 0.25rem; }
.search-card-meta { color: var(--text-muted); font-size: 0.85rem; }
.search-card-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.criteria-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.6rem 0; }
.tag {
  background: #f1f2f5;
  border-radius: 6px;
  padding: 0.2rem 0.55rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.status-line { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.4rem; }
.status-line.error { color: var(--danger); }

.listings-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}
.listing-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  background: #fafafa;
  display: flex;
  flex-direction: column;
}
.listing-card img {
  width: 100%;
  height: 100px;
  object-fit: cover;
  background: #e5e7eb;
}
.listing-card .listing-body { padding: 0.5rem 0.6rem; }
.listing-card .listing-price { font-weight: 700; font-size: 0.9rem; }
.listing-card .listing-title {
  font-size: 0.78rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.listing-card .listing-meta { font-size: 0.72rem; color: var(--text-muted); }

/* --- Modals --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h2 { margin-top: 0; }
.modal form { display: flex; flex-direction: column; gap: 0.9rem; }
.modal label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}
.modal label.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}
.modal input[type="text"],
.modal input[type="number"],
.modal input[type="password"],
.modal select {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--text);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
fieldset { border: 1px solid var(--border); border-radius: 6px; padding: 0.5rem 0.7rem; }
legend { font-size: 0.8rem; color: var(--text-muted); padding: 0 0.3rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }

.error { color: var(--danger); font-size: 0.85rem; min-height: 1em; margin: 0; }
.success { color: var(--success); font-size: 0.85rem; min-height: 1em; margin: 0; }
.hint { color: var(--text-muted); font-size: 0.78rem; margin: -0.5rem 0 0; }

@media (max-width: 600px) {
  .form-row { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 0.6rem; }
}
