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

body { 
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 
               'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', sans-serif;
  background: #f5f5f0; 
  color: #2a2a2a;
  -webkit-tap-highlight-color: transparent;
}

.app { max-width: 820px; margin: 0 auto; padding: 16px; }

/* ─── 상단 헤더 ─── */
header { 
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px; padding-bottom: 12px;
  border-bottom: 2px solid #2d4a3e;
  flex-wrap: wrap; gap: 8px;
}
header h1 { font-size: 22px; color: #2d4a3e; }
.header-actions { display: flex; gap: 8px; align-items: center; font-size: 13px; }

.status { color: #888; font-size: 12px; min-width: 100px; text-align: right; }
.status.saving { color: #c08020; }
.status.saved { color: #2d4a3e; }
.status.error { color: #c03030; }
.status.conflict { color: #c03030; font-weight: 600; }

.btn-primary, .btn-ghost {
  padding: 7px 14px; font-size: 13px; border-radius: 6px; cursor: pointer;
  font-family: inherit; font-weight: 500;
}
.btn-primary { background: #2d4a3e; color: #fff; border: 1px solid #2d4a3e; }
.btn-primary:hover { background: #1f3329; }
.btn-ghost { background: #fff; color: #2d4a3e; border: 1px solid #d0d0c8; }
.btn-ghost:hover { background: #f0efe8; }
.logout { color: #888; text-decoration: none; font-size: 13px; padding: 0 4px; }

/* ─── 사용법 안내 ─── */
.hint { 
  font-size: 12px; color: #888; margin: 10px 4px 14px; line-height: 1.6;
}
.hint code, .hint kbd {
  background: #e8e8e0; padding: 1px 6px; border-radius: 3px;
  font-family: 'SF Mono', Consolas, monospace; font-size: 11px;
}

/* ─── 에디터 영역 ─── */
.editor {
  min-height: 70vh; padding: 20px 24px;
  background: #fff; border: 1px solid #d8d8d0; border-radius: 8px;
  font-size: 15px; line-height: 1.4;
  font-family: -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 
               'Malgun Gothic', 'Noto Sans KR', sans-serif;
  white-space: pre-wrap; word-wrap: break-word;
  outline: none;
  tab-size: 4;
  -moz-tab-size: 4;
}
.editor:focus { 
  border-color: #2d4a3e; 
  box-shadow: 0 0 0 3px rgba(45,74,62,0.08); 
}

.editor .line { 
  min-height: 1.4em; position: relative; padding-left: 0;
}

.editor .line { 
  min-height: 1.4em; position: relative; padding-left: 0;
}

/* 메인 업무(depth-0) 위쪽에 살짝 여백 - 시각적 구분 */
.editor .line:not(.depth-1):not(.depth-2):not(.empty) {
  margin-top: 0.4em;
}
.editor .line:first-child {
  margin-top: 0;
}

.editor .line.depth-1 { padding-left: 80px; ... }

.editor .line.depth-1 { padding-left: 80px; color: #444; font-size: 0.85em; }
.editor .line.depth-2 { padding-left: 90px; color: #666; font-size: 0.85em; }

.editor .line.empty { min-height: 0.7em; }

/* ─── 날짜 배지 ─── */
.editor .date-tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 4px;
  font-weight: 600;
  margin-right: 6px;
  font-size: 0.92em;
  letter-spacing: 0.3px;
  min-width: 46px;
  text-align: center;
}

.editor .date-tag.overdue {
  background: #f0d4d4;
  color: #a04040;
  border: 1px solid #e8c0c0;
}

.editor .date-tag.today {
  background: #2d4a3e;
  color: #fff;
  border: 1px solid #2d4a3e;
}

.editor .date-tag.future {
  background: #e0e8ec;
  color: #4a6b7a;
  border: 1px solid #c8d5dc;
}

.editor:empty::before {
  content: '여기에 입력하세요. 예: 05/18 노트북거치대 설치';
  color: #b8b8b0; pointer-events: none;
}

/* ─── 로그인 화면 ─── */
.login-wrap { 
  max-width: 360px; margin: 80px auto; padding: 32px;
  background: #fff; border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.06);
}
.login-wrap h1 { 
  font-size: 28px; color: #2d4a3e; margin-bottom: 24px; text-align: center; 
}
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-form input, .login-form button {
  padding: 12px 14px; font-size: 16px; 
  border: 1px solid #d0d0c8; border-radius: 6px;
}
.login-form button { 
  background: #2d4a3e; color: #fff; border: none; 
  cursor: pointer; font-weight: 600; 
}
.error { color: #c03030; font-size: 13px; text-align: center; }

/* ─── 히스토리 모달 ─── */
.modal[hidden] { display: none !important; }
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-content {
  background: #fff; border-radius: 8px; width: 90%; max-width: 480px;
  max-height: 80vh; display: flex; flex-direction: column;
}
.modal-header { 
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid #e8e8e0;
}
.modal-header h2 { font-size: 16px; }
.close { 
  background: none; border: none; font-size: 24px; 
  cursor: pointer; color: #888; 
}
.history-list { list-style: none; overflow-y: auto; padding: 8px 0; }
.history-list li {
  padding: 12px 20px; cursor: pointer; border-bottom: 1px solid #f0efe8;
}
.history-list li:hover { background: #faf9f4; }
.history-list .time { font-size: 12px; color: #888; margin-bottom: 4px; }
.history-list .preview { 
  font-size: 13px; color: #444; 
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; 
}

/* ─── 완료 영역 페이지 ─── */
.done-page { max-width: 820px; margin: 0 auto; padding: 16px; }
.done-page header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px; padding-bottom: 12px;
  border-bottom: 2px solid #2d4a3e;
}
.done-page h1 { font-size: 22px; color: #2d4a3e; }
.done-page .back-link { 
  color: #2d4a3e; text-decoration: none; font-size: 14px; 
  padding: 6px 12px; border: 1px solid #d0d0c8; border-radius: 6px;
  background: #fff;
}
.done-page .back-link:hover { background: #f0efe8; }

.done-group {
  background: #fff; border-radius: 8px; padding: 16px 20px;
  margin-bottom: 16px; border: 1px solid #e8e8e0;
}
.done-group .group-date {
  font-size: 13px; color: #2d4a3e; font-weight: 600;
  margin-bottom: 10px; padding-bottom: 8px;
  border-bottom: 1px solid #f0efe8;
}

/* 완료 항목 + 액션 버튼 가로 배치 */
.done-item-wrap {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px dashed #f0efe8;
}
.done-item-wrap:last-child { border-bottom: none; }
.done-item-content { flex: 1; min-width: 0; }
.done-item-actions {
  display: flex; gap: 6px; flex-shrink: 0;
  opacity: 0.6;
  transition: opacity 0.15s;
}
.done-item-wrap:hover .done-item-actions { opacity: 1; }

.done-group .item { 
  padding: 2px 0; line-height: 1.4;
  color: #888; text-decoration: line-through;
}
.done-group .item.depth-1 { padding-left: 64px; font-size: 0.85em; }
.done-group .item.depth-2 { padding-left: 84px; font-size: 0.85em; }
.done-group .empty-msg { color: #aaa; font-size: 14px; text-align: center; padding: 40px 0; }

/* 액션 버튼 */
.action-btn {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  border: 1px solid;
  background: #fff;
  white-space: nowrap;
}
.action-btn.restore {
  color: #2d4a3e;
  border-color: #c0d0c8;
}
.action-btn.restore:hover {
  background: #e8efe9;
}
.action-btn.delete {
  color: #a04040;
  border-color: #e0c0c0;
}
.action-btn.delete:hover {
  background: #f4d4d4;
}

/* ─── 안드로이드 최적화 ─── */
.editor { font-size: 16px; }

html, body { height: 100%; }
body { min-height: 100vh; min-height: 100dvh; }

.btn-primary, .btn-ghost, .logout {
  min-height: 40px; display: inline-flex; 
  align-items: center; justify-content: center;
}

.editor { -webkit-user-select: text; user-select: text; }
header, .hint, .header-actions { 
  -webkit-user-select: none; user-select: none; 
}

@supports (padding-top: env(safe-area-inset-top)) {
  body { 
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

@media (max-height: 500px) {
  header { padding-bottom: 6px; }
  .hint { display: none; }
}

@media (max-width: 600px) {
  .app { padding: 10px; }
  .editor { padding: 14px 16px; }
  header h1 { font-size: 18px; }
  .header-actions { font-size: 12px; }
  .btn-primary, .btn-ghost { padding: 6px 10px; }
  .editor .line.depth-1 { padding-left: 75px; }
  .editor .line.depth-2 { padding-left: 85px; }
  /* 모바일에서 액션 버튼 항상 보이게 */
  .done-item-actions { opacity: 1; }
  .action-btn { padding: 3px 8px; font-size: 11px; }
}