:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #222536;
  --border: #2d3148;
  --text: #e2e8f0;
  --muted: #64748b;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --journal: #10b981;
  --link: #3b82f6;
  --danger: #ef4444;
  --radius: 8px;
  --sidebar-w: 220px;
}

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

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  height: 100vh;
  overflow: hidden;
}

/* ── LOGIN ── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.5rem 2rem;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.login-box h1 { font-size: 1.5rem; font-weight: 700; }
.login-subtitle { color: var(--muted); font-size: 0.875rem; }
.login-box form { display: flex; flex-direction: column; gap: 0.75rem; }
.login-box input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.625rem 0.75rem;
  font-size: 0.9rem;
  outline: none;
  transition: border-color .15s;
}
.login-box input:focus { border-color: var(--accent); }
.login-box button[type=submit] {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0.65rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.login-box button[type=submit]:hover { background: var(--accent-hover); }
.error-msg { color: var(--danger); font-size: 0.8rem; }

/* ── LAYOUT ── */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
}

/* ── SIDEBAR ── */
#sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.logo { font-weight: 700; font-size: 1rem; }
.btn-new {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  width: 28px; height: 28px;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.btn-new:hover { background: var(--accent-hover); }

#main-nav {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0.5rem 0;
}
.nav-item {
  display: block;
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
  font-size: 0.875rem;
  transition: background .1s, color .1s;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--surface2); color: var(--text); font-weight: 600; }

.sidebar-section {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.5rem 0.5rem;
}
.section-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 0 0.5rem 0.4rem;
}
#tag-list { display: flex; flex-direction: column; gap: 1px; }
.tag-nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.8rem;
  transition: background .1s, color .1s;
}
.tag-nav-item:hover { background: var(--surface2); color: var(--text); }
.tag-nav-item.active { background: var(--surface2); color: var(--text); font-weight: 600; }
.tag-nav-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-count {
  background: var(--surface2);
  border-radius: 10px;
  padding: 0 0.4rem;
  font-size: 0.7rem;
  color: var(--muted);
}
.tag-del {
  display: none;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.72rem;
  line-height: 1;
  padding: 0 0 0 0.4rem;
}
.tag-del:hover { color: var(--danger); }
.tag-nav-item:hover .tag-del { display: inline-flex; }
.tag-nav-item:hover .tag-count { display: none; }

.sidebar-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--muted);
}
#sidebar-user {
  font-weight: 600;
  color: var(--text);
}
.sidebar-footer-actions {
  display: flex;
  gap: 0.9rem;
}
.btn-link {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0;
}
.btn-link:hover { color: var(--text); }

/* ── CONTENT ── */
#content {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#topbar {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.search-wrap { position: relative; }
#search-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  outline: none;
  transition: border-color .15s;
}
#search-input:focus { border-color: var(--accent); }

#entry-list {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
#empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: var(--muted);
}

/* ── CARDS ── */
.entry-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  cursor: pointer;
  transition: border-color .15s, background .1s;
}
.entry-card:hover { border-color: var(--accent); background: var(--surface2); }
.card-head {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  margin-bottom: 0.25rem;
}
.type-badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  flex-shrink: 0;
  margin-top: 2px;
}
.type-badge--journal { background: rgba(16,185,129,.15); color: var(--journal); }
.type-badge--link    { background: rgba(59,130,246,.15); color: var(--link); }

.card-title {
  font-weight: 600;
  font-size: 0.9rem;
  flex: 1;
  line-height: 1.3;
}
.card-url {
  font-size: 0.75rem;
  color: var(--link);
  word-break: break-all;
  margin-bottom: 0.2rem;
}
.card-excerpt {
  font-size: 0.8rem;
  color: var(--muted);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 0.4rem;
}
.card-foot {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.card-date { font-size: 0.7rem; color: var(--muted); margin-right: auto; }
.tag-chip {
  background: var(--surface2);
  border-radius: 4px;
  padding: 0.1rem 0.45rem;
  font-size: 0.7rem;
  color: var(--muted);
}

/* ── MODALS ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-box--wide { max-width: 700px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-head h2 { font-size: 1rem; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.25rem;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

/* ── FORM ── */
#entry-form {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1.25rem;
  overflow-y: auto;
}
.form-row { display: flex; flex-direction: column; gap: 0.35rem; }
.form-row label { font-size: 0.75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.form-row .hint { font-weight: 400; text-transform: none; letter-spacing: 0; }
.form-row input,
.form-row textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.55rem 0.75rem;
  font-size: 0.875rem;
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
  resize: vertical;
}
.form-row input:focus,
.form-row textarea:focus { border-color: var(--accent); }

.type-row { flex-direction: row; gap: 1rem; }
.type-opt { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; font-size: 0.875rem; }
.type-opt input { width: auto; }

.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.25rem;
}
.form-actions-right { display: flex; gap: 0.5rem; }

/* ── BUTTONS ── */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0.55rem 1.1rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.55rem 1rem;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background .15s;
}
.btn-secondary:hover { background: var(--border); }
.btn-danger {
  background: none;
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 0.55rem 1rem;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background .15s;
}
.btn-danger:hover { background: rgba(239,68,68,.1); }

/* ── TAG SUGGESTIONS ── */
.tag-suggestions {
  position: absolute;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 160px;
  overflow-y: auto;
  z-index: 200;
  width: 100%;
}
.tag-sug-item {
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  font-size: 0.8rem;
}
.tag-sug-item:hover { background: var(--border); }
.form-row { position: relative; }

/* ── DETAIL ── */
.detail-type-badge { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
#detail-content {
  padding: 1.25rem;
  overflow-y: auto;
  flex: 1;
}
.detail-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  line-height: 1.3;
}
.detail-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}
.detail-url {
  margin-bottom: 0.75rem;
}
.detail-url a {
  color: var(--link);
  font-size: 0.875rem;
  word-break: break-all;
  text-decoration: none;
}
.detail-url a:hover { text-decoration: underline; }
.detail-body {
  color: var(--text);
  font-size: 0.9rem;
  white-space: pre-wrap;
  line-height: 1.7;
}
.detail-tags {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.detail-actions {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  flex-shrink: 0;
}

/* ── CALENDAR ── */
#calendar-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

#cal-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#cal-month-label {
  font-size: 0.95rem;
  font-weight: 700;
  flex: 1;
  text-align: center;
}
.cal-nav-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 30px; height: 30px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
}
.cal-nav-btn:hover { background: var(--border); }
.cal-today-btn { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.cal-new-btn   { padding: 0.3rem 0.7rem; font-size: 0.8rem; }

#cal-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

#cal-grid-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0 0.75rem 0.75rem;
  min-width: 0;
}

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  padding: 0.4rem 0 0.3rem;
  flex-shrink: 0;
}
.cal-weekday {
  text-align: center;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

#cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 4px;
  flex: 1;
  min-height: 0;
}

.cal-day {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.4rem;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: border-color .1s, background .1s;
}
.cal-day:hover { border-color: var(--accent); background: var(--surface2); }
.cal-day.today  { border-color: var(--accent); }
.cal-day.selected { background: rgba(99,102,241,.12); border-color: var(--accent); }
.cal-day.other-month { opacity: 0.35; }

.cal-day-num {
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1;
  margin-bottom: 1px;
  display: flex;
}
.today .cal-day-num {
  background: var(--accent);
  color: #fff;
  width: 18px; height: 18px;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
}

.cal-task-pill {
  font-size: 0.62rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: var(--surface2);
  border-radius: 3px;
  padding: 1px 4px;
  line-height: 1.5;
  color: var(--text);
}
.cal-task-pill.done { text-decoration: line-through; color: var(--muted); opacity: .6; }
.cal-task-more { font-size: 0.6rem; color: var(--muted); padding: 1px 4px; }

/* ── DAY PANEL ── */
#cal-day-panel {
  width: 260px;
  min-width: 260px;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .2s, min-width .2s;
}
#cal-day-panel.hidden-panel {
  width: 0;
  min-width: 0;
  border-left: none;
}

#cal-day-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 0.5rem;
}
#cal-day-title {
  font-weight: 700;
  font-size: 0.82rem;
  line-height: 1.3;
  flex: 1;
  text-transform: capitalize;
}

#cal-day-tasks {
  flex: 1;
  overflow-y: auto;
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.cal-task-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  background: var(--surface2);
  border-radius: 6px;
  border: 1px solid transparent;
  transition: border-color .1s;
}
.cal-task-item:hover { border-color: var(--border); }

.cal-check {
  width: 15px; height: 15px;
  border: 2px solid var(--border);
  border-radius: 3px;
  flex-shrink: 0;
  margin-top: 2px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .1s, border-color .1s;
}
.cal-check.checked { background: var(--accent); border-color: var(--accent); }
.cal-check.checked::after { content: '✓'; color: #fff; font-size: 0.6rem; }

.cal-task-info { flex: 1; min-width: 0; cursor: pointer; }
.cal-task-name { font-size: 0.8rem; font-weight: 500; line-height: 1.3; }
.cal-task-name.done { text-decoration: line-through; color: var(--muted); }
.cal-task-time { font-size: 0.68rem; color: var(--muted); }
.cal-task-rec  { font-size: 0.62rem; color: var(--accent); }

.cal-day-add-btn {
  display: block;
  width: 100%;
  background: none;
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: var(--muted);
  padding: 0.45rem;
  font-size: 0.78rem;
  cursor: pointer;
  text-align: center;
  transition: border-color .1s, color .1s;
}
.cal-day-add-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── TASK FORM ── */
.form-row-inline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.weekday-picker {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}
.wd-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}
.wd-opt input { display: none; }
.wd-opt span {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.3rem 0.45rem;
  font-size: 0.72rem;
  font-weight: 600;
  transition: background .1s, border-color .1s, color .1s;
  user-select: none;
}
.wd-opt input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── GOALS + MOTIVATION SHARED ── */
#goals-view, #motivation-view {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.25rem 2.5rem;
}
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.page-header h2 { font-size: 1.25rem; }
.page-header h3 { font-size: 1rem; color: var(--muted); font-weight: 600; }
.page-empty {
  text-align: center;
  color: var(--muted);
  padding: 3rem 1rem;
}
.page-empty p { margin-bottom: 1rem; }

/* ── GOALS ── */
#goals-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.9rem;
}
.goal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--muted);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.goal-card:hover { background: var(--surface2); }
.goal-card.status-active { border-left-color: var(--accent); }
.goal-card.status-done   { border-left-color: var(--journal); opacity: 0.75; }
.goal-card.status-paused { border-left-color: #f59e0b; }
.goal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}
.goal-title { font-weight: 600; font-size: 0.95rem; }
.goal-status-badge {
  flex-shrink: 0;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}
.goal-status-badge.active { background: rgba(99,102,241,.15); color: var(--accent-hover); }
.goal-status-badge.done   { background: rgba(16,185,129,.15); color: var(--journal); }
.goal-status-badge.paused { background: rgba(245,158,11,.15); color: #f59e0b; }
.goal-desc {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.7rem;
  white-space: pre-wrap;
}
.goal-progress-wrap {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}
.goal-progress-bar {
  flex: 1;
  height: 7px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
}
.goal-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .2s;
}
.goal-progress-pct { font-size: 0.72rem; color: var(--muted); min-width: 2.4rem; text-align: right; }
.goal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--muted);
}
.goal-edit-hint { color: var(--accent); opacity: 0; transition: opacity .15s; }
.goal-card:hover .goal-edit-hint { opacity: 1; }

/* range input */
.form-row input[type=range] { width: 100%; accent-color: var(--accent); }

/* ── MOTIVATION ── */
#quote-hero {
  background: linear-gradient(135deg, rgba(99,102,241,.18), rgba(59,130,246,.10));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  text-align: center;
  margin-bottom: 1.75rem;
}
#quote-hero-text {
  font-size: 1.4rem;
  line-height: 1.5;
  font-weight: 500;
  font-style: italic;
  max-width: 640px;
  margin: 0 auto 0.9rem;
}
#quote-hero-author {
  font-size: 0.9rem;
  color: var(--accent-hover);
  font-weight: 600;
  margin-bottom: 1.25rem;
}
#quotes-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.9rem;
}
.quote-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.quote-card:hover { border-color: var(--accent); background: var(--surface2); }
.quote-text { font-size: 0.9rem; line-height: 1.5; font-style: italic; }
.quote-author {
  margin-top: 0.6rem;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
  text-align: right;
}

/* ── SETTINGS ── */
.settings-section-title {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 0.75rem;
}
.settings-msg {
  font-size: 0.8rem;
  margin: 0.25rem 0 0.5rem;
}
.settings-msg.ok  { color: var(--journal); }
.settings-msg.err { color: var(--danger); }

/* ── UTILS ── */
.hidden { display: none !important; }
