/* ═══════════════════════════════════════════════
   CoChartOS — Global Design System v2
   ═══════════════════════════════════════════════ */

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

/* 1. Remove iridescent/wave background entirely */
body, .app-background, .main-content, .page-wrapper {
  background: #f8f9fb !important;
  background-image: none !important;
}

/* 2. Global design tokens */
:root {
  --bg-app: #f8f9fb;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f4f5f7;
  --border: #e8eaed;
  --border-focus: #2a9d8f;
  --text-primary: #0f1117;
  --text-secondary: #5f6b7a;
  --text-muted: #9aa3ae;
  --accent: #2a9d8f;
  --accent-dim: rgba(42,157,143,0.08);
  --success: #12b76a;
  --success-dim: rgba(18,183,106,0.08);
  --warning: #f79009;
  --danger: #f04438;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --font: 'Inter', system-ui, sans-serif;
}

/* 3. Typography */
* { font-family: var(--font); -webkit-font-smoothing: antialiased; }
h1 { font-size: 22px; font-weight: 600; color: var(--text-primary); margin: 0; }
h2 { font-size: 17px; font-weight: 600; color: var(--text-primary); margin: 0; }
p, td, li { font-size: 14px; color: var(--text-secondary); line-height: 1.6; }

body {
  font-family: var(--font);
  background: var(--bg-app);
  color: var(--text-primary);
  min-height: 100vh;
  margin: 0;
  padding: 0;
}

/* 4. All cards */
.card, .panel, .section-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

/* ═══════════════════════════════════
   5. Buttons — global standard
   ═══════════════════════════════════ */
.btn-primary {
  background: #2a9d8f;
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 0 16px;
  height: 36px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
  font-family: var(--font);
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary:hover { background: #3d8ef0; }

.btn-outline {
  background: transparent;
  color: #5f6b7a;
  border: 1px solid #e8eaed;
  border-radius: 8px;
  padding: 0 16px;
  height: 36px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  white-space: nowrap;
}
.btn-outline:hover { border-color: #2a9d8f; color: #2a9d8f; }

.btn-danger {
  background: transparent;
  color: #f04438;
  border: 1px solid rgba(240,68,56,0.2);
  border-radius: 8px;
  padding: 0 16px;
  height: 36px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* ═══════════════════════════════════
   6. Inputs — global standard
   ═══════════════════════════════════ */
input, select, textarea {
  background: #f4f5f7;
  border: 1px solid #e8eaed;
  border-radius: 8px;
  padding: 0 14px;
  height: 40px;
  font-size: 14px;
  color: #0f1117;
  font-family: 'Inter', system-ui;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: #2a9d8f;
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(42,157,143,0.12);
}
input::placeholder, textarea::placeholder { color: #9aa3ae; }
textarea { height: auto; padding: 10px 14px; resize: vertical; }
select {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239aa3ae' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 38px;
}

/* ═══════════════════════════════════
   7. Status Badges — global standard
   ═══════════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid transparent;
}
.badge-active, .badge-final { background: rgba(18,183,106,0.1); color: #12b76a; border-color: rgba(18,183,106,0.2); }
.badge-draft { background: rgba(247,144,9,0.1); color: #f79009; border-color: rgba(247,144,9,0.2); }
.badge-pending { background: rgba(42,157,143,0.1); color: #2a9d8f; border-color: rgba(42,157,143,0.2); }
.badge-cardiology { background: rgba(220,38,38,0.08); color: #dc2626; border-color: rgba(220,38,38,0.15); }
.badge-neurology { background: rgba(124,58,237,0.08); color: #7c3aed; border-color: rgba(124,58,237,0.15); }
.badge-psychiatry { background: rgba(109,40,217,0.08); color: #6d28d9; border-color: rgba(109,40,217,0.15); }
.badge-internal { background: rgba(37,99,235,0.08); color: #2563eb; border-color: rgba(37,99,235,0.15); }
.badge-emergency { background: rgba(234,88,12,0.08); color: #ea580c; border-color: rgba(234,88,12,0.15); }
.badge-general { background: rgba(107,114,128,0.08); color: #6b7280; border-color: rgba(107,114,128,0.15); }
.badge-follow_up { background: rgba(42,157,143,0.08); color: #2a9d8f; border-color: rgba(42,157,143,0.15); }
.badge-new_admission { background: rgba(18,183,106,0.08); color: #12b76a; border-color: rgba(18,183,106,0.2); }
.badge-consult { background: rgba(124,58,237,0.08); color: #7c3aed; border-color: rgba(124,58,237,0.15); }
.badge-discharge { background: rgba(234,88,12,0.08); color: #ea580c; border-color: rgba(234,88,12,0.15); }

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

.app-main {
  flex: 1;
  background: var(--bg-app);
  overflow-y: auto;
  min-height: 100vh;
}

/* ═══════════════════════════════════
   Sidebar — 220px navigation
   ═══════════════════════════════════ */
.app-sidebar {
  width: 220px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
  position: sticky;
  top: 0;
  z-index: 50;
}

.sidebar-top {
  padding: 1.25rem 1rem;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
}

.sidebar-logo-img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: contain;
}

.sidebar-logo-text {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.sidebar-logo-accent {
  color: var(--accent);
}

.sidebar-role-badge {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  padding-left: 42px;
}

/* Sidebar Nav Items */
.sidebar-nav {
  flex: 1;
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-nav-item {
  height: 38px;
  border-radius: 8px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  transition: all 0.12s;
  position: relative;
  cursor: pointer;
}

.sidebar-nav-icon {
  width: 16px;
  height: 16px;
  color: #9aa3ae;
  flex-shrink: 0;
}

.sidebar-nav-label {
  font-size: 13px;
  font-weight: 500;
  color: #5f6b7a;
}

.sidebar-nav-item:hover {
  background: #f4f5f7;
}

.sidebar-nav-item:hover .sidebar-nav-icon,
.sidebar-nav-item:hover .sidebar-nav-label {
  color: #0f1117;
}

.sidebar-nav-item.active {
  background: rgba(42,157,143,0.08);
}

.sidebar-nav-item.active .sidebar-nav-icon,
.sidebar-nav-item.active .sidebar-nav-label {
  color: #2a9d8f;
}

.sidebar-nav-item.active .sidebar-nav-label {
  font-weight: 600;
}

.sidebar-notification-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  position: absolute;
  top: 8px;
  left: 22px;
}

/* Sidebar Bottom Section */
.sidebar-bottom {
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-plan-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
}

.sidebar-plan-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.sidebar-plan-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.sidebar-plan-manage {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}
.sidebar-plan-manage:hover { text-decoration: underline; }

.sidebar-plan-credits-text {
  font-size: 12px;
  color: var(--text-secondary);
}

.sidebar-plan-progress {
  height: 6px;
  background: #f4f5f7;
  border-radius: 4px;
  margin-top: 4px;
  overflow: hidden;
}

.sidebar-plan-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.3s;
}

.sidebar-plan-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--success);
  margin-top: 6px;
}

.sidebar-plan-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
}

.sidebar-collapse-btn {
  background: none;
  border: none;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 0;
  text-align: left;
  font-family: var(--font);
}
.sidebar-collapse-btn:hover { color: var(--text-secondary); }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(42,157,143,0.12);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.sidebar-user-role {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-signout {
  background: none;
  border: none;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  font-family: var(--font);
}
.sidebar-signout:hover { color: var(--danger); }

/* Sidebar collapsed state */
.app-sidebar.collapsed {
  width: 60px;
}
.app-sidebar.collapsed .sidebar-logo-text,
.app-sidebar.collapsed .sidebar-role-badge,
.app-sidebar.collapsed .sidebar-nav-label,
.app-sidebar.collapsed .sidebar-plan-card,
.app-sidebar.collapsed .sidebar-collapse-btn,
.app-sidebar.collapsed .sidebar-user-name,
.app-sidebar.collapsed .sidebar-user-role,
.app-sidebar.collapsed .sidebar-signout,
.app-sidebar.collapsed .sidebar-notification-dot {
  display: none;
}
.app-sidebar.collapsed .sidebar-nav-item {
  justify-content: center;
  padding: 0;
}
.app-sidebar.collapsed .sidebar-user {
  justify-content: center;
}

/* ═══════════════════════════════════
   Mobile Header (for sidebar pages)
   ═══════════════════════════════════ */
.mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.mobile-header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text-primary);
}

.mobile-header-logo img {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}

.mobile-header-logo span {
  font-size: 15px;
  font-weight: 700;
}

.mobile-menu-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

/* ═══════════════════════════════════
   Mobile Responsive — 375px+
   ═══════════════════════════════════ */
@media (max-width: 768px) {
  /* Root — safe area insets for notch/safe zones */
  * {
    max-width: 100vw;
  }

  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  /* App layout */
  .app-layout {
    flex-direction: column;
  }

  .app-main {
    min-height: auto;
  }

  /* Sidebar — hamburger menu */
  .app-sidebar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 220px;
    z-index: 200;
    box-shadow: var(--shadow-md);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .app-sidebar.open {
    display: flex;
  }

  .app-sidebar.collapsed {
    width: 220px; /* Show full on mobile when open */
  }

  /* Mobile header — shows when sidebar is hidden */
  .mobile-header {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 100;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  .mobile-menu-btn {
    width: 40px;
    height: 40px;
    min-height: 44px;
  }

  /* Sidebar overlay */
  .mobile-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 199;
  }

  .mobile-sidebar-overlay.open {
    display: block;
  }

  /* Buttons — ensure touch targets */
  .btn-primary,
  .btn-outline,
  .btn-danger {
    min-height: 44px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Inputs — proper touch targets */
  input,
  select,
  textarea {
    min-height: 44px;
    font-size: 16px; /* Prevents zoom on iOS */
  }

  /* Tables — horizontal scroll on mobile */
  table {
    font-size: 13px;
  }
  thead th {
    padding: 10px 8px;
    font-size: 11px;
  }
  tbody td {
    padding: 10px 8px;
    font-size: 12px;
  }

  /* Badges */
  .badge {
    font-size: 11px;
    padding: 2px 8px;
    min-height: 28px;
    display: inline-flex;
    align-items: center;
  }

  /* Toast — avoid notch area */
  .toast {
    bottom: calc(1.5rem + env(safe-area-inset-bottom));
    left: env(safe-area-inset-left);
    right: env(safe-area-inset-right);
    max-width: calc(100vw - 2rem - env(safe-area-inset-left) - env(safe-area-inset-right));
    transform: translateX(0) translateY(8px);
  }
  .toast.show {
    transform: translateX(0) translateY(0);
  }
}

/* ═══════════════════════════════════
   Toast notifications
   ═══════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-primary);
  opacity: 0;
  transition: all 0.2s ease;
  pointer-events: none;
  z-index: 999;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
