/* ═══════════════════════════════════════════════════════════════
   FlowBoard — Dark-mode Productivity Dashboard
   Design system: Deep navy + glassmorphism + vivid accents
   ═══════════════════════════════════════════════════════════════ */

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

:root {
  --bg-base:       #080e1a;
  --bg-surface:    #0f172a;
  --bg-panel:      #111827;
  --bg-card:       rgba(255,255,255,0.04);
  --bg-hover:      rgba(255,255,255,0.07);
  --border:        rgba(255,255,255,0.08);
  --border-active: rgba(255,255,255,0.18);

  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #475569;

  --accent:        #6366f1;
  --accent-glow:   rgba(99,102,241,.35);
  --success:       #10b981;
  --warning:       #f59e0b;
  --danger:        #ef4444;

  --radius-sm:  6px;
  --radius-md:  12px;
  --radius-lg:  18px;
  --radius-xl:  24px;

  --shadow-sm:  0 1px 3px rgba(0,0,0,.4);
  --shadow-md:  0 4px 16px rgba(0,0,0,.5);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.6);
  --shadow-glow: 0 0 24px var(--accent-glow);

  --font: 'Inter', system-ui, sans-serif;
  --transition: 0.18s ease;
}

html { font-size: 16px; scroll-behavior: smooth; overflow-x: hidden; width: 100%; }

body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  width: 100%;
  background-image:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(99,102,241,.12), transparent),
    radial-gradient(ellipse 60% 40% at 80% 110%, rgba(16,185,129,.08), transparent);
}

/* ── Utility ─────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Scrollbars ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-active); border-radius: 99px; }

/* ══════════════════════════════════════════════════════════════
   HEADER
   ══════════════════════════════════════════════════════════════ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(8,14,26,.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
}

.header-inner {
  max-width: 1600px;
  margin: 0 auto;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-shrink: 0;
}
.brand-icon { font-size: 1.4rem; }
.brand-name {
  font-size: 1.15rem;
  font-weight: 700;
  background: linear-gradient(135deg, #a5b4fc, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.month-nav {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}
.month-title {
  font-size: 1.05rem;
  font-weight: 600;
  min-width: 160px;
  text-align: center;
  letter-spacing: .02em;
}
.nav-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  width: 36px; height: 36px;
  font-size: 1.3rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.nav-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-active);
  color: var(--text-primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}

.streak-badge {
  background: linear-gradient(135deg, rgba(245,158,11,.15), rgba(239,68,68,.1));
  border: 1px solid rgba(245,158,11,.25);
  border-radius: 99px;
  padding: .3rem .9rem;
  font-size: .82rem;
  font-weight: 600;
  color: var(--warning);
  white-space: nowrap;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn-primary {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: .5rem 1.1rem;
  font-family: var(--font);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: 0 2px 8px rgba(99,102,241,.3);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(99,102,241,.45);
}
.btn-primary:active { transform: translateY(0); }
.btn-full { width: 100%; padding: .75rem; }

/* ══════════════════════════════════════════════════════════════
   DASHBOARD LAYOUT
   ══════════════════════════════════════════════════════════════ */
.dashboard {
  width: 95%;
  margin: 0 auto;
  padding: 1rem 0 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

@media (min-width: 768px) {
  .dashboard {
    width: 90%;
    display: grid;
    grid-template-columns: 1fr;
    padding: 1.5rem 0 3rem;
  }
}

@media (min-width: 1100px) {
  .dashboard {
    width: 100%;
    max-width: 1600px;
    padding: 1.5rem 2rem 3rem;
    grid-template-columns: 1fr 360px;
  }
}

/* ── Panel ───────────────────────────────────────────────────── */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  overflow: hidden;
}

.panel-header { margin-bottom: 1.25rem; }
.panel-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: .01em;
}
.panel-subtitle {
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: .2rem;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
/* Added padding-bottom to allow scrolling past the chat widget */
.sidebar { display: flex; flex-direction: column; gap: 1.5rem; padding-bottom: 100px !important; }

/* ══════════════════════════════════════════════════════════════
   HABIT GRID (FIXED STICKY CSS)
   ══════════════════════════════════════════════════════════════ */
.grid-wrapper {
  overflow-x: auto;
  position: relative;
  width: 100%;
  max-width: 100vw;
  -webkit-overflow-scrolling: touch;
  display: block; 
}

.habit-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 3px;
  min-width: 640px;
}

/* Day header row */
.day-header-row th {
  font-size: .68rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  padding: 0 2px 8px;
  white-space: nowrap;
  user-select: none;
}
/* Force top-left corner to sit above everything */
.day-header-row th:first-child {
  position: sticky !important;
  left: 0 !important;
  background-color: #111827 !important; /* Matches panel bg perfectly */
  z-index: 12 !important;
}

.day-header-row .today-header {
  color: var(--accent);
  position: relative;
}
.day-header-row .today-header::after {
  content: '';
  position: absolute;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 4px; height: 4px;
  background: var(--accent);
  border-radius: 99px;
}

/* Habit label column (The Sticky Fix) */
.habit-label-cell {
  padding: 4px 12px 4px 4px;
  white-space: nowrap;
  position: sticky !important;
  left: 0 !important;
  background-color: #111827 !important; /* Matches panel bg perfectly */
  z-index: 11 !important;
  box-shadow: 2px 0 5px rgba(0,0,0,0.3); /* Creates depth over scrolling cells */
}
.habit-label-inner {
  display: flex;
  align-items: center;
  gap: .5rem;
}
.habit-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.habit-name {
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-primary);
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.habit-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: .75rem;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: opacity var(--transition), color var(--transition);
  margin-left: auto;
}
.habit-row:hover .habit-delete-btn { opacity: 1; }
.habit-delete-btn:hover { color: var(--danger); }

/* Habit cells (checkboxes) */
.habit-cell {
  padding: 2px;
  text-align: center;
}
.cell-btn {
  width: 26px; height: 26px;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  position: relative;
  overflow: hidden;
}
.cell-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.cell-btn:hover {
  border-color: var(--border-active);
  transform: scale(1.15);
}
.cell-btn.done {
  border-color: transparent;
  box-shadow: 0 0 8px currentColor;
}
.cell-btn.done::before {
  content: '✓';
  font-size: .65rem;
  font-weight: 700;
  color: #fff;
  position: relative;
  z-index: 1;
}
.cell-btn.done::after { opacity: 0.9; }

/* Future day (greyed) */
.cell-btn.future {
  opacity: 0.25;
  cursor: not-allowed;
  pointer-events: none;
}

/* Today column highlight */
.today-col .cell-btn {
  border-color: rgba(99,102,241,.4);
}

/* Grid loading */
.grid-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  padding: 3rem;
  color: var(--text-muted);
  font-size: .9rem;
}

/* ══════════════════════════════════════════════════════════════
   PROGRESS RINGS
   ══════════════════════════════════════════════════════════════ */
.rings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 1rem;
}

.ring-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  padding: .75rem .5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: all var(--transition);
}
.ring-card:hover {
  background: var(--bg-hover);
  border-color: var(--border-active);
  transform: translateY(-2px);
}

.ring-canvas-wrap {
  position: relative;
  width: 80px; height: 80px;
}
.ring-canvas-wrap canvas { width: 80px !important; height: 80px !important; }

.ring-pct {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  font-weight: 700;
  color: var(--text-primary);
}

.ring-label {
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.2;
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ring-streak {
  font-size: .68rem;
  color: var(--warning);
  font-weight: 600;
}

/* ══════════════════════════════════════════════════════════════
   TODOS
   ══════════════════════════════════════════════════════════════ */
.todo-count-badge {
  background: var(--accent);
  color: #fff;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 700;
  padding: .1rem .55rem;
  margin-left: .5rem;
}

.todo-add-form {
  display: flex;
  gap: .5rem;
  margin-bottom: 1rem;
}
.todo-input {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: .88rem;
  padding: .55rem .9rem;
  outline: none;
  transition: border-color var(--transition);
}
.todo-input::placeholder { color: var(--text-muted); }
.todo-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

.btn-add-todo {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  width: 40px; height: 40px;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
  box-shadow: 0 2px 8px rgba(99,102,241,.3);
}
.btn-add-todo:hover { transform: scale(1.08); box-shadow: 0 4px 16px rgba(99,102,241,.45); }

.todo-list { list-style: none; display: flex; flex-direction: column; gap: .45rem; }

.todo-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem .8rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  animation: slideIn .2s ease;
}
.todo-item:hover {
  background: var(--bg-hover);
  border-color: var(--border-active);
}
.todo-item.completed { opacity: .55; }
.todo-item.completed .todo-text { text-decoration: line-through; color: var(--text-muted); }

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

.todo-checkbox {
  width: 18px; height: 18px;
  border-radius: 5px;
  border: 2px solid var(--border-active);
  background: transparent;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  cursor: pointer;
}
.todo-item.completed .todo-checkbox {
  background: var(--success);
  border-color: var(--success);
}
.todo-item.completed .todo-checkbox::after { content: '✓'; color: #fff; font-size: .7rem; font-weight: 700; }

.todo-text {
  flex: 1;
  font-size: .88rem;
  color: var(--text-primary);
  line-height: 1.3;
}

.todo-del-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: .8rem;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: all var(--transition);
  flex-shrink: 0;
}
.todo-item:hover .todo-del-btn { opacity: 1; }
.todo-del-btn:hover { color: var(--danger); }

/* ══════════════════════════════════════════════════════════════
   EMPTY STATE
   ══════════════════════════════════════════════════════════════ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2.5rem 1rem;
  gap: .75rem;
  color: var(--text-muted);
  font-size: .88rem;
  text-align: center;
}
.empty-icon { font-size: 2.5rem; }

/* ══════════════════════════════════════════════════════════════
   SPINNER
   ══════════════════════════════════════════════════════════════ */
.spinner {
  width: 22px; height: 22px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════════════════════════
   MODAL
   ══════════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity:0 } to { opacity:1 } }

.modal-card {
  background: #131d30;
  border: 1px solid var(--border-active);
  border-radius: var(--radius-xl);
  padding: 2rem;
  width: min(420px, calc(100vw - 2rem));
  position: relative;
  box-shadow: var(--shadow-lg);
  animation: popIn .2s cubic-bezier(.34,1.56,.64,1);
}
@keyframes popIn { from { transform: scale(.9); opacity:0; } to { transform: scale(1); opacity:1;} }

.modal-close {
  position: absolute;
  top: 1rem; right: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  width: 30px; height: 30px;
  cursor: pointer;
  font-size: .8rem;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
}

.habit-form { display: flex; flex-direction: column; gap: 1rem; }

.form-label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: .04em;
  text-transform: uppercase;
}
.form-input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: .95rem;
  padding: .65rem .9rem;
  outline: none;
  transition: border-color var(--transition);
}
.form-input::placeholder { color: var(--text-muted); }
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

.color-picker-row {
  display: flex;
  align-items: center;
  gap: .75rem;
}
.form-color {
  width: 40px; height: 40px;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  background: none;
  padding: 0;
}
.color-swatches { display: flex; gap: .4rem; flex-wrap: wrap; }
.swatch-label { cursor: pointer; display: inline-block; }
.hidden-radio { opacity: 0; position: absolute; width: 0; height: 0; margin: 0; }
.swatch {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all .15s ease;
}
.swatch-label:hover .swatch, .swatch.active {
  transform: scale(1.2);
  border-color: rgba(255,255,255,.6);
}
.hidden-radio:checked + .swatch {
  transform: scale(1.2);
  border-color: #fff;
  box-shadow: 0 0 8px rgba(255,255,255,0.4);
}

/* ══════════════════════════════════════════════════════════════
   TOAST
   ══════════════════════════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1e293b;
  border: 1px solid var(--border-active);
  color: var(--text-primary);
  padding: .65rem 1.25rem;
  border-radius: 99px;
  font-size: .88rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  transition: transform .25s cubic-bezier(.34,1.56,.64,1), opacity .25s ease;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ==========================================
   AI CHAT WIDGET (DARK THEME)
   ========================================== */

/* --- TOGGLE BUTTON & PULSE --- */
.chat-widget-container {
    position: fixed !important;
    bottom: 24px !important;
    right: 24px !important;
    z-index: 9999;
}

#chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6); /* Purple/Indigo gradient */
    color: white;
    border: none;
    font-size: 28px;
    cursor: pointer;
    position: relative;
    z-index: 2;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#chat-toggle-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.6);
}

.pulse-ring {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: #8b5cf6;
    border-radius: 50%;
    z-index: 1;
    animation: ping 2s cubic-bezier(0, 0, 0.2, 1) infinite;
}

@keyframes ping {
    75%, 100% { transform: scale(1.6); opacity: 0; }
}

/* ═════════════════════════════════════════════════════════════════════════════
   PREMIUM AI CO-PILOT WIDGET UI (React Dimensions: 327x505)
═════════════════════════════════════════════════════════════════════════════ */

.chat-window {
    position: fixed;
    bottom: 96px; 
    right: 24px;  
    width: 327px;  /* Exact width from React */
    height: 505px; /* Exact height from React */
    background-color: #1e1e2e;
    border: 1px solid #334155;
    border-radius: 24px; /* Exact rounded corners from React */
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    
    /* Smooth Spring Animation */
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px) scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.chat-window.open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

/* ─── SCALED DOWN HEADER ─── */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center; /* Changed from flex-start to center */
    padding: 16px 16px 12px 16px; /* Tighter padding */
    background-color: #1e1e2e;
    border-bottom: 1px solid #2a3441;
    border-top-left-radius: 24px;
    border-top-right-radius: 24px;
}

.header-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.header-info strong { color: #ffffff; font-size: 14.5px; font-weight: 700; }
.header-info span { color: #6366f1; font-size: 11px; font-weight: 500; }

#chat-close-btn {
    background: none; border: none; color: #94a3b8;
    font-size: 18px; cursor: pointer; padding: 0;
    line-height: 1; transition: color 0.2s;
}
#chat-close-btn:hover { color: #ffffff; }

/* ─── SCALED DOWN BUBBLES & CHAT AREA ─── */
.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 14px 16px; /* Tighter padding */
    overflow-y: auto;
    flex-grow: 1;
}

.chat-home-view {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 8px;
}

.chat-home-view p { color: #f8fafc; font-size: 14.5px; margin: 0; line-height: 1.5; }

.suggestion-chips {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chip {
    background-color: #283345;
    color: #cbd5e1;
    border: 1px solid #3b4b63;
    padding: 12px 16px;
    border-radius: 12px;
    text-align: left;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.chip:hover {
    background-color: #334155;
    border-color: #6366f1;
    color: #ffffff;
    transform: translateY(-1px);
}

/* ─── 3. I-MESSAGE BUBBLES ─── */
.msg-user {
    align-self: flex-end;
    background-color: #6366f1; 
    color: #ffffff;
    padding: 8px 12px;
    border-radius: 18px 18px 4px 18px; 
    max-width: 90%; /* Let it stretch a bit more */
    font-size: 13px; /* Slightly smaller text */
    line-height: 1.4;
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}

.msg-ai {
    align-self: flex-start;
    background-color: #334155; 
    color: #f8fafc;
    padding: 8px 12px;
    border-radius: 4px 18px 18px 18px; 
    max-width: 90%; 
    font-size: 13px; /* Slightly smaller text */
    line-height: 1.4;
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}

/* Markdown Formatting */
.msg-ai p { margin: 0 0 8px 0; }
.msg-ai p:last-child { margin: 0; }
.msg-ai ul { margin: 8px 0; padding-left: 20px; list-style-type: disc; }
.msg-ai li { margin-bottom: 6px; }
.msg-ai strong { color: #ffffff; font-weight: 600; }

/* ─── SCALED DOWN INPUT AREA ─── */
.chat-input-area {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px 14px 16px; /* Tighter padding */
    background-color: #1e1e2e;
    border-top: 1px solid #2a3441;
    border-bottom-left-radius: 24px;
    border-bottom-right-radius: 24px;
}

#chat-input {
    flex-grow: 1;
    background-color: #0f172a; 
    border: 1px solid #334155;
    color: white;
    padding: 10px 14px;
    border-radius: 20px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
    width: 100%; /* Prevents squishing */
}

#chat-input:focus { border-color: #6366f1; }

#mic-btn {
    background: none; border: none; color: #94a3b8;
    font-size: 16px; cursor: pointer; padding: 4px;
}
#mic-btn:hover { color: #ffffff; }

#send-btn {
    background-color: #6366f1; color: white; border: none;
    width: 32px; /* Smaller button */
    height: 32px; 
    font-size: 14px;
    border-radius: 50%;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: transform 0.2s; flex-shrink: 0; /* Prevents button from shrinking */
}
#send-btn:hover { transform: scale(1.05); }

/* ==========================================
   AUTHENTICATION OVERLAY
   ========================================== */
.auth-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(17, 20, 34, 0.95); /* Deep navy base */
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}

.auth-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.auth-card {
    background: #1c2136;
    border: 1px solid #2a2f45;
    border-radius: 24px;
    width: 100%;
    max-width: 420px;
    padding: 40px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.auth-header {
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-brand {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.auth-brand-icon {
    font-size: 24px;
}

.auth-brand-name { color: #f8fafc; }

.auth-header h2 {
    color: #e2e8f0;
    font-size: 24px;
    font-weight: 600;
}

.auth-header p {
    color: #94a3b8;
    font-size: 14px;
    margin: 0;
}

#auth-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.auth-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-field label {
    font-size: 13px;
    font-weight: 500;
    color: #cbd5e1;
    text-align: left;
}

.auth-field input {
    width: 100%;
    padding: 14px 16px;
    background: #111422;
    border: 1px solid #2a2f45;
    border-radius: 12px;
    color: #f8fafc;
    font-size: 15px;
    transition: all 0.2s ease;
    outline: none;
}

.auth-field input:focus {
    border-color: #8b5cf6;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
}

.auth-field input::placeholder { color: #475569; }

.btn-auth {
    padding: 14px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 12px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-auth:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.btn-auth:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.auth-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    padding: 12px;
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
}

.auth-error.hidden { display: none; }

.auth-footer {
    text-align: center;
    border-top: 1px solid #2a2f45;
    padding-top: 20px;
    margin-top: 4px;
}

.auth-footer p {
    color: #94a3b8;
    font-size: 14px;
    margin: 0;
}

#auth-switch-btn {
    background: none;
    border: none;
    color: #8b5cf6;
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
    padding: 0;
    margin-left: 4px;
    transition: color 0.2s;
}

#auth-switch-btn:hover { color: #a78bfa; text-decoration: underline; }

/* 3. Todo Widget rules */
.todo-widget-container {
    position: fixed;
    bottom: 30px;
    left: 30px;
    z-index: 9999;
}

#todo-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #10b981, #059669); /* Green gradient */
    color: white;
    border: none;
    font-size: 28px;
    cursor: pointer;
    position: relative;
    z-index: 2;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#todo-toggle-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.6);
}

.todo-pulse-ring {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: #10b981;
    border-radius: 50%;
    z-index: 1;
    animation: ping 2s cubic-bezier(0, 0, 0.2, 1) infinite;
}

/* --- TODO WINDOW MAIN CONTAINER --- */
.todo-window {
    position: fixed !important;
    bottom: 110px !important;
    left: 30px !important;
    width: 360px !important;
    height: 520px !important;
    max-height: 80vh !important;
    background: #151828 !important; 
    border: 1px solid #2a2f45 !important;
    border-radius: 24px !important;
    box-shadow: 0 15px 35px rgba(0,0,0,0.5) !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    z-index: 9999 !important;
    
    /* Animation Style */
    opacity: 0 !important; 
    transform: translateY(20px) scale(0.95) !important; 
    pointer-events: none !important; 
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1) !important;
}

.todo-window.open {
    opacity: 1 !important;
    transform: translateY(0) scale(1) !important;
    pointer-events: auto !important;
}

.todo-window .todo-list {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 20px;
}

/* ══════════════════════════════════════════════════════════════
   USER PROFILE UI
   ══════════════════════════════════════════════════════════════ */
.profile-badge {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #14b8a6, #0d9488);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(20, 184, 166, 0.4);
    transition: transform 0.2s;
}
.profile-badge:hover { transform: scale(1.1); }

/* ══════════════════════════════════════════════════════════════
   MOBILE UI OVERRIDES (Popups, Buttons, Inputs)
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    /* 1. Header & Navigation Fixes */
    .app-header { padding: 1.2rem 1rem 0; height: auto; }
    .header-inner {
        height: auto;
        display: grid;
        grid-template-columns: 1fr auto auto;
        grid-template-areas:
            "brand streak profile"
            "nav nav nav"
            "add add add";
        gap: 1.2rem 0.6rem;
    }
    .brand { grid-area: brand; }
    .month-nav { grid-area: nav; justify-content: center; }
    .header-actions { display: contents; }
    #btn-add-habit { grid-area: add; width: 100%; margin: 0; }
    .streak-badge { grid-area: streak; justify-self: flex-end; }
    #profile-badge { grid-area: profile; }

    /* 2. Font Sizing & Text Truncation */
    html { font-size: 14px; }
    .habit-label-cell {
        white-space: normal !important;
        min-width: 140px;
    }
    .habit-name {
        max-width: 140px;
        white-space: normal;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        line-height: 1.3;
    }

    /* 3. Habit Matrix Grid Scaling */
    .day-header-row th { min-width: 44px; }
    .habit-cell { min-width: 44px; }
    .cell-btn { width: 34px; height: 34px; }

    /* Mobile overrides for modals and buttons */
    .btn-primary, .btn-auth, .btn-add-todo, #btn-logout {
        padding: 14px 20px !important;
        min-height: 50px !important;
        font-size: 16px !important;
    }
    .form-input, .todo-input, .auth-field input, #chat-input {
        padding: 14px 16px !important;
        font-size: 16px !important;
    }
    .modal-card {
        width: 100% !important;
        max-width: 90vw !important;
        padding: 1.5rem !important;
        max-height: 90vh;
        overflow-y: auto;
    }
    .auth-card {
        width: 100% !important;
        max-width: 90vw !important;
        padding: 20px !important;
    }
    .chat-window {
        width: 90vw !important;
        right: 5vw !important;
        height: 60vh !important;
        bottom: 90px !important;
    }
    .todo-window {
        width: 90vw !important;
        left: 5vw !important;
        height: 60vh !important;
        bottom: 90px !important;
    }
    #todo-toggle-btn, #chat-toggle-btn {
        width: 54px;
        height: 54px;
        font-size: 24px;
    }
    
    /* 4. Floating Action Buttons padding */
    .todo-widget-container { bottom: 32px; left: 24px; }
    .chat-widget-container { bottom: 32px !important; right: 24px !important; }
}