:root {
  --forest: #2d4a3e;
  --forest-dark: #1f3429;
  --sage: #8a9a5b;
  --sand: #d4c5a0;
  --earth: #3e2c1f;
  --cream: #f5f1e8;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --border: #e5e0d4;
  --card-bg: #ffffff;
  --shadow: 0 2px 12px rgba(45,74,62,0.08);
  --radius: 14px;
}

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

html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--cream);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select { font: inherit; }
ul { list-style: none; }

.hidden { display: none !important; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--forest) 0%, var(--forest-dark) 100%);
}
.login-card {
  background: var(--cream);
  border-radius: var(--radius);
  padding: 40px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.logo { text-align: center; margin-bottom: 32px; }
.logo-mark {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--forest);
  color: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 22px;
  margin: 0 auto 16px;
  letter-spacing: 1px;
}
.logo h1 { font-size: 22px; color: var(--forest); font-weight: 600; }
.tagline { color: var(--muted); font-size: 14px; margin-top: 4px; }
#login-form { display: flex; flex-direction: column; gap: 12px; }
#login-form input {
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fff;
  outline: none;
  transition: border-color 0.15s;
}
#login-form input:focus { border-color: var(--forest); }
#login-form button {
  padding: 14px 16px;
  background: var(--forest);
  color: var(--cream);
  border-radius: 10px;
  font-weight: 600;
  transition: background 0.15s;
}
#login-form button:hover { background: var(--forest-dark); }
.error-msg { color: #c0392b; font-size: 13px; text-align: center; min-height: 18px; }

/* App layout */
.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 60px;
}
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px 16px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--forest);
  color: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}
.brand-text h1 { font-size: 18px; color: var(--forest); font-weight: 600; }
.sync-label { font-size: 12px; color: var(--muted); }
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--cream);
  border: 1.5px solid var(--border);
  font-size: 18px;
  color: var(--forest);
  transition: transform 0.3s;
}
.icon-btn:hover { background: #fff; }
.icon-btn.spinning { transform: rotate(360deg); }

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 4px;
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  transition: all 0.15s;
}
.tab:hover { color: var(--forest); }
.tab.active {
  background: var(--forest);
  color: var(--cream);
}

/* Panels */
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn 0.2s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 16px;
  padding: 0 4px;
}
.panel-header h2 { color: var(--forest); font-size: 24px; font-weight: 600; }
.muted { color: var(--muted); font-size: 13px; }

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card h3 { color: var(--forest); font-size: 16px; font-weight: 600; }
.card h3 + p, .card h3 + ul { margin-top: 12px; }
.card p { line-height: 1.6; color: #333; }
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 16px;
}

/* Stat grid */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.stat-grid.two { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 640px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}
.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--forest);
  margin-top: 6px;
}
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Pacing bar */
.pacing-bar {
  width: 100%;
  height: 12px;
  background: var(--cream);
  border-radius: 6px;
  overflow: hidden;
  margin: 8px 0;
}
.pacing-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--sage), var(--forest));
  width: 0%;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
.pacing-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 14px;
}
.pacing-meta span:first-child { font-weight: 600; color: var(--forest); }

/* Sparkline */
.sparkline-wrap { padding: 8px 0; }
#sparkline { width: 100%; height: 100px; }
.sparkline-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

/* Charts */
.chart-wrap { padding: 8px 0; }
.chart-wrap svg { width: 100%; height: 160px; }

/* Feed */
.feed-list { display: flex; flex-direction: column; gap: 12px; }
.feed-card {
  background: var(--card-bg);
  border-left: 4px solid var(--sage);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
}
.feed-card .feed-time {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.feed-card h4 {
  color: var(--forest);
  margin: 6px 0;
  font-size: 15px;
}
.feed-card p { font-size: 14px; line-height: 1.5; color: #333; }
.loading { text-align: center; padding: 40px; color: var(--muted); }

/* Lists */
.list li {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  line-height: 1.5;
}
.list li:last-child { border-bottom: none; }

/* Task list */
.task-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.task-form input {
  flex: 1;
  min-width: 180px;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  outline: none;
}
.task-form input:focus { border-color: var(--forest); }
.task-form select {
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fff;
}
.task-form button {
  padding: 12px 20px;
  background: var(--forest);
  color: var(--cream);
  border-radius: 10px;
  font-weight: 600;
}
.task-form button:hover { background: var(--forest-dark); }

.task-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.task-list li:last-child { border-bottom: none; }
.task-list input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--forest);
  cursor: pointer;
}
.task-list .task-text { flex: 1; }
.task-list li.done .task-text {
  text-decoration: line-through;
  color: var(--muted);
}
.priority-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  text-transform: uppercase;
}
.priority-badge.high { background: #fee; color: #c0392b; }
.priority-badge.medium { background: #fef5e6; color: #b8730d; }
.priority-badge.low { background: #e8f0e5; color: #5a7a3e; }

/* Links grid */
.links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.link-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  text-decoration: none;
  color: var(--forest);
  font-weight: 600;
  font-size: 13px;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
}
.link-card:hover { transform: translateY(-2px); }
.link-card .link-icon {
  font-size: 28px;
  margin-bottom: 8px;
}

/* Palette */
.palette {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.swatch {
  aspect-ratio: 1;
  border-radius: 10px;
  display: flex;
  align-items: flex-end;
  padding: 10px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid rgba(0,0,0,0.05);
}

/* Buttons */
.danger {
  padding: 12px 20px;
  background: #c0392b;
  color: #fff;
  border-radius: 10px;
  font-weight: 600;
}
.danger:hover { background: #a93225; }

/* Small inline buttons */
.btn-small {
  padding: 6px 14px;
  background: var(--forest);
  color: #fff;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
}
.btn-small:hover { background: var(--forest-dark); }
.btn-small:disabled { background: #9aa9a2; cursor: default; }

/* Stat grid variations */
.stat-grid.three { grid-template-columns: repeat(3, 1fr); }

/* History table */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 560px;
}
.history-table th {
  text-align: left;
  padding: 10px 8px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.history-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.history-table tr:last-child td { border-bottom: none; }

/* Rebook radar list */
.rebook-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.rebook-item:last-child { border-bottom: none; }
.rebook-item > div:first-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.status-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.status-badge.due { background: #fef3cd; color: #8a6a00; }
.status-badge.overdue { background: #fde3d4; color: #a84300; }
.status-badge.lapsed { background: #f8d7da; color: #842029; }
