/* Design system for the trailer rental app.
 *
 * Loaded unconditionally. Tailwind utilities (compiled bundle or Play CDN)
 * handle layout; everything with a name here is a stable component the
 * templates rely on, so the UI keeps its look even without the CSS build.
 */

:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #e4e7ec;
  --text: #101828;
  --muted: #667085;
  --brand: #1d4ed8;
  --brand-weak: #eff4ff;
  --success: #067647;
  --success-weak: #ecfdf3;
  --info: #175cd3;
  --info-weak: #eff8ff;
  --warn: #b54708;
  --warn-weak: #fffaeb;
  --danger: #b42318;
  --danger-weak: #fef3f2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
}

* { box-sizing: border-box; }

html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body { touch-action: manipulation; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 6px;
}

[x-cloak] { display: none !important; }

/* ── shell ─────────────────────────────────────────────────────────────── */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  display: none;
  width: 248px;
  flex: 0 0 248px;
  padding: 22px 16px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 20px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, #1d4ed8, #0ea5e9);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 15px;
}
.brand-text { font-weight: 650; line-height: 1.15; }
.brand-text small { display: block; color: var(--muted); font-weight: 500; font-size: 11px; }

.nav-list { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px;
  color: #344054; font-weight: 500;
}
.nav-link:hover { background: #f2f4f7; text-decoration: none; }
.nav-link.is-active { background: var(--brand-weak); color: var(--brand); font-weight: 600; }
.nav-link svg { width: 18px; height: 18px; flex: none; }

.sidebar-footer { margin-top: auto; padding-top: 18px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20; backdrop-filter: blur(6px);
}
/* Back, title and page actions share one line on every screen size. The title
   truncates instead of pushing the row to a second line. */
.topbar > .inline-row { flex: 1 1 auto; min-width: 0; flex-wrap: nowrap; }
.topbar h1 {
  font-size: 1.15rem; flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-meta { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; flex: 0 0 auto; }
.topbar .back-btn {
  width: 38px; height: 38px; min-height: 38px; padding: 0; flex: none;
  border-radius: 10px; font-size: 20px; line-height: 1;
}
@media (max-width: 767px) {
  /* Comfortable touch target for the back arrow. */
  .topbar .back-btn { width: 44px; height: 44px; min-height: 44px; font-size: 22px; }
}

.content { padding: 16px 16px 88px; width: 100%; max-width: 1240px; margin: 0 auto; }

.bottom-nav {
  position: fixed; inset: auto 0 0 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--panel); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 2px; font-size: 11px; color: var(--muted); border-radius: 10px;
}
.bottom-nav a svg { width: 20px; height: 20px; }
.bottom-nav a.is-active { color: var(--brand); background: var(--brand-weak); }
.bottom-nav a:hover { text-decoration: none; }

@media (min-width: 1024px) {
  .sidebar { display: flex; flex-direction: column; }
  .content { padding: 24px 28px 64px; }
  .bottom-nav { display: none; }
  .topbar { padding: 16px 28px; }
}

/* ── surfaces ──────────────────────────────────────────────────────────── */

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.card-header h2 { font-size: 1rem; }
@media (max-width: 767px) {
  .rental-detail-head { flex-wrap: wrap; }
  .rental-actions { width: 100%; flex-wrap: nowrap; }
  .rental-actions .btn { flex: 1 1 0; }
}
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }
.card + .card { margin-top: 16px; }
/* Grid/flex gaps already space these cards; the sibling margin would offset every
   second tile and make its height smaller than the row. */
.grid > .card + .card { margin-top: 0; }

.grid { display: grid; gap: 16px; }
.grid-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-two { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) {
  .grid-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid-two { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
  /* Две равные плитки (расходы и прибыль) — не 3:2, как график с боковой колонкой. */
  .grid-expenses { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* Три итоговые плитки расходов занимают всю ширину, а не 3/4 строки. */
  .grid-expenses-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* «Ещё»: плитки-ссылки в две колонки, кнопки «Открыть» больше не нужны. */
.more-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.more-tile { display: block; color: inherit; transition: border-color .15s, box-shadow .15s; }
.more-tile .card-body { padding: 12px 14px; }
.more-tile:hover { border-color: #b9c6ff; box-shadow: 0 4px 12px rgba(16, 24, 40, .08); }
.more-tile:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
@media (max-width: 599px) {
  .more-grid { grid-template-columns: minmax(0, 1fr); }
}

.stat { padding: 14px 16px; display: flex; flex-direction: column; }
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.stat-value { font-size: 1.5rem; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-value.small { font-size: 1.15rem; }
.stat-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
/* Equal slots keep every dashboard tile the same height: two label lines, one
   value line, two hint lines. Without this, long labels and hints made some
   cards taller even inside one row. 36px = two 18px line boxes at 12px. */
.stat .stat-label,
.stat .stat-hint { min-height: 36px; }
.stat .stat-value {
  min-height: 32px; line-height: 1.2;
  display: flex; align-items: center;
}
.stat-value.is-success { color: var(--success); }
.stat-value.is-danger { color: var(--danger); }
.stat-value.is-warn { color: var(--warn); }

/* ── controls ──────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 38px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); color: #344054;
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease, transform 60ms ease;
}
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: #1a43c0; }
.btn-danger { background: var(--danger-weak); border-color: #fecdca; color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 550; color: #344054; }
.field-input {
  width: 100%; min-height: 42px; padding: 9px 12px;
  border: 1px solid #d0d5dd; border-radius: 10px; background: #fff;
  font: inherit; color: var(--text);
}
.field-input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12); }
.field-input.is-invalid { border-color: #f04438; }
textarea.field-input { min-height: 72px; resize: vertical; }
.field-hint { font-size: 12px; color: var(--muted); }
.field-error { font-size: 12px; color: var(--danger); }
.field-row { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .field-row.two { grid-template-columns: 1fr 1fr; } }

.field-checkbox { width: 18px; height: 18px; accent-color: var(--brand); }

/* ── badges, tabs, tables ──────────────────────────────────────────────── */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: #f2f4f7; color: #344054; white-space: nowrap;
}
.badge-success { background: var(--success-weak); color: var(--success); }
.badge-info { background: var(--info-weak); color: var(--info); }
.badge-warn { background: var(--warn-weak); color: var(--warn); }
.badge-danger { background: var(--danger-weak); color: var(--danger); }
.badge-muted { background: #f2f4f7; color: #475467; }

/* A small colour marker for trailers: the list, rentals and the form use it. */
.color-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 6px; vertical-align: middle; flex: none;
  box-shadow: inset 0 0 0 1px rgba(16, 24, 40, 0.18);
}
.color-dot[hidden] { display: none; }
.color-input { padding: 4px; cursor: pointer; }
.color-input::-webkit-color-swatch-wrapper { padding: 0; }
.color-input::-webkit-color-swatch { border: 0; border-radius: 6px; }

/* Payback bar in the trailers table: revenue divided by the purchase price. */
.payback { display: flex; flex-direction: column; gap: 5px; min-width: 150px; }
.payback-bar { height: 6px; background: #eaecf0; border-radius: 999px; overflow: hidden; }
.payback-fill { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.payback-fill.is-complete { background: var(--success); }
.payback-caption { font-size: 11px; white-space: nowrap; }

/* Утро / вечер под датами аренды. */
.slot-toggle { margin-top: 6px; }
.slot-toggle > div { display: flex; gap: 4px; padding: 3px; background: #f2f4f7; border-radius: 10px; }
.slot-toggle > div > div { flex: 1; display: flex; }
.slot-toggle label {
  position: relative; flex: 1; text-align: center; cursor: pointer;
  padding: 6px 10px; border-radius: 8px; font-size: 13px; color: #475467;
  transition: background .15s, color .15s, box-shadow .15s;
}
.slot-toggle label:has(input:checked) {
  background: #fff; color: var(--brand); font-weight: 600;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.12);
}
.slot-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.slot-toggle label:has(input:focus-visible) { outline: 2px solid var(--brand); outline-offset: 1px; }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 4px; background: #f2f4f7; border-radius: 12px; }
.tab {
  padding: 7px 12px; border-radius: 9px; font-size: 13px; font-weight: 550;
  color: #475467; white-space: nowrap;
}
.tab:hover { background: #fff; text-decoration: none; }
.tab.is-active { background: #fff; color: var(--brand); box-shadow: var(--shadow); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--muted); font-weight: 600; padding: 10px 12px;
  border-bottom: 1px solid var(--line); white-space: nowrap; background: #fcfcfd;
}
.table td { padding: 12px; border-bottom: 1px solid #f2f4f7; vertical-align: middle; }
.table tbody tr:hover { background: #fcfcfd; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .actions { text-align: right; white-space: nowrap; }
.table a.row-link { font-weight: 600; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.inline-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.spacer { flex: 1; }

.empty-state { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty-state strong { display: block; color: var(--text); margin-bottom: 4px; }

/* ── messages & dialogs ────────────────────────────────────────────────── */

.messages { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.message { padding: 10px 14px; border-radius: 10px; font-size: 14px; border: 1px solid transparent; }
.message.success { background: var(--success-weak); color: var(--success); border-color: #abefc6; }
.message.error { background: var(--danger-weak); color: var(--danger); border-color: #fecdca; }
.message.warning { background: var(--warn-weak); color: var(--warn); border-color: #fedf89; }
.message.info { background: var(--info-weak); color: var(--info); border-color: #b2ddff; }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 60; background: rgba(16, 24, 40, 0.45);
  display: grid; place-items: center; padding: 16px;
}
.modal {
  width: min(560px, 100%); max-height: 90vh; overflow: auto;
  background: var(--panel); border-radius: 16px; box-shadow: 0 20px 40px rgba(16, 24, 40, 0.2);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 16px; }

/* ── rental calc & calendar ────────────────────────────────────────────── */

.calc-card { background: var(--brand-weak); border: 1px solid #d1e0ff; border-radius: var(--radius); padding: 14px 16px; }
.calc-total { font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.calc-line { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: #344054; }
.calc-conflict { background: var(--danger-weak); border-color: #fecdca; color: var(--danger); }

.calendar { --dot: 9px; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.calendar-wide { max-width: 760px; margin: 0 auto; }
.calendar-header { flex-wrap: wrap; }
.calendar-nav { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }
.calendar-current { margin-left: auto; }
@media (max-width: 767px) {
  .calendar-nav { width: 100%; justify-content: space-between; }
}
.calendar-head { font-size: 11px; text-transform: uppercase; color: var(--muted); text-align: center; padding: 4px 0; }
.calendar-day {
  aspect-ratio: 1 / 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 2px; border-radius: 8px; min-width: 0; overflow: hidden;
  font-size: 13px; background: #fff; border: 1px solid #f2f4f7;
}
.calendar-day-number { font-size: 13px; line-height: 1; }
.calendar-day.is-outside { color: #98a2b3; background: transparent; border-color: transparent; }
.calendar-day.is-busy { background: #fee4e2; color: var(--danger); border-color: #fecdca; font-weight: 600; }
.calendar-day.has-entries { background: #f9fafb; border-color: #e4e7ec; }
.calendar-day.is-today { outline: 2px solid var(--brand); }
.calendar-day.is-selected { background: var(--brand); color: #fff; }
.calendar-dots { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; max-width: 100%; min-width: 0; }
.calendar-dot {
  width: var(--dot); height: var(--dot); border-radius: 50%; display: inline-block;
  box-shadow: inset 0 0 0 1px rgba(16, 24, 40, 0.15);
}
/* A lone half takes half a dot: flat on the open side, no empty half. */
.calendar-dots > .calendar-dot.is-half-left {
  width: calc(var(--dot) / 2); height: var(--dot);
  border-radius: calc(var(--dot) / 2) 0 0 calc(var(--dot) / 2);
}
.calendar-dots > .calendar-dot.is-half-right {
  width: calc(var(--dot) / 2); height: var(--dot);
  border-radius: 0 calc(var(--dot) / 2) calc(var(--dot) / 2) 0;
}
/* Half dots keep the ring on their contour. */
.calendar-dot.is-half-left,
.calendar-dot.is-half-right { box-shadow: inset 0 0 0 1px rgba(16, 24, 40, 0.35); }
@media (max-width: 767px) {
  .calendar { --dot: 8px; }
}
.calendar-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 16px; }
.calendar-legend-item { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--text); }
.calendar-legend-item:hover { color: var(--brand); text-decoration: none; }
.calendar-legend-item .color-dot { margin-right: 0; }
.calendar-legend-note { margin-bottom: 0; }

@media (min-width: 768px) {
  .calendar-wide { --dot: 10px; }
  .calendar-wide .calendar-head { font-size: 12px; }
  .calendar-wide .calendar-day { gap: 5px; }
  .calendar-wide .calendar-day-number { font-size: 20px; font-weight: 500; }
}

/* ── free trailers card (calendar sidebar) ─────────────────────────────── */

.calendar-layout { display: grid; gap: 16px; }
.calendar-side { min-width: 0; }
/* The month keeps its own 760 px rhythm inside `.calendar-wide`; the grid
   column only gets narrower, so the calendar stays centred in its card. */
@media (min-width: 1100px) {
  .calendar-layout { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
  .calendar-side { position: sticky; top: 16px; }
}

.free-trailers-form { display: flex; flex-direction: column; gap: 10px; }
.free-trailers-fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.free-trailers-fields .field { gap: 4px; }
.free-trailers-fields .field-input { padding: 8px 10px; }
/* Two slot toggles share one 360 px card: tighter than the rental form. */
.free-trailers-card .slot-toggle { margin-top: 0; }
.free-trailers-card .slot-toggle > div { gap: 3px; padding: 2px; }
.free-trailers-card .slot-toggle label { padding: 5px 6px; font-size: 12px; }
.free-slots-hint { margin: 0; }
.free-trailers-results { margin-top: 14px; transition: opacity .15s; }
.free-trailers-results.htmx-request { opacity: .45; }
.free-slot-error { margin: 0 0 10px; }

.free-summary {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; flex-wrap: wrap; margin-bottom: 10px;
}

.free-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.free-item {
  display: flex; flex-direction: column; gap: 6px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel);
}
/* Name and price share one line; a long name wraps instead of moving the price. */
.free-item-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.free-item-title {
  display: flex; align-items: center; flex-wrap: wrap; gap: 2px 6px;
  min-width: 0; line-height: 1.35;
}
.free-item-title .color-dot { margin-right: 0; }
.free-item-name { font-weight: 600; overflow-wrap: anywhere; }
.free-item-title .small { overflow-wrap: anywhere; }
.free-item-price {
  display: flex; flex-direction: column; align-items: flex-end;
  text-align: right; flex: none; line-height: 1.25;
}
.free-item-price strong { font-variant-numeric: tabular-nums; white-space: nowrap; }
.free-item-notes { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.free-note { max-width: 100%; font-size: 12px; line-height: 1.35; color: var(--warn); }
/* A handover that cannot happen in time: danger colour on a weak red pill. */
.free-note.is-late {
  padding: 2px 6px; border-radius: 6px;
  color: var(--danger); background: var(--danger-weak);
}
.free-item-foot { display: flex; justify-content: flex-end; }

/* Handover hints stay small; the busy list is collapsed until asked for. */
.free-busy { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.free-busy > summary {
  display: flex; align-items: center; gap: 6px;
  cursor: pointer; color: var(--muted); font-size: 13px; font-weight: 550;
  list-style: none;
}
.free-busy > summary::-webkit-details-marker { display: none; }
.free-busy > summary::before {
  content: ""; width: 6px; height: 6px; flex: none; margin-left: 2px;
  border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 140ms ease;
}
.free-busy[open] > summary::before { transform: rotate(45deg); }
.free-busy-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.free-busy-item {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px;
}
.free-busy-head { display: flex; align-items: center; flex-wrap: wrap; gap: 2px 6px; font-size: 13px; line-height: 1.35; }
.free-busy-head .color-dot { margin-right: 0; }
.free-busy-head .small, .free-busy-rental { overflow-wrap: anywhere; }

.free-empty { padding: 24px 8px; }
.free-repair { margin: 10px 0 0; font-size: 12px; }

@media (max-width: 767px) {
  .calendar-layout { gap: 12px; }
  .free-trailers-results { margin-top: 12px; }
  /* Two fixed rows per trailer: title + plate, then price + days. */
  .free-item-head {
    flex-direction: column;
    align-items: flex-start;
    flex-wrap: nowrap;
    gap: 2px;
  }
  /* Inline flow keeps the dot next to the name and lets a long name wrap. */
  .free-item-title { display: block; width: 100%; line-height: 1.35; }
  .free-item-title .color-dot { margin-right: 6px; }
  .free-item-title .small { margin-left: 4px; }
  .free-item-price { flex-direction: row; align-items: baseline; gap: 6px; }
  .free-item-foot .btn { flex: 1; }
}

/* ── comparison table (План / Факт / Разница) ──────────────────────────── */

/* Четыре колонки не влезают в 375 px, поэтому на узком экране каждая строка
   превращается в блок: подпись сверху, три значения с подписями под ней. */
.compare { display: grid; font-size: 14px; }
.compare-head { display: none; }
.compare-row {
  display: grid;
  gap: 6px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(16, 24, 40, 0.08);
}
.compare-row:last-child { border-bottom: 0; }
.compare-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}
.compare-values { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.compare-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.compare-cap {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.compare-sub { font-size: 11px; color: var(--muted); }
.compare-cell.is-total { font-weight: 700; }
.compare-cell.is-success { color: var(--success); }
.compare-cell.is-danger { color: var(--danger); }

@media (min-width: 560px) {
  .compare-head,
  .compare-row {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) repeat(3, minmax(0, 1fr));
    gap: 10px;
    align-items: center;
  }
  .compare-head {
    padding: 0 0 8px;
    border-bottom: 1px solid var(--line);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
  }
  .compare-head span:not(:first-child) { text-align: right; }
  .compare-row { padding: 10px 0; gap: 10px; }
  .compare-label { font-size: 14px; text-transform: none; letter-spacing: 0; color: var(--text); }
  .compare-values { display: contents; }
  .compare-cell { align-items: flex-end; text-align: right; }
  .compare-cap { display: none; }
}

/* ── chart ─────────────────────────────────────────────────────────────── */

.chart { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding-top: 8px; }
.chart-bar { flex: 1; min-width: 4px; background: #b2ccff; border-radius: 4px 4px 0 0; position: relative; }
.chart-bar:hover { background: var(--brand); }
.chart-bar span { position: absolute; bottom: -22px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--muted); }
.chart-caption { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 26px; }

/* ── tariff comparison chart ───────────────────────────────────────────── */
.tariff-controls { justify-content: space-between; flex-wrap: wrap; gap: 8px 12px; margin-bottom: 8px; }
.tariff-chart { display: block; width: 100%; max-width: 900px; height: auto; }
.tariff-chart text { fill: var(--muted); font-size: 11px; }
.tariff-chart .tariff-grid-line { stroke: #eaecf0; stroke-width: 1; }
.tariff-chart .tariff-axis-line { stroke: #d0d5dd; stroke-width: 1; }
.tariff-legend { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-top: 6px; }
.tariff-legend-item { display: inline-flex; align-items: flex-start; gap: 7px; font-size: 13px; color: var(--text); }
.tariff-swatch { width: 18px; height: 4px; border-radius: 2px; display: inline-block; margin-top: 7px; flex: none; }

@media (max-width: 767px) {
  .tariff-chart text { font-size: 18px; }
}

@media (max-width: 767px) {
  /* 31 подпись в узкой карточке сливается: на телефоне показываем каждый второй день. */
  .chart-bar:nth-child(odd) span { display: none; }
  .chart-bar span { font-size: 9px; }
}

/* ── auth ──────────────────────────────────────────────────────────────── */

.auth-main { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(420px, 100%); }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }

/* Mobile list cards */
.rental-cards { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.rental-card { padding: 14px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; min-width: 0; }
.rental-card-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.rental-card-head > div { min-width: 0; }
.rental-card-title { font-weight: 650; }
.rental-card-meta { display: flex; gap: 10px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.rental-card-dates { white-space: nowrap; }

/* ── profit distribution ───────────────────────────────────────────────── */
.profit-card .card-header { align-items: flex-start; }
.profit-totals { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; margin-bottom: 12px; }
.profit-totals > div:last-child { text-align: right; }
.profit-totals .field-label { font-size: 12px; }
.profit-totals strong { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.profit-transfer {
  text-align: center; padding: 14px; border-radius: 12px; background: #f8fafc;
}
.profit-transfer-amount {
  font-size: 2rem; font-weight: 750; line-height: 1.1;
  color: var(--brand); font-variant-numeric: tabular-nums;
}
.profit-transfer-amount.is-zero, .profit-transfer.is-zero .profit-transfer-amount { color: var(--muted); }
.profit-transfer-route { margin-top: 5px; font-size: 1.05rem; font-weight: 650; }
.profit-transfer.is-zero .profit-transfer-route { color: var(--success); }
/* Расходы в распределении: мельче полученных сумм, приглушённые. */
.profit-expenses { margin-top: 8px; margin-bottom: 0; }
.profit-expenses .field-label { font-size: 11px; color: var(--muted); }
.profit-expenses strong { font-size: 1rem; font-weight: 600; color: var(--muted); }
/* Net-остатки «на руках»: главнее расходов, поэтому крупнее и с чертой сверху. */
.profit-net {
  margin-top: 10px; margin-bottom: 12px; padding-top: 10px;
  border-top: 1px solid var(--line);
}
.profit-net .field-label { font-size: 12px; }
.profit-net strong { font-size: 1.35rem; }
/* Маленькая ссылка-действие внутри плитки статистики. */
.stat-link {
  margin-top: 6px; font-size: 12px; font-weight: 600;
  color: var(--brand); text-decoration: none;
}
.stat-link:hover { text-decoration: underline; }
/* Журнал расходов: на телефоне второстепенные колонки скрыты, чтобы сумма
   и назначение были видны без горизонтальной прокрутки. */
@media (max-width: 767px) {
  .expense-comment, .expense-author { display: none; }
}

/* ── partial payments ──────────────────────────────────────────────────── */
.pay-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.pay-summary .field-label { font-size: 11px; text-transform: uppercase; letter-spacing: .02em; }
.pay-summary strong { display: block; margin-top: 2px; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.pay-summary .is-success { color: var(--success); }
.pay-summary .is-danger { color: var(--danger); }
.pay-progress { height: 8px; background: #eaecf0; border-radius: 99px; overflow: hidden; }
.pay-progress > span { display: block; height: 100%; background: var(--brand); border-radius: inherit; }
.payment-list { border-top: 1px solid var(--line); }
.payment-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.payment-row:last-child { border-bottom: 0; padding-bottom: 0; }
.payment-row strong { font-variant-numeric: tabular-nums; }
.payment-row .btn-ghost { color: var(--danger); padding: 0 6px; min-height: 26px; }
.payment-form { border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 10px; }
.pay-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ── fixed-rate tier switch ─────────────────────────────────────────────── */
.threshold-cell { text-align: center; vertical-align: middle; }
.switch {
  position: relative; display: inline-flex; width: 40px; height: 22px;
  vertical-align: middle; cursor: pointer;
}
.switch-input {
  position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none;
}
.switch-track {
  position: absolute; inset: 0; border-radius: 999px; background: #d0d5dd;
  transition: background 140ms ease;
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(16, 24, 40, .2);
  transition: transform 140ms ease;
}
.switch-input:checked + .switch-track { background: var(--brand); }
.switch-input:checked + .switch-track::after { transform: translateX(18px); }
.switch-input:disabled + .switch-track { opacity: .35; }
.tier-threshold-row td { background: #f8fafc; }
.tier-delete-row td { opacity: .55; }
#tier-rows input[name$="-DELETE"] { display: none; }
.tier-actions-cell { white-space: nowrap; }
.tier-table .field-input { min-height: 36px; }
.tariff-chart-compact { max-width: 100%; }
.tariff-chart-compact text { font-size: 16px; }
@media (max-width: 767px) { .tariff-chart-compact text { font-size: 20px; } }

@media (max-width: 767px) {
  .rental-status-tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}
.rental-card-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

/* ── change history ────────────────────────────────────────────────────── */

/* Одно сохранение карточки — одна строка; изменённые поля раскрываются ниже
   строками той же таблицы, поэтому «Поле / Было / Стало» стоят в своих
   колонках и не съезжают относительно шапки. */
.history-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 0; border: 0; background: none;
  font: inherit; font-weight: 600; color: var(--brand);
  cursor: pointer; text-align: left; white-space: nowrap;
}
.history-toggle:hover { text-decoration: underline; }
.history-chevron { display: inline-block; transition: transform 140ms ease; }
.history-toggle[aria-expanded="true"] .history-chevron { transform: rotate(90deg); }

.history-change-row[hidden] { display: none; }
.history-change-row > td {
  background: #fcfcfd;
  padding-top: 6px;
  padding-bottom: 6px;
  vertical-align: top;
}
.history-field { color: var(--muted); }
.history-old { color: var(--muted); text-decoration: line-through; }
.history-new { font-weight: 600; }

@media (max-width: 767px) {
  .desktop-only { display: none !important; }
  .table-wrap.desktop-only { display: none; }
}
@media (min-width: 768px) {
  .mobile-only { display: none !important; }
}
