:root {
  --header-bg: #0a2535;
  --header-text: #ffffff;
  --bg: #f4f6f8;
  --card-bg: #ffffff;
  --text: #1c2733;
  --text-muted: #6b7785;
  --border: #e3e7eb;
  --border-strong: #cfd5dc;
  --primary: #e87a1f;
  --primary-hover: #d96a10;
  --primary-soft: #fff2e6;
  --danger: #c0392b;
  --shadow: 0 4px 18px rgba(10, 37, 53, 0.08);
  --radius: 10px;
  --header-h: 60px;
  --sidebar-w: 300px;
  --transition: 0.28s cubic-bezier(.4,.0,.2,1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 1rem; }

/* ---------- Header ---------- */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--header-bg);
  color: var(--header-text);
  display: flex;
  align-items: center;
  padding: 0 16px;
  z-index: 50;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.app-title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.2px;
  pointer-events: none;
}
.header-spacer { flex: 1; }

.hamburger {
  width: 42px;
  height: 42px;
  background: transparent;
  border: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  padding: 0;
  border-radius: 6px;
  transition: transform var(--transition), background var(--transition);
}
.hamburger:hover { background: rgba(255,255,255,0.08); }
.hamburger span {
  display: block;
  width: 22px;
  height: 2.5px;
  background: #fff;
  border-radius: 2px;
  transition: transform var(--transition), opacity var(--transition);
}
.hamburger.open { transform: rotate(90deg); }

.header-action {
  width: 42px;
  height: 42px;
  background: transparent;
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background var(--transition);
  z-index: 1;
}
.header-action:hover { background: rgba(255,255,255,0.08); }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  max-width: 85vw;
  background: #fff;
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform var(--transition);
  z-index: 40;
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 18px rgba(0,0,0,0.08);
}
.sidebar.open { transform: translateX(0); }
.sidebar-inner {
  padding: 18px 14px;
  overflow-y: auto;
  flex: 1;
}
.sidebar-backdrop {
  position: fixed;
  top: var(--header-h);
  left: 0; right: 0; bottom: 0;
  background: rgba(10, 37, 53, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
  z-index: 35;
}
.sidebar-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

.village-list {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.village-row {
  display: flex;
  align-items: stretch;
  border-radius: 8px;
  transition: background var(--transition);
}
.village-row:hover { background: var(--primary-soft); }
.village-row.active { background: var(--primary-soft); }
.village-item {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: transparent;
  border: none;
  text-align: left;
  font-size: 0.97rem;
  color: var(--text);
  border-radius: 8px 0 0 8px;
  min-width: 0;
}
.village-item span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.village-row.active .village-item {
  color: var(--primary);
  font-weight: 600;
}
.village-edit {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0 8px 8px 0;
  transition: color var(--transition), background var(--transition);
}
.village-edit:hover {
  color: var(--primary);
  background: rgba(232,122,31,0.12);
}
.village-row.active .village-edit { color: var(--primary); }
.village-empty {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 12px;
  text-align: center;
}

/* ---------- Main ---------- */
.main {
  padding-top: calc(var(--header-h) + 20px);
  padding-left: 16px;
  padding-right: 16px;
  padding-bottom: 60px;
  max-width: 900px;
  margin: 0 auto;
  transition: margin-left var(--transition);
}

/* On large screens keep sidebar overlay style — content stays centered */
@media (min-width: 900px) {
  .main { padding-left: 24px; padding-right: 24px; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 8px;
  border: 2px solid var(--primary);
  background: transparent;
  color: var(--primary);
  font-weight: 600;
  font-size: 0.95rem;
  transition: background var(--transition), color var(--transition), transform 0.08s;
  text-decoration: none;
  line-height: 1.2;
}
.btn:hover {
  background: var(--primary);
  color: #fff;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; border-width: 1.5px; }
.btn-ghost {
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-ghost:hover {
  background: var(--bg);
  color: var(--text);
}
.btn-danger {
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-danger-solid {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger-solid:hover {
  background: #a5301f;
  border-color: #a5301f;
  color: #fff;
}
.icon-btn {
  background: transparent;
  border: 1.5px solid var(--border-strong);
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-soft);
}

/* ---------- Page headers ---------- */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}
.page-header h2 { margin: 0; font-size: 1.4rem; }
.breadcrumb {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.breadcrumb a {
  color: var(--text-muted);
  text-decoration: none;
  cursor: pointer;
}
.breadcrumb a:hover { color: var(--primary); }

/* ---------- Cards ---------- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
}
.card-clickable {
  cursor: pointer;
  transition: transform 0.1s, box-shadow var(--transition);
}
.card-clickable:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 22px rgba(10, 37, 53, 0.12);
}
.card-body { padding: 16px 18px; }
.card-title { margin: 0 0 4px; font-size: 1.05rem; font-weight: 600; }
.card-meta { font-size: 0.85rem; color: var(--text-muted); }

.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-muted);
}
.empty-state h3 { margin: 0 0 8px; color: var(--text); font-weight: 600; }

/* ---------- Collapsible (Přidat záznam) ---------- */
.collapsible {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}
.collapsible-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  font-size: 1.02rem;
}
.collapsible-header .chev {
  transition: transform var(--transition);
  font-size: 1.1rem;
}
.collapsible.open .collapsible-header .chev { transform: rotate(180deg); }
.collapsible-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease;
}
.collapsible.open .collapsible-body {
  max-height: 12000px;
}
.collapsible-inner { padding: 18px; }

/* ---------- Form ---------- */
.section {
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 12px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--header-bg);
}
.section-title .actions { display: flex; gap: 6px; }

.field {
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
}
.field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 5px;
}
.field input[type="text"],
.field input[type="number"],
.field input[type="date"],
.field input[type="password"],
.field input[type="email"],
.field input[type="tel"],
.field select,
.field textarea {
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  transition: border var(--transition), box-shadow var(--transition);
  width: 100%;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(232, 122, 31, 0.15);
}
.field textarea { resize: vertical; min-height: 60px; }

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

/* Multi-select chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  padding: 6px 12px;
  border-radius: 20px;
  background: #fff;
  border: 1.5px solid var(--border-strong);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}
.chip:hover { border-color: var(--primary); }
.chip.selected {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Repeater (multi-instance subgroup) */
.repeater-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 10px;
  position: relative;
}
.repeater-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.repeater-item-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.subgroup {
  background: var(--bg);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 37, 53, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  animation: fadeIn 0.18s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  animation: slideUp 0.22s cubic-bezier(.4,.0,.2,1);
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 1.1rem; }
.modal-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 6px;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.modal-footer .spacer { flex: 1; min-width: 0; }

/* Read-only view */
.readonly-section {
  margin-bottom: 18px;
}
.readonly-section h4 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  color: var(--primary);
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}
.readonly-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 0.9rem;
  margin-bottom: 4px;
}
.readonly-row .k { color: var(--text-muted); min-width: 130px; }
.readonly-row .v { color: var(--text); font-weight: 500; word-break: break-word; }
.readonly-empty { color: var(--text-muted); font-style: italic; font-size: 0.88rem; }

/* AI export box */
.ai-export-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
  max-height: 280px;
  overflow-y: auto;
  margin-bottom: 12px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--header-bg);
  color: #fff;
  padding: 12px 22px;
  border-radius: 24px;
  font-size: 0.92rem;
  z-index: 200;
  transition: transform 0.3s cubic-bezier(.4,.0,.2,1);
  box-shadow: 0 6px 24px rgba(0,0,0,0.25);
  max-width: 90vw;
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ---------- Save bar ---------- */
.save-bar {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

/* ---------- Building list ---------- */
.building-list { display: flex; flex-direction: column; gap: 10px; }

/* ---------- History ---------- */
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
}
.history-card:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}
.history-card .date {
  font-weight: 600;
  color: var(--text);
}
.history-card .arrow { color: var(--primary); font-size: 1.2rem; }

/* ---------- Section heading ---------- */
.section-heading {
  margin: 4px 0 12px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--header-bg);
  letter-spacing: 0.2px;
}

/* ---------- Login ---------- */
.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #0a2535 0%, #143447 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}
.login-card {
  background: #fff;
  border-radius: 14px;
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.login-title {
  margin: 0 0 4px;
  font-size: 1.5rem;
  color: var(--header-bg);
  text-align: center;
}
.login-sub {
  margin: 0 0 22px;
  color: var(--text-muted);
  text-align: center;
  font-size: 0.92rem;
}
.login-error {
  background: #fde6e2;
  color: var(--danger);
  border: 1px solid #f5c4bc;
  padding: 8px 12px;
  border-radius: 7px;
  font-size: 0.88rem;
  margin-top: 6px;
}

/* Hide app shell until authed */
body:not(.authed) .app-header,
body:not(.authed) .sidebar,
body:not(.authed) .sidebar-backdrop,
body:not(.authed) .main {
  display: none !important;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .app-title { font-size: 1rem; }
  .main { padding-left: 12px; padding-right: 12px; }
  .card-body, .collapsible-inner { padding: 14px; }
  .btn { padding: 9px 14px; font-size: 0.9rem; }
  .modal { max-height: 95vh; }
}

@media (min-width: 1100px) {
  .main { max-width: 1000px; }
}
