:root {
  --bg: #f3f6fb; --panel: #ffffff; --line: #dfe6f0; --line-strong: #cfd9e6;
  --text: #1f2a3d; --muted: #66768d; --primary: #2876d1; --primary-dark: #1058ab;
  --header: #0f1a2f; --soft: #eef4fb; --danger: #d84a4a; --ok: #1d9a63;
  --radius: 14px; --shadow: 0 1px 2px rgba(16, 32, 64, .05), 0 4px 16px rgba(16, 32, 64, .05);
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* buttons */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: #fff; color: #25354b; cursor: pointer; text-decoration: none; font-weight: 500; white-space: nowrap;
}
button:hover, .btn:hover { background: #f3f8ff; }
button:disabled { opacity: .55; cursor: default; }
button:focus-visible, .btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.primary:hover { background: var(--primary-dark); }
.ghost { background: transparent; }
.sm { min-height: 34px; padding: 5px 11px; font-size: 13px; border-radius: 9px; }
.danger { color: var(--danger); }
.danger-link { background: none; border: 0; color: var(--danger); padding: 0; min-height: 0; margin-top: 14px; }
.danger-link:hover { background: none; text-decoration: underline; }
.icon { min-height: 36px; width: 36px; padding: 0; border: 0; background: transparent; font-size: 16px; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--header); color: #fff;
  display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 60px;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.brand .logo { font-size: 26px; color: #71c8ff; line-height: 1; }
.brand b { display: block; font-size: 17px; line-height: 1.1; }
.brand small { display: block; color: #b3c6e4; font-size: 11px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: #c8d6ec; text-decoration: none; padding: 8px 12px; border-radius: 9px; font-weight: 500; }
.nav a:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.nav a.active { color: #fff; background: rgba(113, 200, 255, .18); }
body:not(.is-admin) .admin-only { display: none !important; }
.me { display: flex; align-items: center; gap: 10px; color: #c8d6ec; font-size: 13px; }
.me button { color: #fff; background: transparent; border-color: rgba(255, 255, 255, .25); min-height: 34px; padding: 4px 12px; }
.me button:hover { background: rgba(255, 255, 255, .1); }
.role { font-size: 11px; background: rgba(255, 255, 255, .12); padding: 2px 8px; border-radius: 99px; margin-left: 6px; }

/* page */
.view { max-width: 1240px; margin: 0 auto; padding: 24px 20px 60px; }
.loading, .empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 24px; line-height: 1.2; letter-spacing: -.01em; text-wrap: balance; }
.sub { margin: 4px 0 0; color: var(--muted); }
.head-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { margin-bottom: 10px; }
.crumbs a { text-decoration: none; color: var(--muted); font-weight: 500; }
.crumbs a:hover { color: var(--primary); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat span { display: block; color: var(--muted); font-size: 12px; }
.stat b { display: block; font-size: 22px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat.accent b { color: var(--ok); font-size: 18px; margin-top: 6px; }

/* filters */
.filters { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.filters input, .filters select { min-height: 40px; border: 1px solid var(--line-strong); border-radius: 10px; padding: 8px 12px; background: #fff; }
.filters input { flex: 1 1 260px; }
.filters select { flex: 0 1 200px; }

/* orders list */
.orders { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.order-row {
  display: grid; grid-template-columns: 70px minmax(150px, 1.2fr) minmax(160px, 1.5fr) minmax(110px, .9fr) 140px 150px;
  gap: 14px; align-items: center; padding: 13px 18px; border-top: 1px solid var(--line); color: inherit; text-decoration: none;
}
.order-row:first-child { border-top: 0; }
a.order-row:hover { background: #f7faff; }
.order-row.head { background: #f7f9fc; color: var(--muted); font-size: 12px; font-weight: 600; padding-top: 10px; padding-bottom: 10px; }
.order-row > div { min-width: 0; }
.order-row span { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order-row b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-num { font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.c-addr { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-sum { text-align: right; font-variant-numeric: tabular-nums; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600;
  color: var(--c); background: color-mix(in srgb, var(--c) 12%, white); white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--c); }

/* order page */
.order-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.status-select { min-height: 40px; border-radius: 10px; border: 1px solid var(--line-strong); padding: 6px 12px; font-weight: 600; background: #fff; }
.rooms { display: grid; gap: 12px; }
.room { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 16px; border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.room-media { display: grid; gap: 8px; align-content: start; }
.room-shot { padding: 0; border: 0; min-height: 0; border-radius: 10px; overflow: hidden; display: block; background: #0f1a2f; }
.room-shot img { display: block; width: 100%; aspect-ratio: 16 / 10; object-fit: cover; }
.viewer { position: fixed; inset: 0; z-index: 70; background: rgba(8, 14, 26, .9); display: flex; align-items: center; justify-content: center; padding: 16px; }
.viewer figure { margin: 0; max-width: min(1400px, 100%); }
.viewer img { display: block; max-width: 100%; max-height: calc(100dvh - 80px); border-radius: 10px; }
.viewer figcaption { color: #c8d6ec; margin-top: 8px; text-align: center; }
.viewer .icon { position: absolute; top: 12px; right: 12px; color: #fff; }
.room-preview { display: flex; align-items: center; justify-content: center; background: #f8fbff; border-radius: 10px; height: 150px; overflow: hidden; text-decoration: none; border: 1px solid #e7eef7; }
.room-preview svg { width: 100%; height: 100%; }
.no-plan { color: var(--muted); font-size: 12px; text-align: center; padding: 10px; }
.room-body { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.room-title { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.room-title b { font-size: 15px; }
.room-title span { font-size: 12px; }
.room-metrics { display: flex; flex-wrap: wrap; gap: 6px; }
.room-metrics span { background: var(--soft); border-radius: 8px; padding: 3px 8px; font-size: 12px; color: #335a85; font-variant-numeric: tabular-nums; }
.room-total { font-size: 18px; font-weight: 700; color: var(--ok); font-variant-numeric: tabular-nums; }
.room-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }

.estimate table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.estimate td, .estimate th { padding: 9px 4px; border-top: 1px solid var(--line); text-align: left; }
.estimate th { color: var(--muted); font-size: 12px; font-weight: 600; border-top: 0; }
.estimate td:nth-child(n+2), .estimate th:nth-child(n+2) { text-align: right; }
.estimate tfoot td { font-weight: 700; font-size: 16px; color: var(--ok); border-top: 2px solid var(--line-strong); }

.info { margin: 0; display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 8px 10px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; overflow-wrap: anywhere; white-space: pre-line; }
.log { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow: auto; }
.log li { padding: 8px 0; border-top: 1px solid var(--line); }
.log li:first-child { border-top: 0; }
.log small { display: block; color: var(--muted); font-size: 12px; }

/* users table */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 11px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
.table th { background: #f7f9fc; color: var(--muted); font-size: 12px; font-weight: 600; border-top: 0; }
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
.off { opacity: .55; }

/* prices */
.price-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }
.price-sample { background: #eef7f0; border: 1px solid #d0ead7; border-radius: 12px; padding: 14px 16px; color: #237349; }
.price-sample b { font-size: 20px; display: block; margin-top: 2px; font-variant-numeric: tabular-nums; }
.prices-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }

/* forms */
label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: #5b6f88; font-weight: 500; }
label input, label select, label textarea {
  width: 100%; min-height: 40px; padding: 8px 11px; border: 1px solid var(--line-strong); border-radius: 9px; background: #fff; font-size: 14px; color: var(--text);
}
label textarea { resize: vertical; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--text); }
label.check input { width: 18px; min-height: 18px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.input-unit { position: relative; }
.input-unit input { padding-right: 70px; font-variant-numeric: tabular-nums; }
.input-unit em { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); font-size: 12px; pointer-events: none; }

/* modal */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(15, 26, 47, .45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { background: #fff; border-radius: 16px; width: min(520px, 100%); max-height: calc(100dvh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 6px; }
.modal-head h2 { margin: 0; font-size: 18px; }
#modalForm { padding: 8px 18px 18px; display: grid; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.form-error { color: var(--danger); font-size: 13px; min-height: 1px; }
.form-error:empty { display: none; }

.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 60; background: #14233b; color: #fff; padding: 11px 18px; border-radius: 10px; box-shadow: 0 8px 30px rgba(0, 0, 0, .25); max-width: calc(100% - 32px); }
.toast.bad { background: var(--danger); }

.print-only { display: none; }

/* login */
.login-page { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(1200px 600px at 20% -10%, #1d3a66 0%, transparent 60%), var(--header); }
.login-card { background: #fff; border-radius: 18px; padding: 28px; width: min(380px, 100%); box-shadow: 0 30px 80px rgba(0, 0, 0, .35); display: grid; gap: 14px; }
.login-card .brand { color: var(--text); margin-bottom: 4px; }
.login-card .brand small { color: var(--muted); }

@media (max-width: 1000px) {
  .order-grid, .prices-layout { grid-template-columns: 1fr; }
  /* Address and visit time stay visible: it is where and when the master goes. */
  .order-row.head { display: none; }
  .order-row { grid-template-columns: 60px minmax(0, 1fr) 130px 140px; grid-template-areas: "num client status sum" "num addr addr addr"; row-gap: 4px; }
  .order-row .c-num { grid-area: num; }
  .order-row .c-client { grid-area: client; }
  .order-row .c-status { grid-area: status; }
  .order-row .c-sum { grid-area: sum; }
  .order-row .c-addr { grid-area: addr; white-space: normal; font-size: 13px; }
  .order-row .c-addr span { display: inline; margin-left: 8px; }
  .order-row .c-master { display: none; }
}
@media (max-width: 700px) {
  .topbar { height: auto; flex-wrap: wrap; gap: 6px 12px; padding: 10px 16px; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  .me { margin-left: auto; }
  .me #meName { display: none; }
  .view { padding: 16px 16px 48px; }
  .page-head h1 { font-size: 20px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .order-row.head { display: none; }
  .order-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "client sum" "addr addr" "status num"; gap: 6px 12px; padding: 12px 14px; }
  .order-row .c-addr span { display: block; margin-left: 0; }
  .order-row .c-client { grid-area: client; }
  .order-row .c-sum { grid-area: sum; }
  .order-row .c-status { grid-area: status; }
  .order-row .c-num { grid-area: num; text-align: right; font-size: 12px; }
  .room { grid-template-columns: 1fr; }
  .room-preview { height: 170px; }
  .row2 { grid-template-columns: 1fr; }
  .info { grid-template-columns: 100px minmax(0, 1fr); }
}

@media print {
  body { background: #fff; }
  .topbar, .crumbs, .head-btns, .room-actions, .no-print, .toast, .modal, .card-head button { display: none !important; }
  .print-only { display: block; }
  .view { padding: 0; max-width: none; }
  .order-grid { grid-template-columns: 1fr; }
  .card { box-shadow: none; break-inside: avoid; }
  .room { break-inside: avoid; grid-template-columns: 150px 1fr; }
  .room-preview { height: 120px; }
}

/* catalog */
.cat-kinds { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; padding-bottom: 2px; }
.cat-kinds button { border-radius: 99px; min-height: 38px; padding: 6px 14px; background: #fff; }
.cat-kinds button span { color: var(--muted); font-size: 12px; margin-left: 2px; }
.cat-kinds button.on { background: var(--header); border-color: var(--header); color: #fff; }
.cat-kinds button.on span { color: #b3c6e4; }
.seg-sm { display: inline-flex; background: #e9eef5; border-radius: 10px; padding: 3px; gap: 2px; }
.seg-sm button { border: 0; background: transparent; min-height: 32px; padding: 4px 11px; border-radius: 8px; }
.seg-sm button.on { background: #fff; color: var(--primary); box-shadow: 0 1px 3px rgba(16, 32, 64, .12); font-weight: 600; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.cat-card { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.cat-open { display: block; width: 100%; padding: 0; border: 0; border-radius: 0; background: none; text-align: left; white-space: normal; min-height: 0; font-weight: 400; }
.cat-open:hover { background: #f7faff; }
.cat-ph { height: 130px; display: flex; align-items: center; justify-content: center; background: #f5f8fc; border-bottom: 1px solid var(--line); overflow: hidden; }
.cat-ph img { width: 100%; height: 100%; object-fit: contain; }
.cat-ph.big { height: 180px; width: 180px; border: 1px solid var(--line); border-radius: 12px; }
.ph { color: #b9c7d8; font-size: 38px; line-height: 1; }
.ph.sm { font-size: 20px; }
.cat-body { padding: 10px 12px 12px; display: grid; gap: 3px; }
.cat-body b { font-size: 14px; line-height: 1.3; }
.cat-body .muted { font-size: 12px; }
.cat-price { font-weight: 700; color: var(--ok); font-variant-numeric: tabular-nums; }
.cat-price small { font-weight: 500; color: var(--muted); margin-left: 2px; }
.star { color: #e7a92a; }
.cat-card > .star { position: absolute; top: 8px; left: 10px; font-size: 18px; text-shadow: 0 1px 2px #fff; }
.cat-acts { position: absolute; top: 6px; right: 6px; display: flex; gap: 2px; opacity: .85; }
.cat-acts .icon { width: 30px; min-height: 30px; background: rgba(255, 255, 255, .9); border-radius: 8px; font-size: 13px; }
.cat-table td.thumb { width: 52px; }
.cat-table td.thumb img { width: 44px; height: 44px; object-fit: contain; border-radius: 6px; background: #f5f8fc; }
.cat-table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cat-table td.acts { text-align: right; }

.modal-card.wide { width: min(980px, 100%); }
.item-form { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 18px; }
.item-photo { display: grid; gap: 8px; align-content: start; justify-items: start; }
.item-fields { display: grid; gap: 12px; min-width: 0; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 12px; }
.form-h { margin: 8px 0 0; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.small { font-size: 12px; }
.parts { display: grid; gap: 6px; }
.part-row { display: grid; grid-template-columns: 70px 1fr 1fr; gap: 10px; align-items: end; }
.part-row b { padding-bottom: 10px; }
.kit-tabs { margin-bottom: 4px; }
.kit-list { display: grid; gap: 8px; }
.kit-row { display: grid; grid-template-columns: minmax(0, 1fr) 150px 80px auto 36px; gap: 8px; align-items: center; }
.kit-row input, .kit-row select { min-height: 38px; border: 1px solid var(--line-strong); border-radius: 9px; padding: 6px 9px; background: #fff; width: 100%; }
.kit-row .check { font-size: 12px; color: var(--muted); white-space: nowrap; }
.kit-row .check input { width: 16px; min-height: 16px; }
.kit-add { justify-self: start; }

.estimate tr.grp td { background: #f5f8fc; font-weight: 600; color: #3b5170; }
.estimate td:nth-child(n+2), .estimate th:nth-child(n+2) { white-space: nowrap; }
.cost-box { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.cost-box div { background: var(--soft); border-radius: 10px; padding: 10px 12px; }
.cost-box span { display: block; font-size: 12px; color: var(--muted); }
.cost-box b { font-variant-numeric: tabular-nums; }
.cost-box b.pos { color: var(--ok); }
.cost-box b.neg { color: var(--danger); }
.hidden-lines { margin-top: 10px; font-size: 13px; color: var(--muted); }
.hidden-lines ul { margin: 6px 0 0; padding-left: 18px; }

@media (max-width: 700px) {
  .item-form { grid-template-columns: 1fr; }
  .cat-ph.big { width: 100%; }
  .grid3, .grid4 { grid-template-columns: 1fr 1fr; }
  .kit-row { grid-template-columns: 1fr 1fr; }
  .kit-row .kit-item { grid-column: 1 / -1; }
  .cost-box { grid-template-columns: 1fr; }
  .cat-grid { grid-template-columns: 1fr 1fr; }
}
[hidden] { display: none !important; }
.form-h .small { text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 6px; }

/* order adjustments and calendar */
.estimate tfoot tr.sub td { font-size: 13px; font-weight: 500; color: #3b5170; border-top: 1px solid var(--line); }
.adj-row { display: grid; grid-template-columns: minmax(0, 1fr) 70px 64px 110px 36px; gap: 6px; margin-bottom: 6px; }
.adj-row input { min-height: 38px; border: 1px solid var(--line-strong); border-radius: 9px; padding: 6px 9px; width: 100%; }
.cal-day { margin-bottom: 16px; }
.cal-day h2 { font-size: 15px; margin: 0 0 8px; color: #3b5170; }
.cal-day h2::first-letter { text-transform: uppercase; }
.cal-day.today h2 { color: var(--primary); }
.cal-item { display: grid; grid-template-columns: 56px 80px minmax(0, 1fr) minmax(0, 180px) auto; gap: 12px; align-items: center; padding: 11px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 6px; color: inherit; text-decoration: none; }
.cal-item:hover { background: #f7faff; }
.cal-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.cal-kind { font-size: 12px; font-weight: 600; color: #7b5cd6; }
.cal-kind.inst { color: #9b4f2a; }
.cal-main { min-width: 0; }
.cal-main b, .cal-main span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-main span, .cal-who { color: var(--muted); font-size: 12.5px; }
@media (max-width: 700px) {
  .cal-item { grid-template-columns: 50px minmax(0, 1fr) auto; }
  .cal-kind, .cal-who { display: none; }
  .adj-row { grid-template-columns: 1fr 1fr 1fr; }
  .adj-row .a-name { grid-column: 1 / -1; }
}

/* bulk prices */
fieldset.checks { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px 10px; margin: 0; display: grid; gap: 6px; }
fieldset.checks legend { font-size: 13px; color: var(--muted); padding: 0 4px; }

/* install the app from the login page */
.install-link { background: transparent; border: 1px solid var(--line-strong); color: var(--primary); min-height: 42px; }
