/*
 * Techo Todo — 手账风格待办应用
 * Design direction: 日系子弹日记 / 温暖手账美学
 */

/* ===== CSS Custom Properties ===== */
:root {
  --paper: #faf5ed;
  --paper-dark: #f0e8d8;
  --paper-darker: #e6dcc8;
  --ink: #3d3226;
  --ink-light: #8c7b6d;
  --ink-lighter: #b8a99a;
  --accent: #c7513b;
  --accent-soft: #e8a090;
  --accent-wash: #fdf0ec;
  --amber: #d4903b;
  --amber-soft: #f5d9a8;
  --amber-wash: #fef8f0;
  --sage: #7a9e7e;
  --sage-soft: #c5d8c7;
  --sage-wash: #f3f8f2;
  --sky: #6b8fa3;
  --sky-soft: #bcd4de;
  --sky-wash: #f2f6f8;
  --tape-washi: rgba(231, 199, 155, 0.85);
  --tape-mint: rgba(180, 215, 200, 0.8);
  --tape-rose: rgba(225, 180, 175, 0.8);
  --shadow-soft: 0 2px 12px rgba(61, 50, 38, 0.06);
  --shadow-card: 0 1px 3px rgba(61, 50, 38, 0.08), 0 1px 2px rgba(61, 50, 38, 0.06);
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 14px;
  --font-title: 'Caveat', 'ZCOOL KuaiLe', cursive;
  --font-body: 'Noto Serif SC', 'Noto Sans SC', 'Source Han Serif SC', serif;
  --font-ui: 'Noto Sans SC', system-ui, sans-serif;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background-color: #f5efe0;
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(210, 180, 140, 0.12) 0%, transparent 70%),
    radial-gradient(ellipse at 80% 20%, rgba(200, 160, 120, 0.10) 0%, transparent 60%);
  min-height: 100vh;
  line-height: 1.7;
}

/* Paper texture overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.025'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
  pointer-events: none;
  z-index: 0;
}

/* ===== Typography ===== */
h1, h2, h3, h4 {
  font-family: var(--font-title);
  font-weight: 600;
  line-height: 1.25;
  color: var(--ink);
}

h1 { font-size: clamp(1.8rem, 3.5vw, 2.6rem); }
h2 { font-size: clamp(1.3rem, 2.5vw, 1.7rem); }
h3 { font-size: 1.1rem; }

/* ===== Layout ===== */
.app-container {
  position: relative;
  z-index: 1;
  display: flex;
  min-height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  gap: 0;
}

/* ===== Auth Pages ===== */
.auth-page {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  background: var(--paper);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft), 0 0 0 1px rgba(61,50,38,0.04);
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  position: relative;
}

/* Tape decoration on auth card */
.auth-card::before {
  content: '';
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%) rotate(-2deg);
  width: 80px;
  height: 28px;
  background: var(--tape-washi);
  border-radius: 2px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.auth-card h1 {
  text-align: center;
  margin-bottom: 8px;
  font-size: 2.2rem;
  color: var(--accent);
}

.auth-card .subtitle {
  text-align: center;
  color: var(--ink-light);
  font-size: 0.9rem;
  margin-bottom: 32px;
  font-family: var(--font-body);
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--ink-light);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--paper-darker);
  border-radius: var(--radius-md);
  background: #fefdfa;
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--ink);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  outline: none;
}

.form-input:focus {
  border-color: var(--accent-soft);
  box-shadow: 0 0 0 3px var(--accent-wash);
}

.form-input::placeholder {
  color: var(--ink-lighter);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 28px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  line-height: 1.4;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(199,81,59,0.25);
}

.btn-primary:hover { background: #b84531; box-shadow: 0 4px 14px rgba(199,81,59,0.35); }
.btn-primary:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 2px; }

.btn-ghost {
  background: transparent;
  color: var(--ink-light);
  padding: 8px 16px;
}

.btn-ghost:hover { background: var(--paper-dark); color: var(--ink); }

.btn-block { width: 100%; }

.btn-sm { padding: 6px 14px; font-size: 0.82rem; }

.btn-icon {
  width: 36px; height: 36px; padding: 0;
  border-radius: 50%;
  font-size: 1.1rem;
  background: transparent;
  color: var(--ink-light);
}

.btn-icon:hover { background: var(--paper-dark); color: var(--ink); }

.auth-switch {
  text-align: center;
  margin-top: 24px;
  font-size: 0.85rem;
  color: var(--ink-light);
}

.auth-switch a {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 500;
}

.auth-switch a:hover { color: #a04230; }

.error-msg {
  background: var(--accent-wash);
  color: var(--accent);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 16px;
  border-left: 3px solid var(--accent-soft);
  display: none;
}

.error-msg.show { display: block; }

/* ===== Sidebar ===== */
.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--paper);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 24px;
  height: calc(100vh - 48px);
  overflow-y: auto;
}

.sidebar-header {
  padding: 0 20px 20px;
  border-bottom: 2px dotted var(--paper-darker);
  margin-bottom: 8px;
}

.sidebar-header h1 {
  font-size: 1.6rem;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.sidebar-header .brand-tag {
  font-size: 0.7rem;
  color: var(--ink-lighter);
  font-family: var(--font-body);
  margin-top: 2px;
}

.nav-section {
  padding: 8px 12px;
}

.nav-section-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-lighter);
  padding: 0 8px 6px;
  font-family: var(--font-ui);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s ease;
  color: var(--ink-light);
  font-family: var(--font-body);
  font-size: 0.9rem;
  position: relative;
}

.nav-item:hover { background: var(--paper-dark); color: var(--ink); }
.nav-item.active { background: var(--amber-wash); color: var(--amber); font-weight: 600; }

.nav-item .nav-icon {
  font-size: 1.2rem;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.nav-item .nav-count {
  margin-left: auto;
  font-size: 0.75rem;
  background: var(--paper-darker);
  color: var(--ink-light);
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
  min-width: 24px;
  text-align: center;
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 2px dotted var(--paper-darker);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-footer .user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: flex; align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: var(--font-ui);
}

.sidebar-footer .user-name {
  font-size: 0.85rem;
  color: var(--ink);
  flex: 1;
  font-family: var(--font-body);
}

/* ===== Main Panel ===== */
.main-panel {
  flex: 1;
  padding: 0 0 0 24px;
  min-width: 0;
}

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

.main-header h2 {
  color: var(--ink);
  font-size: 1.7rem;
}

.main-header-actions {
  display: flex;
  gap: 8px;
}

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

.task-card {
  background: var(--paper);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.task-card:hover {
  box-shadow: 0 3px 12px rgba(61,50,38,0.10);
}

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

.task-card.completed .task-title {
  text-decoration: line-through;
  text-decoration-color: var(--ink-lighter);
  text-decoration-thickness: 2px;
}

.task-card-body {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
}

.task-checkbox {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid var(--paper-darker);
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
  background: #fefdfa;
}

.task-checkbox:hover { border-color: var(--sage); background: var(--sage-wash); }

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

.task-checkbox.checked::after {
  content: '✓';
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}

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

.task-title {
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--ink);
  margin-bottom: 4px;
  word-break: break-word;
}

.task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.task-badge {
  font-size: 0.72rem;
  padding: 2px 10px;
  border-radius: 10px;
  font-family: var(--font-ui);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.badge-due { background: var(--sky-wash); color: var(--sky); }
.badge-due.overdue { background: var(--accent-wash); color: var(--accent); }
.badge-important { background: var(--amber-wash); color: var(--amber); }
.badge-repeat { background: var(--sage-wash); color: var(--sage); }
.badge-note { background: var(--paper-dark); color: var(--ink-light); }

.task-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.task-card:hover .task-actions { opacity: 1; }

.task-actions .btn-icon {
  width: 30px; height: 30px;
  font-size: 0.9rem;
}

/* Steps */
.task-steps {
  border-top: 1px dashed var(--paper-darker);
  padding: 10px 18px 14px 52px;
  display: none;
}

.task-steps.open { display: block; }

.step-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  font-size: 0.85rem;
  color: var(--ink-light);
}

.step-item.completed { color: var(--ink-lighter); text-decoration: line-through; }

.step-check {
  width: 16px; height: 16px;
  border-radius: 3px;
  border: 1.5px solid var(--paper-darker);
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  transition: all 0.15s ease;
}

.step-check:hover { border-color: var(--sage); }
.step-check.checked { background: var(--sage); border-color: var(--sage); color: #fff; }

.step-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0 2px;
  font-size: 0.78rem;
  color: var(--ink-lighter);
  cursor: pointer;
  font-family: var(--font-ui);
}

.step-toggle:hover { color: var(--ink-light); }

/* ===== Add Task Bar ===== */
.add-task-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: var(--paper);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  margin-bottom: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.add-task-bar:hover { box-shadow: 0 3px 12px rgba(61,50,38,0.10); }

.add-task-bar .plus-icon {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.add-task-bar span {
  color: var(--ink-lighter);
  font-family: var(--font-body);
  font-size: 0.9rem;
}

/* ===== Modal/Dialog ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(40,30,20,0.3);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-sheet {
  background: var(--paper);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 40px rgba(61,50,38,0.15);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
}

/* Washi tape on modal */
.modal-sheet::before {
  content: '';
  position: absolute;
  top: -8px;
  right: 40px;
  width: 60px;
  height: 22px;
  background: var(--tape-mint);
  border-radius: 2px;
  transform: rotate(3deg);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 28px 0;
}

.modal-header h3 {
  font-size: 1.3rem;
}

.modal-body { padding: 20px 28px 28px; }

.modal-body .form-group { margin-bottom: 16px; }
.modal-body .form-group:last-child { margin-bottom: 0; }

.modal-body textarea.form-input {
  resize: vertical;
  min-height: 70px;
}

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 0 28px 24px;
}

/* ===== Detail Panel ===== */
.detail-panel {
  background: var(--paper);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  padding: 28px;
  margin-top: 16px;
  position: relative;
}

.detail-panel h3 {
  font-size: 1.25rem;
  margin-bottom: 4px;
}

.detail-panel .detail-meta {
  color: var(--ink-light);
  font-size: 0.82rem;
  margin-bottom: 16px;
}

.detail-panel .detail-note {
  background: var(--paper-dark);
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--ink-light);
  line-height: 1.6;
  margin-bottom: 16px;
  white-space: pre-wrap;
}

.detail-steps { margin-top: 12px; }
.detail-steps h4 { font-size: 0.9rem; color: var(--ink-light); margin-bottom: 8px; }

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

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state p {
  font-family: var(--font-body);
  font-size: 0.95rem;
}

/* ===== Loading Skeleton ===== */
.skeleton {
  background: linear-gradient(90deg, var(--paper-dark) 25%, var(--paper-darker) 50%, var(--paper-dark) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.skeleton-line { height: 16px; margin-bottom: 8px; }
.skeleton-line.short { width: 60%; }

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--ink);
  color: var(--paper);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-family: var(--font-body);
  box-shadow: 0 4px 16px rgba(61,50,38,0.15);
  animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 340px;
}

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

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
    padding: 12px;
  }
  .sidebar {
    width: 100%;
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 2px;
    padding: 12px 8px;
    overflow-x: auto;
    border-radius: var(--radius-md);
  }
  .sidebar-header { display: none; }
  .sidebar-footer { display: none; }
  .nav-section { display: flex; gap: 4px; padding: 0; }
  .nav-section-title { display: none; }
  .nav-item { padding: 8px 12px; font-size: 0.8rem; border-radius: 20px; }
  .nav-item .nav-count { display: none; }
  .main-panel { padding: 16px 0 0; }
  .modal-sheet { max-width: 100%; margin: 12px; }
}

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

/* ===== Utility ===== */
.hidden { display: none !important; }
.flex-center { display: flex; align-items: center; justify-content: center; }
