:root {
  --bg: #FAFAF7;
  --surface: #FFFFFF;
  --border: #E5E2DA;
  --text: #2C2C2C;
  --text-muted: #8A8680;
  --green: #6B8F71;
  --green-light: #EAF2EB;
  --yellow: #E8C76B;
  --yellow-light: #FDF6DC;
  --red: #D97B6C;
  --red-light: #FAECEA;
  --accent: #4A7C59;
  --shadow: 0 1px 4px rgba(0,0,0,0.06);
}

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

body {
  font-family: 'Noto Serif TC', serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── HEADER ── */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-family: 'Noto Serif TC', serif;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.05em;
}

.logo span {
  font-size: 11px;
  font-family: 'Noto Serif TC', serif;
  font-weight: 300;
  color: var(--text-muted);
  margin-left: 8px;
  letter-spacing: 0.1em;
}

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

.date-display {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 300;
}

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

.date-nav-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: 'Noto Serif TC', serif;
  transition: all 0.15s;
}

.date-nav-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.date-picker {
  position: absolute;
  top: 0;
  left: 24px;
  opacity: 0;
  pointer-events: none;
  font-family: 'Noto Serif TC', serif;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 6px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  cursor: pointer;
  transition: opacity 0.15s;
}

.date-picker.show {
  opacity: 1;
  pointer-events: auto;
}

.date-nav-btn.today-btn.hidden {
  display: none;
}

.nav-tabs {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.nav-tab {
  padding: 6px 16px;
  font-size: 13px;
  font-family: 'Noto Serif TC', serif;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-muted);
  transition: all 0.15s;
}

.nav-tab.active {
  background: var(--accent);
  color: #fff;
  font-weight: 500;
}

/* ── GOALS BAR ── */
.goals-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.goal-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.goal-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.goal-input {
  font-family: 'Noto Serif TC', serif;
  font-size: 13px;
  border: none;
  border-bottom: 1px dashed var(--border);
  background: transparent;
  color: var(--text);
  padding: 2px 4px;
  outline: none;
  min-width: 120px;
  transition: border-color 0.15s;
}

.goal-input:focus {
  border-bottom-color: var(--accent);
}

.goal-separator {
  width: 1px;
  height: 20px;
  background: var(--border);
}

/* ── MAIN LAYOUT ── */
.main {
  padding: 20px 24px;
  max-width: 1400px;
  margin: 0 auto;
}

.page { display: none; }
.page.active { display: block; }

/* ── TABLE ── */
.table-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

thead th {
  background: var(--bg);
  padding: 10px 12px;
  text-align: left;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

thead th:not(:last-child) {
  border-right: 1px solid var(--border);
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #FDFCFA; }

td {
  padding: 3px 12px;
  vertical-align: middle;
  border-right: 1px solid var(--border);
}

td:last-child { border-right: none; }

.td-time {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  width: 60px;
  white-space: nowrap;
  font-family: 'Noto Serif TC', serif;
}

.cell-input {
  font-family: 'Noto Serif TC', serif;
  font-size: 13px;
  border: none;
  background: transparent;
  color: var(--text);
  outline: none;
  width: 100%;
  padding: 2px 0;
  resize: none;
  min-height: 15px;
}

.cell-input:focus {
  background: var(--green-light);
  padding: 2px 4px;
  border-radius: 3px;
}

.cell-input::placeholder { color: #D0CCC4; }

.cell-box {
  font-family: 'Noto Serif TC', serif;
  font-size: 13px;
  border: none;
  background: transparent;
  color: var(--text);
  outline: none;
  width: 100%;
  padding: 5px 0;
  resize: none;
  min-height: 15px;
  border-radius: 4px;
}

.category-select {
  font-family: 'Noto Serif TC', serif;
  font-size: 12px;
  border: none;
  border-radius: 4px;
  padding: 3px 6px;
  background: transparent;
  color: var(--text);
  outline: none;
  cursor: pointer;
}

.cat-social  { background: #E8CDD2; border-color: #B5838D; color: #7A4A55; }
.cat-sleep   { background: #EEDDD8; border-color: #D4A5A0; color: #8A5A55; }
.cat-study   { background: #F2ECDA; border-color: #E5D5A0; color: #7A6B3D; }
.cat-growth  { background: #D5DDD2; border-color: #A5B5A0; color: #4A6048; }
.cat-work    { background: #D2DDE5; border-color: #A0B0C0; color: #4A6070; }
.cat-routine { background: #DDD5EA; border-color: #B0A5C0; color: #5A4A70; }

.engagement-grid {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.eng-cell {
  flex: 1;
  height: 18px;
  border: none;
  border-right: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  transition: background 0.1s;
}

.eng-cell:last-child { border-right: none; }
.eng-cell:hover { opacity: 0.8; }
.eng-cell.low  { background: var(--red); }
.eng-cell.mid  { background: var(--yellow); }
.eng-cell.high { background: var(--green); }

.td-feedback { min-width: 140px; }

/* ── DIARY SECTION ── */
.diary-section {
  margin-top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 24px;
  box-shadow: var(--shadow);
}

.section-title {
  font-family: 'Noto Serif TC', serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.diary-input {
  width: 100%;
  min-height: 100px;
  font-family: 'Noto Serif TC', serif;
  font-size: 14px;
  line-height: 1.8;
  border: none;
  outline: none;
  resize: vertical;
  color: var(--text);
  background: transparent;
}

.diary-input::placeholder { color: #C8C4BC; }

/* ── CHARTS PAGE ── */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

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

.chart-card.full { grid-column: 1 / -1; }

.chart-title {
  font-family: 'Noto Serif TC', serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

canvas { max-width: 100%; }

/* ── TASKS TABLE ── */
.tasks-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}

.tasks-table th {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.tasks-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}

.tasks-table tr:last-child td { border-bottom: none; }

.task-input {
  font-family: 'Noto Serif TC', serif;
  font-size: 13px;
  border: none;
  background: transparent;
  outline: none;
  width: 100%;
  color: var(--text);
}

.task-input::placeholder { color: #D0CCC4; }

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  min-width: 80px;
}

.progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 3px;
  transition: width 0.3s;
}

.progress-input {
  font-size: 12px;
  width: 36px;
  border: none;
  background: transparent;
  outline: none;
  color: var(--text-muted);
  text-align: right;
}

.btn-add {
  margin-top: 12px;
  padding: 6px 14px;
  font-family: 'Noto Serif TC', serif;
  font-size: 12px;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 400;
}

.btn-add:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── LEGEND ── */
.legend {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 4px;
}

.legend-green { background: var(--green); }
.legend-yellow { background: var(--yellow); }
.legend-red { background: var(--red); }

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .charts-grid { grid-template-columns: 1fr; gap: 12px; }
  .chart-card { padding: 14px; }
  .chart-title { font-size: 13px; margin-bottom: 10px; padding-bottom: 8px; }
  .goals-bar { flex-wrap: wrap; gap: 12px; }
  .header { padding: 10px 16px; }
  .main { padding: 12px; }
  .tasks-table { min-width: 500px; }
}

/* ── LOGIN SCREEN ── */
.login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.login-screen.show {
  opacity: 1;
  pointer-events: auto;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 48px 40px;
  text-align: center;
  box-shadow: var(--shadow);
  max-width: 380px;
  width: 90%;
}

.login-logo {
  font-family: 'Noto Serif TC', serif;
  font-size: 28px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.05em;
}

.login-sub {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  margin-top: 4px;
}

.login-desc {
  font-size: 14px;
  color: var(--text-muted);
  margin: 24px 0;
  line-height: 1.8;
}

.btn-google-login {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 24px;
  font-family: 'Noto Serif TC', serif;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-google-login:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.login-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 16px;
}

/* ── APP CONTENT ── */
.app-content {
  transition: opacity 0.3s;
}

.app-content.hide {
  opacity: 0;
  pointer-events: none;
}

/* ── USER MENU ── */
.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  display: none;
}

.user-name {
  font-size: 12px;
  color: var(--text-muted);
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-logout {
  padding: 4px 10px;
  font-family: 'Noto Serif TC', serif;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-logout:hover {
  border-color: var(--red);
  color: var(--red);
}
