/* AI-Doctor PWA — Liquid Glass Design System
   Style: Apple iOS Liquid Glass / Glassmorphism
   Base: dark gradient background, frosted glass surfaces
   Cyrillic: system-ui stack (SF Pro on Apple, Segoe UI on Windows)
   Fallback: solid semi-transparent backgrounds when backdrop-filter unavailable
*/

/* ── Reset & Base ─────────────────────────────────────────────────── */

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

:root {
  /* Core glass palette */
  --glass-white:        rgba(255, 255, 255, 0.12);
  --glass-white-mid:    rgba(255, 255, 255, 0.18);
  --glass-border:       rgba(255, 255, 255, 0.20);
  --glass-border-light: rgba(255, 255, 255, 0.12);

  /* User bubble: blue-tinted glass */
  --glass-user:         rgba(32, 120, 220, 0.72);
  --glass-user-border:  rgba(80, 160, 255, 0.35);
  --glass-user-text:    #ffffff;

  /* Assistant bubble: frosted white glass */
  --glass-assist:       rgba(255, 255, 255, 0.15);
  --glass-assist-border:rgba(255, 255, 255, 0.28);
  --glass-assist-text:  #f0f4ff;

  /* Accent */
  --accent:             #4ba3f5;

  /* Text */
  --text-primary:       rgba(255, 255, 255, 0.92);
  --text-secondary:     rgba(255, 255, 255, 0.55);
  --text-muted:         rgba(255, 255, 255, 0.38);

  /* Error: warm glass tint */
  --glass-error:        rgba(220, 60, 60, 0.22);
  --glass-error-border: rgba(255, 100, 100, 0.30);
  --glass-error-text:   rgba(255, 180, 180, 0.95);

  /* Offline: amber glass */
  --glass-offline:      rgba(180, 100, 20, 0.35);
  --glass-offline-border:rgba(255, 160, 60, 0.40);

  /* Radius scale */
  --radius-xl:   24px;
  --radius-lg:   18px;
  --radius-md:   14px;
  --radius-sm:   10px;
  --radius-full: 999px;

  /* Layout */
  --header-height: 64px;

  /* Typography */
  --font-size-base: 16px;
  --font-size-sm:   14px;
  --font-size-xs:   12px;

  /* Motion */
  --ease-glass: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --duration:   0.22s;

  /* Blur */
  --blur-heavy: 24px;
  --blur-mid:   16px;
  --blur-light: 10px;
}

html {
  font-size: var(--font-size-base);
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
               "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background:
    linear-gradient(145deg, #0d1b2a 0%, #1a2540 30%, #0f2035 60%, #162035 100%);
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100dvh;
  overflow: hidden;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Ambient glow orbs — decorative, pointer-events none */
body::before,
body::after {
  content: "";
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}

body::before {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(32, 90, 200, 0.18) 0%, transparent 70%);
  top: -120px;
  right: -120px;
  filter: blur(60px);
}

body::after {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(10, 60, 140, 0.14) 0%, transparent 70%);
  bottom: -100px;
  left: -100px;
  filter: blur(60px);
}

/* Screen-reader only */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ── App Shell ────────────────────────────────────────────────────── */

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 800px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

/* ── Header ───────────────────────────────────────────────────────── */

.app-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  padding-top: env(safe-area-inset-top, 0px);
  height: calc(var(--header-height) + env(safe-area-inset-top, 0px));

  background: var(--glass-white-mid);
  backdrop-filter: blur(var(--blur-heavy));
  -webkit-backdrop-filter: blur(var(--blur-heavy));
  border-bottom: 1px solid var(--glass-border);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.08) inset,
    0 4px 24px rgba(0, 0, 0, 0.30);
}

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

.header-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: var(--glass-white);
  border: 1px solid var(--glass-border);
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.20);
}

.app-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text-primary);
}

.app-subtitle {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  display: block;
  line-height: 1.2;
  letter-spacing: 0.01em;
}

.status-indicator {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  background: var(--glass-white);
  border: 1px solid var(--glass-border-light);
  border-radius: var(--radius-full);
  padding: 4px 12px;
  opacity: 0;
  transition: opacity var(--duration) var(--ease-glass);
  white-space: nowrap;
  backdrop-filter: blur(var(--blur-light));
  -webkit-backdrop-filter: blur(var(--blur-light));
}

.status-indicator.visible {
  opacity: 1;
}

/* ── Chat Container ───────────────────────────────────────────────── */

.chat-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.messages {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* Thin translucent scrollbar */
.messages::-webkit-scrollbar {
  width: 4px;
}

.messages::-webkit-scrollbar-track {
  background: transparent;
}

.messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-full);
}

.messages::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* ── Empty State ──────────────────────────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  height: 100%;
  padding: 40px 32px;
  text-align: center;
  animation: fadeIn 0.5s var(--ease-glass);
}

.empty-icon {
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--glass-white);
  border: 1px solid var(--glass-border);
  border-radius: 22px;
  backdrop-filter: blur(var(--blur-mid));
  -webkit-backdrop-filter: blur(var(--blur-mid));
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.06) inset,
    0 8px 32px rgba(0, 0, 0, 0.25);
}

.empty-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.empty-subtitle {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  line-height: 1.7;
  max-width: 240px;
}

/* ── Message Bubbles ──────────────────────────────────────────────── */

.message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: slideUp 0.26s var(--ease-glass);
}

.message--user {
  align-self: flex-end;
  align-items: flex-end;
}

.message--assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.message__bubble {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: var(--font-size-base);
  line-height: 1.58;
  word-break: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

/* User bubble: blue-tinted glass */
.message--user .message__bubble {
  background: var(--glass-user);
  border: 1px solid var(--glass-user-border);
  color: var(--glass-user-text);
  border-bottom-right-radius: var(--radius-sm);
  backdrop-filter: blur(var(--blur-mid));
  -webkit-backdrop-filter: blur(var(--blur-mid));
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.15) inset,
    0 6px 24px rgba(0, 0, 0, 0.30);
}

/* Assistant bubble: frosted white glass */
.message--assistant .message__bubble {
  background: var(--glass-assist);
  border: 1px solid var(--glass-assist-border);
  color: var(--glass-assist-text);
  border-bottom-left-radius: var(--radius-sm);
  backdrop-filter: blur(var(--blur-mid));
  -webkit-backdrop-filter: blur(var(--blur-mid));
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.10) inset,
    0 6px 24px rgba(0, 0, 0, 0.28);
}

.message__meta {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: 5px;
  padding: 0 4px;
  letter-spacing: 0.01em;
}

/* ── Markdown inside bubbles ──────────────────────────────────────── */

.message__bubble p { margin: 0 0 8px; }
.message__bubble p:last-child { margin-bottom: 0; }

.message__bubble strong { font-weight: 650; }
.message__bubble em { font-style: italic; }

.message__bubble ul,
.message__bubble ol {
  padding-left: 20px;
  margin: 6px 0;
}

.message__bubble li {
  margin-bottom: 4px;
}

.message__bubble h1,
.message__bubble h2,
.message__bubble h3 {
  font-weight: 650;
  margin: 12px 0 5px;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.message__bubble h1 { font-size: 1.15em; }
.message__bubble h2 { font-size: 1.08em; }
.message__bubble h3 { font-size: 1.02em; }

/* Inline code — glass chip */
.message__bubble code {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 5px;
  padding: 1px 6px;
  font-family: "SFMono-Regular", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.87em;
  color: rgba(180, 220, 255, 0.95);
}

.message--user .message__bubble code {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.22);
  color: rgba(255, 255, 255, 0.90);
}

/* Code block */
.message__bubble pre {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin: 8px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.message__bubble pre code {
  background: none;
  border: none;
  padding: 0;
  color: rgba(200, 230, 255, 0.88);
  font-size: 0.85em;
}

/* Links */
.message__bubble a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message--user .message__bubble a {
  color: rgba(200, 230, 255, 0.90);
}

/* Blockquote */
.message__bubble blockquote {
  border-left: 2px solid rgba(255, 255, 255, 0.25);
  padding-left: 12px;
  margin: 6px 0;
  color: var(--text-secondary);
  font-style: italic;
}

.message__bubble hr {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  margin: 10px 0;
}

/* ── Typing / Loading Indicator ───────────────────────────────────── */

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  border-bottom-left-radius: var(--radius-sm);
  background: var(--glass-assist);
  border: 1px solid var(--glass-assist-border);
  backdrop-filter: blur(var(--blur-mid));
  -webkit-backdrop-filter: blur(var(--blur-mid));
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.10) inset,
    0 4px 16px rgba(0, 0, 0, 0.22);
  align-self: flex-start;
  max-width: 130px;
  animation: slideUp 0.22s var(--ease-glass);
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  animation: typingPulse 1.4s ease-in-out infinite;
  flex-shrink: 0;
}

.typing-dot:nth-child(2) { animation-delay: 0.18s; }
.typing-dot:nth-child(3) { animation-delay: 0.36s; }

.typing-label {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  font-style: italic;
  white-space: nowrap;
}

/* ── Offline Banner ───────────────────────────────────────────────── */

.offline-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--glass-offline);
  border-top: 1px solid var(--glass-offline-border);
  border-bottom: 1px solid var(--glass-offline-border);
  color: rgba(255, 200, 120, 0.95);
  font-size: var(--font-size-sm);
  font-weight: 500;
  padding: 10px 20px;
  text-align: center;
  justify-content: center;
  flex-shrink: 0;
  backdrop-filter: blur(var(--blur-light));
  -webkit-backdrop-filter: blur(var(--blur-light));
  animation: slideDown 0.22s var(--ease-glass);
}

.offline-banner[hidden] { display: none; }

/* ── Input Area ───────────────────────────────────────────────────── */

.input-area {
  flex-shrink: 0;
  padding: 12px 14px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--glass-white);
  border-top: 1px solid var(--glass-border);
  backdrop-filter: blur(var(--blur-heavy));
  -webkit-backdrop-filter: blur(var(--blur-heavy));
  box-shadow:
    0 -1px 0 rgba(255, 255, 255, 0.07) inset,
    0 -4px 24px rgba(0, 0, 0, 0.25);
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 100%;
}

.message-input {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-full);
  padding: 10px 18px;
  font-size: var(--font-size-base);
  font-family: inherit;
  background: rgba(255, 255, 255, 0.10);
  color: var(--text-primary);
  resize: none;
  outline: none;
  line-height: 1.45;
  transition:
    border-color var(--duration) var(--ease-glass),
    box-shadow var(--duration) var(--ease-glass),
    background var(--duration) var(--ease-glass);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  backdrop-filter: blur(var(--blur-light));
  -webkit-backdrop-filter: blur(var(--blur-light));
}

.message-input:focus {
  border-color: rgba(75, 163, 245, 0.60);
  background: rgba(255, 255, 255, 0.13);
  box-shadow:
    0 0 0 3px rgba(75, 163, 245, 0.15),
    0 2px 12px rgba(0, 0, 0, 0.20);
}

.message-input::placeholder {
  color: var(--text-muted);
}

/* Send button */
.send-button {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(32, 110, 220, 0.75);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition:
    background var(--duration) var(--ease-glass),
    transform var(--duration) var(--ease-glass),
    opacity var(--duration) var(--ease-glass),
    box-shadow var(--duration) var(--ease-glass);
  touch-action: manipulation;
  backdrop-filter: blur(var(--blur-light));
  -webkit-backdrop-filter: blur(var(--blur-light));
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.20) inset,
    0 4px 16px rgba(0, 0, 0, 0.30);
}

.send-button:disabled {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.10);
  cursor: not-allowed;
  opacity: 0.45;
  box-shadow: none;
}

.send-button:not(:disabled):hover {
  background: rgba(40, 130, 240, 0.88);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.25) inset,
    0 6px 20px rgba(32, 110, 220, 0.40);
}

.send-button:not(:disabled):active {
  transform: scale(0.92);
  box-shadow: none;
}

/* ── Error Message ────────────────────────────────────────────────── */

.message--error .message__bubble {
  background: var(--glass-error);
  border-color: var(--glass-error-border);
  color: var(--glass-error-text);
  backdrop-filter: blur(var(--blur-light));
  -webkit-backdrop-filter: blur(var(--blur-light));
}

.message--error .message__bubble a {
  color: rgba(255, 180, 180, 0.90);
}

/* ── Animations ───────────────────────────────────────────────────── */

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

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

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes typingPulse {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.55;
  }
  30% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

/* ── Desktop (>= 600px) ───────────────────────────────────────────── */

@media (min-width: 600px) {
  .messages {
    padding: 24px 28px 12px;
    gap: 14px;
  }

  .message {
    max-width: 72%;
  }

  .input-area {
    padding: 14px 28px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }

  .app-title {
    font-size: 19px;
  }

  .message__bubble {
    padding: 13px 18px;
  }
}

/* Desktop: heavier blur — more GPU budget on large screens */
@media (min-width: 1024px) {
  :root {
    --blur-heavy: 32px;
    --blur-mid:   20px;
  }

  body::before {
    width: 700px;
    height: 700px;
    top: -150px;
    right: -150px;
  }
}

/* ── Backdrop-filter fallback ─────────────────────────────────────── */
/* For browsers that don't support backdrop-filter (Firefox < 103, some Android) */

@supports not (backdrop-filter: blur(1px)) {
  .app-header {
    background: rgba(12, 22, 45, 0.96);
  }

  .message--user .message__bubble {
    background: rgba(25, 90, 200, 0.92);
  }

  .message--assistant .message__bubble {
    background: rgba(35, 55, 95, 0.94);
  }

  .typing-indicator {
    background: rgba(35, 55, 95, 0.94);
  }

  .input-area {
    background: rgba(12, 22, 45, 0.96);
  }

  .message-input {
    background: rgba(25, 45, 85, 0.90);
  }

  .send-button {
    background: rgba(28, 95, 210, 0.95);
  }

  .offline-banner {
    background: rgba(140, 80, 20, 0.88);
  }
}

/* ── Reduced motion ───────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Reduced transparency ─────────────────────────────────────────── */
/* iOS/macOS "Reduce Transparency" accessibility setting */

@media (prefers-reduced-transparency: reduce) {
  .app-header {
    background: rgba(8, 18, 38, 0.98);
  }

  .message--user .message__bubble {
    background: rgba(22, 80, 190, 0.98);
  }

  .message--assistant .message__bubble {
    background: rgba(28, 48, 88, 0.98);
  }

  .typing-indicator {
    background: rgba(28, 48, 88, 0.98);
  }

  .input-area {
    background: rgba(8, 18, 38, 0.98);
  }

  .message-input {
    background: rgba(20, 38, 75, 0.98);
  }

  .send-button {
    background: rgba(25, 90, 200, 0.98);
  }
}

/* ════════════════════════════════════════════════════════════════════
   CALENDAR SCHEDULE VIEW (REQ-012)
   ════════════════════════════════════════════════════════════════════ */

/* ── Header actions wrapper ───────────────────────────────────────── */

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Calendar icon button (in chat header) ────────────────────────── */

.calendar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--glass-border);
  background: var(--glass-white);
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  flex-shrink: 0;
  transition:
    background var(--duration) var(--ease-glass),
    color var(--duration) var(--ease-glass),
    transform var(--duration) var(--ease-glass),
    box-shadow var(--duration) var(--ease-glass);
  touch-action: manipulation;
  backdrop-filter: blur(var(--blur-light));
  -webkit-backdrop-filter: blur(var(--blur-light));
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.20);
}

.calendar-btn:hover {
  background: var(--glass-white-mid);
  color: #ffffff;
  box-shadow: 0 2px 12px rgba(75, 163, 245, 0.25);
}

.calendar-btn:active {
  transform: scale(0.92);
}

/* ── Calendar overlay (full-screen) ──────────────────────────────── */

.calendar-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  /* Background matches app body */
  background:
    linear-gradient(145deg, #0d1b2a 0%, #1a2540 30%, #0f2035 60%, #162035 100%);
  background-attachment: fixed;
  animation: calSlideIn 0.28s var(--ease-glass);
}

.calendar-overlay[hidden] {
  display: none;
}

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

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

.calendar-overlay.closing {
  animation: calSlideOut 0.22s var(--ease-glass) forwards;
}

/* ── Calendar panel layout ────────────────────────────────────────── */

.calendar-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

/* ── Calendar header ──────────────────────────────────────────────── */

.calendar-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top, 0px);
  height: calc(var(--header-height) + env(safe-area-inset-top, 0px));

  background: var(--glass-white-mid);
  backdrop-filter: blur(var(--blur-heavy));
  -webkit-backdrop-filter: blur(var(--blur-heavy));
  border-bottom: 1px solid var(--glass-border);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.08) inset,
    0 4px 24px rgba(0, 0, 0, 0.30);
}

.calendar-back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--accent);
  font-size: var(--font-size-sm);
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  transition: opacity var(--duration) var(--ease-glass);
  touch-action: manipulation;
  min-width: 70px;
}

.calendar-back-btn:hover {
  opacity: 0.75;
}

.calendar-back-btn:active {
  opacity: 0.5;
}

.calendar-date-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  justify-content: center;
}

.cal-date-label {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  letter-spacing: -0.01em;
  line-height: 1.2;
  /* Fixed min-width prevents layout shift when date changes */
  min-width: 180px;
}

.cal-nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  border: 1px solid var(--glass-border-light);
  background: var(--glass-white);
  color: rgba(255, 255, 255, 0.80);
  cursor: pointer;
  flex-shrink: 0;
  transition:
    background var(--duration) var(--ease-glass),
    transform var(--duration) var(--ease-glass);
  touch-action: manipulation;
  backdrop-filter: blur(var(--blur-light));
  -webkit-backdrop-filter: blur(var(--blur-light));
}

.cal-nav-btn:hover {
  background: var(--glass-white-mid);
  color: #ffffff;
}

.cal-nav-btn:active {
  transform: scale(0.88);
}

/* ── Calendar body (scrollable content) ──────────────────────────── */

.calendar-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 16px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  -webkit-overflow-scrolling: touch;
}

.calendar-body::-webkit-scrollbar {
  width: 4px;
}

.calendar-body::-webkit-scrollbar-track {
  background: transparent;
}

.calendar-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-full);
}

/* ── Loading state ────────────────────────────────────────────────── */

.cal-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 60px 24px;
  text-align: center;
}

.cal-loading-dots {
  display: flex;
  gap: 8px;
}

.cal-loading-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
  animation: typingPulse 1.4s ease-in-out infinite;
}

.cal-loading-dot:nth-child(2) { animation-delay: 0.18s; }
.cal-loading-dot:nth-child(3) { animation-delay: 0.36s; }

.cal-loading-text {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

/* ── Empty / error states ─────────────────────────────────────────── */

.cal-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 60px 24px;
  text-align: center;
  animation: fadeIn 0.3s var(--ease-glass);
}

.cal-empty-icon {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--glass-white);
  border: 1px solid var(--glass-border);
  border-radius: 18px;
  backdrop-filter: blur(var(--blur-mid));
  -webkit-backdrop-filter: blur(var(--blur-mid));
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  color: var(--text-secondary);
}

.cal-empty-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
}

.cal-empty-subtitle {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  line-height: 1.6;
  max-width: 240px;
}

.cal-error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 60px 24px;
  text-align: center;
  animation: fadeIn 0.3s var(--ease-glass);
}

.cal-error-icon {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--glass-error);
  border: 1px solid var(--glass-error-border);
  border-radius: 18px;
  color: var(--glass-error-text);
}

.cal-error-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--glass-error-text);
}

.cal-error-subtitle {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  line-height: 1.6;
  max-width: 240px;
}

.cal-retry-btn {
  margin-top: 4px;
  padding: 10px 24px;
  border-radius: var(--radius-full);
  border: 1px solid var(--glass-border);
  background: var(--glass-white-mid);
  color: var(--text-primary);
  font-size: var(--font-size-sm);
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition:
    background var(--duration) var(--ease-glass),
    transform var(--duration) var(--ease-glass);
  touch-action: manipulation;
  backdrop-filter: blur(var(--blur-light));
  -webkit-backdrop-filter: blur(var(--blur-light));
}

.cal-retry-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.cal-retry-btn:active {
  transform: scale(0.96);
}

/* ── Time-of-day groups ───────────────────────────────────────────── */

.cal-group {
  margin-bottom: 28px;
  animation: fadeIn 0.3s var(--ease-glass);
}

.cal-group:last-child {
  margin-bottom: 0;
}

.cal-group-label {
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 10px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.cal-group-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.10);
}

/* ── Medication entry card ────────────────────────────────────────── */

.cal-entry {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  background: var(--glass-white);
  border: 1px solid var(--glass-border-light);
  backdrop-filter: blur(var(--blur-mid));
  -webkit-backdrop-filter: blur(var(--blur-mid));
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.07) inset,
    0 4px 16px rgba(0, 0, 0, 0.22);
  margin-bottom: 10px;
  transition: border-color var(--duration) var(--ease-glass);
}

.cal-entry:last-child {
  margin-bottom: 0;
}

/* Time-critical: amber border highlight */
.cal-entry--critical {
  border-color: rgba(255, 180, 60, 0.40);
  background: rgba(255, 165, 0, 0.07);
  box-shadow:
    0 1px 0 rgba(255, 200, 80, 0.10) inset,
    0 4px 16px rgba(0, 0, 0, 0.22),
    0 0 0 1px rgba(255, 180, 60, 0.15);
}

/* Status-specific left accent */
.cal-entry--taken   { border-left: 3px solid rgba(72, 199, 116, 0.70); }
.cal-entry--missed  { border-left: 3px solid rgba(220, 60, 60, 0.70); }
.cal-entry--skipped { border-left: 3px solid rgba(140, 140, 160, 0.60); }
.cal-entry--taken-late { border-left: 3px solid rgba(255, 170, 50, 0.70); }
.cal-entry--pending { border-left: 3px solid rgba(75, 163, 245, 0.50); }

/* ── Entry time column ────────────────────────────────────────────── */

.cal-entry-time {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  min-width: 44px;
}

.cal-time-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  line-height: 1;
}

/* Status badge (icon + color dot) */
.cal-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cal-status-dot--taken      { background: rgba(72, 199, 116, 0.90); }
.cal-status-dot--missed     { background: rgba(220, 60, 60, 0.90); }
.cal-status-dot--skipped    { background: rgba(140, 140, 160, 0.80); }
.cal-status-dot--taken-late { background: rgba(255, 170, 50, 0.90); }
.cal-status-dot--pending    { background: rgba(75, 163, 245, 0.70); }

/* ── Entry content ────────────────────────────────────────────────── */

.cal-entry-content {
  flex: 1;
  min-width: 0;
}

.cal-entry-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.cal-med-name {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  word-break: break-word;
}

.cal-dosage {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
  padding-top: 1px;
}

/* Badges row */
.cal-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

/* Shared badge style */
.cal-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

/* Critical badge */
.cal-badge--critical {
  background: rgba(255, 180, 60, 0.18);
  border: 1px solid rgba(255, 180, 60, 0.35);
  color: rgba(255, 210, 100, 0.95);
}

/* Status badge */
.cal-badge--taken {
  background: rgba(72, 199, 116, 0.14);
  border: 1px solid rgba(72, 199, 116, 0.30);
  color: rgba(100, 220, 140, 0.95);
}

.cal-badge--missed {
  background: rgba(220, 60, 60, 0.14);
  border: 1px solid rgba(220, 60, 60, 0.30);
  color: rgba(255, 130, 130, 0.95);
}

.cal-badge--skipped {
  background: rgba(140, 140, 160, 0.14);
  border: 1px solid rgba(140, 140, 160, 0.25);
  color: rgba(180, 180, 200, 0.90);
}

.cal-badge--taken-late {
  background: rgba(255, 170, 50, 0.14);
  border: 1px solid rgba(255, 170, 50, 0.30);
  color: rgba(255, 200, 100, 0.95);
}

.cal-badge--pending {
  background: rgba(75, 163, 245, 0.12);
  border: 1px solid rgba(75, 163, 245, 0.25);
  color: rgba(120, 190, 255, 0.90);
}

/* Food timing note */
.cal-food-timing {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  margin-top: 5px;
  display: flex;
  align-items: center;
  gap: 4px;
  line-height: 1.4;
}

.cal-food-icon {
  flex-shrink: 0;
  opacity: 0.70;
}

/* Course day indicator */
.cal-course-day {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: 3px;
}

/* Actual time (taken-late) */
.cal-actual-time {
  font-size: var(--font-size-xs);
  color: rgba(255, 200, 100, 0.80);
  margin-top: 3px;
}

/* ── Conflicts banner ─────────────────────────────────────────────── */

.cal-conflicts {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--glass-error);
  border: 1px solid var(--glass-error-border);
  color: var(--glass-error-text);
  font-size: var(--font-size-sm);
  line-height: 1.5;
  margin-bottom: 20px;
  animation: fadeIn 0.3s var(--ease-glass);
}

.cal-conflicts-icon {
  flex-shrink: 0;
  margin-top: 1px;
}

/* ── Offline notice inside calendar ──────────────────────────────── */

.cal-offline-notice {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--glass-offline);
  border: 1px solid var(--glass-offline-border);
  color: rgba(255, 200, 120, 0.95);
  font-size: var(--font-size-sm);
  font-weight: 500;
  margin-bottom: 16px;
  animation: fadeIn 0.3s var(--ease-glass);
}

/* ── Desktop adjustments ──────────────────────────────────────────── */

@media (min-width: 600px) {
  .calendar-header {
    padding: 0 28px;
    padding-top: env(safe-area-inset-top, 0px);
  }

  .calendar-body {
    padding: 28px 28px;
    padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  }

  .cal-date-label {
    font-size: 17px;
    min-width: 220px;
  }

  .cal-entry {
    padding: 16px 18px;
  }
}

/* ── Backdrop-filter fallback ─────────────────────────────────────── */

@supports not (backdrop-filter: blur(1px)) {
  .calendar-overlay {
    background: rgba(10, 20, 42, 0.99);
  }

  .calendar-header {
    background: rgba(12, 22, 45, 0.98);
  }

  .cal-entry {
    background: rgba(28, 45, 80, 0.94);
  }

  .calendar-btn {
    background: rgba(28, 45, 80, 0.92);
  }
}

/* ── Reduced transparency ─────────────────────────────────────────── */

@media (prefers-reduced-transparency: reduce) {
  .calendar-header {
    background: rgba(8, 18, 38, 0.98);
  }

  .cal-entry {
    background: rgba(22, 38, 70, 0.98);
  }
}
