:root {
  --bg: #f5f6f8;
  --card: #fff;
  --text: #18212f;
  --muted: #667085;
  --line: #d9e1ea;
  --accent: #0f766e;
  --accent-dark: #0a5e58;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

button,
input,
select,
textarea,
.photo-button {
  font: inherit;
}

.app {
  width: min(1040px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

.start-screen {
  min-height: calc(100vh - 64px);
  display: grid;
  align-content: center;
  gap: 24px;
}

.brand {
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 800;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 32px;
}

h2 {
  font-size: 20px;
}

.role-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.role-card,
.panel,
.object-card,
.modal {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.role-card {
  min-height: 150px;
  display: grid;
  align-content: start;
  justify-items: start;
  gap: 8px;
  padding: 18px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.role-card svg {
  width: 28px;
  height: 28px;
  color: var(--accent);
}

.role-card:not(:disabled):hover {
  border-color: rgba(15, 118, 110, 0.55);
}

.role-card:disabled {
  cursor: default;
  opacity: 0.58;
}

.role-card strong {
  font-size: 21px;
}

.role-card span,
.object-card span,
.empty,
label {
  color: var(--muted);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.top-actions,
.field-with-action {
  display: flex;
  align-items: center;
  gap: 8px;
}

.back-button {
  min-height: 32px;
  margin-bottom: 8px;
  padding: 0 2px 0 0;
  background: transparent;
  color: var(--accent);
  border: 0;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  font-weight: 750;
}

button:disabled {
  cursor: default;
  opacity: 0.52;
}

button,
.photo-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button svg,
.photo-button svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  stroke-width: 2.25;
}

.role-card {
  display: grid;
  justify-content: stretch;
}

.primary,
.secondary {
  padding: 0 16px;
  cursor: pointer;
}

.compact {
  min-width: max-content;
  padding: 0 12px;
}

.primary {
  background: var(--accent);
  color: #fff;
}

.primary:hover {
  background: var(--accent-dark);
}

.secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
}

.field {
  display: grid;
  gap: 8px;
}

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.field-head .photo-button,
.field-head .secondary {
  min-height: 40px;
}

.field-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.contact-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.contact-list {
  display: grid;
  gap: 8px;
}

.contact-card {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) 34px;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.contact-view-list {
  display: grid;
  gap: 8px;
}

.contact-view-card {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.panel {
  padding: 16px;
}

.owner-filters {
  margin-bottom: 10px;
}

.panel-head {
  margin-bottom: 14px;
}

.object-list {
  display: grid;
  gap: 14px;
}

.retailer-list {
  display: grid;
  gap: 12px;
}

.retailer-card {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.retailer-logo {
  width: 88px;
  height: 88px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f6;
  color: var(--accent);
}

.retailer-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.retailer-main {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.retailer-title-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.retailer-title-row > div {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.retailer-title-row strong {
  font-size: 18px;
}

.retailer-title-row span,
.retailer-meta,
.retailer-footer,
.retailer-comment {
  color: var(--muted);
}

.retailer-meta,
.retailer-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 13px;
  font-weight: 700;
}

.retailer-meta a {
  color: var(--accent);
}

.retailer-comment {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
}

.object-card {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 12px;
  padding: 14px;
}

.object-gallery,
.unit-gallery {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.object-photo,
.unit-photo {
  width: 100%;
  min-height: 86px;
  border-radius: 8px;
  background: #eef2f6;
  object-fit: cover;
}

.object-photo.extra,
.unit-photo.extra {
  min-height: 44px;
}

.object-photo.empty-photo,
.unit-photo.empty-photo {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
}

.object-body {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.object-main {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 0.8fr) 0.6fr 0.6fr;
  gap: 12px;
  align-items: start;
}

.object-card strong,
.object-card span {
  display: block;
}

.object-actions,
.unit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.small-button {
  min-height: 34px;
  padding: 0 12px;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.unit-list {
  display: grid;
  gap: 8px;
}

.dictionary-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}

.dictionary-item {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.view-content {
  display: grid;
  gap: 14px;
}

.view-gallery {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.gallery-photo {
  min-height: 120px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.view-gallery img,
.view-empty-photo {
  width: 100%;
  min-height: 120px;
  border-radius: 8px;
  background: #eef2f6;
  object-fit: cover;
}

.view-empty-photo {
  display: grid;
  place-items: center;
  color: var(--muted);
}

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

.view-row {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.view-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.view-row strong {
  overflow-wrap: anywhere;
}

.view-section {
  display: grid;
  gap: 10px;
}

.view-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.view-section-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.view-section h3 {
  margin: 0;
  font-size: 18px;
}

.view-unit-list {
  display: grid;
  gap: 8px;
}

.view-unit-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.segmented {
  display: inline-flex;
  min-height: 34px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f6;
}

.segmented button {
  min-height: 28px;
  padding: 0 10px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.segmented button.is-selected {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.units-table {
  display: grid;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.unit-filters {
  display: grid;
  grid-template-columns: repeat(6, minmax(108px, 1fr)) minmax(128px, 1.05fr) 76px;
  gap: 6px;
  align-items: end;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  overflow-x: auto;
}

.unit-filters label {
  gap: 4px;
  font-size: 12px;
}

.unit-filters input,
.unit-filters select {
  height: 34px;
  min-height: 34px;
  padding: 0 9px;
  background: #fff;
}

.filter-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.filter-actions button {
  width: 34px;
  min-height: 34px;
  flex: 0 0 34px;
  padding: 0;
}

.units-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 58px 88px 118px 118px 86px;
  min-height: 48px;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  border-top: 1px solid var(--line);
}

.units-row:first-child {
  border-top: 0;
}

.units-head {
  min-height: 40px;
  background: #fbfcfd;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.units-row strong,
.units-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.icon-action {
  width: 34px;
  min-height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.icon-action:hover {
  border-color: rgba(15, 118, 110, 0.5);
  color: var(--accent);
}

.icon-action.danger:hover {
  border-color: rgba(185, 28, 28, 0.45);
  color: #b91c1c;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip,
.muted-chip {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
  font-weight: 750;
}

.muted-chip {
  color: var(--muted);
  background: #fbfcfd;
}

.chip.removable {
  cursor: pointer;
}

.chip svg {
  width: 14px;
  height: 14px;
}

.compact-chips {
  gap: 4px;
}

.units-chess {
  display: grid;
  gap: 8px;
}

.chess-floor {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 8px;
  align-items: stretch;
}

.chess-floor-label {
  display: grid;
  place-items: center;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.chess-cells {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 8px;
}

.chess-cell {
  display: grid;
  align-content: center;
  justify-content: stretch;
  min-height: 54px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.chess-cell strong,
.chess-cell span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chess-cell span {
  color: var(--muted);
  font-size: 12px;
}

.view-plan-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.view-plan-card,
.floor-plan-card {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.view-plan-card {
  grid-template-columns: 92px minmax(0, 1fr) auto;
}

.floor-plan-list {
  display: grid;
  gap: 8px;
}

.floor-plan-preview {
  width: 92px;
  height: 68px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f6;
  padding: 0;
  cursor: pointer;
}

.floor-plan-preview img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.floor-plan-meta {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.floor-plan-card .unit-actions {
  grid-column: 1 / -1;
  justify-content: flex-end;
}

.floor-plan-meta strong,
.view-plan-card strong {
  white-space: nowrap;
}

.floor-plan-meta span,
.view-plan-card span {
  overflow-wrap: anywhere;
}

.pdf-preview {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  gap: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.pdf-preview svg {
  width: 22px;
  height: 22px;
}

.unit-card {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.unit-photo {
  min-height: 58px;
}

.unit-gallery {
  grid-template-columns: 1fr;
}

.unit-meta {
  display: grid;
  gap: 4px;
}

.unit-meta span {
  color: var(--muted);
}

.empty {
  padding: 22px;
  text-align: center;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.38);
}

.modal {
  width: min(520px, 100%);
  max-height: min(860px, calc(100vh - 36px));
  overflow: auto;
  display: grid;
  gap: 12px;
  padding: 18px;
  box-shadow: 0 20px 70px rgba(15, 23, 42, 0.22);
}

.view-modal {
  width: min(920px, calc(100vw - 36px));
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
}

.editor-modal {
  width: min(920px, 100%);
  max-height: min(860px, calc(100vh - 36px));
  overflow: auto;
}

.retailer-modal {
  width: min(820px, calc(100vw - 36px));
}

.image-preview-modal {
  width: min(1040px, calc(100vw - 36px));
  max-height: min(880px, calc(100vh - 36px));
  overflow: auto;
}

#image-preview-full {
  width: 100%;
  max-height: calc(100vh - 150px);
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f6;
}

.modal-head,
.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal > .actions {
  position: sticky;
  bottom: -18px;
  margin: 0 -18px -18px;
  padding: 12px 18px 18px;
  border-top: 1px solid var(--line);
  background: var(--card);
  z-index: 3;
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  background: #f2f4f7;
  color: var(--text);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.icon-button svg {
  width: 20px;
  height: 20px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 750;
}

input {
  width: 100%;
  height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--text);
}

select {
  width: 100%;
  height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--text);
}

textarea {
  width: 100%;
  min-height: 86px;
  resize: vertical;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--text);
}

input[type="file"] {
  height: 42px;
  padding: 7px 10px;
  line-height: 26px;
}

input[type="file"]::file-selector-button {
  height: 26px;
  margin: 0 8px 0 0;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 700;
}

.photo-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.photo-uploader {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.attachment-frame {
  min-height: 48px;
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.photo-button {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-weight: 750;
  cursor: pointer;
}

.photo-count {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.photo-preview {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.logo-preview {
  display: grid;
  justify-items: start;
}

.logo-preview img {
  width: 120px;
  height: 80px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f6;
}

.city-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  max-height: 190px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.city-option {
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.city-option input {
  width: 14px;
  height: 14px;
  padding: 0;
}

.photo-chip {
  position: relative;
  min-height: 72px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f6;
}

.photo-chip img {
  width: 100%;
  height: 72px;
  display: block;
  object-fit: cover;
}

.photo-chip button {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 26px;
  min-height: 26px;
  padding: 0;
  border-radius: 999px;
  background: rgba(24, 33, 47, 0.78);
  color: #fff;
  cursor: pointer;
}

.photo-chip button svg {
  width: 15px;
  height: 15px;
}

.compact-empty {
  padding: 14px;
}

.editor-grid,
.crop-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.editor-grid label {
  grid-template-rows: 16px 42px;
  align-items: start;
}

.editor-note {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.mark-status {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.unit-mark-preview {
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f6;
}

.plan-editor {
  display: grid;
  gap: 12px;
}

.canvas-wrap {
  width: 100%;
  max-height: 520px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f6;
}

#plan-canvas {
  max-width: 100%;
  display: block;
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.mark-canvas-wrap {
  max-height: 620px;
}

#mark-canvas {
  max-width: 100%;
  display: block;
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: crosshair;
}

.editor-tools {
  display: grid;
  gap: 10px;
}

.crop-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.is-active {
  border-color: rgba(15, 118, 110, 0.55);
  background: rgba(15, 118, 110, 0.08);
  color: var(--accent);
}

@media (max-width: 780px) {
  .role-grid,
  .object-card,
  .retailer-card,
  .object-main,
  .unit-card,
  .view-grid,
  .view-unit-card,
  .view-plan-list,
  .view-plan-card,
  .floor-plan-card,
  .contact-grid,
  .contact-card,
  .contact-view-card,
  .form-grid,
  .city-grid,
  .editor-grid,
  .crop-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .top-actions,
  .field-with-action,
  .field-head,
  .photo-uploader,
  .view-section-head,
  .view-section-actions,
  .modal-head,
  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .view-gallery {
    grid-template-columns: 1fr;
  }

  .photo-preview {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .floor-plan-preview {
    width: 100%;
    height: 120px;
  }

  .units-table {
    overflow-x: auto;
  }

  .units-row {
    grid-template-columns: 140px 70px 96px 130px 120px 86px;
    min-width: 690px;
  }

  .chess-floor {
    grid-template-columns: 1fr;
  }
}
