/* Apartment Watch — mobile-first, hand-written, two-accent palette. */

:root {
  --ink: #1c2422;
  --ink-soft: #55625d;
  --ground: #faf8f4;
  --surface: #ffffff;
  --line: #e4ded2;
  --primary: #1f4b43;
  --primary-ink: #ffffff;
  --accent: #d98e48;
  --accent-ink: #2a1a06;
  --danger: #a34a3d;
  --ok: #2f6f52;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(28, 36, 34, 0.06), 0 4px 16px rgba(28, 36, 34, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--ground);
  color: var(--ink);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Tahoma, Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
}

a {
  color: var(--primary);
}

img {
  max-width: 100%;
  display: block;
}

button,
input,
textarea,
select {
  font: inherit;
}

/* ---- Topbar --------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--primary);
  color: var(--primary-ink);
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  text-decoration: none;
  color: var(--primary-ink);
}

.topbar__brand img {
  width: 28px;
  height: 28px;
}

.topbar__nav {
  display: flex;
  gap: 4px;
}

.topbar__nav a {
  color: var(--primary-ink);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0.85;
}

.topbar__nav a.active,
.topbar__nav a:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.14);
}

/* ---- Layout ----------------------------------------------------------- */

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.page-header h1 {
  font-size: 20px;
  margin: 0;
}

/* ---- Buttons ------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.1;
}

.btn:hover {
  border-color: var(--primary);
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
}

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 13px;
}

.btn[disabled] {
  opacity: 0.5;
  cursor: default;
}

/* ---- Install banner ---------------------------------------------------- */

.install-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--primary);
  color: var(--primary-ink);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
}

.install-banner__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
}

.install-banner__text strong {
  font-size: 14px;
}

.install-banner__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.install-banner .btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.install-banner #install-dismiss {
  background: transparent;
  border: none;
  color: var(--primary-ink);
  font-size: 20px;
  padding: 0 6px;
  line-height: 1;
  opacity: 0.8;
}

/* ---- Tabs ------------------------------------------------------------- */

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 16px;
  -webkit-overflow-scrolling: touch;
}

.tabs a {
  white-space: nowrap;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  background: var(--surface);
}

.tabs a.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
}

/* ---- Ad grid / cards ---------------------------------------------------- */

.ad-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 640px) {
  .ad-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .ad-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.ad-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
}

.ad-card__image {
  aspect-ratio: 4 / 3;
  background: var(--line);
  overflow: hidden;
  position: relative;
}

.ad-card__image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ad-card__body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.ad-card__title {
  font-size: 14px;
  font-weight: 700;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ad-card__price {
  color: var(--primary);
  font-weight: 700;
  font-size: 15px;
}

.ad-card__meta {
  color: var(--ink-soft);
  font-size: 13px;
}

.ad-card__specs {
  color: var(--primary);
  font-weight: 600;
}

.badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  color: #fff;
}

.badge-active {
  background: var(--ok);
}

.badge-deleted {
  background: var(--danger);
}

.badge-out_of_filter {
  background: var(--ink-soft);
}

.badge-new {
  background: var(--accent);
  color: var(--accent-ink);
}

.badge-source {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  margin-inline-start: 6px;
}

/* ---- Ad detail --------------------------------------------------------- */

.gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

@media (min-width: 640px) {
  .gallery {
    grid-template-columns: repeat(3, 1fr);
  }
}

.gallery img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  cursor: zoom-in;
  background: var(--line);
}

.specs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 16px 0;
}

@media (min-width: 640px) {
  .specs {
    grid-template-columns: repeat(4, 1fr);
  }
}

.spec-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  text-align: center;
}

.status-note {
  background: #fbeee7;
  border: 1px solid #eac9b8;
  color: var(--danger);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
}

.description {
  white-space: pre-line;
  font-size: 14px;
  color: var(--ink);
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}

.lightbox.open {
  display: flex;
}

.lightbox img {
  max-height: 90vh;
  max-width: 100%;
  border-radius: 6px;
}

.lightbox__close {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top));
  inset-inline-end: 16px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: none;
  border-radius: 999px;
  width: 36px;
  height: 36px;
  font-size: 18px;
  cursor: pointer;
}

/* ---- Confirm dialog -------------------------------------------------------- */

.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 110;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}

.dialog-backdrop.open {
  display: flex;
}

.dialog {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow);
}

.dialog h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.dialog p {
  margin: 0 0 16px;
  font-size: 14px;
  color: var(--ink-soft);
}

.dialog__actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ---- Forms --------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card h2 {
  margin-top: 0;
  font-size: 16px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--ink-soft);
}

input[type="text"],
input[type="password"],
input[type="url"],
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--ink);
  margin-bottom: 14px;
}

textarea {
  min-height: 120px;
  resize: vertical;
  font-family: inherit;
}

.filter-group {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 14px;
}

.filter-group:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

.filter-group__title {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--ink-soft);
}

.filter-group__options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface);
  margin-bottom: 0;
}

.filter-checkbox:has(input:checked) {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
}

.filter-checkbox input {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  margin: 0;
  flex-shrink: 0;
}

.field-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.hint {
  color: var(--ink-soft);
  font-size: 13px;
  margin-top: -8px;
  margin-bottom: 14px;
}

.flash {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
}

.flash-ok {
  background: #e7f3ec;
  border: 1px solid #bcdfcb;
  color: var(--ok);
}

.flash-error {
  background: #fbeee7;
  border: 1px solid #eac9b8;
  color: var(--danger);
}

/* ---- Login ---------------------------------------------------------------- */

.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-card img {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
}

.login-card h1 {
  font-size: 18px;
  margin: 0 0 18px;
}

.login-card .btn-primary {
  width: 100%;
  padding: 12px;
}

.login-card label {
  text-align: start;
}

/* ---- Misc ------------------------------------------------------------------ */

.muted {
  color: var(--ink-soft);
  font-size: 13px;
}

.empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 48px 16px;
}

.log-tail {
  background: #0f1613;
  color: #cfe8db;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  padding: 12px;
  border-radius: 8px;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #ecf3ef;
    --ink-soft: #a9b8b1;
    --ground: #12211c;
    --surface: #182f28;
    --line: #24463c;
  }

  /* --primary (a dark green) stays the same in both themes since it still
     works as a BACKGROUND (topbar, primary buttons always carry their own
     white text) — but used as foreground TEXT on --surface, which dark mode
     does redefine to a near-matching dark tone above, it becomes nearly
     invisible. Override the text-color usages specifically rather than
     redefining --primary itself, which would wrongly also recolor those
     backgrounds. */
  .ad-card__price,
  .ad-card__specs {
    color: var(--ink);
  }

  .status-note {
    background: #3a2018;
    border-color: #5a2f22;
  }

  .flash-ok {
    background: #17352500;
    background: #16302460;
    border-color: #2f6f52;
  }

  .flash-error {
    background: #3a201860;
    border-color: #a34a3d;
  }
}
