*, *::before, *::after { box-sizing: border-box; }

html { font-size: 16px; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.1;
  margin: 0 0 var(--space-3);
}
h1 { font-size: 2.25rem; }
h2 { font-size: 1.5rem; }
p { margin: 0 0 var(--space-4); }
a { color: var(--accent); }
code, kbd {
  font-family: var(--font-mono);
  font-size: 0.95em;
  background: var(--surface-2);
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
}

/* Layout */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.5rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text);
  text-decoration: none;
}
.topbar .who { color: var(--text-muted); font-size: 0.9rem; margin-right: var(--space-3); }
.topbar form { display: inline; }

.page { max-width: 44rem; margin: 0 auto; padding: var(--space-6) var(--space-4); }
.page--narrow { max-width: 26rem; }
.center { min-height: 100vh; display: grid; place-items: center; padding: var(--space-4); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: var(--space-6);
  width: 100%;
}
.card + .card { margin-top: var(--space-5); }
.card header { margin-bottom: var(--space-5); }
.card header p { color: var(--text-muted); margin: 0; }
.eyebrow {
  font-family: var(--font-display);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0 0 var(--space-1);
}

/* Forms */
.field { margin-bottom: var(--space-4); }
.field label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: var(--space-1); }
.field .hint { color: var(--text-muted); font-size: 0.85rem; margin: var(--space-1) 0 0; }
input[type="text"], input[type="password"] {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.75rem;
}
input:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
input.code {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  letter-spacing: 0.3em;
  text-align: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font: inherit;
  font-weight: 600;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  background: var(--surface-2);
  color: var(--text);
}
.btn--primary { background: var(--accent); color: var(--accent-text); }
.btn--primary:hover { background: var(--accent-hover); }
.btn--danger { color: var(--danger); border-color: var(--danger-border); background: var(--surface); }
.btn--danger:hover { background: var(--danger-bg); }
.btn--block { width: 100%; }
.btn--link { background: none; padding: 0; color: var(--accent); text-decoration: underline; font-weight: 400; }
.actions { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; margin-top: var(--space-5); }

/* Alerts */
.alert {
  border: 1px solid;
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  font-size: 0.95rem;
}
.alert--ok { background: var(--ok-bg); color: var(--ok-text); border-color: var(--ok-border); }
.alert--warn { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-border); }
.alert--error { background: var(--danger-bg); color: var(--danger-text); border-color: var(--danger-border); }

/* Status */
.status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  border: 1px solid;
}
.status::before { content: ''; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: currentColor; }
.status--on { background: var(--ok-bg); color: var(--ok-text); border-color: var(--ok-border); }
.status--off { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-border); }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-2) var(--space-5); margin: 0 0 var(--space-4); }
dl.facts dt { color: var(--text-muted); }
dl.facts dd { margin: 0; }

/* 2FA setup */
.setup { display: grid; grid-template-columns: 1fr; gap: var(--space-5); }
@media (min-width: 40rem) { .setup { grid-template-columns: 200px 1fr; } }
.qr {
  display: block;
  width: 200px;
  height: 200px;
  padding: var(--space-2);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.secret {
  display: block;
  font-family: var(--font-mono);
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  word-break: break-all;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  margin: var(--space-2) 0 var(--space-4);
}
ol.steps { padding-left: 1.25rem; margin: 0 0 var(--space-4); }
ol.steps li { margin-bottom: var(--space-2); }

/* Listings */
.page--wide { max-width: 80rem; }
.toolbar { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-4); }
.toolbar h1 { margin-bottom: var(--space-1); }
.actions--tight { margin-top: 0; }
.warn { color: var(--warn-text); }
.empty h2 { margin-top: 0; }

.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--space-4);
}
.listing {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.listing--new { border-color: var(--accent); }
.listing__media { position: relative; display: block; aspect-ratio: 4 / 3; background: var(--surface-2); text-decoration: none; color: inherit; }
.listing__media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.listing__placeholder { display: grid; place-items: center; height: 100%; color: var(--text-muted); font-size: 0.9rem; }
.badge {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  background: var(--accent);
  color: var(--accent-text);
  font-family: var(--font-display);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}
.listing__body { padding: var(--space-3) var(--space-4) var(--space-4); display: flex; flex-direction: column; gap: var(--space-1); }
.listing__top { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-2); }
.listing__price { font-family: var(--font-display); font-weight: 700; font-size: 1.5rem; }
.listing__title { font-family: var(--font-body); font-weight: 600; font-size: 1rem; line-height: 1.35; margin: 0; }
.listing__title a { color: var(--text); text-decoration: none; }
.listing__title a:hover { text-decoration: underline; }
.listing__meta { margin: 0; font-size: 0.9rem; color: var(--text-muted); }
.listing__loc { margin: 0; font-size: 0.9rem; }
.listing__summary {
  margin: var(--space-1) 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Tabs */
.tabs { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-4); border-bottom: 1px solid var(--border); }
.tab {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  color: var(--text-muted); text-decoration: none; font-weight: 600; font-size: 0.95rem;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab--active { color: var(--text); border-bottom-color: var(--accent); }
.tab .count { font-size: 0.8rem; background: var(--surface-2); border-radius: 999px; padding: 0.05rem 0.5rem; }

/* Change badges and states */
.badge--drop { background: var(--ok-text); color: #fff; }
.badge--up { background: var(--warn-text); color: #fff; }
.badge--repost { background: var(--text-muted); color: #fff; }
.badge--removed { background: var(--danger); color: #fff; }
.listing--drop { border-color: var(--ok-border); }
.listing--removed { opacity: 0.75; }
.listing--removed .listing__media img { filter: grayscale(0.6); }
.listing__was { color: var(--text-muted); font-size: 1rem; font-weight: 400; margin-left: var(--space-2); }
.listing__note { margin: 0; font-size: 0.85rem; color: var(--text-muted); }
.listing--drop .listing__note { color: var(--ok-text); }
.listing--removed .listing__note { color: var(--danger-text); }

/* Dashboard */
.columns { display: grid; grid-template-columns: 1fr; gap: var(--space-5); align-items: start; }
@media (min-width: 60rem) { .columns { grid-template-columns: 1.1fr 0.9fr; } }
.columns .card + .card { margin-top: var(--space-5); }
.stats { list-style: none; margin: var(--space-4) 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: var(--space-3); }
.stats a { display: block; text-decoration: none; color: inherit; background: var(--surface-2); border-radius: var(--radius-md); padding: var(--space-3); }
.stats a:hover { outline: 1px solid var(--border-strong); }
.stat__n { display: block; font-family: var(--font-display); font-weight: 700; font-size: 2rem; line-height: 1; }
.stat__l { display: block; font-size: 0.85rem; color: var(--text-muted); margin-top: var(--space-1); }

.feed { list-style: none; margin: 0; padding: 0; }
.feed__item { display: grid; grid-template-columns: 0.75rem 1fr; gap: var(--space-3); padding: var(--space-3) 0; border-top: 1px solid var(--border); }
.feed__item:first-child { border-top: 0; padding-top: 0; }
.feed__dot { width: 0.75rem; height: 0.75rem; border-radius: 50%; margin-top: 0.3rem; background: var(--border-strong); }
.feed__item--new .feed__dot { background: var(--accent); }
.feed__item--price_drop .feed__dot { background: var(--ok-text); }
.feed__item--price_increase .feed__dot { background: var(--warn-text); }
.feed__item--removed .feed__dot { background: var(--danger); }
.feed__head { display: flex; justify-content: space-between; gap: var(--space-2); }
.feed__type { font-weight: 600; font-size: 0.9rem; }
.feed__title { display: block; color: var(--text); text-decoration: none; font-size: 0.95rem; line-height: 1.35; margin: 0.1rem 0; }
.feed__title:hover { text-decoration: underline; }

/* Card: media as a button, contact block, actions */
button.listing__media { width: 100%; border: 0; padding: 0; cursor: pointer; font: inherit; }
button.listing__media:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.photo-count {
  position: absolute; right: var(--space-2); bottom: var(--space-2);
  background: rgb(0 0 0 / 0.6); color: #fff; font-size: 0.75rem; font-weight: 600;
  padding: 0.15rem 0.5rem; border-radius: 999px;
}
.contact { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.contact--stack { flex-direction: column; align-items: flex-start; margin: 0 0 var(--space-4); }
.contact__item {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-size: 0.85rem; font-weight: 600; text-decoration: none; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 0.2rem 0.6rem 0.2rem 0.35rem; max-width: 100%;
}
.contact__item:hover { border-color: var(--border-strong); }
.contact__k {
  font-family: var(--font-display); text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.7rem;
  background: var(--accent); color: var(--accent-text); border-radius: 999px; padding: 0.05rem 0.4rem;
}
.contact__item--link .contact__k { background: var(--text-muted); color: #fff; }
.contact__item--reply .contact__k { background: var(--border-strong); color: var(--text); }
.contact__item--link { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.listing__actions { display: flex; gap: var(--space-2); margin-top: var(--space-3); }
.btn--small { padding: 0.35rem 0.75rem; font-size: 0.85rem; }
.btn--ghost { background: transparent; border-color: var(--border); }

/* Preview dialog */
.preview { border: 0; padding: 0; background: transparent; max-width: none; max-height: none; width: 100vw; height: 100vh; }
.preview::backdrop { background: rgb(0 0 0 / 0.7); }
.preview__frame {
  position: relative; margin: 3vh auto; width: min(1040px, 96vw); max-height: 94vh; overflow: auto;
  background: var(--surface); color: var(--text); border-radius: var(--radius-lg); box-shadow: var(--shadow);
}
.preview__close {
  position: absolute; top: var(--space-2); right: var(--space-2); z-index: 2;
  width: 2.25rem; height: 2.25rem; border-radius: 50%; border: 0; cursor: pointer;
  background: rgb(0 0 0 / 0.6); color: #fff; font-size: 1.5rem; line-height: 1;
}
.preview__gallery { position: relative; background: #0b0d10; width: 100%; height: min(62vh, 600px); display: grid; place-items: center; }
.preview__main { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; display: block; }
.preview__nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 2.75rem; height: 2.75rem; border-radius: 50%;
  border: 0; cursor: pointer; background: rgb(0 0 0 / 0.55); color: #fff; font-size: 2rem; line-height: 1;
}
.preview__nav--prev { left: var(--space-3); }
.preview__nav--next { right: var(--space-3); }
.preview__counter { position: absolute; bottom: var(--space-2); right: var(--space-3); color: #fff; font-size: 0.85rem; background: rgb(0 0 0 / 0.55); padding: 0.1rem 0.5rem; border-radius: 999px; }
.preview--single .preview__nav, .preview--single .preview__thumbs { display: none; }
.preview__thumbs { display: flex; gap: var(--space-2); overflow-x: auto; padding: var(--space-2) var(--space-3); background: var(--surface-2); scrollbar-width: thin; }
.preview__thumbs img { width: 84px; height: 63px; object-fit: cover; border-radius: var(--radius-sm); cursor: pointer; opacity: 0.6; flex: 0 0 auto; border: 2px solid transparent; }
.preview__thumbs img.is-active, .preview__thumbs img:hover { opacity: 1; border-color: var(--accent); }
.preview__body { padding: var(--space-5); }
.preview__head { display: flex; justify-content: space-between; gap: var(--space-4); align-items: flex-start; flex-wrap: wrap; margin-bottom: var(--space-4); }
.preview__title { font-family: var(--font-body); font-weight: 600; font-size: 1.25rem; line-height: 1.3; margin: 0 0 var(--space-1); }
.preview__price { text-align: right; }
.preview__now { font-family: var(--font-display); font-weight: 700; font-size: 2rem; line-height: 1; display: block; }
.badge--inline { position: static; display: inline-block; margin-top: var(--space-2); }
.preview__cols { display: grid; grid-template-columns: 1fr; gap: var(--space-5); }
@media (min-width: 48rem) { .preview__cols { grid-template-columns: 1.4fr 1fr; } }
.preview__cols h3 { font-size: 1.1rem; margin: 0 0 var(--space-2); }
.preview__cols aside h3 { margin-top: var(--space-3); }
.preview__cols aside h3:first-child { margin-top: 0; }
.preview__text { font: inherit; font-size: 0.95rem; white-space: pre-wrap; word-break: break-word; margin: 0; background: none; padding: 0; }
.history { list-style: none; margin: 0; padding: 0; font-size: 0.9rem; }
.history li { padding: 0.2rem 0; border-top: 1px solid var(--border); }
.history li:first-child { border-top: 0; }
#preview-open { margin-top: var(--space-4); }

/* Main nav */
.nav { display: flex; gap: var(--space-1); flex: 1; margin-left: var(--space-4); flex-wrap: wrap; }
.nav__link { padding: 0.35rem 0.75rem; border-radius: var(--radius-md); color: var(--text-muted); text-decoration: none; font-weight: 600; font-size: 0.95rem; }
.nav__link:hover { color: var(--text); background: var(--surface-2); }
.nav__link--active { color: var(--text); background: var(--surface-2); }
@media (max-width: 40rem) { .topbar { flex-wrap: wrap; } .nav { order: 3; width: 100%; margin: var(--space-2) 0 0; } }

/* Forms: extra controls */
textarea, select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md); padding: 0.6rem 0.75rem;
}
textarea { resize: vertical; }
input[type="datetime-local"] { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-md); padding: 0.55rem 0.75rem; }
.row { display: grid; grid-template-columns: 1fr; gap: 0 var(--space-4); }
@media (min-width: 36rem) { .row { grid-template-columns: 2fr 1fr; } }
.danger-zone { margin-top: var(--space-5); padding-top: var(--space-4); border-top: 1px solid var(--border); }

/* Templates */
.tpl__head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-3); flex-wrap: wrap; }
.tpl__head h2 { margin: 0; }
.tpl__head form { display: inline; }
.tpl__body { font: inherit; font-size: 0.95rem; white-space: pre-wrap; margin: var(--space-3) 0 0; background: var(--surface-2); padding: var(--space-3); border-radius: var(--radius-md); }
.compose { display: grid; gap: var(--space-2); margin-bottom: var(--space-3); }
.compose textarea { font-size: 0.9rem; }

/* Calendar */
.cal-layout { display: grid; grid-template-columns: 1fr; gap: var(--space-5); align-items: start; }
@media (min-width: 64rem) { .cal-layout { grid-template-columns: 1fr 20rem; } }
.cal-card { padding: var(--space-3); }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.cal__dow { text-align: center; font-family: var(--font-display); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.8rem; color: var(--text-muted); padding: var(--space-1) 0 var(--space-2); }
.cal__cell { min-height: 6.5rem; background: var(--surface-2); border-radius: var(--radius-sm); padding: var(--space-1); display: flex; flex-direction: column; gap: 2px; }
.cal__cell--empty { background: transparent; }
.cal__cell--past { opacity: 0.7; }
.cal__cell--today { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal__day { align-self: flex-end; font-weight: 600; font-size: 0.85rem; color: var(--text-muted); text-decoration: none; width: 1.6rem; height: 1.6rem; display: grid; place-items: center; border-radius: 50%; }
.cal__day:hover { background: var(--accent); color: var(--accent-text); }
.cal__cell--today .cal__day { background: var(--accent); color: var(--accent-text); }
.cal__item {
  display: block; font-size: 0.78rem; line-height: 1.25; text-decoration: none; color: var(--text);
  background: var(--surface); border-left: 3px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 0.15rem 0.35rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cal__item--viewing { border-left-color: var(--accent); }
.cal__item:hover { background: var(--bg); }
.cal__time { font-weight: 600; color: var(--text-muted); }
@media (max-width: 40rem) { .cal__cell { min-height: 4rem; } .cal__item { font-size: 0.65rem; } }

.agenda { list-style: none; margin: 0; padding: 0; }
.agenda__item { display: grid; grid-template-columns: 64px 1fr; gap: var(--space-3); padding: var(--space-3) 0; border-top: 1px solid var(--border); align-items: start; }
.agenda__item:first-child { border-top: 0; padding-top: 0; }
.agenda__img { width: 64px; height: 48px; object-fit: cover; border-radius: var(--radius-sm); background: var(--surface-2); display: block; }
.agenda__title { color: var(--text); font-weight: 600; text-decoration: none; display: block; }
.agenda__title:hover { text-decoration: underline; }
.linked { display: flex; gap: var(--space-4); align-items: center; margin-bottom: var(--space-4); }
.linked__img { width: 120px; height: 90px; object-fit: cover; border-radius: var(--radius-md); }

.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }
.mt { margin-top: var(--space-4); display: inline-block; }
