:root {
  --color-brand-blue: #005794;
  --color-brand-blue-hover: #004a80;
  --color-brand-blue-active: #003f6d;
  --color-brand-blue-soft: #e8f1f8;
  --color-brand-blue-muted: #2e5b8a;
  --color-bg-page: #f6f7f9;
  --color-bg-surface: #ffffff;
  --color-bg-muted: #f1f3f5;
  --color-border: #e5e7eb;
  --color-border-strong: #d8dce1;
  --color-text-primary: #111111;
  --color-text-secondary: #3f3f3f;
  --color-text-muted: #8b8b8b;
  --color-text-on-blue: #ffffff;
  --color-danger: #b4233c;
  --color-danger-soft: #fff1f3;
  --color-warning: #b7791f;
  --color-success: #177245;
  --sidebar-width: 220px;
  --header-height: 60px;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  font-family: Montserrat, "SF Pro Display", "SF Pro Text", system-ui,
    -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--color-text-primary);
  background: var(--color-bg-page);
  font-size: 14px;
  line-height: 1.4;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: var(--color-bg-page);
}

.login-panel {
  width: min(420px, 100%);
  padding: 28px;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.login-logo {
  width: 178px;
  max-width: 100%;
  display: block;
  margin-bottom: 24px;
}

.login-title {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 600;
  line-height: 1.2;
}

.login-subtitle {
  margin: 0 0 20px;
  color: var(--color-text-secondary);
  line-height: 1.45;
}

.login-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 12px;
  background: var(--color-bg-surface);
  border-right: 1px solid var(--color-border);
}

.brand {
  padding: 2px 8px 10px;
  border-bottom: 1px solid var(--color-border);
}

.brand img {
  width: 160px;
  max-width: 100%;
  display: block;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-button {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  color: var(--color-text-secondary);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  font-weight: 600;
  text-align: left;
}

.nav-button:hover {
  color: var(--color-text-primary);
  background: var(--color-bg-muted);
}

.nav-button.is-active {
  color: var(--color-text-on-blue);
  background: var(--color-brand-blue);
  border-color: var(--color-brand-blue);
}

.sidebar-footer {
  margin-top: auto;
}

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

.topbar {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 24px;
  background: var(--color-bg-surface);
  border-bottom: 1px solid var(--color-border);
}

.topbar h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 600;
  line-height: 1.2;
}

.content {
  width: 100%;
  max-width: none;
  padding: 18px 24px 32px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.status-line {
  min-height: 16px;
  margin: 0 0 10px;
  color: var(--color-text-muted);
  font-size: 13px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1040px;
}

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

.data-table th {
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

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

.entity-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
}

.thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  background: var(--color-bg-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  flex: 0 0 auto;
}

.thumb-frame,
.image-preview,
.detail-image-frame,
.participant-avatar {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  flex: 0 0 auto;
}

.thumb-frame {
  width: 52px;
  height: 52px;
}

.thumb-frame img,
.image-preview img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.thumb-frame.avatar {
  border-radius: 999px;
}

.thumb-frame.avatar img {
  border-radius: inherit;
}

.image-placeholder {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  background: var(--color-bg-muted);
}

.thumb-frame.is-empty .image-placeholder,
.thumb-frame.is-broken .image-placeholder,
.image-preview.is-empty .image-placeholder,
.image-preview.is-broken .image-placeholder,
.detail-image-frame.is-empty .image-placeholder,
.detail-image-frame.is-broken .image-placeholder,
.participant-avatar.is-empty .image-placeholder,
.participant-avatar.is-broken .image-placeholder {
  display: flex;
}

.image-strip {
  display: flex;
  align-items: center;
  gap: 5px;
}

.image-strip .thumb-frame {
  width: 34px;
  height: 34px;
}

.avatar {
  border-radius: 999px;
}

.entity-title {
  display: -webkit-box;
  overflow: hidden;
  color: var(--color-text-primary);
  font-weight: 600;
  line-height: 1.25;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.link-button {
  width: 100%;
  padding: 0;
  text-align: left;
  background: transparent;
  border: 0;
}

.link-button:hover {
  color: var(--color-brand-blue);
}

.entity-meta {
  display: -webkit-box;
  overflow: hidden;
  margin-top: 4px;
  color: var(--color-text-secondary);
  font-size: 12px;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.contact-value {
  display: block;
  max-width: 220px;
  overflow: hidden;
  color: var(--color-text-secondary);
  font-size: 12px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  white-space: nowrap;
}

.button {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 12px;
  color: var(--color-text-primary);
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  font-weight: 600;
  text-decoration: none;
}

.button:hover {
  background: var(--color-bg-muted);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.button.primary {
  color: var(--color-text-on-blue);
  background: var(--color-brand-blue);
  border-color: var(--color-brand-blue);
}

.button.primary:hover {
  background: var(--color-brand-blue-hover);
  border-color: var(--color-brand-blue-hover);
}

.button.danger {
  color: var(--color-danger);
  border-color: #f3c4cd;
  background: var(--color-danger-soft);
}

.button.icon-only {
  width: 34px;
  padding: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  color: var(--color-brand-blue);
  background: var(--color-brand-blue-soft);
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-free {
  color: #805600;
  background: #fff2bf;
}

.badge-resident {
  color: var(--color-brand-blue);
  background: var(--color-brand-blue-soft);
}

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

.field label {
  color: var(--color-text-secondary);
  font-size: 12px;
  font-weight: 600;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  color: var(--color-text-primary);
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  outline: none;
}

.toolbar-select {
  width: 190px;
  max-width: 100%;
}

.toolbar-search {
  width: 250px;
}

.textarea {
  min-height: 96px;
  padding: 9px 10px;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--color-brand-blue);
  box-shadow: 0 0 0 3px var(--color-brand-blue-soft);
}

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

.image-manager {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.image-manager-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.image-manager-header label {
  color: var(--color-text-primary);
  font-size: 13px;
  font-weight: 600;
}

.image-manager-header p {
  margin: 4px 0 0;
  color: var(--color-text-muted);
  font-size: 12px;
  line-height: 1.35;
}

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

.image-tile {
  min-width: 0;
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 8px;
  padding: 7px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.image-preview {
  width: 78px;
  height: 58px;
}

.image-tile-info {
  min-width: 0;
}

.image-tile-info a {
  display: block;
  overflow: hidden;
  color: var(--color-text-secondary);
  font-size: 12px;
  line-height: 1.35;
  text-overflow: ellipsis;
  text-decoration: none;
  white-space: nowrap;
}

.image-tile-info a:hover {
  color: var(--color-brand-blue);
  text-decoration: underline;
}

.image-empty {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--color-text-muted);
  background: var(--color-bg-muted);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
}

.image-controls {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) auto auto;
  gap: 8px;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.image-manager.is-loading {
  opacity: 0.72;
  pointer-events: none;
}

.detail-view {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
}

.detail-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.detail-layout {
  padding: 20px;
}

.detail-layout-with-sidebar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 18px;
  align-items: start;
}

.detail-main {
  max-width: 920px;
}

.detail-image-frame {
  width: 100%;
  background: var(--color-bg-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.detail-image-frame img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.detail-hero {
  height: clamp(220px, 30vw, 380px);
  margin-bottom: 20px;
}

.detail-kicker {
  margin-bottom: 8px;
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}

.detail-title {
  max-width: 860px;
  margin: 0;
  font-size: 28px;
  font-weight: 600;
  line-height: 1.18;
  letter-spacing: 0;
}

.detail-lead {
  max-width: 820px;
  margin: 12px 0 0;
  color: var(--color-text-secondary);
  font-size: 16px;
  line-height: 1.5;
}

.detail-meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 18px;
}

.detail-field {
  min-height: 64px;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 12px;
  background: var(--color-bg-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.detail-field span {
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.detail-field strong {
  color: var(--color-text-primary);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
}

.detail-text {
  max-width: 820px;
  margin-top: 20px;
  color: var(--color-text-primary);
  font-size: 15px;
  line-height: 1.65;
}

.detail-text p {
  margin: 0 0 14px;
}

.detail-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 22px;
}

.detail-gallery-item {
  aspect-ratio: 4 / 3;
}

.detail-sidebar {
  position: sticky;
  top: calc(var(--header-height) + 18px);
  display: grid;
  gap: 10px;
  padding: 12px;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.detail-sidebar h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

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

.participant-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.participant-avatar {
  width: 36px;
  height: 36px;
  border-radius: 999px;
}

.participant-avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border-radius: inherit;
}

.participant-name {
  min-width: 0;
  color: var(--color-text-primary);
  font-weight: 600;
  line-height: 1.25;
}

.participant-empty {
  padding: 18px 10px;
  color: var(--color-text-muted);
  background: var(--color-bg-muted);
  border-radius: var(--radius-md);
  text-align: center;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(17, 17, 17, 0.36);
}

.dialog {
  width: min(720px, 100%);
  max-height: min(820px, 92vh);
  display: flex;
  flex-direction: column;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.dialog-header,
.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
}

.dialog-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.dialog-body {
  display: grid;
  gap: 12px;
  overflow: auto;
  padding: 16px;
}

.dialog-footer {
  justify-content: flex-end;
  border-top: 1px solid var(--color-border);
  border-bottom: 0;
}

.empty {
  padding: 36px 20px;
  color: var(--color-text-muted);
  text-align: center;
}

.error {
  color: var(--color-danger);
}

.muted {
  color: var(--color-text-muted);
}

.hidden {
  display: none !important;
}

@media (max-width: 1100px) {
  .detail-layout-with-sidebar {
    grid-template-columns: 1fr;
  }

  .detail-sidebar {
    position: static;
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 16px;
  }

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

  .nav-button {
    justify-content: center;
  }

  .sidebar-footer {
    display: none;
  }

  .topbar {
    padding: 0 16px;
  }

  .content {
    padding: 16px;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .image-controls {
    grid-template-columns: 1fr;
  }

  .image-tile {
    grid-template-columns: 74px minmax(0, 1fr) 34px;
  }

  .image-preview {
    width: 74px;
  }

  .detail-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .detail-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .detail-layout {
    padding: 16px;
  }

  .detail-layout-with-sidebar {
    grid-template-columns: 1fr;
  }

  .detail-sidebar {
    position: static;
  }

  .detail-title {
    font-size: 26px;
  }

  .detail-hero {
    height: 240px;
  }

  .detail-meta-grid {
    grid-template-columns: 1fr;
  }
}
