/* ==================== CSS Variables ==================== */
:root {
  --primary-color: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #3b82f6;
  --secondary-color: #6b7280;
  --success-color: #22c55e;
  --warning-color: #eab308;
  --danger-color: #ef4444;

  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --bg-tertiary: #f3f4f6;

  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;

  --border-color: #e5e7eb;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

  --sidebar-width: 260px;
  --header-height: 64px;
  --border-radius: 8px;
  --transition: all 0.2s ease;
}

/* ==================== Reset & Base ==================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

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

a:hover {
  text-decoration: underline;
}

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

.sidebar {
  width: var(--sidebar-width);
  background: var(--text-primary);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 100;
}

.sidebar-header {
  padding: 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo {
  font-size: 20px;
  font-weight: 700;
  color: white;
}

.clinic-name {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 4px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  transition: var(--transition);
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  text-decoration: none;
}

.nav-item.active {
  background: var(--primary-color);
  color: white;
}

.nav-icon {
  font-size: 18px;
}

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

.user-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

#sidebar-user-email {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.9);
}

.role-badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.8);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 24px;
  min-height: 100vh;
}

/* ==================== Pages ==================== */
.page {
  display: none;
}

.page.active {
  display: block;
}

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

.page-header h2 {
  font-size: 24px;
  font-weight: 600;
}

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

/* ==================== Date Range ==================== */
.date-range {
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.date-input {
  width: 150px;
}

/* ==================== Revenue Total ==================== */
.revenue-total {
  margin-top: 6px;
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ==================== Metric Cards ==================== */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 24px;
}

.metric-card {
  background: var(--bg-primary);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

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

.metric-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.metric-icon {
  font-size: 24px;
}

.metric-body {
  padding: 20px;
}

.metric-value {
  font-size: 36px;
  font-weight: 700;
  color: var(--text-primary);
}

.metric-label {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.metric-comparison {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
  font-size: 13px;
  color: var(--text-secondary);
}

.metric-chart {
  padding: 16px 20px 20px;
  height: 200px;
}

/* ==================== Patient Stats ==================== */
.patient-stats,
.review-stats {
  display: flex;
  gap: 24px;
}

.stat-item {
  text-align: center;
}

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

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.conversion-rate {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 20px !important;
}

.conversion-rate.green {
  background: rgba(34, 197, 94, 0.1);
  color: var(--success-color);
}

.conversion-rate.yellow {
  background: rgba(234, 179, 8, 0.1);
  color: var(--warning-color);
}

.conversion-rate.red {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger-color);
}

/* ==================== Stars ==================== */
.stars {
  font-size: 20px;
  color: #fbbf24;
}

.stars .empty {
  color: #d1d5db;
}

.legelisten-link {
  display: inline-block;
  margin-top: 16px;
  font-size: 13px;
}

/* ==================== Forms ==================== */
.form-container {
  display: grid;
  gap: 24px;
}

.form-section {
  background: var(--bg-primary);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
  padding: 24px;
}

.form-section h3 {
  font-size: 18px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

.form-section h4 {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 20px 0 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

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

.form-group label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.text-input,
.select-input {
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  font-size: 14px;
  transition: var(--transition);
  background: var(--bg-primary);
}

.text-input:focus,
.select-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.file-input {
  padding: 8px;
  border: 2px dashed var(--border-color);
  border-radius: var(--border-radius);
  width: 100%;
  cursor: pointer;
}

.form-actions {
  margin-top: 24px;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.help-text {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

/* ==================== Buttons ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--border-radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

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

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

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--border-color);
}

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

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

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

/* ==================== Tables ==================== */
.users-table-container {
  background: var(--bg-primary);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 14px 20px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.data-table th {
  background: var(--bg-secondary);
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.data-table tbody tr:hover {
  background: var(--bg-secondary);
}

/* ==================== Modal ==================== */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--bg-primary);
  border-radius: var(--border-radius);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

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

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

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-secondary);
  cursor: pointer;
}

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

.modal-content form {
  padding: 24px;
}

/* ==================== Login Page ==================== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-color) 100%);
}

.login-container {
  width: 100%;
  max-width: 400px;
  padding: 20px;
}

.login-card {
  background: var(--bg-primary);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  padding: 40px;
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.login-header h1 {
  font-size: 24px;
  color: var(--primary-color);
}

.login-header p {
  color: var(--text-secondary);
  margin-top: 8px;
}

.login-card .form-group {
  margin-bottom: 20px;
}

.error-message {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger-color);
  padding: 12px;
  border-radius: var(--border-radius);
  font-size: 14px;
  margin-bottom: 16px;
}

.login-footer {
  margin-top: 24px;
  text-align: center;
  font-size: 13px;
  color: var(--text-secondary);
}

/* ==================== Toast Notifications ==================== */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 14px 20px;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  animation: slideIn 0.3s ease;
  min-width: 280px;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

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

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

.toast.info {
  background: var(--primary-color);
  color: white;
}

/* ==================== Loading States ==================== */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ==================== Responsive ==================== */
@media (max-width: 1024px) {
  .metrics-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
  }

  .main-content {
    margin-left: 0;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-controls {
    width: 100%;
  }

  .header-controls .select-input {
    flex: 1;
  }

  .patient-stats,
  .review-stats {
    flex-wrap: wrap;
  }
}

/* ==================== Revenue Analysis ==================== */
.ra-content {
  display: grid;
  gap: 24px;
}

.ra-pie-wrapper {
  padding: 20px;
  height: 400px;
}

.text-right {
  text-align: right;
}

.data-table tfoot td {
  border-top: 2px solid var(--text-primary);
  background: var(--bg-secondary);
  font-weight: 600;
}

.ra-diff {
  font-size: 12px;
  font-weight: 500;
}

.ra-diff.green {
  color: var(--success-color);
}

.ra-diff.red {
  color: var(--danger-color);
}

/* ==================== TAR Analysis Page ==================== */
.tar-content {
  display: grid;
  gap: 24px;
}

.tar-stats {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}

.tar-base-toggle .select-input {
  width: auto;
  font-size: 13px;
}

/* ==================== Accounting Page ==================== */
.acc-content {
  display: grid;
  gap: 24px;
}

.acc-summary {
  display: flex;
  gap: 24px;
  margin-bottom: 24px;
}

.acc-summary-card {
  flex: 1;
  background: var(--bg-primary);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
  padding: 20px;
  text-align: center;
}

.acc-summary-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
}

.acc-summary-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.acc-view {
  display: none;
}

.acc-view.active {
  display: block;
}

/* ==================== Utility ==================== */
.hidden {
  display: none !important;
}

.admin-only {
  display: none;
}

body.role-admin .admin-only {
  display: flex;
}

/* ==================== Settings Page ==================== */
.settings-container {
  background: var(--bg-primary);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
  padding: 24px;
  max-width: 600px;
}

.settings-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.settings-list {
  display: flex;
  flex-direction: column;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-color);
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-label {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

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

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #d1d5db;
  border-radius: 26px;
  transition: var(--transition);
}

.toggle-slider::before {
  content: "";
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: var(--transition);
}

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

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

.toggle-switch input:focus + .toggle-slider {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* ==================== Seat Banner ==================== */
.seat-banner {
  background: linear-gradient(135deg, #dbeafe, #ede9fe);
  border: 1px solid #93c5fd;
  border-radius: var(--border-radius);
  padding: 14px 20px;
  margin-bottom: 20px;
}

.seat-banner-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.seat-banner-content span {
  font-size: 14px;
  font-weight: 500;
  color: #1e40af;
}

/* ==================== Seat Modal Items ==================== */
.seat-modal-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-color);
}

.seat-modal-item:last-child {
  border-bottom: none;
}

.seat-modal-item label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
  flex: 1;
}

.seat-modal-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary-color);
}

.seat-modal-item input[type="checkbox"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.linked-badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
  background: #dcfce7;
  color: #16a34a;
  font-weight: 600;
}

/* ==================== Agent Status Banner ==================== */
.agent-status-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
}

.agent-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.agent-dot.green { background: var(--success-color); }
.agent-dot.orange { background: var(--warning-color); }
.agent-dot.red { background: var(--danger-color); }

/* ==================== Compare Page ==================== */
.compare-controls { display: grid; gap: 16px; }
.compare-control-row { display: flex; gap: 16px; flex-wrap: wrap; }
.compare-control-row .form-group { flex: 1; min-width: 200px; }
