@import url('https://fonts.googleapis.com/css2?family=Heebo:wght@300;400;500;600;700;800&display=swap');

:root {
  /* Light Theme Colors (Default) */
  --bg-primary: #FFF8F5;
  --bg-card: #FFFFFF;
  --bg-elevated: #FFF0EB;
  
  --accent-primary: #E8837C;
  --accent-secondary: #9B8EC4;
  --accent-success: #7BC4A0;
  --accent-warning: #F5C26B;
  --accent-danger: #E57373;
  
  --text-primary: #2D2438;
  --text-secondary: #8A7D96;
  --text-tertiary: #B8ACBF;
  
  --border: #F0E4EC;
  --border-strong: #E0D0DC;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(45,36,56,0.06);
  --shadow-md: 0 4px 16px rgba(45,36,56,0.1);
  --shadow-lg: 0 8px 32px rgba(45,36,56,0.14);

  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-round: 999px;

  /* Font Family */
  --font-family: 'Heebo', sans-serif;

  /* Font Sizes */
  --fs-xs: 0.75rem;     /* 12px */
  --fs-sm: 0.8125rem;   /* 13px */
  --fs-base: 0.9375rem; /* 15px */
  --fs-md: 1.0625rem;   /* 17px */
  --fs-lg: 1.25rem;     /* 20px */
  --fs-xl: 1.5rem;      /* 24px */
  --fs-2xl: 1.875rem;   /* 30px */
  --fs-3xl: 2.25rem;    /* 36px */

  /* Spacing Scale */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;
  
  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.2s ease;
  --transition-slow: 0.3s ease;
}

/* Dark Mode Overrides */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1A1118;
    --bg-card: #2A1F28;
    --bg-elevated: #352A33;
    
    --text-primary: #F0E8F4;
    --text-secondary: #A89BB5;
    --text-tertiary: #6B5F75;
    
    --border: #3A2F38;
    --border-strong: #4F434D;

    --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  }
}

/* An explicit light choice must beat the prefers-color-scheme block above. */
[data-theme='light'] {
  --bg-primary: #FFF8F5;
  --bg-card: #FFFFFF;
  --bg-elevated: #FFF0EB;

  --text-primary: #2D2438;
  --text-secondary: #8A7D96;
  --text-tertiary: #B8ACBF;

  --border: #F0E4EC;
  --border-strong: #E0D0DC;

  --shadow-sm: 0 2px 8px rgba(45,36,56,0.06);
  --shadow-md: 0 4px 16px rgba(45,36,56,0.1);
  --shadow-lg: 0 8px 32px rgba(45,36,56,0.14);
}

[data-theme='dark'] {
  --bg-primary: #1A1118;
  --bg-card: #2A1F28;
  --bg-elevated: #352A33;
  
  --text-primary: #F0E8F4;
  --text-secondary: #A89BB5;
  --text-tertiary: #6B5F75;
  
  --border: #3A2F38;
  --border-strong: #4F434D;

  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
}

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

html {
  font-family: var(--font-family);
  direction: rtl; /* Right-to-left layout for Hebrew */
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--accent-primary);
  text-decoration: none;
  transition: color var(--transition-normal);
}

a:hover {
  color: var(--accent-danger);
}

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

input, button, textarea, select {
  font: inherit;
}

p, h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
}

/* Layout Utilities */
.container {
  width: 100%;
  max-width: 768px;
  margin-inline: auto;
  padding-inline: var(--space-md);
}

.screen {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  position: relative;
}

.screen-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-card);
  padding: var(--space-md);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.screen-content {
  flex: 1;
  padding: var(--space-md);
  overflow-y: auto;
}

.screen-with-nav .screen-content {
  padding-bottom: calc(70px + env(safe-area-inset-bottom) + var(--space-md));
}

.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-align-center { display: flex; align-items: center; }
.flex-wrap { flex-wrap: wrap; }

.gap-xs { gap: var(--space-xs); }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-md);
}

@media (max-width: 480px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

/* Typography */
.text-xs { font-size: var(--fs-xs); }
.text-sm { font-size: var(--fs-sm); }
.text-base { font-size: var(--fs-base); }
.text-md { font-size: var(--fs-md); }
.text-lg { font-size: var(--fs-lg); }
.text-xl { font-size: var(--fs-xl); }
.text-2xl { font-size: var(--fs-2xl); }
.text-3xl { font-size: var(--fs-3xl); }

.font-light { font-weight: 300; }
.font-regular { font-weight: 400; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.font-extrabold { font-weight: 800; }

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-accent { color: var(--accent-primary); }
.text-success { color: var(--accent-success); }
.text-warning { color: var(--accent-warning); }
.text-danger { color: var(--accent-danger); }
.text-white { color: #FFFFFF; }

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}

.card:active {
  transform: scale(0.98);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: var(--fs-base);
  border: none;
  cursor: pointer;
  transition: all var(--transition-normal);
  font-family: inherit;
  text-decoration: none;
  line-height: 1.2;
}

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

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--accent-primary);
  color: #FFFFFF;
}
.btn-primary:hover {
  background: #d87670;
}

.btn-secondary {
  background: var(--accent-secondary);
  color: #FFFFFF;
}

.btn-ghost {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid transparent;
}
.btn-ghost:hover {
  background: var(--bg-elevated);
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--accent-primary);
  color: var(--accent-primary);
}

.btn-danger {
  background: var(--accent-danger);
  color: #FFFFFF;
}

.btn-sm {
  padding: 6px 12px;
  font-size: var(--fs-sm);
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 14px 24px;
  font-size: var(--fs-md);
  border-radius: var(--radius-lg);
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-lg);
}

/* Inputs */
.input-group {
  display: flex;
  flex-direction: column;
  margin-bottom: var(--space-md);
}

.input-label {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.input, .textarea, .select {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: inherit;
  font-size: var(--fs-base);
  transition: border-color var(--transition-normal);
}

.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent-primary);
  outline: none;
}

.textarea {
  resize: vertical;
  min-height: 100px;
}

.input-error {
  border-color: var(--accent-danger);
}
.error-msg {
  color: var(--accent-danger);
  font-size: var(--fs-xs);
  margin-top: 4px;
}

/* Chips & Badges */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 500;
  line-height: 1.2;
}

.chip-primary { background: var(--accent-primary); color: white; }
.chip-secondary { background: var(--accent-secondary); color: white; }
.chip-success { background: var(--accent-success); color: white; }
.chip-warning { background: var(--accent-warning); color: #FFF; }
.chip-danger { background: var(--accent-danger); color: white; }

.chip-outline { background: transparent; border: 1px solid var(--border-strong); color: var(--text-secondary); }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent-danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  inset-inline: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  z-index: 100;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 12px;
  font-size: 10px;
  color: var(--text-tertiary);
  text-decoration: none;
  transition: color var(--transition-normal);
  flex: 1;
}

.bottom-nav-item.active {
  color: var(--accent-primary);
}

.bottom-nav-item .nav-icon {
  font-size: 22px;
  margin-bottom: 2px;
}

/* Floating Action Button */
.fab {
  position: fixed;
  bottom: calc(70px + env(safe-area-inset-bottom) + 16px);
  inset-inline-end: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent-primary);
  color: white;
  border: none;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  z-index: 99;
  cursor: pointer;
  transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}

.fab:active {
  transform: scale(0.92);
}

.fab.pulse {
  animation: fab-pulse 2s infinite;
}

@keyframes fab-pulse {
  0%, 100% { box-shadow: var(--shadow-lg); }
  50% { box-shadow: 0 0 0 12px rgba(232,131,124,0.2); }
}

/* Task Card */
.task-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-md);
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  margin-bottom: var(--space-sm);
  transition: all var(--transition-normal);
  position: relative;
  overflow: hidden;
}

.task-card:active {
  background: var(--bg-elevated);
}

.task-card.completed {
  opacity: 0.6;
}

.task-card.completed .task-title {
  text-decoration: line-through;
  color: var(--text-secondary);
}

.task-checkbox {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-strong);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  color: transparent;
  margin-top: 2px;
}

.task-card.completed .task-checkbox {
  background: var(--accent-success);
  border-color: var(--accent-success);
  color: white;
}

.task-checkbox:active {
  transform: scale(0.85);
}

.task-card.completed .task-checkbox svg {
  animation: check-bounce 0.4s ease forwards;
}

.task-content {
  flex: 1;
  min-width: 0; /* for truncation */
}

.task-title {
  font-size: var(--fs-base);
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
  transition: color 0.2s;
}

.task-meta {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
  font-size: var(--fs-xs);
  color: var(--text-secondary);
}

.task-assignee {
  display: flex;
  align-items: center;
  gap: 4px;
}

.task-due {
  display: flex;
  align-items: center;
  gap: 4px;
}

.task-due.overdue {
  color: var(--accent-danger);
  font-weight: 500;
}

.task-priority-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.task-indicators {
  display: flex;
  gap: 4px;
  align-items: center;
  color: var(--text-tertiary);
  font-size: var(--fs-xs);
}

/* Progress Bar */
.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  width: 100%;
}

.progress-fill {
  height: 100%;
  background: var(--accent-success);
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* Modal & Bottom Sheet */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  z-index: 200;
  opacity: 0;
  transition: opacity var(--transition-slow);
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-card);
  width: 90%;
  max-width: 400px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  transform: scale(0.95);
  opacity: 0;
  transition: all var(--transition-normal);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}

.modal-overlay.active .modal {
  transform: scale(1);
  opacity: 1;
}

.bottom-sheet {
  background: var(--bg-card);
  width: 100%;
  max-width: 768px;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  box-shadow: var(--shadow-lg);
  position: absolute;
  bottom: 0;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}

.modal-overlay.active .bottom-sheet {
  transform: translateY(0);
}

.modal-header {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header-title {
  font-size: var(--fs-lg);
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px;
}

.modal-body {
  padding: var(--space-lg);
  overflow-y: auto;
}

.modal-footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--space-md);
  justify-content: flex-end;
}

/* Avatar */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-weight: 600;
  flex-shrink: 0;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-sm {
  width: 28px;
  height: 28px;
  font-size: 12px;
}

.avatar-lg {
  width: 48px;
  height: 48px;
  font-size: 20px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: env(safe-area-inset-top, 20px);
  inset-inline: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  z-index: 999;
  pointer-events: none;
  padding: var(--space-md);
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
  animation: toast-slide-in 0.3s cubic-bezier(0.175, 0.885, 0.32, 1) forwards;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  max-width: 90vw;
  font-size: var(--fs-sm);
  font-weight: 500;
  border: 1px solid var(--border);
}

.toast.fade-out {
  animation: fade-out 0.3s ease forwards;
}

.toast-success { border-inline-start: 4px solid var(--accent-success); }
.toast-error { border-inline-start: 4px solid var(--accent-danger); }
.toast-info { border-inline-start: 4px solid var(--accent-secondary); }

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-2xl) var(--space-lg);
  flex: 1;
}

.empty-state-icon {
  font-size: 64px;
  margin-bottom: var(--space-md);
  opacity: 0.8;
}

.empty-state-title {
  font-size: var(--fs-xl);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
}

.empty-state-text {
  font-size: var(--fs-base);
  color: var(--text-secondary);
  max-width: 300px;
  margin-bottom: var(--space-lg);
}

/* Filter Tabs */
.filter-tabs {
  display: flex;
  gap: var(--space-xs);
  overflow-x: auto;
  padding: var(--space-sm) var(--space-md);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
  background: var(--bg-primary);
}

.filter-tabs::-webkit-scrollbar {
  display: none; /* Chrome, Safari */
}

.filter-tab {
  padding: 8px 16px;
  border-radius: 999px;
  white-space: nowrap;
  font-size: var(--fs-sm);
  font-weight: 500;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: none;
  cursor: pointer;
  transition: all var(--transition-normal);
  font-family: inherit;
}

.filter-tab:hover {
  background: var(--border);
}

.filter-tab.active {
  background: var(--accent-primary);
  color: white;
}

/* Comment Thread */
.comment-thread {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.comment-item {
  display: flex;
  gap: var(--space-sm);
}

.comment-content {
  background: var(--bg-elevated);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-lg);
  border-start-start-radius: 4px; /* chat bubble effect RTL */
  flex: 1;
}

.comment-item.mine .comment-content {
  background: rgba(232,131,124,0.1); /* light accent-primary */
  border-start-start-radius: var(--radius-lg);
  border-start-end-radius: 4px;
}

.comment-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.comment-author {
  font-weight: 600;
  font-size: var(--fs-sm);
}

.comment-time {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
}

.comment-text {
  font-size: var(--fs-sm);
  color: var(--text-primary);
}

.comment-input-area {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-md);
  align-items: flex-end;
}

/* Photo Gallery */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-xs);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-top: var(--space-sm);
}

.photo-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  cursor: pointer;
  transition: opacity 0.2s;
  background: var(--bg-elevated);
}

.photo-thumb:hover {
  opacity: 0.9;
}

.photo-add-btn {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: 1px dashed var(--border-strong);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: var(--fs-xs);
  gap: 4px;
}

/* Activity Log */
.activity-log {
  display: flex;
  flex-direction: column;
}

.activity-item {
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--border);
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.activity-content {
  flex: 1;
}

.activity-text {
  font-size: var(--fs-sm);
  color: var(--text-primary);
}

.activity-time {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  margin-top: 2px;
}

/* Stats Card */
.stat-card {
  text-align: center;
  padding: var(--space-md);
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.stat-value {
  font-size: var(--fs-2xl);
  font-weight: 700;
  color: var(--accent-primary);
  line-height: 1.2;
}

.stat-label {
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  font-weight: 500;
}

/* Priority Selector */
.priority-options {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.priority-option {
  flex: 1;
  min-width: 70px;
  padding: 8px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  text-align: center;
  cursor: pointer;
  font-size: var(--fs-sm);
  font-weight: 500;
  transition: all var(--transition-fast);
}

.priority-option:hover {
  background: var(--bg-elevated);
}

.priority-option.selected {
  border-color: currentColor;
  background: currentColor;
  color: white !important;
}

/* Swipe Actions */
.swipe-actions {
  position: absolute;
  top: 0;
  bottom: 0;
  inset-inline-end: 0;
  display: flex;
  z-index: 0;
}

.swipe-action-btn {
  width: 70px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: white;
  border: none;
  font-size: var(--fs-xs);
}

.swipe-action-btn.delete { background: var(--accent-danger); }
.swipe-action-btn.edit { background: var(--accent-secondary); }

/* the card front must slide to reveal actions */
.swipeable-front {
  background: var(--bg-card);
  width: 100%;
  position: relative;
  z-index: 1;
  transition: transform 0.2s ease-out;
}

/* Category Cards (Home Grid) */
.category-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-sm);
}

.category-card {
  padding: var(--space-md);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  border: 1px solid var(--border);
  text-align: center;
  cursor: pointer;
  transition: transform var(--transition-normal), box-shadow var(--transition-normal);
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: var(--shadow-sm);
}

.category-card:active {
  transform: scale(0.96);
}

.category-icon {
  font-size: 32px;
  margin-bottom: var(--space-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--bg-elevated);
}

.category-name {
  font-size: var(--fs-sm);
  font-weight: 600;
  margin-top: var(--space-xs);
  color: var(--text-primary);
}

.category-count {
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Animations */
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes slide-up {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes slide-in-start {
  from { transform: translateX(30px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
} /* RTL: translateX positive means comes from left */

@keyframes check-bounce {
  0% { transform: scale(0); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes toast-slide-in {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Utility Classes */
.hidden { display: none !important; }
.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;
}

.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.text-center { text-align: center; }
.text-start { text-align: start; }
.text-end { text-align: end; }

.mt-xs { margin-top: var(--space-xs); }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }

.mb-xs { margin-bottom: var(--space-xs); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }

.ml-auto { margin-inline-start: auto; } /* Logical margin-left for RTL */
.mr-auto { margin-inline-end: auto; }   /* Logical margin-right for RTL */
.mx-auto { margin-inline: auto; }

.w-full { width: 100%; }
.h-full { height: 100%; }

.rounded-full { border-radius: 9999px; }

.animate-fade-in { animation: fade-in 0.3s ease forwards; }
.animate-slide-up { animation: slide-up 0.4s ease forwards; }

.relative { position: relative; }
.absolute { position: absolute; }

/* Auth Screen Specific */
.auth-screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #FFF8F5 0%, #F5E6F0 50%, #EDE4F5 100%);
  padding: var(--space-lg);
  text-align: center;
}

[data-theme='dark'] .auth-screen {
  background: linear-gradient(135deg, #1A1118 0%, #221620 50%, #1a1622 100%);
}

.auth-logo {
  font-size: 64px;
  margin-bottom: var(--space-md);
  animation: slide-up 0.6s ease;
}

.auth-title {
  font-size: var(--fs-2xl);
  font-weight: 700;
  margin-bottom: var(--space-sm);
  color: var(--text-primary);
}

.auth-subtitle {
  font-size: var(--fs-md);
  color: var(--text-secondary);
  margin-bottom: var(--space-xl);
}

.pin-input-container {
  display: flex;
  gap: var(--space-sm);
  direction: ltr; /* Always LTR for PIN dots */
  margin: var(--space-xl) 0;
}

.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  transition: all var(--transition-normal);
  background: transparent;
}

.pin-dot.filled {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  transform: scale(1.1);
}

.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-sm);
  max-width: 280px;
  margin: 0 auto;
  direction: ltr;
}

.numpad-key {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: var(--fs-xl);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}

.numpad-key:active {
  transform: scale(0.92);
  background: var(--accent-primary);
  color: white;
}

.numpad-key.delete-key {
  font-size: var(--fs-md);
  background: transparent;
  box-shadow: none;
}

.member-select {
  display: flex;
  gap: var(--space-md);
  margin-top: var(--space-xl);
  flex-wrap: wrap;
  justify-content: center;
}

.member-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-xl);
  border: 2px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  transition: all var(--transition-normal);
  min-width: 120px;
}

.member-btn:active {
  transform: scale(0.95);
}

.member-btn.selected {
  border-color: var(--accent-primary);
  background: rgba(232,131,124,0.08); /* faint primary */
}

/* Shopping List Specific */
.shopping-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border);
  transition: all var(--transition-normal);
  background: var(--bg-card);
}

.shopping-item:last-child {
  border-bottom: none;
}

.shopping-item.bought {
  opacity: 0.5;
  background: var(--bg-elevated);
}

.shopping-item.bought .shopping-name {
  text-decoration: line-through;
}

.shopping-quick-add {
  position: sticky;
  top: 0; /* Adjust if screen header is present */
  background: var(--bg-primary);
  padding: var(--space-sm) var(--space-md);
  z-index: 10;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: var(--space-sm);
}

.quantity-stepper {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.quantity-stepper button {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--bg-card);
  color: var(--text-primary);
  font-weight: bold;
  cursor: pointer;
}

.quantity-stepper span {
  min-width: 20px;
  text-align: center;
  font-size: var(--fs-sm);
  font-weight: 600;
}

/* Settings Specific */
.settings-group {
  margin-bottom: var(--space-lg);
}

.settings-group-title {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-sm);
  padding: 0 var(--space-md);
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.settings-item:hover {
  background: var(--bg-elevated);
}

.settings-item:first-child {
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.settings-item:last-child {
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  border-bottom: none;
}

.toggle-switch {
  width: 48px;
  height: 28px;
  border-radius: 14px;
  background: var(--border-strong);
  position: relative;
  cursor: pointer;
  transition: background var(--transition-normal);
  flex-shrink: 0;
}

.toggle-switch.active {
  background: var(--accent-primary);
}

.toggle-switch::after {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: white;
  top: 3px;
  inset-inline-start: 3px;
  transition: transform var(--transition-normal);
  box-shadow: var(--shadow-sm);
}

/* In RTL, translating negatively moves it to the left (logical end) */
.toggle-switch.active::after {
  transform: translateX(-20px);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* Loading Spinner */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: auto;
}

.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  gap: var(--space-md);
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  flex: 1;
}

/* Specific z-index layers */
.z-0 { z-index: 0; }
.z-10 { z-index: 10; }
.z-50 { z-index: 50; }
.z-100 { z-index: 100; }
.z-200 { z-index: 200; }

/* ==========================================================================
   Screen components
   Added in 1.1 — the screens previously inlined these styles per element.
   ========================================================================== */

.noscript-warning {
  padding: var(--space-lg);
  text-align: center;
  color: var(--text-primary);
}

/* Category & priority palettes -------------------------------------------- */
.cat-house    { --cat-color: #E8837C; --cat-soft: rgba(232,131,124,0.16); }
.cat-shopping { --cat-color: #9B8EC4; --cat-soft: rgba(155,142,196,0.16); }
.cat-general  { --cat-color: #5FA982; --cat-soft: rgba(123,196,160,0.16); }
.cat-projects { --cat-color: #C9922F; --cat-soft: rgba(245,194,107,0.20); }
.cat-events   { --cat-color: #4A87C0; --cat-soft: rgba(91,155,213,0.16); }

/* The amber and green hues need lifting to stay readable on the dark surface. */
@media (prefers-color-scheme: dark) {
  .cat-general  { --cat-color: #7BC4A0; }
  .cat-projects { --cat-color: #F5C26B; }
  .cat-events   { --cat-color: #5B9BD5; }
}

[data-theme='dark'] .cat-general  { --cat-color: #7BC4A0; }
[data-theme='dark'] .cat-projects { --cat-color: #F5C26B; }
[data-theme='dark'] .cat-events   { --cat-color: #5B9BD5; }

[data-theme='light'] .cat-general  { --cat-color: #5FA982; }
[data-theme='light'] .cat-projects { --cat-color: #C9922F; }
[data-theme='light'] .cat-events   { --cat-color: #4A87C0; }

.chip-cat {
  background: var(--cat-soft, var(--bg-elevated));
  color: var(--cat-color, var(--text-secondary));
  font-weight: 600;
}

.category-card.cat-house,
.category-card.cat-shopping,
.category-card.cat-general,
.category-card.cat-projects,
.category-card.cat-events {
  border-block-start: 3px solid var(--cat-color);
}

.prio-low    { --prio-color: #5FA982; }
.prio-medium { --prio-color: #C9922F; }
.prio-high   { --prio-color: #E8837C; }
.prio-urgent { --prio-color: #E57373; }

.task-priority-dot { background: var(--prio-color, var(--border-strong)); }
.priority-option   { color: var(--prio-color, var(--text-primary)); }

/* Offline banner ---------------------------------------------------------- */
.offline-bar {
  background: var(--accent-warning);
  color: #3B2A05;
  text-align: center;
  padding: 6px var(--space-md);
  font-size: var(--fs-xs);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 60;
}

/* Toasts ------------------------------------------------------------------ */
.toast-text { flex: 1; }

.toast-action {
  background: none;
  border: none;
  color: var(--accent-primary);
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: 700;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.toast-action:hover { background: var(--bg-elevated); }

/* Home -------------------------------------------------------------------- */
.home-header { align-items: flex-start; }

.greeting {
  font-size: var(--fs-xl);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

.header-date {
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  margin-top: 2px;
}

.home-section { margin-bottom: var(--space-lg); }

.section-title {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}

.stat-value-success { color: var(--accent-success); }
.stat-value-danger  { color: var(--accent-danger); }
.stat-card-danger   { border-color: var(--accent-danger); background: var(--bg-elevated); }

/* Task list --------------------------------------------------------------- */
.search-bar {
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.sort-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: 0 var(--space-md) var(--space-sm);
}

.select-sm,
.input-inline {
  width: auto;
  min-width: 130px;
  padding: 8px 12px;
  font-size: var(--fs-sm);
}

.task-content { cursor: pointer; }

/* Dense list: the app opens straight onto every task, so rows are tightened to
   fit more of the list on one screen than the roomier card layout allowed. */
.task-list-dense .task-card {
  padding: 10px var(--space-md);
  margin-bottom: 6px;
  border-radius: var(--radius-md);
  align-items: center;
}

.task-list-dense .task-title {
  margin-bottom: 2px;
  font-size: var(--fs-base);
}

.task-list-dense .task-meta {
  gap: var(--space-xs);
  row-gap: 2px;
}

.task-list-dense .chip-cat {
  padding: 1px 8px;
  font-size: 11px;
}

/* A heading per category, so one long list still reads as grouped. */
.task-group-heading {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  margin: var(--space-md) 0 var(--space-xs);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--cat-color, var(--text-secondary));
}

.task-group-heading:first-child { margin-top: 0; }

.task-group-heading .task-group-count {
  color: var(--text-tertiary);
  font-weight: 400;
}

.task-group-heading::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.task-checkbox {
  background: transparent;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  font-family: inherit;
}

.task-qty {
  font-weight: 600;
  color: var(--text-secondary);
}

.task-due.due-soon {
  color: var(--accent-warning);
  font-weight: 500;
}

/* Task detail ------------------------------------------------------------- */
.detail-content { padding-bottom: calc(90px + env(safe-area-inset-bottom)); }

.detail-section { margin-bottom: var(--space-md); }

.detail-section .field + .field { margin-top: var(--space-md); }

.detail-title-input {
  width: 100%;
  font-size: var(--fs-xl);
  font-weight: 700;
  color: var(--text-primary);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  outline: none;
  padding: 4px 0;
  font-family: inherit;
  transition: border-color var(--transition-slow);
}

.detail-title-input:focus { border-bottom-color: var(--accent-primary); }

.detail-desc-input {
  width: 100%;
  font-size: var(--fs-base);
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid transparent;
  outline: none;
  padding: 8px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  resize: none;
  overflow: hidden;
  transition: all var(--transition-slow);
}

.detail-desc-input:focus {
  border-color: var(--accent-primary);
  background: var(--bg-primary);
}

.chip-row {
  display: flex;
  gap: var(--space-xs);
  flex-wrap: wrap;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.chip-row::-webkit-scrollbar { display: none; }

.chip-toggle {
  padding: 8px 14px;
  border-radius: var(--radius-round);
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: var(--fs-sm);
  white-space: nowrap;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chip-toggle:hover { background: var(--bg-elevated); }

.chip-toggle.selected {
  border-color: var(--cat-color, var(--accent-primary));
  background: var(--cat-soft, rgba(232,131,124,0.16));
  color: var(--cat-color, var(--accent-primary));
  font-weight: 600;
}

.range-input {
  width: 100%;
  accent-color: var(--accent-primary);
}

.detail-action-bar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  padding: var(--space-md);
  padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom));
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  z-index: 90;
}

.save-indicator {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  inset-inline-start: 50%;
  transform: translateX(50%);
  background: var(--text-primary);
  color: var(--bg-card);
  padding: 8px 16px;
  border-radius: var(--radius-round);
  font-size: var(--fs-sm);
  opacity: 0;
  transition: opacity var(--transition-slow);
  pointer-events: none;
  z-index: 120;
}

.save-indicator.visible { opacity: 1; }
.save-indicator.success { background: var(--accent-success); color: #FFF; }
.save-indicator.error   { background: var(--accent-danger); color: #FFF; }

.link-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: 8px 12px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
}

.link-item a { color: var(--accent-primary); }

.photo-cell { position: relative; }

.photo-remove {
  position: absolute;
  top: 4px;
  inset-inline-end: 4px;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #FFF;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-viewer .photo-viewer-inner {
  position: relative;
  max-width: 92vw;
  max-height: 88vh;
}

.photo-viewer img {
  max-width: 92vw;
  max-height: 88vh;
  border-radius: var(--radius-md);
}

.photo-viewer-close {
  position: absolute;
  top: 8px;
  inset-inline-end: 8px;
  background: rgba(0,0,0,0.55);
  color: #FFF;
  border-radius: 50%;
  width: 36px;
  height: 36px;
}

/* Shopping ---------------------------------------------------------------- */
.shopping-quick-add > .input { flex: 1; }

.shopping-content { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }

.shopping-section { padding: 0; overflow: hidden; }

.shopping-name {
  flex: 1;
  font-size: var(--fs-base);
  color: var(--text-primary);
  overflow-wrap: anywhere;
}

.shopping-actions {
  position: fixed;
  inset-inline: 0;
  bottom: calc(70px + env(safe-area-inset-bottom));
  padding: var(--space-sm) var(--space-md);
  background: linear-gradient(to top, var(--bg-primary) 70%, transparent);
  z-index: 90;
}

.quantity-stepper button:disabled { opacity: 0.4; cursor: not-allowed; }

/* Settings ---------------------------------------------------------------- */
.settings-item-stack {
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-xs);
  cursor: default;
}

.settings-field-row {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

.settings-field-row > .input { flex: 1; min-width: 0; }

.connection-status {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  font-weight: 600;
}

.connection-status.ok      { color: var(--accent-success); }
.connection-status.fail    { color: var(--accent-danger); }
.connection-status.pending { color: var(--accent-warning); }

/* Auth -------------------------------------------------------------------- */
.auth-error {
  min-height: 20px;
  margin-bottom: var(--space-sm);
}

.numpad-key-empty {
  background: transparent;
  box-shadow: none;
  pointer-events: none;
}

.member-avatar { font-size: 40px; }

/* Photo avatars ----------------------------------------------------------- */
.avatar-xl {
  width: 88px;
  height: 88px;
  font-size: 40px;
}

/* Inline face beside a name, in chips and task metadata. */
.avatar-inline {
  display: inline-flex;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  vertical-align: middle;
  background: var(--bg-elevated);
}

.avatar-inline img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.task-assignee,
.chip-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Lock-screen portrait — the "welcome home" moment. A rounded card rather than
   a circle, because a circle crops a wide photo badly. */
.auth-portrait {
  width: min(300px, 74vw);
  aspect-ratio: 3 / 2;
  object-fit: cover;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  margin-bottom: var(--space-lg);
  animation: slide-up 0.6s ease;
  border: 3px solid var(--bg-card);
}

.member-name {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text-primary);
}

.pin-input-container.shake { animation: shake 0.4s ease-in-out; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-8px); }
  75%      { transform: translateX(8px); }
}

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