/* ==========================================================================
   DOSEFIEL HEALTH — DESIGN SYSTEM (Apple Health Inspired + Smart Dashboard)
   Acessibilidade WCAG 2.2 AA, Modo Claro/Escuro, Modo TDAH e Modo Idoso
   ========================================================================== */

:root {
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-light: #e0f2fe;
  --primary-dark: #0c4a6e;
  --secondary: #0d9488;
  --accent: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --purple: #8b5cf6;
  
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --border-subtle: #e2e8f0;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(15,23,42,0.06);
  --shadow-lg: 0 12px 28px rgba(15,23,42,0.1);
  --shadow-glow: 0 0 20px rgba(2,132,199,0.25);
  
  --font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-base: 16px;
  --tap-target: 48px;
  --transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="dark"] {
  --bg-app: #090d16;
  --bg-card: #131b2e;
  --bg-subtle: #1e293b;
  --border-subtle: #2a374f;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;
  
  --primary-light: #082f49;
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
}

/* Modo Idoso (Acessibilidade Ampliada) */
body.mode-senior {
  --font-base: 20px;
  --tap-target: 64px;
  --radius-md: 18px;
  font-weight: 500;
}
body.mode-senior button, body.mode-senior .btn {
  font-size: 1.15rem;
  padding: 16px 24px;
  min-height: 60px;
}
body.mode-senior .card {
  border-width: 2px;
  border-color: #cbd5e1;
}

/* Modo TDAH (Foco e Rotina Sem Distrações) */
body.mode-adhd .distraction-free-hide {
  display: none !important;
}
body.mode-adhd .adhd-highlight {
  box-shadow: 0 0 0 4px #0284c7, 0 10px 25px rgba(2,132,199,0.3) !important;
  border-color: #0284c7 !important;
}

/* Modo Discreto (Privacidade nas Notificações e Telas) */
body.mode-discrete .discrete-blur {
  filter: blur(5px);
  user-select: none;
  transition: var(--transition);
}
body.mode-discrete .discrete-blur:hover {
  filter: none;
}

/* Reset Básico */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-base);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Container do Aplicativo */
.app-container {
  display: flex;
  flex: 1;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  position: relative;
}

/* Sidebar / Navegação Desktop */
.app-sidebar {
  width: 280px;
  background: var(--bg-card);
  border-right: 1px solid var(--border-subtle);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
}

.brand-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--primary);
}

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

/* Navegação e Links */
.nav-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-subtle);
  padding: 12px 12px 4px;
  letter-spacing: 0.05em;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  transition: var(--transition);
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

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

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

.nav-item .icon {
  font-size: 1.2rem;
  width: 24px;
  display: flex;
  justify-content: center;
}

/* Área Principal de Conteúdo */
.app-main {
  flex: 1;
  padding: 24px;
  padding-bottom: 96px; /* Espaço para barra inferior móvel */
  max-width: 1000px;
  margin: 0 auto;
  width: 100%;
}

/* Barra Superior Mobile / Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.profile-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}

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

/* Banner de Notificação e PWA */
.alert-banner {
  background: var(--primary-light);
  border-left: 4px solid var(--primary);
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

/* Cards e Layout Grid */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

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

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* Card Hero: Próxima Medicação */
.card-next-dose {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  color: white;
  border: none;
  box-shadow: var(--shadow-glow);
  padding: 28px;
}

.card-next-dose .card-subtitle {
  color: rgba(255, 255, 255, 0.8);
}

.dose-time-display {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 16px 0;
}

.time-large {
  font-size: 2.8rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
}

.countdown-badge {
  background: rgba(255, 255, 255, 0.2);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  font-weight: 600;
  backdrop-filter: blur(8px);
}

/* Botões e Ações */
.btn-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition);
  text-decoration: none;
}

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

.btn-white {
  background: white;
  color: var(--primary-dark);
}
.btn-white:hover {
  background: #f8fafc;
}

.btn-secondary {
  background: var(--bg-subtle);
  color: var(--text-main);
  border-color: var(--border-subtle);
}
.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-danger {
  background: #fee2e2;
  color: #dc2626;
  border-color: #fca5a5;
}
.btn-danger:hover {
  background: #fecaca;
}

.btn-success {
  background: #dcfce7;
  color: #166534;
  border-color: #86efac;
}

.btn-lg {
  padding: 16px 28px;
  font-size: 1.1rem;
  border-radius: var(--radius-md);
}

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
}

/* Linha do Tempo de Medicamentos (Timeline) */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 20px;
  position: relative;
}

.timeline-item {
  display: flex;
  gap: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 18px;
  transition: var(--transition);
  position: relative;
}

.timeline-time-col {
  width: 70px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--border-subtle);
  padding-right: 12px;
}

.time-val {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
}

.timeline-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.drug-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  width: fit-content;
  margin-bottom: 6px;
}

.status-badge {
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: capitalize;
}

.status-confirmed { background: #dcfce7; color: #15803d; }
.status-scheduled { background: #e0f2fe; color: #0369a1; }
.status-delayed { background: #fee2e2; color: #b91c1c; }
.status-skipped { background: #f1f5f9; color: #64748b; }
.status-snoozed { background: #fef3c7; color: #b45309; }

/* Barra Inferior Mobile */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border-subtle);
  padding: 8px 12px 16px;
  z-index: 50;
  justify-content: space-around;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.72rem;
  font-weight: 500;
  border: none;
  background: transparent;
  cursor: pointer;
}

.bottom-nav-item.active {
  color: var(--primary);
  font-weight: 600;
}

.bottom-nav-item .icon {
  font-size: 1.3rem;
}

/* Modais e Overlays */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  max-width: 560px;
  width: 100%;
  padding: 32px;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
}

/* Formulários */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 18px;
}

.form-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
}

.form-input, .form-select, .form-textarea {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-main);
  font-family: inherit;
  font-size: 1rem;
  transition: var(--transition);
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.2);
}

/* Chat Assistente IA */
.chat-window {
  display: flex;
  flex-direction: column;
  height: 480px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-card);
}

.chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-bubble {
  max-width: 80%;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  line-height: 1.45;
}

.bubble-assistant {
  background: var(--bg-subtle);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.bubble-user {
  background: var(--primary);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.chat-input-bar {
  display: flex;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-card);
}

/* Responsividade Mobile */
@media (max-width: 900px) {
  .app-sidebar {
    display: none;
  }
  .bottom-nav {
    display: flex;
  }
  .app-main {
    padding: 16px;
    padding-bottom: 90px;
  }
}

/* Animações e Redução de Movimento */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* DoseFiel finalizacao: tutorial + banner + alto contraste idoso */
body.mode-senior{font-size:20px;}
body.mode-senior .card{border-width:2px;}
#pwa-install-banner,#ios-install-banner{display:none;position:fixed;bottom:76px;left:12px;right:12px;z-index:900;background:#0f172a;color:#fff;padding:12px 14px;border-radius:12px;box-shadow:0 10px 25px rgba(0,0,0,.35);align-items:center;gap:10px;}
.status-delayed{background:#fef2f2;color:#b91c1c;}
.status-taken_late{background:#fef2f2;color:#b91c1c;}
