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

:root {
  --bg-main: #f4f7fb;
  --bg-surface: #ffffff;
  --bg-elevated: #f8fafc;
  --bg-muted: #eef2f7;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --border-color: #dbe3ef;
  --primary: #0d9488;
  --primary-hover: #0f766e;
  --primary-soft: rgba(13, 148, 136, 0.12);
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.12);
  --success: #16a34a;
  --success-soft: rgba(22, 163, 74, 0.12);
  --warning: #d97706;
  --warning-soft: rgba(217, 119, 6, 0.14);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.12);
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
}

[data-theme="dark"] {
  --bg-main: #0b1120;
  --bg-surface: #111827;
  --bg-elevated: #1e293b;
  --bg-muted: #172033;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --border-color: #293548;
  --primary: #14b8a6;
  --primary-hover: #2dd4bf;
  --primary-soft: rgba(20, 184, 166, 0.16);
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.16);
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.16);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.18);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.18);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}

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

body {
  font-family: 'Cairo', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.55;
  min-height: 100vh;
  transition: background 0.2s ease, color 0.2s ease;
}

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

/* Top Global Navigation & Story Bar */
.top-shell {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: var(--shadow-sm);
}

.top-bar {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0.65rem 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.brand-box {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.15rem;
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.28);
}

.brand-title {
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--text-primary);
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Compact Segmented Role Switcher */
.compact-seg {
  display: inline-flex;
  align-items: center;
  background: var(--bg-muted);
  padding: 0.22rem;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  gap: 0.2rem;
  flex-wrap: wrap;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 0.36rem 0.72rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.15s ease;
}

.seg-btn:hover {
  color: var(--text-primary);
  background: rgba(148, 163, 184, 0.12);
}

.seg-btn.active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(13, 148, 136, 0.25);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* 9-Step End-to-End Interactive Story Ribbon */
.story-ribbon {
  background: var(--bg-elevated);
  border-top: 1px solid var(--border-color);
  padding: 0.45rem 1.2rem;
  overflow-x: auto;
}

.story-ribbon-inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.story-step-pill {
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-secondary);
  padding: 0.28rem 0.62rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.15s ease;
}

.story-step-pill:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.story-step-pill.done {
  border-color: var(--success);
  background: var(--success-soft);
  color: var(--success);
}

.story-step-pill.current {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(13, 148, 136, 0.3);
}

.story-step-num {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 800;
}

/* Main Workspace Container */
.workspace-container {
  max-width: 1440px;
  margin: 1rem auto 2.5rem;
  padding: 0 1.2rem;
}

/* Mobile App Unified Frame (for Patient & Coordinator Roles) */
.mobile-layout-wrapper {
  display: grid;
  grid-template-columns: 430px 1fr;
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 1024px) {
  .mobile-layout-wrapper {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .workspace-container {
    margin: 0.4rem auto 1.5rem;
    padding: 0 0.5rem;
  }
  .phone-shell {
    border-radius: 14px;
    min-height: auto;
  }
  .phone-body {
    max-height: none;
    overflow-y: visible;
  }
}

.phone-shell {
  background: var(--bg-surface);
  border: 2px solid var(--border-color);
  border-radius: 26px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 760px;
  position: relative;
}

.phone-Dynamic-header {
  background: linear-gradient(135deg, #0f766e, #1e40af);
  color: #fff;
  padding: 0.9rem 1rem;
}

.phone-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.74rem;
  opacity: 0.92;
  margin-bottom: 0.45rem;
}

.phone-user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.phone-body {
  padding: 0.95rem;
  flex: 1;
  overflow-y: auto;
  max-height: 620px;
}

.phone-bottom-nav {
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-around;
  padding: 0.45rem 0.25rem;
}

.phone-nav-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  padding: 0.3rem 0.55rem;
  border-radius: 10px;
  position: relative;
}

.phone-nav-btn.active {
  color: var(--primary);
  background: var(--primary-soft);
}

/* Cards, Badges, Forms & Buttons */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 0.9rem;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.7rem;
  flex-wrap: wrap;
}

.card-title {
  font-weight: 700;
  font-size: 0.98rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
}

.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.48rem 0.9rem;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: all 0.15s ease;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

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

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

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

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

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

.btn-outline {
  background: var(--bg-surface);
  border-color: var(--border-color);
  color: var(--text-primary);
}
.btn-outline:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-sm {
  padding: 0.3rem 0.62rem;
  font-size: 0.78rem;
}

.btn-block {
  width: 100%;
}

/* Form Controls */
.form-group {
  margin-bottom: 0.7rem;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.form-control {
  width: 100%;
  padding: 0.48rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s ease;
}

.form-control:focus {
  border-color: var(--primary);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.85rem;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.85rem;
}

@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }
}

/* Fullscreen Mobile Map Container for Coordinator (Requirement Section 4) */
.coord-fullscreen-map-shell {
  position: relative;
  height: 620px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border-color);
  background: #e2e8f0;
  display: flex;
  flex-direction: column;
}

.map-filter-chips-bar {
  position: absolute;
  top: 12px;
  right: 12px;
  left: 12px;
  z-index: 450;
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 4px;
}

.map-chip {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 0.3rem 0.68rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}

.map-chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.map-canvas-viewport {
  flex: 1;
  width: 100%;
  height: 100%;
  position: relative;
}

.map-bottom-sheet {
  position: absolute;
  bottom: 0;
  right: 0;
  left: 0;
  z-index: 450;
  background: var(--bg-surface);
  border-top: 2px solid var(--border-color);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -8px 25px rgba(0, 0, 0, 0.15);
  transition: max-height 0.25s ease;
  max-height: 230px;
  overflow-y: auto;
  padding: 0.7rem 1rem;
}

.map-bottom-sheet.expanded {
  max-height: 430px;
}

.sheet-handle {
  width: 44px;
  height: 5px;
  background: var(--border-color);
  border-radius: 999px;
  margin: 0 auto 0.5rem;
  cursor: pointer;
}

/* AI Confidence Field Row */
.ai-field-row {
  padding: 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  margin-bottom: 0.55rem;
}

.ai-field-row.low-confidence {
  border-color: var(--warning);
  background: var(--warning-soft);
}

/* KPI Stat Cards */
.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  box-shadow: var(--shadow-sm);
}

.kpi-val {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--primary);
}

.kpi-lbl {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 600;
}

/* Timeline / Status History */
.timeline-list {
  border-right: 2px solid var(--primary);
  padding-right: 0.85rem;
  margin-right: 0.4rem;
}

[dir="ltr"] .timeline-list {
  border-right: none;
  border-left: 2px solid var(--primary);
  padding-right: 0;
  padding-left: 0.85rem;
}

.timeline-item {
  position: relative;
  padding-bottom: 0.7rem;
  font-size: 0.82rem;
}

.timeline-item::before {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  position: absolute;
  right: -1.18rem;
  top: 0.35rem;
}

[dir="ltr"] .timeline-item::before {
  right: auto;
  left: -1.18rem;
}

/* Toast Notification Banner */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 380px;
}

.toast {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-right: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow-lg);
  font-size: 0.85rem;
  font-weight: 600;
  animation: slideIn 0.2s ease;
}

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

/* Table Styling */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table th, .data-table td {
  padding: 0.6rem 0.65rem;
  border-bottom: 1px solid var(--border-color);
  text-align: inherit;
}

.data-table th {
  background: var(--bg-muted);
  font-weight: 700;
  color: var(--text-secondary);
}

/* ============================================================================
 * Enterprise SaaS Dashboard Layout (Sidebar + Topbar + Login Portal + SVG Icons)
 * ============================================================================ */
.svg-ic {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  vertical-align: middle;
}

.app-enterprise-shell {
  display: flex;
  min-height: 100vh;
  background: var(--bg-main);
}

.app-sidebar {
  width: 264px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 1rem 0.75rem;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 900;
  box-shadow: var(--shadow-sm);
}

[dir="ltr"] .app-sidebar {
  border-left: none;
  border-right: 1px solid var(--border-color);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.4rem 0.5rem 1rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 0.85rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
  overflow-y: auto;
}

.side-nav-btn {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  cursor: pointer;
  text-align: inherit;
  transition: all 0.15s ease;
}

.side-nav-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.side-nav-btn.active {
  background: var(--primary-soft);
  color: var(--primary-hover);
  border-color: rgba(13, 148, 136, 0.28);
  font-weight: 800;
}

.side-nav-badge {
  margin-right: auto;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
}

[dir="ltr"] .side-nav-badge {
  margin-right: 0;
  margin-left: auto;
}

.app-main-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.enterprise-topbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0.7rem 1.35rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 800;
}

.enterprise-content {
  padding: 1.25rem 1.35rem 2.5rem;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

.kpi-modern {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  box-shadow: var(--shadow-sm);
}

.kpi-icon-badge {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Login Gate Portal */
.login-portal-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: radial-gradient(circle at top right, rgba(13, 148, 136, 0.14), transparent 52%), var(--bg-main);
}

.login-portal-grid {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  max-width: 1040px;
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.login-brand-panel {
  background: linear-gradient(155deg, #0b5d56 0%, #0f172a 100%);
  color: #f8fafc;
  padding: 2.4rem 2rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 1.5rem;
}

.login-form-panel {
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (max-width: 960px) {
  .app-enterprise-shell {
    flex-direction: column;
  }
  .app-sidebar {
    width: 100%;
    height: auto;
    position: static;
    border-left: none;
    border-bottom: 1px solid var(--border-color);
  }
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .side-nav-btn {
    width: auto;
  }
  .login-portal-grid {
    grid-template-columns: 1fr;
  }
}
