:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #18202a;
  --muted: #687386;
  --line: #dfe4ea;
  --primary: #176b87;
  --primary-dark: #0f5369;
  --ok: #137a46;
  --warn: #986500;
  --danger: #b42318;
  --info: #185abc;
  font-family: Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

a {
  color: var(--primary);
}

.shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
}

header {
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 3;
}

.topbar {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  min-height: 64px;
}

.brand {
  font-size: 20px;
  font-weight: 700;
}

.subtitle {
  color: var(--muted);
  font-size: 13px;
}

.actions,
.filters,
.forms {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

main {
  padding: 24px 0 48px;
}

.metrics {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  margin-bottom: 18px;
  overflow-x: auto;
  align-items: stretch;
}

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

.metric {
  padding: 8px;
  min-width: 120px;
  width: 120px;
  flex: 0 0 120px;
}

.metric strong {
  display: block;
  font-size: 18px;
  margin-bottom: 2px;
}

.metric span,
.empty,
.hint {
  color: var(--muted);
  font-size: 11px;
}

.metric span,
.empty,
.hint {
  color: var(--muted);
  font-size: 13px;
}

.panel {
  margin-bottom: 18px;
  padding: 16px;
}

.panel h2 {
  font-size: 18px;
  margin: 0 0 14px;
}

label {
  color: #303a46;
  display: grid;
  flex: 1 1 170px;
  font-size: 13px;
  gap: 6px;
}

input,
select,
textarea,
button {
  border-radius: 6px;
  font: inherit;
}

input,
select,
textarea {
  background: #fff;
  border: 1px solid #cbd3dc;
  color: var(--text);
  min-height: 40px;
  padding: 8px 10px;
  width: 100%;
}

select {
  font-size: 11px;
  padding: 5px 8px;
  min-height: 34px;
}

select option {
  font-size: 11px;
  padding: 3px 6px;
}

textarea {
  min-height: 82px;
  resize: vertical;
}

button,
.button {
  align-items: center;
  background: var(--primary);
  border: 1px solid var(--primary);
  color: white;
  cursor: pointer;
  display: inline-flex;
  font-weight: 700;
  justify-content: center;
  min-height: 40px;
  padding: 9px 14px;
  text-decoration: none;
}

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

.button.secondary {
  background: #ffffff;
  color: var(--primary);
}

.button.small {
  font-size: 12px;
  min-height: 32px;
  padding: 6px 10px;
}

.notice {
  background: #e7f4ec;
  border: 1px solid #b9dfc8;
  border-radius: 8px;
  color: #14532d;
  margin-bottom: 18px;
  padding: 12px 14px;
}

.table-wrap {
  overflow-x: visible;
}

.tab-content[data-tab="needs"] .table-wrap table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 12px;
}

.tab-content[data-tab="needs"] .table-wrap th,
.tab-content[data-tab="needs"] .table-wrap td {
  border-bottom: 1px solid var(--line);
  padding: 6px 5px;
  text-align: left;
  vertical-align: top;
  white-space: normal;
  word-break: break-word;
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 10px;
  text-align: left;
  vertical-align: top;
}

th.col-actions,
td.col-actions {
  width: 96px;
}

th.col-role,
td.col-role {
  width: 80px;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.badge {
  border-radius: 999px;
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
  white-space: nowrap;
}

.missing-badge {
  cursor: pointer;
}

.badge.ok {
  background: #dcfce7;
  color: var(--ok);
}

.badge.warn {
  background: #fff3cd;
  color: var(--warn);
}

.badge.danger {
  background: #fee4e2;
  color: var(--danger);
}

.badge.info {
  background: #dbeafe;
  color: var(--info);
}

.badge.muted {
  background: #eef2f6;
  color: var(--muted);
}

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

.form-actions {
  align-self: end;
  flex: 0 0 auto;
}

.mobile-cards {
  display: none;
}

.card {
  padding: 14px;
}

.modal {
  display: none;
}

.modal.active {
  display: block;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 20;
}

.modal-content {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 21;
  width: min(720px, calc(100% - 32px));
  max-height: 90vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px 24px 18px;
  box-shadow: 0 24px 72px rgba(0, 0, 0, 0.18);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.modal-title {
  margin: 0 0 14px;
  font-size: 18px;
}

.modal-body p {
  margin: 0 0 12px;
  line-height: 1.5;
}

.modal-body strong {
  display: inline-block;
  min-width: 110px;
}

.card + .card {
  margin-top: 10px;
}

.tabs-header {
  margin-bottom: 18px;
}

.tabs-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.tab-button {
  border: 1px solid transparent;
  background: #f9fafb;
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}

.tab-button.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.tab-button.tab-alert {
  background: #fef2f2;
  color: var(--danger);
  border-color: #fecaca;
}

.tab-button.tab-alert:hover {
  background: #fee2e2;
}

.tab-button.tab-alert.active {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.desktop-table {
  display: block;
}

@media (max-width: 900px) {
  .shell {
    width: min(100%, calc(100% - 16px));
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .actions {
    justify-content: flex-end;
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
  }

  .tabs-nav {
    justify-content: flex-start;
    overflow-x: auto;
    padding: 10px 8px;
  }

  .tab-button {
    flex: 1 1 auto;
    min-width: 140px;
  }

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

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

  .desktop-table {
    display: none;
  }

  .mobile-cards {
    display: block;
  }
}

@media (max-width: 560px) {
  .metrics {
    grid-template-columns: 1fr;
  }

  .tab-button {
    min-width: 100%;
  }

  .actions {
    justify-content: space-between;
  }
}

.card-title {
  display: flex;
  gap: 8px;
  justify-content: space-between;
  margin-bottom: 8px;
}

.meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.detail-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
}

.detail-notes {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.detail-notes h3 {
  font-size: 14px;
  margin: 10px 0 6px;
}

.detail-notes p {
  margin: 0 0 10px;
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    padding: 12px 0;
  }

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

  .desktop-table {
    display: none;
  }

  .mobile-cards {
    display: block;
  }

  .forms,
  .filters {
    display: grid;
    grid-template-columns: 1fr;
  }

  label,
  .form-actions,
  button,
  .button {
    width: 100%;
  }

  .tabs-nav {
    overflow-x: auto;
    gap: 8px;
  }

  .tab-button {
    font-size: 13px;
    padding: 8px 12px;
    min-width: 90px;
  }
}

/* Tabs styling */
.tabs-header {
  background: var(--panel);
  border-bottom: 2px solid var(--line);
  margin-bottom: 18px;
  position: sticky;
  top: 64px;
  z-index: 2;
}

.tabs-nav {
  display: flex;
  gap: 0;
  overflow-x: auto;
  padding: 0;
  -webkit-overflow-scrolling: touch;
}

.tab-button {
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  cursor: pointer;
  display: inline-block;
  font-size: 14px;
  font-weight: 600;
  min-height: auto;
  padding: 12px 16px;
  text-decoration: none;
  white-space: nowrap;
  margin: 0;
}

.tab-button:hover {
  background: rgba(23, 107, 135, 0.05);
  color: var(--text);
}

.tab-button.active {
  border-bottom-color: var(--primary);
  color: var(--text);
}

.tab-button.tab-alert {
  color: var(--danger);
}

.tab-button.tab-alert.active {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.2s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}
