:root {
  --ink: #18231f;
  --cream: #f2eee5;
  --gold: #d3ae6b;
  --green: #1b4d3e;
  --white: #fffef9;
  --border: rgba(24, 35, 31, 0.12);
  --status-volny-bg: #efe2c4;
  --status-volny-fg: #18231f;
  --status-rez-bg: #d8ddd9;
  --status-rez-fg: #18231f;
  --status-obs-bg: #e8e6e1;
  --status-obs-fg: rgba(24, 35, 31, 0.55);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 50% at 10% 0%, rgba(211, 174, 107, 0.18), transparent 55%),
    linear-gradient(160deg, #ebe6da 0%, var(--cream) 45%, #e4ddd0 100%);
}

.hidden {
  display: none !important;
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 0.85rem 5.5rem;
}

.panel {
  background: color-mix(in srgb, var(--white) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem 1rem 1.1rem;
  box-shadow: 0 8px 28px rgba(24, 35, 31, 0.06);
}

.login-panel {
  width: min(22rem, 100%);
  margin: 10vh auto 0;
}

h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.25rem, 4.5vw, 1.5rem);
  line-height: 1.25;
}

h2 {
  margin: 0 0 0.85rem;
  font-size: 1.05rem;
}

.muted {
  color: rgba(24, 35, 31, 0.65);
  font-size: 0.875rem;
  line-height: 1.4;
}

a {
  color: var(--green);
  overflow-wrap: anywhere;
}

form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-top: 1.25rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: rgba(24, 35, 31, 0.7);
}

input,
select {
  font: inherit;
  font-size: 16px; /* avoid iOS zoom */
  padding: 0.7rem 0.75rem;
  border-radius: 0.65rem;
  border: 1px solid var(--border);
  background: white;
  color: var(--ink);
  width: 100%;
  max-width: 100%;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 0.7rem 1.1rem;
  font-weight: 600;
  min-height: 44px;
}

button.primary,
#login-form button {
  background: var(--gold);
  color: var(--ink);
}

button.primary:hover,
#login-form button:hover {
  background: #e0c285;
}

button.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--ink);
}

.error {
  color: #8b1e1e;
  font-size: 0.9rem;
  margin: 0;
}

.top {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.top-copy {
  min-width: 0;
}

.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: stretch;
}

.action-bar .primary,
.action-bar .ghost {
  flex: 1 1 auto;
  min-width: calc(50% - 0.25rem);
}

.saved-at {
  flex: 1 1 100%;
  font-size: 0.8rem;
}

.desktop-only {
  display: none;
}

.mobile-only {
  display: block;
}

.grid {
  display: grid;
  gap: 0.85rem;
}

.table-wrap {
  overflow: visible;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.55rem 0.4rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(24, 35, 31, 0.55);
}

.unit-id {
  font-weight: 700;
}

select.status {
  min-width: 0;
  width: 100%;
  font-weight: 600;
  border-width: 1px;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

select.status.status-volny {
  background: var(--status-volny-bg);
  color: var(--status-volny-fg);
  border-color: rgba(211, 174, 107, 0.55);
}

select.status.status-rezervovany {
  background: var(--status-rez-bg);
  color: var(--status-rez-fg);
  border-color: rgba(24, 35, 31, 0.2);
}

select.status.status-obsadeny {
  background: var(--status-obs-bg);
  color: var(--status-obs-fg);
  border-color: rgba(24, 35, 31, 0.12);
}

select.status option {
  background: white;
  color: var(--ink);
  font-weight: 600;
}

select.status option[value="voľný"] {
  background: var(--status-volny-bg);
}

select.status option[value="rezervovaný"] {
  background: var(--status-rez-bg);
}

select.status option[value="obsadený"] {
  background: var(--status-obs-bg);
  color: var(--status-obs-fg);
}

/* Mobile: rows as cards */
@media (max-width: 719px) {
  .data-table thead {
    display: none;
  }

  .data-table,
  .data-table tbody {
    display: block;
    width: 100%;
  }

  .data-table tr {
    display: grid;
    gap: 0.45rem 0.75rem;
    grid-template-columns: 1fr auto;
    align-items: center;
    margin: 0 0 0.65rem;
    padding: 0.85rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 0.85rem;
    background: rgba(255, 254, 249, 0.75);
  }

  .data-table tr:last-child {
    margin-bottom: 0;
  }

  .data-table td {
    border: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
  }

  .data-table td::before {
    content: attr(data-label);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: rgba(24, 35, 31, 0.5);
  }

  .flats-table td[data-label="Byt"] {
    grid-column: 1;
    grid-row: 1;
  }

  .flats-table td.cell-status {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: start;
    min-width: 8.5rem;
  }

  .flats-table td[data-label="Poschodie"] {
    grid-column: 1;
  }

  .flats-table td[data-label="Dispozícia"],
  .flats-table td[data-label="Plocha"] {
    grid-column: 1 / -1;
  }

  .parking-table td[data-label="Miesto"] {
    grid-column: 1;
  }

  .parking-table td.cell-status {
    grid-column: 2;
    min-width: 8.5rem;
  }

  /* Sticky save on mobile */
  .action-bar {
    position: sticky;
    bottom: 0.65rem;
    z-index: 20;
    margin-top: 0.5rem;
    padding: 0.65rem;
    border-radius: 1rem;
    background: color-mix(in srgb, var(--white) 94%, transparent);
    border: 1px solid var(--border);
    box-shadow: 0 10px 28px rgba(24, 35, 31, 0.12);
    backdrop-filter: blur(8px);
  }

  .modal-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .modal-actions .btn-link,
  .modal-actions button {
    width: 100%;
  }
}

@media (min-width: 720px) {
  #app {
    padding: 1.5rem 1rem 3rem;
  }

  .panel {
    padding: 1.25rem 1.35rem;
  }

  .desktop-only {
    display: block;
  }

  .mobile-only {
    display: none !important;
  }

  .top {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
  }

  .top .saved-at {
    text-align: right;
    margin: 0;
    max-width: 14rem;
  }

  .action-bar {
    position: static;
    margin-top: 1rem;
    padding: 0;
    border: 0;
    box-shadow: none;
    background: transparent;
    backdrop-filter: none;
    justify-content: flex-end;
  }

  .action-bar .primary,
  .action-bar .ghost {
    flex: 0 1 auto;
    min-width: 0;
  }

  select.status {
    min-width: 9.5rem;
    width: auto;
  }

  .cell-status {
    width: 1%;
    white-space: nowrap;
  }
}

@media (min-width: 900px) {
  .grid {
    grid-template-columns: 1.3fr 1fr;
    align-items: start;
  }
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(24, 35, 31, 0.45);
  backdrop-filter: blur(2px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(22rem, 100%);
  margin: 0;
}

.modal-card h2 {
  margin: 0 0 0.5rem;
}

.modal-card #modal-body {
  margin: 0 0 1.25rem;
  line-height: 1.45;
}

.modal-card #modal-body a {
  font-weight: 600;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: flex-end;
  align-items: center;
}

.btn-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid var(--gold);
  padding: 0.55rem 1rem;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--ink);
  text-decoration: none;
  background: transparent;
  min-height: 44px;
}

.btn-link:hover {
  background: rgba(211, 174, 107, 0.18);
}

.modal.is-error .modal-card h2 {
  color: #8b1e1e;
}
