/* ===== CSS Custom Properties ===== */
:root {
  --bg: #f5f5f7;
  --bg-card: #ffffff;
  --bg-input: #f0f0f3;
  --text: #1d1d1f;
  --text-secondary: #86868b;
  --text-tertiary: #aeaeb2;
  --accent: #4a90d9;
  --accent-light: #e8f0fe;
  --danger: #e94560;
  --danger-light: #fde8ec;
  --success: #34c759;
  --border: #e5e5ea;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.12);
  --radius: 14px;
  --radius-sm: 10px;
  --transition: 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --max-width: 600px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0d1a;
    --bg-card: #1a1a2e;
    --bg-input: #16213e;
    --text: #e8e8ed;
    --text-secondary: #98989d;
    --text-tertiary: #636366;
    --accent: #5ba3f5;
    --accent-light: #1a2a4a;
    --danger: #e94560;
    --danger-light: #3a1520;
    --success: #30d158;
    --border: #2c2c3a;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.5);
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

input, button {
  font-family: inherit;
  font-size: inherit;
  border: none;
  outline: none;
  background: none;
  color: inherit;
}

ul {
  list-style: none;
}

/* ===== Screen Transitions ===== */
.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.3s ease;
}

.screen[hidden] {
  display: none !important;
}

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

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

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

@keyframes checkPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* ===== Login Screen ===== */
#login-screen {
  justify-content: center;
  align-items: center;
  padding: 24px;
  background: linear-gradient(135deg, var(--bg) 0%, var(--accent-light) 100%);
}

.login-card {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 40px 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-icon {
  font-size: 48px;
  margin-bottom: 8px;
}

.login-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.login-subtitle {
  color: var(--text-secondary);
  font-size: 15px;
  margin-bottom: 28px;
}

.login-card .input-group {
  margin-bottom: 12px;
}

.login-card .error-text {
  color: var(--danger);
  font-size: 14px;
  margin-top: 4px;
  animation: shake 0.4s ease;
}

.login-card.shake {
  animation: shake 0.4s ease;
}

/* ===== Buttons ===== */
.btn {
  cursor: pointer;
  transition: all var(--transition);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

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

.btn-primary {
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: 16px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  min-width: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-primary:hover {
  filter: brightness(1.1);
}

.btn-icon {
  font-size: 22px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}

.btn-icon:hover {
  background: var(--bg-input);
}

.btn-danger-icon:hover {
  background: var(--danger-light);
  color: var(--danger);
}

.btn-text {
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
}

.btn-text:hover {
  background: var(--accent-light);
}

.btn-danger {
  background: var(--danger);
  color: white;
  font-weight: 600;
  font-size: 15px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  min-height: 44px;
}

.btn-full {
  width: 100%;
  margin-top: 12px;
}

/* ===== Input Group ===== */
.input-group {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.input-group input {
  flex: 1;
  background: var(--bg-input);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 16px;
  min-height: 48px;
  transition: border-color var(--transition);
}

.input-group input:focus {
  border-color: var(--accent);
}

.input-group input::placeholder {
  color: var(--text-tertiary);
}

/* ===== Top Bar ===== */
.top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  padding-top: calc(12px + var(--safe-top));
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  max-width: 100%;
}

.top-bar-title {
  flex: 1;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.user-badge {
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--bg-input);
  padding: 6px 12px;
  border-radius: 20px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.user-badge:hover, .user-badge:focus {
  background: var(--accent-light);
  color: var(--accent);
}

/* ===== View Tabs ===== */
.view-tabs {
  display: flex;
  gap: 0;
  padding: 0 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  max-width: 100%;
}

.view-tab {
  flex: 1;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.view-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.view-tab:hover:not(.active) {
  color: var(--text);
  background: var(--bg-input);
}

/* ===== Board View (Kanban) ===== */
.board-container {
  flex: 1;
  padding: 12px 0 24px;
  padding-bottom: calc(24px + var(--safe-bottom));
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  scroll-snap-type: x mandatory;
  padding-left: 16px;
  padding-right: 16px;
}

.board-container[hidden] {
  display: none !important;
}

.board-column {
  flex: 0 0 280px;
  max-height: calc(100dvh - 160px);
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  scroll-snap-align: start;
  overflow: hidden;
}

.board-column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.board-column-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.board-column-count {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-input);
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
  flex-shrink: 0;
}

.board-column-items {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px;
}

.board-item {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: all var(--transition);
  touch-action: manipulation;
  border: 1px solid var(--border);
}

.board-item:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transform: translateY(-1px);
}

.board-item:active {
  transform: scale(0.98);
}

.board-item-text {
  font-size: 14px;
  line-height: 1.4;
  word-break: break-word;
}

.board-item-text.checked {
  text-decoration: line-through;
  color: var(--text-tertiary);
}

.board-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-tertiary);
}

.board-item-checkbox {
  width: 20px;
  height: 20px;
  min-width: 20px;
  border: 2px solid var(--border);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: transparent;
  cursor: pointer;
  transition: all var(--transition);
  margin-right: 4px;
}

.board-item-checkbox.checked {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.board-column-footer {
  padding: 8px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.board-add-btn {
  width: 100%;
  padding: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  background: none;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}

.board-add-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-light);
}

/* Mobile: snap columns to full width for swipe */
@media (max-width: 600px) {
  .board-column {
    flex: 0 0 calc(100vw - 48px);
  }
}

/* ===== Status Bar ===== */
.status-bar {
  padding: 6px 16px;
  font-size: 12px;
  color: var(--text-tertiary);
  text-align: center;
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
}

/* ===== Lists Container ===== */
.lists-container {
  flex: 1;
  padding: 8px 16px 24px;
  padding-bottom: calc(24px + var(--safe-bottom));
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
}

/* ===== List Card ===== */
.list-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all var(--transition);
  animation: slideInUp 0.3s ease backwards;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.list-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  transform: translateY(-1px);
}

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

.list-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.list-card-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.list-card-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.list-card-count {
  font-size: 13px;
  color: var(--text-secondary);
}

.list-card-delete {
  font-size: 16px;
  min-width: 32px;
  min-height: 32px;
  opacity: 0.4;
  transition: opacity var(--transition);
  padding: 0;
}

.list-card:hover .list-card-delete,
.list-card:focus-within .list-card-delete {
  opacity: 0.7;
}

.list-card-delete:hover {
  opacity: 1 !important;
  background: var(--danger-light);
  color: var(--danger);
}

@media (hover: none) {
  .list-card-delete {
    opacity: 0.5;
  }
}

.board-column-delete {
  font-size: 14px;
  min-width: 28px;
  min-height: 28px;
  opacity: 0.4;
  padding: 0;
  transition: opacity var(--transition);
}

.board-column-delete:hover {
  opacity: 1;
  background: var(--danger-light);
  color: var(--danger);
}

.list-card-progress {
  height: 4px;
  background: var(--bg-input);
  border-radius: 2px;
  overflow: hidden;
}

.list-card-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.list-card-progress-fill.complete {
  background: var(--success);
}

/* ===== Add Item Bar ===== */
.add-item-bar {
  padding: 12px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  max-width: 100%;
}

.add-item-bar .input-group {
  max-width: var(--max-width);
  margin: 0 auto;
}

/* ===== Items Container ===== */
.items-container {
  flex: 1;
  padding: 8px 16px 24px;
  padding-bottom: calc(24px + var(--safe-bottom));
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ===== Item List ===== */
.item-list {
  margin-bottom: 8px;
}

.item-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  animation: slideInUp 0.25s ease backwards;
  position: relative;
  overflow: hidden;
}

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

/* Checkbox */
.item-checkbox {
  width: 26px;
  height: 26px;
  min-width: 26px;
  border: 2px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  margin-top: 1px;
  font-size: 14px;
  color: transparent;
  touch-action: manipulation;
}

.item-checkbox:hover {
  border-color: var(--accent);
}

.item-checkbox.checked {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  animation: checkPop 0.3s ease;
}

.item-content {
  flex: 1;
  min-width: 0;
}

.item-text {
  font-size: 16px;
  line-height: 1.4;
  word-break: break-word;
  cursor: text;
  padding: 2px 0;
  border-radius: 4px;
  transition: background var(--transition);
}

.item-text:focus {
  outline: none;
  background: var(--accent-light);
}

.item-meta {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.item-delete {
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text-tertiary);
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition);
  opacity: 0;
  touch-action: manipulation;
  flex-shrink: 0;
}

.item-row:hover .item-delete,
.item-row:focus-within .item-delete {
  opacity: 1;
}

.item-delete:hover {
  background: var(--danger-light);
  color: var(--danger);
}

/* Mobile: always show delete */
@media (hover: none) {
  .item-delete {
    opacity: 0.5;
  }
}

/* Checked items styling */
.item-list-checked .item-text {
  text-decoration: line-through;
  color: var(--text-tertiary);
}

.item-list-checked .item-row {
  opacity: 0.6;
}

.item-list-checked .item-meta {
  opacity: 0.6;
}

/* ===== Checked Section Divider ===== */
.checked-divider {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 4px 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ===== Loading ===== */
.loading-spinner {
  display: flex;
  justify-content: center;
  padding: 40px;
}

.loading-spinner[hidden] {
  display: none;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-secondary);
}

.empty-state[hidden] {
  display: none;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 16px;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 24px;
  animation: fadeIn 0.2s ease;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-overlay[hidden] {
  display: none !important;
}

.modal-card {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 28px 24px;
  width: 100%;
  max-width: 340px;
  box-shadow: var(--shadow-lg);
  animation: slideInUp 0.3s ease;
}

.modal-card h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 4px;
}

.modal-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 20px;
}

.modal-card input {
  width: 100%;
  background: var(--bg-input);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 16px;
  min-height: 48px;
  transition: border-color var(--transition);
}

.modal-card input:focus {
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ===== Toast ===== */
#toast-container {
  position: fixed;
  top: calc(16px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 400px;
}

.toast {
  background: var(--bg-card);
  color: var(--text);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  animation: slideInUp 0.3s ease;
  border-left: 4px solid var(--accent);
  pointer-events: auto;
}

.toast.error {
  border-left-color: var(--danger);
}

.toast.success {
  border-left-color: var(--success);
}

.toast.hiding {
  animation: fadeOut 0.3s ease forwards;
}

@keyframes fadeOut {
  to { opacity: 0; transform: translateY(-10px); }
}

/* ===== Pull to Refresh indicator ===== */
.pull-indicator {
  text-align: center;
  padding: 12px;
  color: var(--text-tertiary);
  font-size: 13px;
  transition: opacity 0.2s;
}

/* ===== Responsive ===== */
@media (min-width: 601px) {
  .lists-container,
  .items-container,
  .add-item-bar .input-group,
  .status-bar {
    max-width: var(--max-width);
  }

  .top-bar {
    justify-content: center;
  }

  .top-bar > * {
    max-width: var(--max-width);
  }
}

/* ===== Drag & Reorder ===== */
.dragging {
  opacity: 0.9;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25) !important;
  transform: scale(1.03) !important;
  border-radius: var(--radius);
  transition: none !important;
}

.drag-placeholder {
  background: var(--accent-light);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  margin-bottom: 10px;
  opacity: 0.5;
  transition: height 0.2s ease;
}

/* Board placeholder */
.board-container > .drag-placeholder {
  flex: 0 0 280px;
  margin-bottom: 0;
  margin-right: 0;
  min-height: 100px;
}

@media (max-width: 600px) {
  .board-container > .drag-placeholder {
    flex: 0 0 calc(100vw - 48px);
  }
}

/* ===== No animation on silent refresh ===== */
.no-anim {
  animation: none !important;
}

/* ===== Disable text selection on interactive elements ===== */
.list-card, .item-checkbox, .btn {
  user-select: none;
  -webkit-user-select: none;
}

/* ===== Accessibility ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== Scrollbar (desktop) ===== */
@media (hover: hover) {
  ::-webkit-scrollbar {
    width: 6px;
  }
  ::-webkit-scrollbar-track {
    background: transparent;
  }
  ::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
  }
}
