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

:root {
  --bg:          #0f1117;
  --surface:     #1a1f2e;
  --surface-2:   #222840;
  --border:      #2a3050;
  --text:        #e8eaf0;
  --text-muted:  #6b7280;
  --green:       #22c55e;
  --green-dim:   #16a34a;
  --red:         #ef4444;
  --amber:       #f59e0b;
  --blue:        #3b82f6;
  --accent:      #6366f1;
  --font:        'Inter', system-ui, -apple-system, sans-serif;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 4px 24px rgba(0,0,0,0.4);
  --transition:  0.18s ease;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ── Utilities ──────────────────────────────────────────────────────────────── */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.text-green  { color: var(--green); }
.text-red    { color: var(--red); }
.text-amber  { color: var(--amber); }
.text-muted  { color: var(--text-muted); }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.mono        { font-variant-numeric: tabular-nums; }

/* ── Login Page ─────────────────────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
  animation: fadeUp 0.3s ease;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}

.login-logo svg { color: var(--green); }

.login-logo span {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.login-card h1 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 6px;
}

.login-card p {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 28px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-control {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 11px 14px;
  font-size: 15px;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}

.form-control.error {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(239,68,68,0.12);
}

.error-msg {
  font-size: 13px;
  color: var(--red);
  margin-top: 8px;
  min-height: 18px;
  opacity: 0;
  transition: opacity var(--transition);
}

.error-msg.visible { opacity: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  border: none;
  transition: background var(--transition), transform var(--transition), opacity var(--transition);
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
  padding: 13px;
  font-size: 15px;
  margin-top: 8px;
}

.btn-primary:hover:not(:disabled) { background: #5254cc; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-green {
  background: var(--green);
  color: #000;
}

.btn-green:hover:not(:disabled) { background: var(--green-dim); }

.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red);
}

.btn-danger:hover { background: rgba(239,68,68,0.1); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-8px); }
  40%       { transform: translateX(8px); }
  60%       { transform: translateX(-5px); }
  80%       { transform: translateX(5px); }
}

.shake { animation: shake 0.4s ease; }

/* ── App Shell ──────────────────────────────────────────────────────────────── */
.app { display: flex; flex-direction: column; min-height: 100vh; }

/* ── Top Nav ────────────────────────────────────────────────────────────────── */
.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.4px;
}

.nav-brand svg { color: var(--green); }

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

.nav-logout {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}

.nav-logout:hover { color: var(--text); background: var(--surface-2); }

/* ── Cumulative Summary Bar ─────────────────────────────────────────────────── */
.summary-bar {
  display: flex;
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
}

.summary-stat {
  flex: 1;
  background: var(--surface);
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.summary-stat .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  font-weight: 500;
}

.summary-stat .value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}

.summary-stat .sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Main Content ───────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ── Section Header ─────────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-header h2 {
  font-size: 16px;
  font-weight: 600;
}

/* ── Target Cards Row ───────────────────────────────────────────────────────── */
.cards-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 4px;
}

.cards-row::-webkit-scrollbar { height: 4px; }
.cards-row::-webkit-scrollbar-track { background: transparent; }
.cards-row::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.target-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  min-width: 260px;
  max-width: 300px;
  flex-shrink: 0;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
  position: relative;
}

.target-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow);
  transform: translateY(-2px);
}

.target-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

.target-card.completed {
  border-color: var(--green-dim);
  opacity: 0.8;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 8px;
}

.card-name {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
}

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge-daily   { background: rgba(99,102,241,0.15); color: var(--accent); }
.badge-weekly  { background: rgba(59,130,246,0.15); color: var(--blue); }
.badge-monthly { background: rgba(245,158,11,0.15); color: var(--amber); }
.badge-yearly  { background: rgba(34,197,94,0.15);  color: var(--green); }

.card-balance {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.8px;
  font-variant-numeric: tabular-nums;
  margin-bottom: 4px;
}

.card-balance-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 14px;
}

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

.progress-fill.behind { background: var(--amber); }
.progress-fill.far-behind { background: var(--red); }

.card-stats {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card-stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

.card-stat-row .label { color: var(--text-muted); }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  margin-top: 12px;
}

.status-pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-on-track  { color: var(--green);  background: rgba(34,197,94,0.1); }
.status-ahead     { color: var(--green);  background: rgba(34,197,94,0.15); }
.status-behind    { color: var(--amber);  background: rgba(245,158,11,0.1); }
.status-far-behind{ color: var(--red);    background: rgba(239,68,68,0.1); }
.status-completed { color: var(--blue);   background: rgba(59,130,246,0.1); }

.add-card {
  min-width: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 2px dashed var(--border);
  color: var(--text-muted);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
  background: none;
  flex-shrink: 0;
}

.add-card:hover { border-color: var(--accent); color: var(--accent); }
.add-card svg   { width: 28px; height: 28px; }
.add-card span  { font-size: 13px; font-weight: 600; }

/* ── Detail Panel ───────────────────────────────────────────────────────────── */
.detail-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  animation: fadeUp 0.2s ease;
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}

.detail-header h3 { font-size: 16px; font-weight: 600; }

.detail-actions { display: flex; gap: 10px; align-items: center; }

/* ── Schedule Table ─────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
}

.schedule-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.schedule-table th {
  padding: 11px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.schedule-table th.text-right,
.schedule-table td.text-right { text-align: right; }

.schedule-table td {
  padding: 10px 16px;
  border-bottom: 1px solid rgba(42,48,80,0.5);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

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

.schedule-table tr.row-logged { background: rgba(34,197,94,0.04); }
.schedule-table tr.row-today  { background: rgba(99,102,241,0.07); }
.schedule-table tr.row-future { opacity: 0.55; }
.schedule-table tr.row-recalced { background: rgba(245,158,11,0.05); }

.schedule-table tr.row-today td:first-child {
  border-left: 3px solid var(--accent);
}

/* Inline earn input */
.earn-cell { display: flex; align-items: center; gap: 8px; }

.earn-input {
  width: 110px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 5px 10px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  outline: none;
  transition: border-color var(--transition);
}

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

.save-btn {
  background: var(--green);
  color: #000;
  border: none;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  transition: background var(--transition), opacity var(--transition);
  opacity: 0;
  pointer-events: none;
}

.earn-input:focus ~ .save-btn,
.save-btn:focus,
.save-btn.visible {
  opacity: 1;
  pointer-events: auto;
}

.save-btn:hover { background: var(--green-dim); }

.logged-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.row-status-icon { font-size: 14px; }

/* ── Empty State ────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}

.empty-state svg { margin-bottom: 16px; opacity: 0.4; }
.empty-state h3  { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.empty-state p   { font-size: 14px; margin-bottom: 20px; }

/* ── Modal ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.open { opacity: 1; pointer-events: auto; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  transform: translateY(16px);
  transition: transform 0.2s ease;
}

.modal-overlay.open .modal { transform: translateY(0); }

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

.modal-header h2 { font-size: 17px; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
}

.modal-close:hover { background: var(--surface-2); color: var(--text); }

.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* Modal steps */
.step-indicator {
  display: flex;
  gap: 6px;
  margin-bottom: 24px;
}

.step-dot {
  height: 3px;
  flex: 1;
  border-radius: 2px;
  background: var(--border);
  transition: background 0.3s ease;
}

.step-dot.done   { background: var(--green); }
.step-dot.active { background: var(--accent); }

.step-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.form-row { display: flex; gap: 14px; }
.form-row .form-group { flex: 1; }

.segmented {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.segmented input[type="radio"] { display: none; }

.segmented label {
  flex: 1;
  padding: 8px 4px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  text-transform: none;
  letter-spacing: 0;
}

.segmented input[type="radio"]:checked + label {
  background: var(--accent);
  color: #fff;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.toggle-row label { font-size: 14px; font-weight: 500; }

.toggle {
  position: relative;
  width: 40px;
  height: 22px;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 11px;
  cursor: pointer;
  transition: background var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
}

.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* Preview table in modal */
.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 12px;
}

.preview-table th {
  padding: 8px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.preview-table td {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(42,48,80,0.4);
  font-variant-numeric: tabular-nums;
}

.preview-summary {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.preview-summary .row {
  display: flex;
  justify-content: space-between;
}

.preview-summary .row .label { color: var(--text-muted); }

/* ── Loading Spinner ─────────────────────────────────────────────────────────── */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Animations ──────────────────────────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Toast ──────────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  box-shadow: var(--shadow);
  animation: fadeUp 0.2s ease;
}

.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--accent); }

/* ── Log Nav (Load Previous / Load More) ────────────────────────────────────── */
.log-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.log-nav-bottom {
  border-bottom: none;
  border-top: 1px solid var(--border);
}

.log-nav-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 6px 12px;
}

.log-nav-info {
  font-size: 12px;
  color: var(--text-muted);
}

.log-nav-info-solo {
  font-size: 12px;
  color: var(--text-muted);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

/* ── Edit button on logged rows ──────────────────────────────────────────────── */
.edit-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 3px 5px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity var(--transition), color var(--transition), background var(--transition);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

.earn-cell:hover .edit-btn { opacity: 1; }
.edit-btn:hover { color: var(--accent); background: rgba(99,102,241,0.1); }

.cancel-edit-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: color var(--transition);
}
.cancel-edit-btn:hover { color: var(--red); }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .summary-bar { flex-direction: column; gap: 0; }
  .main-content { padding: 16px; }
  .topnav { padding: 0 16px; }
  .login-card { padding: 32px 24px; }

  .form-row { flex-direction: column; gap: 0; }

  .schedule-table th,
  .schedule-table td { padding: 8px 12px; }
}
