/* ============================================
   JERRY OS - Layout (Responsive: Desktop + Mobile)
   "Cosmic Ocean / Illuminated Abyss" Design System
   No-Line Rule | Tonal Layering | Ghost Borders | Ambient Glows
   ============================================ */

/* APP SHELL - Sidebar | Main | Jerry Panel */
body {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Mobile menu button */
/* Mobile top bar with hamburger + title */
.mobile-top-bar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 48px;
  background: var(--bg-sidebar);
  z-index: 110;
  align-items: center;
  padding: 0 var(--s3);
  gap: var(--s2);
}
.mobile-top-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 800;
  color: var(--text-primary);
}
.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 22px;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: var(--r6);
}
.mobile-menu-btn:hover {
  background: var(--bg-sidebar-hover);
}
@media (max-width: 768px) {
  .mobile-top-bar { display: flex; }
  .mobile-menu-btn { display: flex; }
}

/* ==========================================
   SIDEBAR
   No-Line Rule: use spacing and bg shifts, not border lines.
   Active state: left accent bar + cyan text, no background box.
   ========================================== */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  color: var(--text-sidebar);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
  padding: var(--s4) 0;
  transition: transform 0.2s ease;
  z-index: 100;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s5);
  margin-bottom: var(--s4);
}
.jerry-avatar, .jerry-sphere {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 0 6px rgba(76, 215, 246, 0.4));
}
.sidebar-title {
  font-weight: 700;
  font-size: 18px;
  color: #fff;
}
.sidebar-section {
  margin-bottom: var(--s4);
}
.sidebar-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  padding: var(--s2) var(--s5) var(--s1);
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s5);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-sidebar);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  border-left: 2px solid transparent;
  border-radius: 0;
  text-decoration: none;
}
.sidebar-link:hover {
  background: var(--bg-sidebar-hover);
  color: #fff;
  text-decoration: none;
}
.sidebar-link.active {
  background: transparent;
  color: var(--bio-cyan);
  font-weight: 600;
  border-left: 2px solid var(--bio-cyan);
  border-right: none;
}
.sidebar-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}
/* No-Line Rule: spacing only, no border-top */
.sidebar-bottom {
  margin-top: auto;
  padding-top: var(--s6);
}
.badge {
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: var(--r-full);
  margin-left: auto;
}
.badge:empty { display: none; }

/* ==========================================
   MAIN CONTENT
   Full width - no max-width constraint.
   Background inherits var(--bg-app) from body.
   ========================================== */
.main-content {
  flex: 1 1 0%;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  height: 100vh;
  padding: var(--s8) var(--s10);
  background: var(--bg-app);
}

/* Pages - show/hide */
.page { display: none; width: 100%; }
.page.active { display: block; width: 100%; }

/* Page header */
.page-header {
  margin-bottom: var(--s8);
}
.page-header h1 {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}
.header-date {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: var(--s1);
}

/* ==========================================
   JERRY CHAT PANEL (Legacy - hidden)
   ========================================== */
.jerry-panel { display: none; }
.jerry-panel.open { display: none; }
.jerry-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  border-radius: var(--r16) var(--r16) 0 0;
}
.jerry-panel-title {
  display: flex;
  align-items: center;
  gap: var(--s3);
  font-weight: 700;
  font-size: 16px;
}
.jerry-avatar-sm {
  width: 28px;
  height: 28px;
  border-radius: var(--r6);
  background: var(--jerry-blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
}
.jerry-toggle {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-tertiary);
  padding: var(--s1);
}
.jerry-toggle:hover { color: var(--text-primary); }
.jerry-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--s5);
  display: flex;
  flex-direction: column;
  gap: var(--s4);
}
.jerry-msg {
  max-width: 100%;
  padding: 8px 0;
  font-size: 14px;
  line-height: 1.6;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.jerry-msg:last-child { border-bottom: none; }
.jerry-msg::before {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
}
.jerry-msg.user {
  align-self: stretch;
  background: none !important;
  border: none !important;
  border-bottom: 1px solid rgba(255,255,255,0.06) !important;
  color: var(--text-primary) !important;
}
.jerry-msg.user::before {
  content: 'Jason';
  color: #22c55e;
}
.jerry-msg.assistant {
  align-self: stretch;
  background: none !important;
  border: none !important;
  border-bottom: 1px solid rgba(255,255,255,0.06) !important;
  color: var(--text-primary) !important;
}
.jerry-msg.assistant::before {
  content: 'Jerry';
  color: #ea4335;
}
.jerry-msg p { margin: 0; }
.jerry-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: var(--s2);
  padding: var(--s4) var(--s5);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.jerry-input-wrap textarea {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: var(--r8);
  padding: var(--s3) var(--s4);
  font-size: 14px;
  resize: none;
  max-height: 120px;
  background: var(--bg-input);
  color: var(--text-primary);
}
.jerry-input-wrap textarea:focus {
  outline: none;
  border-color: var(--bio-cyan);
  box-shadow: 0 0 0 2px rgba(76, 215, 246, 0.15);
}
.jerry-send {
  width: 36px;
  height: 36px;
  border-radius: var(--r8);
  border: none;
  background: var(--jerry-blue);
  color: #fff;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.jerry-send:hover { background: var(--jerry-blue-dark); }

/* Jerry Sphere (draggable gold orb) */
.jerry-sphere-wrap {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  z-index: 9998;
  cursor: grab;
  user-select: none;
  filter: drop-shadow(0 4px 12px rgba(212, 168, 67, 0.4));
  transition: filter 0.15s;
}
.jerry-sphere-wrap:hover {
  filter: drop-shadow(0 4px 20px rgba(212, 168, 67, 0.6));
}
.jerry-sphere-wrap:active { cursor: grabbing; }

/* Jerry Chat Float (opens on double-click) */
.jerry-chat-float {
  display: none;
  position: fixed;
  width: 400px;
  max-width: 90vw;
  height: 500px;
  max-height: 85vh;
  background: var(--bg-card-solid);
  border: 1px solid var(--border);
  border-radius: var(--r16);
  flex-direction: column;
  z-index: 9997;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 20px rgba(212, 168, 67, 0.15);
  overflow: hidden;
  min-width: 280px;
  min-height: 300px;
}
.jerry-chat-float.translucent {
  opacity: 0.8;
}
.jerry-chat-float.open {
  display: flex;
}
.jerry-chat-float-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  cursor: grab;
}
.jerry-chat-float-header:active { cursor: grabbing; }
.jerry-chat-float-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--s4);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  min-height: 0;
}
.jerry-chat-float-input {
  padding: 12px 14px;
  flex-shrink: 0;
}
.jerry-input-box {
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  padding: 0;
  display: flex;
  flex-direction: column;
}
.jerry-input-box:focus-within {
  border-color: rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.08);
}
.jerry-input-attachments:empty { display: none; }
.jerry-input-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 14px 0;
}
.jerry-input-attachment-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px 3px 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
}
.jerry-input-attachment-chip button {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.4);
  cursor: pointer;
  font-size: 14px;
  padding: 0 2px;
  line-height: 1;
}
.jerry-input-attachment-chip button:hover { color: #fff; }
.jerry-input-box textarea {
  flex: 1;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 14px;
  font-family: var(--font);
  resize: none;
  line-height: 1.5;
  max-height: 200px;
  overflow-y: auto;
}
.jerry-input-box textarea::placeholder {
  color: rgba(255, 255, 255, 0.35);
}
.jerry-input-box textarea:focus {
  outline: none;
}
.jerry-input-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px 8px;
}
.jerry-input-actions-left {
  display: flex;
  align-items: center;
  gap: 2px;
}
.jerry-input-action {
  color: rgba(255, 255, 255, 0.4);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  border: none;
  background: none;
  display: flex;
  align-items: center;
  transition: all 0.1s;
}
.jerry-input-action:hover { color: rgba(255, 255, 255, 0.7); background: rgba(255,255,255,0.06); }
.jerry-input-send {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s;
}
.jerry-input-send:hover { background: rgba(255, 255, 255, 0.15); color: #fff; }

/* ==========================================
   MODAL - Glassmorphism
   Ghost border, backdrop blur, no harsh outlines.
   ========================================== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open {
  display: flex;
}
.modal {
  background: rgba(26, 31, 45, 0.95);
  border: 1px solid var(--border);
  border-radius: var(--r16);
  box-shadow: var(--shadow-lg), 0 0 40px rgba(76, 215, 246, 0.08);
  backdrop-filter: blur(20px);
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s5) var(--s6);
  /* No-Line Rule: use subtle bg shift instead of border-bottom */
  background: rgba(255, 255, 255, 0.02);
}
.modal-header h3 {
  font-size: 18px;
  font-weight: 700;
}
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-tertiary);
  padding: var(--s1);
}
.modal-body {
  padding: var(--s6);
}
.modal-footer {
  padding: var(--s4) var(--s6);
  /* No-Line Rule: use subtle bg shift instead of border-top */
  background: rgba(255, 255, 255, 0.02);
  display: flex;
  justify-content: flex-end;
  gap: var(--s3);
}

/* ==========================================
   RESPONSIVE - MOBILE
   ========================================== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg), 0 0 40px rgba(76, 215, 246, 0.06);
  }
  .main-content {
    padding: 56px var(--s3) var(--s4);
    width: 100%;
  }
  .page-header h1 { font-size: 20px; }
  .page-hero { min-height: 100px; padding: var(--s5) var(--s4); margin: calc(-1 * var(--s4)) calc(-1 * var(--s3)) var(--s5); }
  .page-hero h1 { font-size: 22px; }
  .section-header h2 { font-size: 15px; }
  .jerry-panel { display: none; }
  .jerry-sphere-wrap { width: 48px; height: 48px; bottom: 16px; right: 16px; }
  .jerry-sphere-wrap svg { width: 48px; height: 48px; }
  .jerry-chat-float { width: 100vw; max-width: 100vw; height: 60vh; bottom: 0; left: 0; border-radius: var(--r16) var(--r16) 0 0; }
  .area-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: var(--s3) !important;
  }
  .area-card { padding: var(--s3); }
  .area-card-icon { font-size: 20px; }
  .area-card-name { font-size: 13px; }
  .area-card-critical { font-size: 11px; }
  .quick-actions {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: var(--s2) !important;
  }
  .quick-btn { font-size: 12px; padding: var(--s3) var(--s2); }
  .view-tabs { gap: var(--s1); overflow-x: auto; flex-wrap: nowrap; }
  .vtab { font-size: 12px; padding: var(--s2) var(--s3); white-space: nowrap; }
  .task-item { padding: var(--s2) var(--s3); }
  .task-name { font-size: 13px; }
  .task-due { font-size: 11px; }
  .task-project { font-size: 10px; padding: 1px 6px; }
  .habit-item { padding: var(--s2); gap: var(--s2); }
  .habit-name { font-size: 13px; }
  .habit-check { width: 20px; height: 20px; }
  .habit-icon { font-size: 14px; }
  .cal-container { border-radius: var(--r8); }
  .cal-nav-title { font-size: 13px; min-width: 120px; }
  .pillar-toggle { gap: 0; }
  .pillar-tab { font-size: 12px; padding: var(--s2) var(--s3); }
  .btn-sm { font-size: 12px; padding: var(--s1) var(--s3); }
  .btn-primary { font-size: 13px; padding: var(--s2) var(--s4); }
  .modal { max-width: 95%; }
  .section { margin-bottom: var(--s5); }
  .kanban-board { gap: var(--s3); }
  .kanban-column { min-width: 220px; padding: var(--s3); }
  .note-card { padding: var(--s3) var(--s4); }
  .note-card-title { font-size: 13px; }
  .connections-grid { grid-template-columns: 1fr !important; }
  .recent-projects-cards { grid-template-columns: 1fr; }
  .projects-toolbar { flex-direction: column; align-items: stretch; }
  .projects-toolbar-left { flex-direction: column; }
  .projects-search { max-width: 100%; }
}

@media (max-width: 480px) {
  .area-grid {
    grid-template-columns: 1fr !important;
  }
  .page-hero h1 { font-size: 20px; }
  .cal-controls { flex-wrap: wrap; gap: var(--s1); }
  .cal-nav-title { min-width: auto; font-size: 12px; }
  .quick-actions { grid-template-columns: 1fr 1fr !important; }
  .quick-btn { font-size: 11px; }
}

/* ==========================================
   MOBILE POLISH - Touch-friendly, clean spacing
   ========================================== */

/* Minimum touch targets (44px per Apple HIG) */
@media (max-width: 768px) {
  button, .sidebar-link, .dash-clickable, .health-cat-card,
  .cat-protocol-card, .cat-exercise-card, .dash-item,
  .body-map-exercise-item, .ws-done-btn, .ws-ex-start-timer {
    min-height: 44px;
  }

  /* Smoother scrolling */
  .main-content {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }

  /* Dashboard metric cards - 2 columns on mobile */
  .dash-metrics-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: var(--s3) !important;
  }
  .dash-metric-value {
    font-size: 22px !important;
  }

  /* Two-column sections go single column */
  .dash-two-col {
    grid-template-columns: 1fr !important;
    gap: var(--s4) !important;
  }

  /* Health category cards - horizontal scroll */
  .health-categories-scroll {
    padding-bottom: var(--s2);
    -webkit-overflow-scrolling: touch;
  }
  .health-cat-card {
    min-width: 130px;
  }

  /* Section headers - wrap on mobile */
  .section-header {
    flex-wrap: wrap;
    gap: var(--s2);
  }

  /* Modal - full width on mobile */
  .modal {
    max-width: 100% !important;
    margin: 0 var(--s2);
    max-height: 90vh;
  }

  /* Body map - stack vertically */
  .body-map-container {
    grid-template-columns: 1fr !important;
  }
  .body-map-views {
    justify-content: center;
  }

  /* Workout session - larger buttons */
  .ws-done-btn {
    padding: var(--s3) var(--s6) !important;
    font-size: 16px !important;
  }
  .ws-rep-input {
    width: 60px !important;
    font-size: 18px !important;
    padding: var(--s3) !important;
  }

  /* Tab bars - scrollable horizontally */
  .view-tabs, .goals-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .view-tabs::-webkit-scrollbar, .goals-tabs::-webkit-scrollbar {
    display: none;
  }

  /* Stats cards on health page */
  .health-stats-row {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Category page - adjustments */
  .cat-hero-title { font-size: 22px !important; }
  .cat-session-grid { grid-template-columns: 1fr !important; }
  .cat-exercises-grid { grid-template-columns: 1fr !important; }
  .cat-stats-row { grid-template-columns: repeat(2, 1fr) !important; }
}

/* Safe area insets for notched phones */
@supports (padding-top: env(safe-area-inset-top)) {
  .mobile-top-bar {
    padding-top: env(safe-area-inset-top);
    height: calc(48px + env(safe-area-inset-top));
  }
  @media (max-width: 768px) {
    .main-content {
      padding-top: calc(56px + env(safe-area-inset-top));
      padding-bottom: env(safe-area-inset-bottom);
    }
  }
}
