/* Планер переезда.
   Идея оформления: комната — это коробка для переезда, название комнаты —
   полоска упаковочного скотча, бюджет — полоса-рулетка с делениями.
   Всё остальное спокойное, чтобы не мешать цифрам. */

:root {
  --wall: #e8ecef;       /* фон — свежие стены новой квартиры */
  --card: #ffffff;
  --ink: #1c232b;
  --muted: #66717d;
  --line: #d2d8de;
  --tape: #f2c230;       /* упаковочный скотч */
  --tape-ink: #3b2f00;
  --accent: #1f5f8b;     /* кнопки, фокус, план */
  --accent-ink: #ffffff;
  --accent-soft: #93bcd9;
  --ok: #2e7d4f;
  --warn-ink: #8a5a00;
  --bad: #c0392b;

  --display: 'Unbounded', 'Arial Black', sans-serif;
  --body: 'Golos Text', 'Segoe UI', Roboto, Arial, sans-serif;

  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --wall: #14181d;
    --card: #1d232a;
    --ink: #e5e9ed;
    --muted: #97a2ae;
    --line: #2f3841;
    --tape: #ddb02a;
    --tape-ink: #2b2200;
    --accent: #5ea3d6;
    --accent-ink: #0d1a24;
    --accent-soft: #2f5f80;
    --ok: #5cc28a;
    --warn-ink: #e3b341;
    --bad: #ef6a5a;
    color-scheme: dark;
  }
}

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

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--wall);
  color: var(--ink);
  font: 400 16px/1.45 var(--body);
  -webkit-font-smoothing: antialiased;
}

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

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Скотч ---------- */

.tape {
  display: inline-block;
  margin: 0;
  padding: 0.4em 1.1em 0.35em;
  border: 0;
  background-color: var(--tape);
  /* лёгкая продольная фактура плёнки */
  background-image: repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.14) 0 2px, transparent 2px 6px);
  color: var(--tape-ink);
  font: 800 1rem/1.15 var(--display);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  transform: rotate(-1.2deg);
  /* рваные края, как у оторванного куска */
  clip-path: polygon(
    6px 0, calc(100% - 6px) 0, 100% 25%, calc(100% - 5px) 50%, 100% 75%, calc(100% - 6px) 100%,
    6px 100%, 0 75%, 5px 50%, 0 25%
  );
  overflow-wrap: anywhere;
  text-align: left;
}

.tape--small { font-size: 0.85rem; }

/* ---------- Кнопки и поля ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.55em 1.1em;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: none;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.6; cursor: default; }

.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn--ghost { border-color: var(--line); color: var(--ink); }
.btn--ghost:hover { background: var(--wall); }

.btn--danger { border-color: var(--line); color: var(--bad); }
.btn--danger:hover { border-color: var(--bad); }

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 500;
  text-decoration: underline;
  cursor: pointer;
}

.icon-btn {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover:not(:disabled) { color: var(--ink); border-color: var(--muted); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }

.field { display: grid; gap: 6px; min-width: 0; margin: 0; padding: 0; border: 0; }
.field__label { padding: 0; font-size: 0.85rem; color: var(--muted); font-weight: 500; }
.field__hint { margin: 0; font-size: 0.8rem; color: var(--muted); }

.input {
  width: 100%;
  min-height: 44px;
  padding: 0.5em 0.75em;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}
.input::placeholder { color: var(--muted); opacity: 0.8; }
textarea.input { resize: vertical; }

.row { display: flex; align-items: flex-end; gap: 8px; }
.row > .input { flex: 1; min-width: 0; }
.row__grow { flex: 1; }
.row__qty { width: 110px; }
.row__dash { align-self: center; color: var(--muted); }

/* Переключатель из нескольких вариантов (радиокнопки в виде кнопок) */
.seg {
  display: flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.seg label { flex: 1; position: relative; }
.seg label + label { border-left: 1px solid var(--line); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.4em 0.6em;
  text-align: center;
  font-weight: 500;
  font-size: 0.92rem;
  line-height: 1.2;
  cursor: pointer;
}
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: -3px; }

/* ---------- Вход ---------- */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.login__box {
  width: 100%;
  max-width: 380px;
  display: grid;
  gap: 16px;
  padding: 0 24px 24px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.login__tape {
  justify-self: center;
  margin-top: -18px;
  font-size: 1.5rem;
}

.login__text { margin: 0; color: var(--muted); text-align: center; }
.login__error { margin: 0; min-height: 1.45em; color: var(--bad); font-weight: 500; }

/* ---------- Шапка и страница ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 880px;
  margin: 0 auto;
  padding: 16px;
}

.top__brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.top__sub { color: var(--muted); font-size: 0.9rem; }

.page {
  max-width: 880px;
  margin: 0 auto;
  padding: 8px 16px 48px;
}

.page__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 40px 0 12px;
}

.page__title {
  margin: 0;
  font: 600 1.6rem/1.2 var(--display);
  letter-spacing: -0.01em;
}

.page__summary {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Бюджет ---------- */

.budget {
  display: grid;
  gap: 18px;
  padding: 20px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.budget__verdict {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 16px;
}

.budget__title {
  margin: 0;
  font: 600 clamp(1.5rem, 5vw, 2.2rem)/1.1 var(--display);
  letter-spacing: -0.02em;
}
.budget--ok .budget__title { color: var(--ok); }
.budget--warn .budget__title { color: var(--warn-ink); }
.budget--bad .budget__title { color: var(--bad); }

.budget__text { margin: 6px 0 0; max-width: 52ch; }
.budget__warn { margin: 0; color: var(--warn-ink); font-weight: 500; }

/* Полоса-рулетка */
.meter {
  position: relative;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--wall);
  overflow: hidden;
}
.meter::after {
  /* деления, как на рулетке: каждые 10% */
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 8px;
  background: repeating-linear-gradient(90deg, var(--muted) 0 1px, transparent 1px 10%);
  opacity: 0.45;
  pointer-events: none;
}
.meter__part { position: absolute; top: 0; bottom: 0; left: 0; }
.meter__reserve { background: repeating-linear-gradient(45deg, var(--line) 0 3px, transparent 3px 7px); }
.meter__range { background: repeating-linear-gradient(-45deg, var(--accent-soft) 0 5px, transparent 5px 9px); }
.meter__plan { background: var(--accent); }
.meter__spent { background: var(--ink); }
.meter__line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  margin-left: -1.5px;
  background: var(--bad);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.8rem;
  color: var(--muted);
}
.legend i {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  border-radius: 2px;
  vertical-align: -1px;
}
.legend__spent { background: var(--ink); }
.legend__plan { background: var(--accent); }
.legend__range { background: repeating-linear-gradient(-45deg, var(--accent-soft) 0 3px, transparent 3px 5px); box-shadow: inset 0 0 0 1px var(--accent-soft); }
.legend__reserve { background: repeating-linear-gradient(45deg, var(--muted) 0 2px, transparent 2px 4px); }
.legend .legend__line { width: 3px; background: var(--bad); }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px 20px;
  margin: 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.stat dt { font-size: 0.8rem; color: var(--muted); }
.stat dd {
  margin: 2px 0 0;
  font-weight: 600;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- Поиск и фильтры ---------- */

.toolbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 28px;
}
.toolbar__search { grid-column: 1 / -1; }

/* ---------- Комнаты-коробки ---------- */

.rooms { display: grid; gap: 32px; }

.room {
  padding: 0 16px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.room__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.room__title { margin: -14px 0 0; min-width: 0; font-size: 1rem; }
.room__tape { cursor: pointer; max-width: 100%; }
.room__chevron { margin-left: 0.5em; font-size: 0.8em; }

.room__tools {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  padding-top: 10px;
}

.room__sum {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}

.room__add { margin-top: 12px; }
.room--closed { padding-bottom: 14px; }

.rooms__empty {
  margin: 0;
  padding: 24px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.rename {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  padding-top: 12px;
}
.rename .input { flex: 1 1 200px; }

/* ---------- Товары ---------- */

.items { margin: 12px 0 0; padding: 0; list-style: none; }

.item {
  padding: 12px 0;
  border-top: 1px solid var(--line);
  cursor: pointer;
}

.item__top { display: flex; align-items: baseline; gap: 10px; }

.status {
  flex-shrink: 0;
  min-width: 76px;
  padding: 1px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
}
.status--chosen { border-color: var(--accent); color: var(--accent); }
.status--bought { border-color: var(--ok); background: var(--ok); color: var(--card); }

.item__name {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  font-weight: 600;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
}
.item__name:hover { text-decoration: underline; }
.item__qty { color: var(--muted); font-weight: 500; }
.item--later .item__name { font-weight: 500; }
.item--bought .item__name { color: var(--muted); }

.item__price {
  white-space: nowrap;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.item__price--unknown { color: var(--warn-ink); }

.item__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  margin-top: 6px;
  padding-left: 86px;
  color: var(--muted);
  font-size: 0.88rem;
}

.tag { font-weight: 500; }
.tag--over { color: var(--bad); font-weight: 600; }

.chip {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}
.chip:hover { border-bottom-style: solid; }

.item__note {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-style: italic;
}

/* ---------- Добавить комнату, данные ---------- */

.add-room {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}
.add-room__field { flex: 1 1 240px; }

.data {
  display: grid;
  gap: 10px;
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}
.data__title { margin: 0; font: 600 1.1rem/1.2 var(--display); }
.data__text { margin: 0; color: var(--muted); }
.data__actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Окна ---------- */

.dialog {
  width: min(580px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.dialog::backdrop { background: rgba(20, 24, 29, 0.55); }

.dialog__form {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 26px);
}

.dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 8px;
}
.dialog__title { margin: 0; font: 600 1.15rem/1.2 var(--display); }

.dialog__body {
  display: grid;
  gap: 18px;
  padding: 8px 16px 16px;
  overflow-y: auto;
}

.dialog__msg { margin: 0; padding: 0 16px 8px; color: var(--bad); font-weight: 500; }
.dialog__msg:empty { display: none; }

.dialog__foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}
.spacer { flex: 1; }

.links { display: grid; gap: 8px; }
.links:empty { display: none; }
.links__actions { display: flex; flex-wrap: wrap; gap: 8px; }

.link-row {
  display: grid;
  grid-template-columns: 1fr 120px 40px;
  grid-template-areas:
    'label price remove'
    'url   url   url';
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.link-row__label { grid-area: label; }
.link-row__price { grid-area: price; }
.link-row__url { grid-area: url; }
.link-row__remove { grid-area: remove; align-self: center; }

/* ---------- Уведомление ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--wall);
  font-weight: 500;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
}

/* ---------- Проверка сервера (check.php) ---------- */

.check { padding-top: 32px; }
.check__verdict { font-weight: 600; font-size: 1.1rem; }
.check__verdict--ok { color: var(--ok); }
.check__verdict--bad { color: var(--bad); }
.check__list { display: grid; gap: 10px; margin: 16px 0; padding: 0; list-style: none; }
.check__item {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.check__mark { font-weight: 800; }
.check__item--ok .check__mark { color: var(--ok); }
.check__item--bad .check__mark { color: var(--bad); }
.check__hint { margin: 4px 0 0; color: var(--muted); }
.check__foot { color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }

/* ---------- Узкие экраны ---------- */

@media (max-width: 720px) {
  .stats { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 520px) {
  .top__sub { display: none; }
  .budget { padding: 16px; }
  /* на телефоне кнопки комнаты всегда отдельной строкой под скотчем — одинаково у всех */
  .room__head { flex-direction: column; align-items: stretch; }
  .room__title { align-self: flex-start; max-width: 100%; }
  .room__tools { justify-content: flex-end; padding-top: 4px; }
  .item__meta { padding-left: 0; }
  .item__top { flex-wrap: wrap; }
  .item__name { flex-basis: calc(100% - 90px); }
  .item__price { margin-left: 86px; }
  .toolbar { grid-template-columns: 1fr; }
  .link-row { grid-template-columns: 1fr 100px 40px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
