/* ═══════════════════════════════════════════════════
   R-TRACK Design System — Modern Healthcare UI
   ═══════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@500;600;700&display=swap');

/* ─── CSS Variables ─── */
:root {
  --primary: #059669;
  --primary-light: #10b981;
  --primary-dark: #047857;
  --primary-50: #ecfdf5;
  --accent: #3b82f6;
  --accent-light: #60a5fa;
  --accent-dark: #2563eb;
  --danger: #ef4444;
  --danger-light: #fca5a5;
  --warning: #f59e0b;
  --warning-light: #fde68a;
  --info: #06b6d4;
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: #059669;
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #ffffff;
  --content-bg: #f1f5f9;
  --card-bg: #ffffff;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --transition: all 0.2s ease;
  --sidebar-width: 260px;
  --sidebar-collapsed: 72px;
  --header-height: 64px;
}

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

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--content-bg);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* ─── Layout ─── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.3s ease;
}

.content-area {
  flex: 1;
  padding: 24px 32px;
  max-width: 1400px;
  width: 100%;
}

/* ─── Sidebar ─── */
.sidebar {
  position: fixed;
  left: 0; top: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: width 0.3s ease;
  overflow: hidden;
}

.sidebar-brand {
  padding: 20px 20px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-brand img { height: 36px; border-radius: 6px; }

.sidebar-brand .brand-text {
  color: #f8fafc;
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.sidebar-brand .brand-sub {
  font-size: 0.7rem;
  color: var(--sidebar-text);
  font-weight: 400;
  font-family: 'Inter', sans-serif;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  overflow-y: auto;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--sidebar-hover); border-radius: 4px; }

.nav-section {
  margin-bottom: 6px;
}

.nav-section-title {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--sidebar-text);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 12px 14px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 450;
  transition: var(--transition);
  margin-bottom: 2px;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #e2e8f0;
}

.nav-item.active {
  background: var(--sidebar-active);
  color: var(--sidebar-text-active);
  font-weight: 600;
}

.nav-item i { width: 20px; height: 20px; flex-shrink: 0; stroke-width: 1.8; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  text-decoration: none;
  transition: var(--transition);
}

.sidebar-user:hover { background: var(--sidebar-hover); color: #fca5a5; }

.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 600; font-size: 0.8rem;
}

.user-info { flex: 1; min-width: 0; }
.user-info .name { font-size: 0.82rem; color: #e2e8f0; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-info .role { font-size: 0.68rem; color: var(--sidebar-text); text-transform: capitalize; }

/* ─── Top Header ─── */
.top-header {
  height: var(--header-height);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 50;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.breadcrumb a { color: var(--primary); text-decoration: none; font-weight: 500; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .sep { color: var(--text-muted); }

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-logos {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-logos img {
  height: 32px;
  opacity: 0.8;
  transition: opacity 0.2s;
}

.header-logos img:hover { opacity: 1; }

/* ─── Page Title ─── */
.page-header {
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.page-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.page-subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ─── Cards ─── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--border-light);
  overflow: hidden;
  transition: var(--transition);
}

.card:hover { box-shadow: var(--shadow-md); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, var(--primary-50), #ffffff);
}

.card-header h3 {
  font-family: 'Outfit', sans-serif;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body { padding: 24px; }

.card-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  background: #fafbfc;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ─── Stat Cards ─── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 16px;
  transition: var(--transition);
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  color: white;
}

.stat-icon.green { background: linear-gradient(135deg, var(--primary), var(--primary-light)); }
.stat-icon.blue { background: linear-gradient(135deg, var(--accent), var(--accent-light)); }
.stat-icon.orange { background: linear-gradient(135deg, var(--warning), #fbbf24); }
.stat-icon.cyan { background: linear-gradient(135deg, var(--info), #22d3ee); }

.stat-info h4 { font-size: 1.5rem; font-weight: 700; color: var(--text-primary); line-height: 1; }
.stat-info p { font-size: 0.8rem; color: var(--text-secondary); margin-top: 4px; }

/* ─── Tables ─── */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

thead th {
  background: var(--primary);
  color: white;
  font-weight: 600;
  padding: 12px 16px;
  text-align: left;
  white-space: nowrap;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

thead th:first-child { border-radius: var(--radius-sm) 0 0 0; }
thead th:last-child { border-radius: 0 var(--radius-sm) 0 0; }

tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-primary);
}

tbody tr { transition: background 0.15s ease; }
tbody tr:hover { background: var(--primary-50); }
tbody tr:nth-child(even) { background: #fafbfc; }
tbody tr:nth-child(even):hover { background: var(--primary-50); }

/* ─── Forms ─── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.form-group label .required { color: var(--danger); }

.form-control {
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-family: 'Inter', sans-serif;
  color: var(--text-primary);
  background: var(--card-bg);
  transition: var(--transition);
  width: 100%;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15);
}

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

select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-section {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.form-section-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--primary-50);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  text-decoration: none;
  transition: var(--transition);
  white-space: nowrap;
}

.btn i { width: 18px; height: 18px; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  box-shadow: 0 2px 4px rgba(5,150,105,0.3);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(5,150,105,0.4);
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: white;
  box-shadow: 0 2px 4px rgba(59,130,246,0.3);
}
.btn-accent:hover {
  background: linear-gradient(135deg, var(--accent-dark), var(--accent));
  transform: translateY(-1px);
}

.btn-danger {
  background: linear-gradient(135deg, var(--danger), #f87171);
  color: white;
}
.btn-danger:hover { background: linear-gradient(135deg, #dc2626, var(--danger)); transform: translateY(-1px); }

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-secondary);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-50); }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ─── Badges ─── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 50px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #e0f2fe; color: #075985; }
.badge-default { background: #f1f5f9; color: #475569; }

/* ─── Alerts / Toast ─── */
.alert {
  padding: 14px 20px;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: #e0f2fe; color: #075985; border: 1px solid #bae6fd; }

/* ─── Filter bar ─── */
.filter-bar {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
  padding: 16px 20px;
  background: #fafbfc;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 20px;
}

.filter-bar .form-group { min-width: 160px; }
.filter-bar .form-control { padding: 8px 12px; font-size: 0.85rem; }

/* ─── Actions Dropdown ─── */
.actions-cell { display: flex; gap: 6px; }
.action-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}

.action-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-50); }
.action-btn.danger:hover { border-color: var(--danger); color: var(--danger); background: #fee2e2; }
.action-btn i { width: 16px; height: 16px; }

/* ─── Voucher Print ─── */
.voucher-print {
  max-width: 600px;
  margin: 20px auto;
  padding: 30px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  background: white;
  font-size: 0.85rem;
}

.voucher-print .voucher-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--primary);
}

.voucher-print .voucher-header img { height: 40px; }
.voucher-print .voucher-title { text-align: center; font-family: 'Outfit', sans-serif; font-weight: 700; }
.voucher-print .info-row { margin-bottom: 6px; }
.voucher-print .info-row strong { display: inline-block; width: 150px; }

@media print {
  .sidebar, .top-header, .no-print { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .content-area { padding: 10mm !important; }
  @page { size: A4; margin: 10mm; }
}

/* ─── Login Page ─── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
  padding: 20px;
}

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

.login-card .login-logo { margin-bottom: 24px; }
.login-card .login-logo img { height: 50px; margin: 0 12px; }

.login-card h1 {
  font-family: 'Outfit', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.login-card .login-sub {
  color: var(--text-secondary);
  font-size: 0.88rem;
  margin-bottom: 32px;
}

.login-card .form-group { text-align: left; margin-bottom: 18px; }

/* ─── Empty State ─── */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state i { width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty-state p { font-size: 0.95rem; }

/* ─── Checkin buttons ─── */
.status-btn {
  padding: 5px 10px;
  font-size: 0.75rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
  transition: var(--transition);
}

.status-btn.saida { background: #dcfce7; color: #166534; }
.status-btn.saida:hover { background: #166534; color: white; }
.status-btn.retorno { background: #fef3c7; color: #92400e; }
.status-btn.retorno:hover { background: #92400e; color: white; }
.status-btn.concluida { background: #e0f2fe; color: #075985; }
.status-btn.concluida:hover { background: #075985; color: white; }
.status-btn.cancelada { background: #fee2e2; color: #991b1b; }
.status-btn.cancelada:hover { background: #991b1b; color: white; }

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .content-area { padding: 16px; }
  .top-header { padding: 0 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
}

/* ─── Toggle Switch ─── */
.form-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.form-switch .label-text {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 22px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #cbd5e1;
  transition: .3s;
  border-radius: 22px;
}

.switch-slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

input:checked + .switch-slider {
  background-color: var(--primary);
}

input:checked + .switch-slider:before {
  transform: translateX(20px);
}
