/* iOS Dark Theme - Mac Todo PWA */
/* Based on Apple Human Interface Guidelines */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  /* iOS Dark Mode Colors */
  --bg-primary: #000000;
  --bg-elevated: #1C1C1E;
  --bg-secondary: #2C2C2E;
  --bg-tertiary: #3A3A3C;

  /* Separators & Borders */
  --separator: #38383A;
  --separator-opaque: #545458;

  /* Labels */
  --label-primary: #FFFFFF;
  --label-secondary: #8E8E93;
  --label-tertiary: #48484A;
  --label-quaternary: #3A3A3C;

  /* System Colors */
  --system-blue: #0A84FF;
  --system-green: #30D158;
  --system-red: #FF453A;
  --system-orange: #FF9F0A;
  --system-yellow: #FFD60A;
  --system-purple: #BF5AF2;
  --system-pink: #FF375F;
  --system-teal: #64D2FF;

  /* Fills */
  --fill-primary: rgba(120, 120, 128, 0.36);
  --fill-secondary: rgba(120, 120, 128, 0.32);
  --fill-tertiary: rgba(120, 120, 128, 0.24);

  /* Safe Areas */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  /* Typography */
  --font-body: 17px;
  --font-callout: 16px;
  --font-subhead: 15px;
  --font-footnote: 13px;
  --font-caption: 12px;
  --font-large-title: 34px;
  --font-title1: 28px;
  --font-title2: 22px;
  --font-title3: 20px;

  /* Shadows */
  --shadow-elevated: 0 8px 32px rgba(0, 0, 0, 0.4);
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.3);
}

html {
  background: var(--bg-primary);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', sans-serif;
  background: var(--bg-primary);
  color: var(--label-primary);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.47;
  font-size: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Container with safe area support */
.container {
  max-width: 428px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px);
  min-height: 100vh;
  min-height: 100dvh;
}

/* Hidden utility */
.hidden {
  display: none !important;
}

/* Loading Screen */
.loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-content {
  text-align: center;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--bg-secondary);
  border-top-color: var(--system-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

.loading-text {
  color: var(--label-secondary);
  font-size: 15px;
}

/* ===== DATE HEADER (iOS Calendar Style) ===== */
.date-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 32px;
  padding-top: 8px;
}

.date-content {
  text-align: left;
}

.date-label {
  font-size: var(--font-subhead);
  font-weight: 600;
  color: var(--system-red);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.date-display {
  font-size: 34px;
  font-weight: 700;
  color: var(--label-primary);
  letter-spacing: 0.37px;
  line-height: 1.1;
}

/* Daily Summary (subtext under date) */
.summary-text {
  font-size: 15px;
  line-height: 1.4;
  color: var(--label-secondary);
  margin: 8px 0 0 0;
  font-weight: 400;
}

.summary-text.loading {
  color: var(--label-tertiary);
}

/* Legacy header support */
header {
  text-align: left;
  margin-bottom: 24px;
  padding-top: 8px;
}

header h1 {
  font-size: var(--font-large-title);
  font-weight: 700;
  color: var(--label-primary);
  letter-spacing: 0.37px;
  margin-bottom: 4px;
}

.subtitle {
  color: var(--label-secondary);
  font-size: var(--font-subhead);
  font-weight: 400;
}

/* ===== TODO FORM ===== */
.todo-form {
  margin-bottom: 24px;
}

.todo-form textarea {
  width: 100%;
  padding: 16px;
  font-size: var(--font-body);
  border: none;
  border-radius: 12px;
  background: var(--bg-elevated);
  color: var(--label-primary);
  transition: box-shadow 0.2s ease;
  resize: none;
  font-family: inherit;
  line-height: 1.47;
  min-height: 56px;
}

.todo-form textarea:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.3);
}

.todo-form textarea::placeholder {
  color: var(--label-tertiary);
}

.todo-form textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== CATEGORIES SECTION ===== */
.categories-container {
  margin-top: 8px;
}

.categories-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding: 0 4px;
}

.categories-header h2 {
  font-size: var(--font-title3);
  font-weight: 600;
  color: var(--label-primary);
  letter-spacing: 0.38px;
}

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

.stats-btn,
.refresh-btn {
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  color: var(--system-blue);
  cursor: pointer;
  border-radius: 22px;
  transition: background 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.stats-btn:active,
.refresh-btn:active,
.logout-btn:active {
  background: var(--fill-tertiary);
}

.refresh-btn.spinning svg {
  animation: spin 1s linear infinite;
}

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

.logout-btn {
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  color: var(--system-red);
  cursor: pointer;
  border-radius: 22px;
  transition: background 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Categories Grid - iOS Grouped Table Style */
.categories-grid {
  background: var(--bg-elevated);
  border-radius: 12px;
  overflow: hidden;
}

.category-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: transparent;
  cursor: pointer;
  transition: background 0.15s ease;
  min-height: 56px;
  position: relative;
}

.category-card:active {
  background: var(--bg-secondary);
}

/* Separator between category cards */
.category-card:not(:last-child)::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 60px;
  right: 0;
  height: 0.5px;
  background: var(--separator);
}

.category-icon {
  font-size: 24px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.category-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.category-title {
  font-weight: 400;
  font-size: var(--font-body);
  color: var(--label-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.category-desc {
  font-size: var(--font-footnote);
  color: var(--label-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.category-count {
  font-size: var(--font-body);
  font-weight: 400;
  color: var(--label-secondary);
  margin-right: 24px;
  min-width: 20px;
  text-align: right;
}

.category-count.has-items {
  font-weight: 600;
  color: var(--system-orange);
}

/* Chevron indicator */
.category-card::before {
  content: '';
  position: absolute;
  right: 16px;
  top: 50%;
  margin-top: -4px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--label-tertiary);
  border-bottom: 2px solid var(--label-tertiary);
  transform: rotate(-45deg);
}

.cache-info {
  text-align: center;
  font-size: var(--font-caption);
  color: var(--label-tertiary);
  margin-top: 12px;
}

/* ===== LIST VIEW ===== */
.list-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  min-height: 44px;
}

.list-header h2 {
  font-size: var(--font-title3);
  font-weight: 600;
  color: var(--label-primary);
  flex: 1;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px 8px 8px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--system-blue);
  font-size: var(--font-body);
  font-weight: 400;
  cursor: pointer;
  transition: background 0.15s ease;
  min-height: 44px;
}

.back-btn:active {
  background: var(--fill-tertiary);
}

.back-btn svg {
  width: 20px;
  height: 20px;
}

/* ===== TODO LIST ===== */
.todo-list {
  list-style: none;
  background: var(--bg-elevated);
  border-radius: 12px;
  overflow: hidden;
}

.todo-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background: transparent;
  transition: background 0.15s ease;
  position: relative;
  min-height: 56px;
  animation: slideIn 0.3s ease;
}

.todo-item:active {
  background: var(--bg-secondary);
}

/* Separator between todo items */
.todo-item:not(:last-child)::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 52px;
  right: 0;
  height: 0.5px;
  background: var(--separator);
}

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

/* Checkbox - iOS Style */
.checkbox {
  width: 24px;
  height: 24px;
  border: 2px solid var(--label-tertiary);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
  margin-top: 2px;
}

.checkbox:active {
  transform: scale(0.9);
}

.todo-item.completed .checkbox {
  background: var(--system-green);
  border-color: var(--system-green);
}

.checkbox svg {
  width: 14px;
  height: 14px;
  stroke: white;
  stroke-width: 3;
  opacity: 0;
  transform: scale(0.5);
  transition: all 0.2s ease;
}

.todo-item.completed .checkbox svg {
  opacity: 1;
  transform: scale(1);
}

/* Todo Content */
.todo-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.todo-text {
  font-size: var(--font-body);
  color: var(--label-primary);
  word-break: break-word;
  line-height: 1.35;
}

.todo-item.completed .todo-text {
  text-decoration: line-through;
  color: var(--label-secondary);
}

.todo-meta {
  display: flex;
  gap: 12px;
  font-size: var(--font-footnote);
  color: var(--label-secondary);
  flex-wrap: wrap;
}

.todo-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.todo-meta svg {
  width: 12px;
  height: 12px;
  opacity: 0.7;
}

.eta-overdue {
  color: var(--system-red) !important;
}

.eta-soon {
  color: var(--system-orange) !important;
}

/* Delete Button */
.delete-btn {
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  color: var(--system-red);
  cursor: pointer;
  border-radius: 22px;
  opacity: 0;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: -10px -8px -10px 0;
}

.todo-item:hover .delete-btn,
.todo-item:active .delete-btn {
  opacity: 1;
}

.delete-btn:active {
  background: rgba(255, 69, 58, 0.15);
  transform: scale(0.9);
}

.delete-btn svg {
  width: 20px;
  height: 20px;
}

/* Always show delete on mobile */
@media (hover: none) {
  .delete-btn {
    opacity: 0.7;
  }
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--label-secondary);
}

.empty-state svg {
  margin-bottom: 16px;
  opacity: 0.4;
  color: var(--label-tertiary);
}

.empty-state p {
  font-size: var(--font-callout);
  color: var(--label-secondary);
}

/* ===== FOOTER STATS ===== */
.stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  padding: 16px 4px;
  padding-bottom: calc(var(--safe-bottom) + 8px);
  color: var(--label-secondary);
  font-size: var(--font-footnote);
}

.clear-btn {
  background: none;
  border: none;
  color: var(--system-red);
  cursor: pointer;
  font-size: var(--font-footnote);
  padding: 8px 12px;
  border-radius: 8px;
  transition: background 0.15s ease;
  font-weight: 400;
}

.clear-btn:active {
  background: rgba(255, 69, 58, 0.15);
}

/* ===== FILTERS (if used) ===== */
.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  justify-content: center;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 8px 16px;
  background: var(--bg-elevated);
  border: none;
  border-radius: 20px;
  color: var(--label-secondary);
  font-size: var(--font-subhead);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 36px;
}

.filter-btn:active {
  background: var(--bg-tertiary);
}

.filter-btn.active {
  background: var(--system-blue);
  color: white;
}

/* ===== TOAST NOTIFICATIONS ===== */
.toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 24px);
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(60, 60, 60, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: white;
  padding: 14px 20px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 1000;
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
  box-shadow: var(--shadow-elevated);
  max-width: calc(100vw - 32px);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.toast-success .toast-icon {
  background: var(--system-green);
  color: white;
}

.toast-error .toast-icon {
  background: var(--system-red);
  color: white;
}

.toast-info .toast-icon {
  background: var(--system-blue);
  color: white;
}

.toast-message {
  font-size: var(--font-subhead);
  font-weight: 500;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 428px) {
  .container {
    padding-left: 16px;
    padding-right: 16px;
  }
}

@media (min-width: 429px) {
  .container {
    padding-left: 20px;
    padding-right: 20px;
  }

  .categories-grid,
  .todo-list {
    box-shadow: var(--shadow-card);
  }
}

/* ===== SCROLLBAR (for desktop) ===== */
::-webkit-scrollbar {
  width: 6px;
}

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

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

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

/* ===== SELECTION ===== */
::selection {
  background: rgba(10, 132, 255, 0.3);
}

/* ===== FOCUS VISIBLE ===== */
:focus-visible {
  outline: 2px solid var(--system-blue);
  outline-offset: 2px;
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--system-blue);
  outline-offset: 2px;
}

textarea:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.3);
}

/* ===== FLOATING ACTION BUTTON ===== */
.fab {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 24px);
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 30px;
  background: var(--system-blue);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(10, 132, 255, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  z-index: 100;
}

.fab:active {
  transform: scale(0.92);
  background: #0070E0;
}

.fab:hover {
  box-shadow: 0 6px 24px rgba(10, 132, 255, 0.5), 0 4px 12px rgba(0, 0, 0, 0.3);
}

.fab svg {
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.fab.open svg {
  transform: rotate(45deg);
}

/* ===== BOTTOM SHEET OVERLAY ===== */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 200;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.sheet-overlay.show {
  opacity: 1;
  visibility: visible;
}

/* ===== BOTTOM SHEET ===== */
.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border-radius: 14px 14px 0 0;
  padding: 8px 16px calc(var(--safe-bottom) + 16px);
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 300;
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
}

.bottom-sheet.show {
  transform: translateY(0);
}

/* Sheet Handle */
.sheet-handle {
  width: 36px;
  height: 5px;
  background: var(--label-quaternary);
  border-radius: 2.5px;
  margin: 0 auto 12px;
}

/* Sheet Header */
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  min-height: 44px;
}

.sheet-title {
  font-size: var(--font-body);
  font-weight: 600;
  color: var(--label-primary);
  text-align: center;
  flex: 1;
}

.sheet-action {
  background: none;
  border: none;
  font-size: var(--font-body);
  color: var(--system-blue);
  cursor: pointer;
  padding: 8px 4px;
  min-width: 60px;
  transition: opacity 0.15s ease;
}

.sheet-action:active {
  opacity: 0.6;
}

.sheet-action-primary {
  font-weight: 600;
}

/* Sheet Form */
.sheet-form {
  margin: 0;
}

.sheet-textarea {
  width: 100%;
  padding: 16px;
  font-size: var(--font-body);
  border: none;
  border-radius: 12px;
  background: var(--bg-secondary);
  color: var(--label-primary);
  resize: none;
  font-family: inherit;
  line-height: 1.47;
  min-height: 120px;
  transition: box-shadow 0.2s ease;
}

.sheet-textarea:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.3);
}

.sheet-textarea::placeholder {
  color: var(--label-tertiary);
}

.sheet-hint {
  font-size: var(--font-footnote);
  color: var(--label-tertiary);
  margin-top: 12px;
  text-align: center;
}

/* Prevent body scroll when sheet is open */
body.sheet-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

/* Adjust container padding to account for FAB */
.container {
  padding-bottom: calc(var(--safe-bottom) + 100px);
}
