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

:root {
  --primary: #2563eb;
  --primary-light: #dbeafe;
  --primary-dark: #1d4ed8;
  --bg: #ffffff;
  --bg-secondary: #f5f5f5;
  --bg-hover: #f0f0f0;
  --text: #1f2937;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --p0: #ef4444;
  --p1: #f59e0b;
  --p2: #3b82f6;
  --p3: #9ca3af;
  --success: #10b981;
  --danger: #ef4444;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --sidebar-width: 220px;
  --topbar-height: 56px;
  --bottomtab-height: 60px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg-secondary);
  color: var(--text);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

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

/* ========== Top Bar ========== */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
}

.top-bar-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.top-bar-date {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ========== Sidebar (PC) ========== */
.sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  z-index: 90;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 8px;
}

.sidebar-logo-text {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
}

.nav-list {
  list-style: none;
  padding: 0 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  user-select: none;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
}

.nav-item.active svg {
  stroke: var(--primary);
}

/* ========== Bottom Tab (Mobile) ========== */
.bottom-tab {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottomtab-height);
  background: var(--bg);
  border-top: 1px solid var(--border);
  z-index: 100;
  align-items: center;
  justify-content: space-around;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1;
  padding: 6px 0;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.tab-item.active {
  color: var(--primary);
}

.tab-item.active svg {
  stroke: var(--primary);
}

/* ========== App Container ========== */
.app-container {
  display: flex;
  height: 100vh;
  padding-top: var(--topbar-height);
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  overflow-y: auto;
  padding: 16px 20px 80px;
  background: var(--bg-secondary);
}

/* ========== Pages ========== */
.page {
  display: none;
}

.page.active {
  display: block;
}

/* ========== Page Header / Filter Bar ========== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-bar {
  display: flex;
  gap: 6px;
}

.filter-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.filter-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.filter-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.sort-toggle {
  display: flex;
  align-items: center;
}

.sort-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.sort-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* ========== Task List ========== */
.task-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.task-group-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 12px 4px 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.task-group-header .priority-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

/* ========== Task Card ========== */
.task-card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  transition: box-shadow 0.15s;
  position: relative;
  border-left: 3px solid transparent;
}

.task-card:hover {
  box-shadow: var(--shadow);
}

.task-card.priority-0 { border-left-color: var(--p0); }
.task-card.priority-1 { border-left-color: var(--p1); }
.task-card.priority-2 { border-left-color: var(--p2); }
.task-card.priority-3 { border-left-color: var(--p3); }

.task-card.status-done {
  opacity: 0.6;
}

.task-card.status-done .task-title {
  text-decoration: line-through;
  color: var(--text-muted);
}

.task-card.status-doing {
  background: #fefce8;
}

/* Checkbox */
.task-checkbox {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
  transition: all 0.15s;
}

.task-checkbox:hover {
  border-color: var(--primary);
}

.task-checkbox.checked {
  background: var(--success);
  border-color: var(--success);
}

.task-checkbox.checked::after {
  content: '';
  width: 6px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  margin-top: -2px;
}

.task-checkbox.priority-0 { border-color: var(--p0); }
.task-checkbox.priority-1 { border-color: var(--p1); }
.task-checkbox.priority-2 { border-color: var(--p2); }
.task-checkbox.priority-3 { border-color: var(--p3); }

/* Task Body */
.task-body {
  flex: 1;
  min-width: 0;
}

.task-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  word-break: break-word;
}

.task-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.task-meta-item {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  color: var(--text-muted);
}

.task-meta-item svg {
  width: 13px;
  height: 13px;
}

.task-tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

/* Task Actions */
.task-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.task-action-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all 0.15s;
}

.task-action-btn:hover {
  background: var(--bg-secondary);
  color: var(--primary);
}

.task-action-btn.timer-active {
  color: var(--danger);
}

/* ========== Priority Badge ========== */
.priority-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
}

.priority-badge.p0 { background: var(--p0); }
.priority-badge.p1 { background: var(--p1); }
.priority-badge.p2 { background: var(--p2); }
.priority-badge.p3 { background: var(--p3); }

/* ========== Empty State ========== */
.empty-state, .placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  color: var(--text-muted);
  text-align: center;
}

.empty-state p, .placeholder p {
  margin-top: 12px;
  font-size: 15px;
  font-weight: 500;
}

.empty-hint, .placeholder-hint {
  font-size: 13px !important;
  font-weight: 400 !important;
  color: var(--text-muted);
  margin-top: 4px !important;
}

/* ========== FAB ========== */
.fab {
  position: fixed;
  bottom: 80px;
  right: 24px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  transition: transform 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.fab:hover {
  transform: scale(1.05);
  box-shadow: 0 12px 20px rgba(37,99,235,0.3);
}

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

/* ========== Modal ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.show {
  display: flex;
}

.modal {
  background: var(--bg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.modal-close:hover {
  background: var(--bg-secondary);
  color: var(--text);
}

/* ========== Form ========== */
.task-form .form-group {
  margin-bottom: 14px;
}

.task-form label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.task-form .required {
  color: var(--danger);
}

.task-form input[type="text"],
.task-form input[type="number"],
.task-form input[type="date"],
.task-form input[type="time"],
.task-form textarea,
.task-form select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s;
}

.task-form input:focus,
.task-form textarea:focus,
.task-form select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.task-form textarea {
  resize: vertical;
}

.form-row {
  display: flex;
  gap: 12px;
}

.flex-1 { flex: 1; }

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ========== Buttons ========== */
.btn {
  padding: 9px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* ========== Context Menu ========== */
.context-menu {
  position: fixed;
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  z-index: 300;
  display: none;
  min-width: 140px;
  padding: 4px;
}

.context-menu.show {
  display: block;
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.1s;
}

.context-menu-item:hover {
  background: var(--bg-secondary);
}

.context-menu-item[data-action="delete"] {
  color: var(--danger);
}

/* ========== Timer Bar ========== */
.timer-bar {
  position: fixed;
  bottom: 140px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  border-radius: 28px;
  padding: 8px 12px 8px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 95;
  box-shadow: var(--shadow-lg);
  max-width: 90%;
}

.timer-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.timer-task-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.timer-elapsed {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #fbbf24;
}

.timer-stop-btn {
  width: 34px;
  height: 34px;
  border: none;
  background: var(--danger);
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.timer-stop-btn:hover {
  opacity: 0.9;
}

/* ========== Toast ========== */
.toast-container {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--text);
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(-10px);
  animation: toastIn 0.2s forwards;
  pointer-events: auto;
}

.toast.out {
  animation: toastOut 0.2s forwards;
}

@keyframes toastIn {
  to { opacity: 1; transform: translateY(0); }
}

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

/* ========== Responsive: Mobile ========== */
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .bottom-tab {
    display: flex;
  }

  .main-content {
    margin-left: 0;
    padding: 12px 14px 100px;
  }

  .top-bar {
    padding: 0 14px;
  }

  .fab {
    bottom: 76px;
    right: 18px;
    width: 48px;
    height: 48px;
  }

  .timer-bar {
    bottom: 136px;
  }

  .modal {
    max-width: 100%;
  }

  .filter-btn {
    padding: 5px 10px;
    font-size: 12px;
  }
}

/* ========== Responsive: Large PC ========== */
@media (min-width: 769px) {
  .bottom-tab {
    display: none;
  }

  .sidebar {
    display: flex;
  }

  .top-bar {
    padding-left: calc(var(--sidebar-width) + 20px);
  }

  .fab {
    bottom: 32px;
    right: 32px;
  }

  .timer-bar {
    bottom: 32px;
    left: calc(var(--sidebar-width) + 50%);
    transform: translateX(calc(-50% - var(--sidebar-width) / 2));
  }

  .modal-overlay {
    align-items: center;
  }

  .modal {
    border-radius: var(--radius-lg);
  }
}

/* ========== Scrollbar ========== */
.main-content::-webkit-scrollbar {
  width: 6px;
}

.main-content::-webkit-scrollbar-track {
  background: transparent;
}

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

.main-content::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

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