/* ==========================================================================
   1. Design Tokens & CSS Variables
   ========================================================================== */
:root {
  /* Brand Palette */
  --mocha-mousse: #A5956F;
  --mocha-dark: #7A6C4D;
  --ethereal-blue: #A0D4E0;
  --ethereal-light: #F0F8FA;
  --moonlit-grey: #F2F0EA;
  --surface-white: #FFFFFF;
  
  /* Text & Feedback */
  --text-dark: #2B2A27;
  --text-muted: #6B685F;
  --alert-red: #D9534F;
  --alert-red-bg: #FFF5F5;
  --success-green: #4E8752;
  --border-light: #E4E0D5;

  /* Typography */
  --font-heading: 'Montserrat', sans-serif;
  --font-body: 'Roboto', sans-serif;

  /* UI Tokens */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-full: 999px;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-sm: 0 2px 8px rgba(43, 42, 39, 0.04);
  --shadow-md: 0 6px 18px rgba(43, 42, 39, 0.08);
}

/* ==========================================================================
   2. Reset & Base Typography
   ========================================================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-body);
  background-color: var(--moonlit-grey);
  color: var(--text-dark);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 {
  font-family: var(--font-heading);
  color: var(--text-dark);
  line-height: 1.3;
}

.card {
  background: var(--surface-white);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(165, 149, 111, 0.15);
}

.section-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 0.6rem;
}

.section-subtext {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* ==========================================================================
   3. Header Landmark
   ========================================================================== */
.site-header {
  background-color: var(--surface-white);
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  z-index: 40;
}

.nav-container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand-logo {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: -0.5px;
}

.brand-logo span {
  color: var(--mocha-mousse);
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.date-chip {
  font-size: 0.82rem;
  background: var(--moonlit-grey);
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-full);
  color: var(--text-muted);
  font-weight: 600;
}

.btn-chat-toggle {
  background: var(--ethereal-light);
  color: var(--text-dark);
  border: 1.5px solid var(--ethereal-blue);
  padding: 0.45rem 1rem;
  border-radius: var(--radius-full);
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition);
}

.btn-chat-toggle:hover {
  background: var(--ethereal-blue);
}

/* ==========================================================================
   4. Macro Grid Layout
   ========================================================================== */
.dashboard-layout {
  flex: 1;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

.dashboard-sidebar,
.dashboard-main-content {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ==========================================================================
   5. Sidebar Components
   ========================================================================== */
.hero-card {
  position: static;
}

.mood-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.mood-btn {
  background: var(--moonlit-grey);
  border: 1px solid transparent;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition);
}

.mood-btn.active {
  background: var(--mocha-mousse);
  color: var(--surface-white);
}

.progress-box {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.progress-details {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.progress-details h2 {
  font-size: 1.1rem;
}

.progress-score {
  font-size: 0.85rem;
  color: var(--mocha-dark);
  font-weight: 600;
}

.progress-track {
  width: 100%;
  height: 10px;
  background: var(--moonlit-grey);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--mocha-mousse), var(--ethereal-blue));
  border-radius: var(--radius-full);
  transition: width 0.4s ease-out;
}

/* Weekly Matrix Dynamic Styles */
.card-header-compact {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.streak-pill {
  background: var(--ethereal-light);
  border: 1px solid var(--ethereal-blue);
  color: var(--text-dark);
  font-size: 0.78rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  font-weight: 600;
}

.days-matrix {
  display: flex;
  justify-content: space-between;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-light);
}

.day-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.day-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.day-slot.is-today .day-label {
  color: var(--mocha-mousse);
  font-weight: 700;
}

.day-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--moonlit-grey);
  border: 2px solid var(--border-light);
  transition: var(--transition);
}

.day-dot.today-pulse {
  background: var(--mocha-mousse);
  border-color: var(--mocha-dark);
  box-shadow: 0 0 0 3px rgba(165, 149, 111, 0.3);
}

/* Daily Focus Note */
.note-card textarea {
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.75rem;
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.9rem;
  resize: vertical;
}

.note-card textarea:focus {
  outline: none;
  border-color: var(--mocha-mousse);
}

.btn-secondary-small {
  margin-top: 0.6rem;
  background: var(--moonlit-grey);
  border: 1px solid var(--border-light);
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-secondary-small:hover {
  background: var(--mocha-mousse);
  color: white;
}

/* ==========================================================================
   6. Task Creator & Input Hub
   ========================================================================== */
.task-input-section h2 {
  font-size: 1.2rem;
  margin-bottom: 0.75rem;
}

.chips-wrapper {
  margin-bottom: 1.25rem;
}

.chips-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.4rem;
}

.chip {
  background: var(--ethereal-light);
  border: 1px dashed var(--ethereal-blue);
  color: var(--text-dark);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  cursor: pointer;
  transition: var(--transition);
}

.chip:hover {
  background: var(--ethereal-blue);
}

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

.input-primary-row {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.input-container {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
}

.input-container input {
  width: 100%;
  padding: 0.85rem 3rem 0.85rem 1rem;
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: var(--font-body);
}

.input-container input:focus {
  outline: none;
  border-color: var(--mocha-mousse);
}

.mic-btn {
  position: absolute;
  right: 0.75rem;
  background: transparent;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
  transition: var(--transition);
}

.mic-btn.listening {
  animation: pulseMic 1.2s infinite ease-in-out;
}

@keyframes pulseMic {
  0% { transform: scale(1); }
  50% { transform: scale(1.25); filter: drop-shadow(0 0 6px rgba(217, 83, 79, 0.7)); }
  100% { transform: scale(1); }
}

.btn {
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  border: none;
  transition: var(--transition);
}

.btn-primary {
  background: var(--mocha-mousse);
  color: var(--surface-white);
}

.btn-primary:hover {
  background: var(--mocha-dark);
}

.input-meta-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--moonlit-grey);
  border-radius: var(--radius-sm);
}

.meta-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.meta-field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.meta-field select,
.meta-field input {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: var(--font-body);
  background: white;
}

.voice-status {
  font-size: 0.8rem;
  color: var(--mocha-dark);
  font-style: italic;
  min-height: 1.2rem;
}

/* ==========================================================================
   7. Routine Stream & Task Strips
   ========================================================================== */
.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.section-title-row h2 {
  font-size: 1.25rem;
}

.stream-actions {
  display: flex;
  gap: 0.85rem;
}

.btn-text {
  background: transparent;
  border: none;
  color: var(--mocha-mousse);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
}

.btn-text.danger-text {
  color: var(--alert-red);
}

.tasks-stream {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  background: var(--surface-white);
  border-radius: var(--radius-md);
  border: 2px dashed rgba(165, 149, 111, 0.3);
}

.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.empty-state h3 {
  font-size: 1.1rem;
  margin-bottom: 0.35rem;
}

.task-strip {
  background: var(--surface-white);
  padding: 1rem 1.25rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  border-left: 5px solid var(--mocha-mousse);
  transition: var(--transition);
}

.task-main {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.check-container {
  display: inline-flex;
  position: relative;
  cursor: pointer;
}

.check-container input {
  opacity: 0;
  position: absolute;
}

.custom-check {
  width: 22px;
  height: 22px;
  border: 2px solid var(--mocha-mousse);
  border-radius: 6px;
  display: inline-block;
  position: relative;
  transition: var(--transition);
}

.check-container input:checked ~ .custom-check {
  background: var(--success-green);
  border-color: var(--success-green);
}

.check-container input:checked ~ .custom-check::after {
  content: '✓';
  color: white;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -55%);
  font-size: 0.75rem;
  font-weight: 700;
}

.task-content {
  flex: 1;
}

.task-title {
  font-size: 1rem;
  font-weight: 600;
}

.task-meta-tags {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.2rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.tag-badge {
  background: var(--moonlit-grey);
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
  font-weight: 500;
}

.tag-badge.priority-high {
  background: #FFE8E8;
  color: var(--alert-red);
}

.task-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.75rem;
}

.delete-btn {
  background: transparent;
  border: none;
  font-size: 1.35rem;
  color: #B3ADA1;
  cursor: pointer;
  line-height: 1;
}

.delete-btn:hover {
  color: var(--alert-red);
}

/* Completed State */
.task-strip.is-completed {
  border-left-color: var(--success-green);
  opacity: 0.7;
}

.task-strip.is-completed .task-title {
  text-decoration: line-through;
  color: var(--text-muted);
}

/* Overdue State & Red Alert Strip */
.task-strip.is-overdue {
  border-left-color: var(--alert-red);
  background: var(--alert-red-bg);
}

.alert-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: rgba(217, 83, 79, 0.1);
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--alert-red);
  font-weight: 600;
}

.alert-pulse {
  width: 8px;
  height: 8px;
  background: var(--alert-red);
  border-radius: 50%;
  animation: pulseAlert 1.4s infinite;
}

@keyframes pulseAlert {
  0% { transform: scale(0.9); opacity: 0.7; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.7; }
}

/* ==========================================================================
   8. AI Coach Drawer & Key Banner
   ========================================================================== */
.ai-drawer {
  position: fixed;
  top: 0;
  right: -100%;
  width: 100%;
  max-width: 380px;
  height: 100%;
  background: var(--surface-white);
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-drawer.open {
  right: 0;
}

.drawer-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--moonlit-grey);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.bot-subtext {
  font-size: 0.75rem;
  color: var(--mocha-dark);
  font-weight: 500;
}

.drawer-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.icon-btn-small {
  background: transparent;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.2rem;
}

.close-drawer-btn {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}

/* Live API Key Banner */
.key-banner {
  display: none;
  background: var(--ethereal-light);
  border-bottom: 1px solid var(--ethereal-blue);
  padding: 0.85rem 1.25rem;
}

.key-banner.active {
  display: block;
}

.key-banner p {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.key-input-row {
  display: flex;
  gap: 0.4rem;
}

.key-input-row input {
  flex: 1;
  padding: 0.35rem 0.6rem;
  font-size: 0.75rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
}

.key-status-text {
  font-size: 0.72rem;
  color: var(--mocha-dark);
  margin-top: 0.25rem;
  display: block;
}

.drawer-body {
  flex: 1;
  padding: 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.chat-bubble {
  max-width: 85%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  line-height: 1.4;
}

.bot-msg {
  background: var(--ethereal-light);
  border-left: 3px solid var(--ethereal-blue);
  align-self: flex-start;
}

.user-msg {
  background: var(--mocha-mousse);
  color: var(--surface-white);
  align-self: flex-end;
}

.drawer-footer {
  padding: 1rem;
  border-top: 1px solid var(--moonlit-grey);
}

.chat-input-form {
  display: flex;
  gap: 0.5rem;
}

.chat-input-form input {
  flex: 1;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}

.btn-chat-send {
  background: var(--mocha-mousse);
  color: white;
  padding: 0.65rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: none;
  z-index: 90;
}

.drawer-backdrop.open {
  display: block;
}

/* ==========================================================================
   9. Footer Landmark
   ========================================================================== */
.site-footer {
  background: var(--surface-white);
  border-top: 1px solid var(--border-light);
  margin-top: auto;
  padding: 1.5rem 1.25rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ==========================================================================
   10. Mobile-First Media Queries
   ========================================================================== */
@media (min-width: 768px) {
  .input-primary-row {
    flex-direction: row;
  }
  .input-meta-row {
    grid-template-columns: repeat(3, 1fr);
  }
  .task-strip {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
  }
  .alert-banner {
    width: 100%;
  }
}

@media (min-width: 1024px) {
  .dashboard-layout {
    grid-template-columns: 340px 1fr;
    align-items: start;
    gap: 2rem;
  }
}