:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-soft: #eff6ff;
  --accent: #6366f1;
  --danger: #ef4444;
  --danger-soft: #fef2f2;
  --success: #10b981;
  --warning: #f59e0b;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 20px rgba(15, 23, 42, 0.05);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* 버튼 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8125rem;
}

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

.btn-outline {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.btn-outline:hover {
  background: var(--surface-alt);
  border-color: #cbd5e1;
}

.btn-danger-outline {
  background: var(--surface);
  border-color: #fecaca;
  color: var(--danger);
}
.btn-danger-outline:hover {
  background: var(--danger-soft);
}

.btn-icon, .btn-icon-sm {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
}
.btn-icon { width: 38px; height: 38px; }
.btn-icon svg { width: 18px; height: 18px; display: block; flex-shrink: 0; }
.btn-icon-sm { width: 30px; height: 30px; }
.btn-icon-sm svg { width: 16px; height: 16px; display: block; flex-shrink: 0; }
.btn-icon:hover, .btn-icon-sm:hover { background: var(--surface-alt); color: var(--primary); }

/* 잠금 화면 */
.lock-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lock-card {
  background: var(--surface);
  padding: 32px;
  border-radius: var(--radius);
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.lock-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.lock-icon svg {
  width: 24px;
  height: 24px;
}

.lock-card h2 {
  font-size: 1.25rem;
  margin-bottom: 6px;
}

.lock-card p {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 18px;
}

.lock-form {
  display: flex;
  gap: 8px;
}

.lock-form input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
}

.error-text {
  color: var(--danger) !important;
  margin-top: 10px !important;
  margin-bottom: 0 !important;
  font-weight: 600;
}

/* 상단 바 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.brand-badge svg {
  width: 20px;
  height: 20px;
}

.brand h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 10px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  pointer-events: none;
}
.search-icon svg {
  width: 15px;
  height: 15px;
}

.search-box input {
  padding: 8px 12px 8px 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  width: 220px;
  background: var(--surface-alt);
  outline: none;
}
.search-box input:focus {
  border-color: var(--primary);
  background: var(--surface);
}

/* 메인 컨테이너 */
.container {
  max-width: 1280px;
  margin: 22px auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.section-header h2, .section-title {
  font-size: 1.05rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.title-icon {
  width: 18px;
  height: 18px;
  color: var(--primary);
  flex-shrink: 0;
}

.section-desc {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* 상단 Bento 2열 레이아웃 (PC 최적화) */
.top-bento-grid {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 20px;
  align-items: stretch;
}

.bento-left-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.memo-section {
  display: flex;
  flex-direction: column;
}

.memo-section .memo-list {
  flex: 1;
  align-content: start;
}

/* D-Day 그리드 (컴팩트) */
.dday-section {
  padding: 16px 18px;
}

.dday-section .section-header {
  align-items: center;
  margin-bottom: 10px;
}

.dday-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dday-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 28px 9px 12px;
  position: relative;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.dday-badge {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.dday-badge.past {
  color: var(--text-muted);
}

.dday-badge.today {
  color: var(--danger);
}

.dday-title {
  font-weight: 700;
  font-size: 0.87rem;
  flex: 1;
  min-width: 110px;
}

.dday-date {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.dday-source-tag {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
}

.card-delete-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: transparent;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px 5px;
  border-radius: 6px;
}
.card-delete-btn:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
}

.memo-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 2px;
}

.card-action-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px 5px;
  border-radius: 6px;
}
.card-action-btn:hover {
  background: rgba(59, 130, 246, 0.1);
  color: var(--primary);
}
.card-action-btn.delete:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
}

/* 데일리 루틴 (단색 앰버 하이라이트 섹션) */
.routine-section {
  padding: 18px 20px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-left: 4px solid #f59e0b;
  box-shadow: var(--shadow);
  position: relative;
}

.routine-section .title-icon {
  color: #d97706;
}

.routine-section .section-header {
  align-items: center;
  margin-bottom: 10px;
}

.routine-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.routine-summary {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: #d97706;
  color: #ffffff;
}

.routine-summary.all-done {
  background: var(--success);
}

.routine-progress-track {
  width: 100%;
  height: 7px;
  background: rgba(217, 119, 6, 0.16);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 14px;
}

.routine-progress-fill {
  height: 100%;
  background: #f59e0b;
  border-radius: 999px;
  transition: width 0.25s ease, background-color 0.2s ease;
}

.routine-summary.all-done ~ .routine-progress-track .routine-progress-fill,
.routine-progress-fill.all-done {
  background: var(--success);
}

.routine-date-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.routine-date-label {
  font-size: 0.84rem;
  font-weight: 700;
  min-width: 96px;
  text-align: center;
  color: #92400e;
}

.routine-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.routine-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1.5px solid #fcd34d;
  background: #ffffff;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 2px 6px rgba(180, 83, 9, 0.06);
  transition: all 0.15s ease;
}

.routine-item:hover {
  border-color: #d97706;
  transform: translateY(-1px);
}

.routine-item.checked {
  background: #10b981;
  border-color: #059669;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
}

.routine-check-box {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 2px solid #cbd5e1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  background: #ffffff;
  transition: all 0.15s ease;
}

.routine-item.checked .routine-check-box {
  background: rgba(255, 255, 255, 0.22);
  border-color: #ffffff;
  color: #ffffff;
}

/* 2단 그리드 */
.main-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 20px;
  align-items: start;
}

.col-left, .col-right {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* 필터 탭 */
.filter-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.tab {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* 문서 목록 */
.doc-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.doc-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-alt);
  transition: border-color 0.15s ease;
}
.doc-item:hover {
  border-color: #bfdbfe;
  background: #fff;
}

.doc-info {
  min-width: 0;
  flex: 1;
}

.doc-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--primary-soft);
  color: var(--primary);
}

.doc-title {
  font-weight: 700;
  font-size: 0.93rem;
  word-break: break-word;
}

.doc-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.doc-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* 북마크 그리드 */
.bookmark-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
}

.bookmark-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--surface-alt);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-decoration: none;
  color: inherit;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.bookmark-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  background: #fff;
}

.bookmark-title {
  font-weight: 700;
  font-size: 0.9rem;
  padding-right: 18px;
}

.bookmark-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* 캘린더 */
.calendar-wrapper {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  background: var(--surface-alt);
}

.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.calendar-weekdays, .calendar-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  gap: 4px;
}

.calendar-weekdays span {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  padding-bottom: 6px;
}
.calendar-weekdays .sun { color: var(--danger); }
.calendar-weekdays .sat { color: var(--primary); }

.cal-day {
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  cursor: pointer;
  position: relative;
  border: 1px solid transparent;
}
.cal-day:hover:not(.empty) {
  background: #e2e8f0;
}
.cal-day.today {
  font-weight: 800;
  border-color: var(--primary);
  color: var(--primary);
}
.cal-day.selected {
  background: var(--primary) !important;
  color: #fff !important;
}
.cal-day.empty {
  cursor: default;
}

.cal-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--warning);
  margin-top: 2px;
}
.cal-day.selected .cal-dot {
  background: #fff;
}

.selected-date-events {
  margin-top: 14px;
}
.selected-date-events h3 {
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.event-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.event-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.85rem;
}

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

/* 가족 메모 */
.memo-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.memo-card {
  border-radius: 12px;
  padding: 14px;
  border: 1px solid #fde68a;
  background: #fefce8;
  position: relative;
}
.memo-card.blue {
  border-color: #bfdbfe;
  background: #eff6ff;
}
.memo-card.green {
  border-color: #a7f3d0;
  background: #ecfdf5;
}
.memo-card.pink {
  border-color: #fbcfe8;
  background: #fdf2f8;
}

.memo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  padding-right: 48px;
}

.memo-author {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text);
}

.memo-date {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.memo-body {
  font-size: 0.88rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* 모달 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

.modal-content.modal-lg {
  max-width: 960px;
  height: 85vh;
}

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

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

.preview-body {
  flex: 1;
  overflow: auto;
  background: #f8fafc;
}

.preview-body iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.builtin-guide {
  padding: 24px;
  line-height: 1.7;
  font-size: 0.94rem;
}
.builtin-guide h3 { margin: 16px 0 8px; font-size: 1.05rem; color: var(--primary-hover); }
.builtin-guide ul { padding-left: 20px; margin-bottom: 12px; }
.builtin-guide li { margin-bottom: 4px; }

.markdown-body {
  padding: 28px 32px;
  line-height: 1.75;
  font-size: 0.95rem;
  color: var(--text);
  background: #ffffff;
}
.markdown-body h1 { font-size: 1.45rem; margin-bottom: 14px; border-bottom: 2px solid var(--border); padding-bottom: 8px; }
.markdown-body h2 { font-size: 1.18rem; margin: 24px 0 10px; color: var(--primary-hover); }
.markdown-body h3 { font-size: 1.02rem; margin: 16px 0 8px; }
.markdown-body p { margin-bottom: 10px; }
.markdown-body ul, .markdown-body ol { padding-left: 22px; margin-bottom: 12px; }
.markdown-body li { margin-bottom: 4px; }
.markdown-body blockquote {
  border-left: 4px solid var(--primary);
  background: var(--primary-soft);
  padding: 10px 14px;
  border-radius: 0 8px 8px 0;
  margin: 12px 0;
  color: var(--text);
}
.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 0.88rem;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.markdown-body th, .markdown-body td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
}
.markdown-body th {
  background: var(--surface-alt);
  font-weight: 700;
}
.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.modal-form {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.82rem;
  font-weight: 600;
}

.form-group input, .form-group select, .form-group textarea {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
}

.checkbox-row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

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

.empty-state {
  text-align: center;
  padding: 22px;
  color: var(--text-muted);
  font-size: 0.85rem;
  border: 1px dashed var(--border);
  border-radius: 10px;
}

.footer {
  max-width: 1280px;
  margin: 0 auto 30px;
  padding: 0 20px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

@media (max-width: 960px) {
  .top-bento-grid,
  .main-grid {
    grid-template-columns: 1fr;
  }
  .search-box input {
    width: 160px;
  }
}

@media (max-width: 640px) {
  .topbar-inner {
    padding: 12px 14px;
    gap: 10px;
    position: relative;
  }
  .brand {
    padding-right: 46px;
  }
  .topbar-actions {
    width: 100%;
    gap: 6px;
  }
  .search-box {
    width: 100%;
    flex: 1;
  }
  .search-box input {
    width: 100%;
    font-size: 16px;
  }
  #settingsBtn {
    position: absolute;
    top: 14px;
    right: 14px;
  }
  .container {
    margin: 14px auto;
    padding: 0 12px;
    gap: 14px;
  }
  .card {
    padding: 16px 14px;
    border-radius: 14px;
  }
  .dday-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
  .doc-item {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .doc-actions {
    justify-content: flex-end;
    flex-wrap: wrap;
  }
  .bookmark-grid {
    grid-template-columns: 1fr;
  }
  .modal {
    padding: 8px;
  }
  .modal-content.modal-lg {
    height: 92dvh;
    max-height: 92dvh;
  }
  .modal-header {
    padding: 12px 14px;
  }
  .modal-header h3 {
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .markdown-body {
    padding: 18px 16px;
    font-size: 0.92rem;
  }
  .form-group input, .form-group select, .form-group textarea {
    font-size: 16px;
  }
}
