/* Buttons ---------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all 120ms ease;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { 
  background: var(--gradient-verdant);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 190, 100, 0.3);
}
.btn-primary:hover:not(:disabled) { 
  filter: brightness(1.05);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 190, 100, 0.4);
}
.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-secondary { 
  background: var(--surface); 
  color: var(--ink); 
  border-color: var(--line-strong);
  box-shadow: 0 1px 0 rgba(0,0,0,0.05);
}
.btn-secondary:hover:not(:disabled) { 
  background: var(--paper);
  border-color: var(--ink-faint);
  transform: translateY(-1px);
}

.btn-attention { 
  background: var(--ember); 
  color: #3a1c00;
  box-shadow: 0 2px 8px rgba(230, 110, 40, 0.3);
}
.btn-attention:hover:not(:disabled) { 
  filter: brightness(1.05);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(230, 110, 40, 0.4);
}

.btn-danger { 
  background: var(--surface); 
  color: var(--danger); 
  border-color: var(--danger);
}
.btn-danger:hover:not(:disabled) { 
  background: var(--danger-tint);
  transform: translateY(-1px);
}

.btn-ghost { 
  background: transparent; 
  color: var(--ink-soft); 
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) { 
  background: var(--paper); 
  color: var(--ink);
}

.btn-sm { 
  padding: var(--space-1) var(--space-3); 
  font-size: var(--text-xs);
}

.btn i {
  font-size: var(--text-base);
  opacity: 0.9;
}

/* Forms ------------------------------------------------------------------- */
label { 
  display: block; 
  font-size: var(--text-sm); 
  font-weight: 600; 
  margin-bottom: var(--space-1);
  color: var(--ink);
}
.field { 
  margin-bottom: var(--space-4);
  position: relative;
}
.field-hint { 
  font-size: var(--text-xs); 
  color: var(--ink-faint); 
  margin-top: var(--space-1);
}
.field-error { 
  font-size: var(--text-xs); 
  color: var(--danger); 
  margin-top: var(--space-1);
}

input, select, textarea {
  width: 100%;
  font-size: var(--text-base);
  font-family: inherit;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--verdant);
  outline: none;
  box-shadow: 0 0 0 3px var(--verdant-tint);
}
input::placeholder, textarea::placeholder {
  color: var(--ink-faint);
}
textarea { 
  resize: vertical; 
  min-height: 80px;
}

.form-row { 
  display: grid; 
  grid-template-columns: 1fr 1fr; 
  gap: var(--space-4);
}
@media (max-width: 640px) { 
  .form-row { 
    grid-template-columns: 1fr; 
  } 
}

/* Panels (dashboard summary blocks — flat, accent bar, NOT a rounded-card-
   with-shadow grid; see design plan) --------------------------------------- */
.panel {
  background: var(--surface-glass);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line-strong);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  transition: all 200ms ease;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  opacity: 0;
  transition: opacity 200ms ease;
}
.panel:hover {
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  transform: translateY(-4px);
  border-left-color: var(--verdant);
  background: var(--surface);
}
.panel:hover::before {
  opacity: 1;
}
.panel-positive { border-left-color: var(--verdant); }
.panel-attention { border-left-color: var(--ember); }

/* Dashboard card icon styling */
.panel-icon {
  font-size: 1.75rem;
  color: var(--verdant);
  margin-bottom: var(--space-3);
  display: block;
  opacity: 0.9;
  transition: all 200ms ease;
}
.panel:hover .panel-icon {
  transform: scale(1.1) rotate(5deg);
  filter: drop-shadow(0 4px 8px rgba(0, 190, 100, 0.4));
}
.panel-positive .panel-icon { 
  color: var(--verdant);
  filter: drop-shadow(0 2px 4px rgba(0, 190, 100, 0.2));
}
.panel-attention .panel-icon { 
  color: var(--ember);
  filter: drop-shadow(0 2px 4px rgba(230, 110, 40, 0.2));
  font-size: 1.25rem;
  color: var(--verdant);
  margin-bottom: var(--space-3);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--verdant-tint);
  opacity: 1;
}
.panel-positive .panel-icon { 
  color: var(--verdant); 
  background: var(--verdant-tint);
}
.panel-attention .panel-icon { 
  color: var(--ember); 
  background: var(--ember-tint);
}

.dashboard-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
  height: 100%;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
@media (max-width: 1100px) {
  .metric-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (max-width: 640px) {
  .metric-grid {
    grid-template-columns: 1fr;
  }
}
.metric-value { 
  font-size: 32px; 
  font-weight: 700; 
  letter-spacing: -0.02em; 
  font-family: var(--font-mono);
  line-height: 1;
  background: var(--gradient-verdant);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
  color: var(--ink);
}
.metric-label { 
  font-size: 13px; 
  color: var(--ink-soft); 
  margin-top: var(--space-2);
  line-height: 1.4;
  font-weight: 500;
}

/* Tables — the primary content surface for this app ------------------------ */
.table-wrap { 
  border: 1px solid var(--line); 
  border-radius: var(--radius-md); 
  overflow: hidden; 
  background: var(--surface-glass);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  box-shadow: 0 1px 0 rgba(0,0,0,0.02);
  margin-bottom: var(--space-6);
}
table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
thead th {
  text-align: left;
  font-weight: 600;
  color: var(--ink-soft);
  padding: var(--space-4) var(--space-5);
  border-bottom: 2px solid var(--line);
  background: linear-gradient(180deg, var(--paper) 0%, var(--surface) 100%);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  position: relative;
}
thead th::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--verdant-tint), transparent);
  opacity: 0;
}
tbody td { 
  padding: var(--space-4) var(--space-5); 
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  transition: background-color 80ms ease;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { 
  background: var(--paper); 
  cursor: pointer;
  transition: background-color 80ms ease;
}
tbody tr:hover td:first-child {
  border-left: 3px solid var(--verdant);
  padding-left: calc(var(--space-4) - 3px);
}
td.num, th.num { 
  text-align: right; 
  font-family: var(--font-mono); 
  font-variant-numeric: tabular-nums; 
}

/* Badges — status/stage indicators ----------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px var(--space-2);
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.badge i {
  font-size: 10px;
  opacity: 0.8;
}
.badge-neutral { 
  background: linear-gradient(135deg, var(--paper) 0%, var(--surface) 100%);
  color: var(--ink-soft); 
  border: 1px solid var(--line-strong); 
}
.badge-positive { 
  background: linear-gradient(135deg, var(--verdant-tint) 0%, var(--verdant-light) 100%);
  color: var(--verdant-dark);
  border: 1px solid var(--verdant);
}
.badge-attention { 
  background: linear-gradient(135deg, var(--ember-tint) 0%, var(--ember-light) 100%);
  color: var(--ember-dark);
  border: 1px solid var(--ember);
}
.badge-danger { 
  background: linear-gradient(135deg, var(--danger-tint) 0%, #fee2e2 100%);
  color: var(--danger);
  border: 1px solid var(--danger);
}

/* Empty states — an invitation to act, not an apology (per writing guidance) */
.empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-5);
  color: var(--ink-soft);
  background: var(--surface-glass);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  border: 2px dashed var(--line);
  border-radius: var(--radius-md);
}
.empty-state .h-section { 
  color: var(--ink); 
  margin-bottom: var(--space-2); 
}
.empty-state i {
  font-size: 3rem;
  color: var(--ink-faint);
  margin-bottom: var(--space-4);
  display: block;
  opacity: 0.5;
}

/* Toasts ------------------------------------------------------------------- */
#toast-region { position: fixed; bottom: var(--space-5); right: var(--space-5); display: flex; flex-direction: column; gap: var(--space-2); z-index: 100; }
.toast {
  background: var(--ink); color: #fff; padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md); font-size: var(--text-sm); 
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  max-width: 360px; display: flex; align-items: center; gap: var(--space-2); justify-content: space-between;
  animation: slideInRight 300ms ease-out;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
.toast i {
  font-size: var(--text-lg);
  opacity: 0.9;
}
.toast.is-error { 
  background: linear-gradient(135deg, var(--danger) 0%, #dc2626 100%);
  box-shadow: 0 8px 24px rgba(220, 38, 38, 0.3);
}
.toast.is-success { 
  background: linear-gradient(135deg, var(--verdant-dark) 0%, var(--verdant) 100%);
  box-shadow: 0 8px 24px rgba(0, 190, 100, 0.3);
}
.toast-action {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease;
}
.toast-action:hover { background: rgba(255,255,255,0.3); }

/* Modal / slide-over drawer (used for create/edit forms) -------------------- */
.overlay {
  position: fixed; inset: 0; background: rgba(20,24,26,0.4);
  display: flex; justify-content: flex-end; z-index: 50;
}
.overlay[hidden] { display: none; }
.drawer {
  background: var(--surface);
  width: min(480px, 100vw);
  height: 100%;
  padding: var(--space-6);
  overflow-y: auto;
  box-shadow: var(--shadow-raised);
}
.drawer-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-5); }
.drawer-wide {
  width: min(720px, 95vw);
}

/* Form sections for grouped fields */
.form-section {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
}
.form-section-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin: 0 0 var(--space-4) 0;
}
.required {
  color: var(--danger);
  margin-left: 2px;
}

/* Facility detail tabs */
.facility-tabs {
  margin-top: var(--space-6);
}
.tab-buttons {
  display: flex;
  gap: var(--space-2);
  border-bottom: 1px solid var(--line);
  padding-bottom: var(--space-2);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}
.tab-btn {
  padding: var(--space-2) var(--space-4);
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: all 120ms ease;
}
.tab-btn:hover {
  background: var(--paper);
  color: var(--ink);
}
.tab-btn.is-active {
  background: var(--verdant-tint);
  color: var(--verdant-dark);
  font-weight: 600;
}
.tab-content {
  animation: fadeIn 180ms ease-out;
}
.tab-content[hidden] { display: none; }

/* Detail page info grids */
.detail-section {
  margin-bottom: var(--space-6);
}
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
}
.info-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.info-item-full {
  grid-column: 1 / -1;
}
.info-label {
  font-size: var(--text-xs);
  color: var(--ink-faint);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.info-value {
  font-size: var(--text-base);
  color: var(--ink);
}
.notes-content {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  white-space: pre-wrap;
  line-height: 1.6;
}

/* --- Quick activity logger: always-available, one tap, per spec's core UX
   rule ("under one minute"). Fixed to the bottom-right on every app view. -- */
#quick-log-trigger {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  z-index: 30;
  border-radius: 999px;
  padding: var(--space-3) var(--space-5);
  box-shadow: var(--shadow-raised);
}

/* Dropdown menus ---------------------------------------------------------- */
.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-raised);
  min-width: 180px;
  z-index: 50;
  overflow: hidden;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border: none;
  text-align: left;
  font-size: var(--text-sm);
  color: var(--ink);
  cursor: pointer;
  transition: background 120ms ease;
}

.dropdown-item:hover {
  background: var(--ink-faint);
}

.dropdown-item i {
  width: 16px;
  text-align: center;
  color: var(--ink-faint);
}

/* Entity selectors -------------------------------------------------------- */
.entity-selector {
  position: relative;
}

.selector-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.selector-trigger:hover {
  border-color: var(--ink-faint);
}

.selector-trigger:focus-within {
  border-color: var(--verdant);
  box-shadow: 0 0 0 2px var(--verdant-faint);
}

.selector-value {
  flex: 1;
  color: var(--ink);
  font-size: var(--text-sm);
}

.selector-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-raised);
  max-height: 280px;
  overflow-y: auto;
  z-index: 50;
}

.selector-option {
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  border-bottom: 1px solid var(--line-faint);
  transition: background 120ms ease;
}

.selector-option:hover {
  background: var(--ink-faint);
}

.selector-option:last-child {
  border-bottom: none;
}

/* Progress bars — KPI completion visualization ------------------------------ */
.progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--verdant);
  transition: width 200ms ease;
}
.progress-fill.is-at-risk { background: var(--ember); }
.progress-fill.is-off-track { background: var(--danger); }

/* Login screen — the one bold moment ---------------------------------------- */
#login-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
#login-screen[hidden] { display: none; }
@media (max-width: 780px) { #login-screen { grid-template-columns: 1fr; } }

.login-brand {
  background: var(--ink);
  color: #fff;
  padding: var(--space-8);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.login-brand .brand-mark span { font-size: var(--text-md); }
.login-brand-statement { font-size: var(--text-2xl); font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; max-width: 20ch; }
.login-brand-sub { color: rgba(255,255,255,0.65); font-size: var(--text-sm); max-width: 34ch; }

.login-form-wrap {
  display: flex; align-items: center; justify-content: center; padding: var(--space-6);
}
.login-form { width: 100%; max-width: 340px; }
.login-form .h-page { margin-bottom: var(--space-6); }

@media (max-width: 780px) { .login-brand { display: none; } }
