/* Swiss-Inspired SaaS Dashboard Design System */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  /* Colors - Light Theme */
  --bg-body: #F9FAFB;
  --bg-surface: #FFFFFF;
  --bg-subtle: #F3F4F6;
  --border-color: #E5E7EB;
  
  --text-primary: #111827;
  --text-secondary: #6B7280;
  --text-tertiary: #9CA3AF;
  
  --accent-primary: #10B981; /* Emerald */
  --accent-hover: #059669;
  --accent-light: #D1FAE5;
  
  --status-waiting-bg: #FEF3C7;
  --status-waiting-text: #92400E;
  --status-consult-bg: #DBEAFE;
  --status-consult-text: #1E40AF;
  --status-completed-bg: #D1FAE5;
  --status-completed-text: #065F46;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-float: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;
  
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;

  --sidebar-width: 260px;
}

[data-theme="dark"] {
  --bg-body: #111827;
  --bg-surface: #1F2937;
  --bg-subtle: #374151;
  --border-color: #374151;
  
  --text-primary: #F9FAFB;
  --text-secondary: #9CA3AF;
  --text-tertiary: #6B7280;
  
  --accent-primary: #10B981;
  --accent-hover: #34D399;
  --accent-light: rgba(16, 185, 129, 0.2);
  
  --status-waiting-bg: rgba(245, 158, 11, 0.2);
  --status-waiting-text: #FBBF24;
  --status-consult-bg: rgba(59, 130, 246, 0.2);
  --status-consult-text: #60A5FA;
  --status-completed-bg: rgba(16, 185, 129, 0.2);
  --status-completed-text: #34D399;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.5;
  font-size: 14px;
  transition: background-color var(--transition-normal), color var(--transition-normal);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

a {
  color: var(--text-primary);
  text-decoration: none;
}

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

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

/* Layout */
.app-container {
  display: flex;
  height: 100vh;
  width: 100%;
}

.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-normal);
  z-index: 40;
}

.sidebar-header {
  height: 64px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  border-bottom: 1px solid var(--border-color);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.03em;
  gap: 12px;
}

.sidebar-logo {
  width: 28px;
  height: 28px;
  background-color: var(--text-primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--bg-surface);
}

.sidebar-nav {
  padding: 24px 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  list-style: none;
  padding-left: 16px;
}

.sidebar-spacer {
  flex: 1;
  list-style: none;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 14px;
  transition: all var(--transition-fast);
  cursor: pointer;
  user-select: none;
  list-style: none;
}

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

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

.nav-item svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
}

.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0; /* Important for flex child truncation */
  height: 100vh;
  overflow: hidden;
}

.topbar {
  height: 64px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  z-index: 30;
}

.search-container {
  position: relative;
  width: 300px;
}

.search-container svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  width: 16px;
  height: 16px;
}

.search-input {
  width: 100%;
  padding: 8px 16px 8px 36px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  background-color: var(--bg-subtle);
  color: var(--text-primary);
  outline: none;
  transition: all var(--transition-fast);
}

.search-input:focus {
  background-color: var(--bg-surface);
  border-color: var(--text-tertiary);
  box-shadow: 0 0 0 2px var(--bg-subtle);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background-color var(--transition-fast);
}

.icon-btn:hover {
  background-color: var(--bg-subtle);
  color: var(--text-primary);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
  position: relative;
}

/* Pages — SPA view toggling */
.page {
  display: none;
}

.page.active-page {
  display: block;
  animation: fadeIn 0.25s ease;
}

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

/* Dashboard Layout */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 32px;
  align-items: start;
}

/* Page header */
.page-header {
  margin-bottom: 28px;
}
.page-header h2 {
  font-size: 22px;
  margin-bottom: 4px;
}
.page-header p {
  color: var(--text-secondary);
  font-size: 13px;
}

/* User avatar */
.user-avatar {
  width: 36px;
  height: 36px;
  background-color: var(--bg-subtle);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
}

/* Calendar nav row */
.cal-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Calendar legend */
.calendar-legend {
  display: flex;
  gap: 24px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
  font-size: 13px;
  color: var(--text-secondary);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}
.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 2px;
}
.legend-dot.available   { background-color: var(--accent-light); }
.legend-dot.unavailable { background-color: var(--bg-surface); border: 1px solid var(--border-color); }


/* Stats Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-bottom: 32px;
}

.stat-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.stat-title {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.03em;
}

/* Forms */
.form-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
}

.form-header {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.form-header h2 {
  font-size: 18px;
  margin-bottom: 4px;
}

.form-header p {
  color: var(--text-secondary);
  font-size: 13px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.form-group label span {
  color: #EF4444; /* Red for required */
}

.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.form-control:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-light);
}

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

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 14px;
  transition: all var(--transition-fast);
  gap: 8px;
}

.btn-primary {
  background-color: var(--text-primary);
  color: var(--bg-surface);
  width: 100%;
  margin-top: 8px;
}

.btn-primary:hover {
  background-color: var(--text-secondary);
  transform: translateY(-1px);
}

.btn-outline {
  border: 1px solid var(--border-color);
  background-color: transparent;
  color: var(--text-primary);
}

.btn-outline:hover {
  background-color: var(--bg-subtle);
}

/* Tables */
.table-container {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table-header-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.table-header-actions h3 {
  font-size: 16px;
}

.table-filters {
  display: flex;
  gap: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

th {
  background-color: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 12px 20px;
  position: sticky;
  top: 0;
  z-index: 10;
}

td {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 14px;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background-color: var(--bg-subtle);
}

.patient-name {
  font-weight: 500;
}

.patient-mobile {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 2px;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 500;
}

.badge-waiting {
  background-color: var(--status-waiting-bg);
  color: var(--status-waiting-text);
}

.badge-consultation {
  background-color: var(--status-consult-bg);
  color: var(--status-consult-text);
}

.badge-completed {
  background-color: var(--status-completed-bg);
  color: var(--status-completed-text);
}

/* Status Select */
.status-select {
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 20px 4px 8px;
  border-radius: var(--radius-sm);
  appearance: none;
  background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%236B7280%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 8px auto;
}

.status-select:hover {
  background-color: rgba(0,0,0,0.05);
}

/* Toast Notification */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toast {
  background-color: var(--text-primary);
  color: var(--bg-surface);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-float);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  font-weight: 500;
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  opacity: 0;
  transform: translateY(20px);
}

.toast.error {
  background-color: #EF4444;
}

.toast.success {
  background-color: var(--accent-primary);
}

.toast.fade-out {
  animation: fadeOut 0.3s ease forwards;
}

@keyframes slideUp {
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOut {
  to { opacity: 0; transform: translateY(10px); }
}

/* Modal for Export */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0,0,0,0.4);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
  backdrop-filter: blur(2px);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background-color: var(--bg-surface);
  border-radius: var(--radius-lg);
  width: 400px;
  max-width: 90%;
  padding: 24px;
  box-shadow: var(--shadow-float);
  transform: scale(0.95);
  transition: transform var(--transition-normal);
}

.modal-overlay.active .modal {
  transform: scale(1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h3 {
  font-size: 18px;
}

.close-btn {
  color: var(--text-tertiary);
}

.close-btn:hover {
  color: var(--text-primary);
}

/* Calendar View Elements */
.calendar-container {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.calendar-day-header {
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  padding-bottom: 8px;
}

.calendar-day {
  aspect-ratio: 1;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 8px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.calendar-day:hover {
  border-color: var(--text-tertiary);
}

.calendar-day.empty {
  border: none;
  cursor: default;
}

.calendar-day .date-num {
  font-size: 14px;
  font-weight: 500;
}

.calendar-day.available {
  background-color: var(--accent-light);
  border-color: var(--accent-light);
}

.calendar-day.available .date-num {
  color: var(--accent-hover);
}

.calendar-day.today {
  border: 2px solid var(--text-primary);
}

/* Visit Check View */
.visit-check-container {
  max-width: 600px;
  margin: 40px auto;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-md);
  text-align: center;
}

.visit-check-icon {
  width: 64px;
  height: 64px;
  background-color: var(--bg-subtle);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px;
  color: var(--text-primary);
}

.visit-check-icon svg {
  width: 32px;
  height: 32px;
}

.visit-check-container h2 {
  font-size: 24px;
  margin-bottom: 8px;
}

.visit-check-container p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.search-large {
  display: flex;
  gap: 12px;
  margin-bottom: 32px;
}

.search-large .form-control {
  font-size: 16px;
  padding: 12px 16px;
}

.search-large .btn {
  padding: 12px 24px;
}

.visit-history {
  text-align: left;
}

.visit-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.visit-date {
  font-weight: 600;
  font-size: 16px;
}

.visit-doc {
  color: var(--text-secondary);
  font-size: 14px;
}

/* Responsive */
.mobile-menu-btn {
  display: none;
}

@media (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
  .form-card {
    position: static;
  }
  .main-content {
    padding: 24px;
  }
  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }
  .search-container {
    width: 220px;
  }
}

@media (max-width: 768px) {
  .mobile-menu-btn {
    display: flex;
  }
  
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-100%);
  }
  
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-float);
  }
  
  .main-content {
    padding: 16px;
  }
  
  .topbar {
    padding: 0 16px;
    gap: 12px;
  }
  
  .search-container {
    width: 100%;
  }
  
  .topbar-actions > div {
    display: none; /* Hide avatar */
  }
  
  .stats-grid {
    grid-template-columns: 1fr;
  }
  
  .form-row {
    grid-template-columns: 1fr;
  }
  
  .table-container {
    overflow-x: auto;
  }
  
  .table-header-actions {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }

  .visit-check-container {
    padding: 20px;
    margin: 16px auto;
  }

  .search-large {
    flex-direction: column;
  }
  
  .search-large .btn {
    width: 100%;
  }

  .calendar-container {
    padding: 16px;
  }

  .calendar-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
  
  .calendar-header .form-group {
    width: 100%;
  }
  
  .calendar-day {
    padding: 4px;
  }
}

/* Skeletons */
.skeleton {
  background: linear-gradient(90deg, var(--bg-subtle) 25%, var(--border-color) 50%, var(--bg-subtle) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Login Overlay */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-body);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.login-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.login-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-float);
  transform: translateY(20px);
  transition: transform var(--transition-normal);
}

.login-overlay.active .login-card {
  transform: translateY(0);
}
