/* === Reset minimo === */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: 0;
  background: transparent;
}

input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
}

/* === Variables === */
:root {
  --primary: #1e3a8a;
  --primary-hover: #1e40af;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --bg: #f9fafb;
  --bg-card: #ffffff;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --radius: 8px;
}

html,
body {
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
}

h1,
h2,
h3 {
  font-weight: 600;
  line-height: 1.25;
}

h1 {
  font-size: 1.5rem;
}

h2 {
  font-size: 1.15rem;
}

h3 {
  font-size: 1rem;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.hidden {
  display: none !important;
}

/* === Buttons === */
.btn-primary,
.btn-secondary,
.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  transition: background-color 0.15s ease, transform 0.05s ease;
  white-space: nowrap;
}

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

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

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: #f3f4f6;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-block {
  width: 100%;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* === Inputs === */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input:not([type]),
select,
textarea {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.15);
}

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

label > span {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  font-size: 13px;
  color: var(--text);
}

/* === Login view === */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
}

.login-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.login-card h1 {
  margin-bottom: 8px;
  color: var(--primary);
}

.login-card p {
  margin-bottom: 24px;
}

#login-form label {
  display: block;
  margin-bottom: 16px;
}

#login-form button {
  margin-top: 8px;
}

/* === Dashboard view === */
.topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  box-shadow: var(--shadow-sm);
}

.brand {
  font-weight: 600;
  font-size: 16px;
  color: var(--primary);
}

.user-info {
  flex: 1;
  text-align: right;
  font-size: 13px;
}

.user-line {
  margin-bottom: 2px;
}

.roles {
  margin-top: 4px;
  display: flex;
  gap: 4px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.role-pill {
  display: inline-block;
  padding: 2px 8px;
  background: #eef2ff;
  color: var(--primary);
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* === Cards === */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

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

/* === Health services grid === */
.services-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.service-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.service-card .name {
  font-weight: 600;
  font-size: 13px;
  text-transform: capitalize;
}

.service-card .latency {
  font-size: 12px;
  color: var(--text-muted);
}

/* === Badges === */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  width: fit-content;
}

.badge-ok {
  background: #d1fae5;
  color: #065f46;
}

.badge-error {
  background: #fee2e2;
  color: #991b1b;
}

.badge-warn {
  background: #fef3c7;
  color: #92400e;
}

.badge-neutral {
  background: #e5e7eb;
  color: #374151;
}

/* === Filters === */
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

/* === Table === */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead {
  background: #f3f4f6;
}

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

th {
  font-weight: 600;
  color: var(--text);
}

tbody tr:hover {
  background: #f9fafb;
}

tbody tr:last-child td {
  border-bottom: 0;
}

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

.row-actions button {
  padding: 5px 10px;
  font-size: 12px;
}

/* === Empty state === */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* === Pagination === */
.pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.pagination .page-size-label {
  margin-left: auto;
}

.pagination select {
  width: auto;
  padding: 6px 10px;
}

/* === Banner === */
.banner {
  padding: 12px 16px;
  background: var(--danger);
  color: #fff;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.banner.banner-warn {
  background: var(--warning);
}

.banner .banner-close {
  background: transparent;
  color: #fff;
  font-weight: 700;
  padding: 0 6px;
}

/* === Toast === */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 18px;
  background: var(--success);
  color: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-weight: 500;
  z-index: 2000;
  animation: slide-in 0.2s ease;
}

.toast.toast-error {
  background: var(--danger);
}

@keyframes slide-in {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* === Modal === */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  background: var(--bg-card);
  border-radius: 12px;
  width: 100%;
  max-width: 540px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-body {
  padding: 20px 24px;
}

.modal-body label {
  display: block;
  margin-bottom: 14px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* === Responsive (mobile) === */
@media (max-width: 768px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    text-align: left;
  }

  .user-info {
    text-align: left;
  }

  .roles {
    justify-content: flex-start;
  }

  .container {
    padding: 16px;
  }

  .section-header {
    flex-direction: column;
    align-items: stretch;
  }

  .modal {
    padding: 0;
  }

  .modal-content {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }

  .pagination {
    justify-content: center;
  }

  .pagination .page-size-label {
    margin-left: 0;
    width: 100%;
    text-align: center;
  }
}
