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

:root {
  --brand: #1a73e8;
  --brand-dark: #1557b0;
  --surface: #ffffff;
  --surface-2: #f8f9fa;
  --border: #e0e0e0;
  --text: #202124;
  --text-2: #5f6368;
  --red: #d93025;
  --green: #188038;
  --orange: #e37400;
  --blue: #1a73e8;
  --gray: #9aa0a6;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.15);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans TC', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ============================================================
   Utilities
   ============================================================ */
.error-msg {
  color: var(--red);
  font-size: 12px;
  margin-top: 6px;
}

.empty-hint {
  color: var(--text-2);
  text-align: center;
  padding: 24px 0;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn-primary {
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: var(--brand-dark); }

.btn-outline {
  background: transparent;
  color: var(--brand);
  border: 1px solid var(--brand);
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s;
}
.btn-outline:hover { background: #e8f0fe; }

.btn-sm { padding: 5px 12px; font-size: 13px; }

.btn-icon {
  background: none;
  border: none;
  color: var(--gray);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  transition: color .15s, background .15s;
}
.btn-icon:hover { color: var(--red); background: #fce8e6; }

.btn-google {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 15px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: box-shadow .15s;
  width: 100%;
  justify-content: center;
}
.btn-google:hover { box-shadow: var(--shadow-md); }

/* ============================================================
   Form inputs
   ============================================================ */
.text-input {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s;
}
.text-input:focus { border-color: var(--brand); }

select.text-input { cursor: pointer; }
.select-sm { padding: 7px 8px; }

.inline-edit-input {
  border: 1px solid var(--brand);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 14px;
  outline: none;
  min-width: 120px;
}

.task-edit-wrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}
.task-edit-wrap .inline-edit-input { flex: 1; }

.btn-task-save {
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-task-save:hover { background: var(--brand-dark); }

.btn-task-cancel {
  background: none;
  border: none;
  color: var(--gray);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
  flex-shrink: 0;
}
.btn-task-cancel:hover { color: var(--red); }

/* ============================================================
   Fullscreen center (login / setup)
   ============================================================ */
.fullscreen-center {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e8f0fe 0%, #f8f9fa 100%);
  z-index: 100;
}

/* Login */
.login-card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  padding: 48px 40px;
  width: 360px;
  text-align: center;
}
.brand { font-size: 28px; font-weight: 700; color: var(--brand); letter-spacing: .5px; }
.brand-sub { color: var(--text-2); margin: 4px 0 28px; font-size: 15px; }

/* Setup */
.setup-card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  padding: 48px 40px;
  width: 400px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.setup-card h2 { font-size: 20px; color: var(--text); }
.setup-card p { color: var(--text-2); }
.setup-input-wrap { text-align: left; }
.setup-input-wrap .text-input { width: 100%; }

/* ============================================================
   Header
   ============================================================ */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}
.header-brand { font-size: 16px; font-weight: 600; color: var(--brand); }
.header-user { display: flex; align-items: center; gap: 12px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.nickname-btn {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px dashed var(--border);
  padding-bottom: 1px;
}
.nickname-btn:hover { color: var(--brand); border-color: var(--brand); }

/* ============================================================
   Tabs
   ============================================================ */
.tab-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  gap: 0;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 14px 20px;
  font-size: 14px;
  color: var(--text-2);
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--brand); }
.tab-btn.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

.tab-content { padding: 24px; max-width: 960px; margin: 0 auto; }

/* ============================================================
   Goal memo
   ============================================================ */
.goal-memo-wrap {
  margin-bottom: 20px;
}

.goal-memo-display {
  background: linear-gradient(135deg, #e8f0fe 0%, #f0f4ff 100%);
  border-radius: var(--radius);
  border-left: 4px solid var(--brand);
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  min-height: 52px;
}
.goal-memo-display:hover .btn-edit-memo { opacity: 1; }

.goal-memo-text {
  flex: 1;
  font-size: 17px;
  color: var(--text);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.goal-memo-placeholder {
  flex: 1;
  font-size: 14px;
  color: var(--text-2);
  font-style: italic;
}

.btn-edit-memo {
  background: none;
  border: none;
  color: var(--brand);
  font-size: 16px;
  cursor: pointer;
  opacity: 0;
  padding: 0 4px;
  flex-shrink: 0;
  transition: opacity .15s;
}

.goal-memo-editor {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--brand);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 2px 8px rgba(26,115,232,.1);
}

.goal-memo-input {
  width: 100%;
  border: none;
  outline: none;
  font-size: 15px;
  color: var(--text);
  line-height: 1.6;
  resize: none;
  font-family: inherit;
  background: transparent;
}

.goal-memo-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}

.goal-memo-count {
  font-size: 12px;
  color: var(--text-2);
  margin-right: auto;
}

/* ============================================================
   Summary grid
   ============================================================ */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.summary-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  text-align: center;
}
.summary-label { font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.summary-value { font-size: 28px; font-weight: 700; color: var(--brand); }

/* ============================================================
   Goal Cards
   ============================================================ */
.goal-list { display: flex; flex-direction: column; gap: 12px; }

.goal-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  overflow: hidden;
}

.goal-card-bar { width: 5px; flex-shrink: 0; }
.goal-bar-blue  { background: var(--blue); }
.goal-bar-orange{ background: var(--orange); }
.goal-bar-green { background: var(--green); }

.goal-card-body { flex: 1; padding: 12px 16px; }

.goal-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.goal-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  flex: 1;
  min-width: 0;
}
.goal-name:hover { color: var(--brand); }

.goal-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.goal-deadline {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
}
.goal-deadline:focus { outline: none; border-color: var(--brand); }

.goal-status-select {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 12px;
  cursor: pointer;
  background: var(--surface);
}

.goal-pct { font-size: 13px; font-weight: 600; color: var(--text-2); min-width: 36px; text-align: right; }

.btn-move-done {
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity .15s;
}
.btn-move-done:hover { opacity: .85; }

.btn-move-active {
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .15s, color .15s;
}
.btn-move-active:hover { border-color: var(--brand); color: var(--brand); }

.btn-expand {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-2);
  padding: 2px 4px;
}
.btn-expand:hover { color: var(--brand); }

/* ============================================================
   Status badges
   ============================================================ */
.status-badge, .priority-badge {
  display: inline-block;
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-blue   { background: #e8f0fe; color: #1a73e8; }
.badge-orange { background: #fef3e2; color: #e37400; }
.badge-green  { background: #e6f4ea; color: #188038; }
.badge-red    { background: #fce8e6; color: #d93025; }
.badge-gray   { background: #f1f3f4; color: #5f6368; }

/* ============================================================
   Task rows
   ============================================================ */
.task-list {
  margin-top: 10px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.task-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.task-checkbox { cursor: pointer; width: 16px; height: 16px; flex-shrink: 0; }

.btn-task-done {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, background .15s, color .15s;
}
.btn-task-done:hover { border-color: var(--green); color: var(--green); }
.btn-task-done.is-done {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.task-text {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  word-break: break-word;
}
.task-text:hover { color: var(--brand); }
.task-done .task-text, .task-text.task-done {
  text-decoration: line-through;
  color: var(--gray);
}

.task-owner-wrap { flex-shrink: 0; }

.task-owner-select, .member-select {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 12px;
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  max-width: 100px;
}
.task-owner-select:focus, .member-select:focus { outline: none; border-color: var(--brand); }

.add-task-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0 2px;
  border-top: 1px dashed var(--border);
  margin-top: 4px;
}
.add-task-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 13px;
  outline: none;
}
.add-task-input:focus { border-color: var(--brand); }

/* ============================================================
   Add Goal section
   ============================================================ */
.add-goal-section { margin-top: 20px; }

.add-goal-form {
  margin-top: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.add-goal-form .text-input { flex: 1; min-width: 160px; }

/* ============================================================
   Todos
   ============================================================ */
.todo-add-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.todo-add-row .text-input { flex: 1; min-width: 200px; }
.owner-wrap { flex-shrink: 0; }

.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-2);
  transition: background .15s, color .15s, border-color .15s;
}
.filter-btn:hover { border-color: var(--brand); color: var(--brand); }
.filter-btn.active { background: var(--brand); color: #fff; border-color: var(--brand); }

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

.todo-row {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
}
.todo-checkbox { cursor: pointer; width: 16px; height: 16px; flex-shrink: 0; }
.todo-text { flex: 1; font-size: 14px; word-break: break-word; }
.todo-done .todo-text { text-decoration: line-through; color: var(--gray); }
.todo-checked .todo-text, .todo-text.todo-checked { text-decoration: line-through; color: var(--gray); }

/* 狀態下拉 */
.status-dropdown-wrap { position: relative; flex-shrink: 0; }

.status-badge-btn { cursor: pointer; user-select: none; }
.status-badge-btn:hover { opacity: .85; }

.status-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  min-width: 100px;
  z-index: 50;
  overflow: hidden;
}

.status-option {
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  transition: background .1s;
}
.status-option:hover { background: var(--surface-2); }
.status-option.active { font-weight: 600; color: var(--brand); }

.btn-edit-todo {
  opacity: 0.4;
  transition: opacity .15s, color .15s;
  font-size: 15px;
  color: var(--text-2);
}
.btn-edit-todo:hover { opacity: 1; color: var(--brand); }

.todo-edit-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.todo-owner { font-size: 12px; color: var(--text-2); flex-shrink: 0; }

.todo-deadline {
  font-size: 12px;
  flex-shrink: 0;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 500;
}
.deadline-normal { color: var(--text-2); background: var(--surface-2); }
.deadline-soon   { color: var(--orange); background: #fef3e2; }
.deadline-overdue{ color: var(--red);    background: #fce8e6; }

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal-card {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 28px 32px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-card h3 { font-size: 16px; font-weight: 600; }
.modal-card .text-input { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* 子任務筆記按鈕 */
.btn-task-note {
  font-size: 14px;
  opacity: 0.3;
  transition: opacity .15s;
  padding: 2px 4px;
}
.task-row:hover .btn-task-note { opacity: 0.6; }
.btn-task-note.has-note { opacity: 1; }
.btn-task-note:hover { opacity: 1 !important; }

/* 子任務詳細描述 Modal */
.modal-task-detail-card {
  width: 480px;
  max-width: 95vw;
  gap: 14px;
}

.modal-task-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.modal-task-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  flex: 1;
}

.modal-task-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.modal-task-desc {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  resize: vertical;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
.modal-task-desc:focus { border-color: var(--brand); }

.modal-task-footer {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 640px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .tab-content { padding: 16px; }
  .goal-card-meta { gap: 6px; }
  .goal-status-select { display: none; }
}
