:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c2330;
  --muted: #6b7280;
  --border: #e3e6ea;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --radius: 12px;
}

/* Dark variables only apply when the html[data-theme] says so. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115;
  --card: #171a21;
  --text: #e5e8ee;
  --muted: #9aa3b2;
  --border: #2a2f3a;
  --accent: #4f83f1;
  --accent-hover: #6b98f5;
  --accent-soft: #1c2740;
  --danger: #f87171;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* When no explicit choice has been made, follow the OS preference. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #0f1115;
    --card: #171a21;
    --text: #e5e8ee;
    --muted: #9aa3b2;
    --border: #2a2f3a;
    --accent: #4f83f1;
    --accent-hover: #6b98f5;
    --accent-soft: #1c2740;
    --danger: #f87171;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }

  /* Keep small components (like the banner) dark-aware even when a data-theme is set. */
  :root[data-theme="light"] .banner,
  :root[data-theme="dark"] .banner {
    background: #2a1516;
    color: #fca5a5;
    border-color: #4a2325;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.banner {
  max-width: 720px;
  margin: 12px auto 0;
  padding: 10px 14px;
  border-radius: 10px;
  background: #fdecec;
  color: #b42318;
  border: 1px solid #f5c2c2;
  font-size: 0.9rem;
}

@media (prefers-color-scheme: dark) {
  .banner {
    background: #2a1516;
    color: #fca5a5;
    border-color: #4a2325;
  }
}

/* Keep the banner legible when dark mode is forced via the toggle, even if the OS is light. */
:root[data-theme="dark"] .banner {
  background: #2a1516;
  color: #fca5a5;
  border-color: #4a2325;
}

.site-header {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 16px 8px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.theme-toggle:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.theme-toggle svg {
  width: 15px;
  height: 15px;
  flex: none;
}

.header-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-main h1 {
  margin: 0;
  font-size: 1.6rem;
}

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

.tagline {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  gap: 16px;
}

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

.card h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.card-head h2 {
  margin: 0;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.total {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.badge {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 0.75rem;
  margin-left: 6px;
  vertical-align: middle;
}

/* ---------- View tabs (List / Calendar) ---------- */

.view-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 14px;
  width: fit-content;
}

.view-tab {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 7px;
  padding: 6px 14px;
  cursor: pointer;
}

.view-tab:hover {
  color: var(--text);
}

.view-tab.active {
  background: var(--card);
  color: var(--accent);
  box-shadow: var(--shadow);
}

/* ---------- Calendar view ---------- */

.calendar-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.calendar-nav h3 {
  margin: 0;
  font-size: 1rem;
  flex: 1;
  text-align: center;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.calendar-weekday {
  background: var(--bg);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  text-align: center;
  padding: 6px 4px;
}

.calendar-cell {
  background: var(--card);
  min-height: 92px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.calendar-cell.other-month {
  background: var(--bg);
}

.calendar-cell.other-month .calendar-day-number {
  color: var(--muted);
  opacity: 0.6;
}

.calendar-cell.today .calendar-day-number {
  background: var(--accent);
  color: #fff;
}

.calendar-day-number {
  font-size: 0.8rem;
  font-weight: 700;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
}

.calendar-day-total {
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 600;
  margin-left: auto;
}

.calendar-cell-head {
  display: flex;
  align-items: center;
  gap: 4px;
}

.calendar-entries {
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow: hidden;
}

.calendar-entry {
  border: none;
  border-left: 3px solid transparent;
  border-radius: 4px;
  padding: 2px 5px;
  font-size: 0.7rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.calendar-more {
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 600;
  background: none;
  border: none;
  padding: 0 5px;
  text-align: left;
  cursor: pointer;
}

/* Task color palette for calendar chips — auto-adapts to light/dark via color-mix() */
.cal-color-0 { --cal-c: #d97706; }
.cal-color-1 { --cal-c: #0ea5e9; }
.cal-color-2 { --cal-c: #8b5cf6; }
.cal-color-3 { --cal-c: #10b981; }
.cal-color-4 { --cal-c: #ec4899; }
.cal-color-5 { --cal-c: #ef4444; }
.cal-color-6 { --cal-c: #6366f1; }
.cal-color-7 { --cal-c: #14b8a6; }

.calendar-entry {
  border-left-color: var(--cal-c, var(--accent));
  background: color-mix(in srgb, var(--cal-c, var(--accent)) 20%, var(--card));
  color: var(--text);
}

@media (max-width: 640px) {
  .calendar-cell {
    min-height: 64px;
  }

  .calendar-weekday {
    font-size: 0.65rem;
  }

  .calendar-entry {
    font-size: 0.62rem;
  }
}

/* ---------- Form ---------- */

.form-row {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 12px;
  margin-bottom: 12px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
}

input,
select,
textarea {
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea {
  resize: vertical;
}

.duration-input {
  display: flex;
  align-items: center;
  gap: 6px;
}

.duration-input input {
  width: 64px;
  flex: none;
  text-align: center;
}

.duration-unit {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.form-actions {
  display: flex;
  gap: 8px;
  align-self: end;
}

.form-actions .btn {
  flex: none;
}

.hidden {
  display: none !important;
}

/* ---------- Autocomplete ---------- */

.autocomplete-field {
  position: relative;
}

.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin: 4px 0 0;
  padding: 4px;
  list-style: none;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 220px;
  overflow-y: auto;
  z-index: 20;
}

.autocomplete-item {
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1.35;
  cursor: pointer;
  word-break: break-word;
}

.autocomplete-item mark {
  background: none;
  color: var(--accent);
  font-weight: 700;
}

.autocomplete-item:hover,
.autocomplete-item.active {
  background: var(--accent-soft);
}

.autocomplete-item .ac-meta {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 500;
  margin-top: 1px;
}

.error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 10px 0 0;
}

/* ---------- Login Modal ---------- */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal-overlay[hidden] {
  display: none !important;
}

.modal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  padding: 24px;
  width: 100%;
  max-width: 360px;
}

.modal-card h2 {
  margin: 0 0 6px;
  font-size: 1.2rem;
}

.modal-note {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 18px;
}

/* ---------- Buttons ---------- */

.btn {
  font: inherit;
  font-weight: 600;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  border: 1px solid transparent;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.8rem;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

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

.btn-ghost:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-icon {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.05rem;
  line-height: 1;
  padding: 2px 7px;
  border-radius: 999px;
}

.btn-icon:hover {
  color: var(--danger);
  background: rgba(220, 38, 38, 0.12);
}

.entry-edit:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.btn-icon:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Task list ---------- */

.task-form {
  display: flex;
  gap: 8px;
}

.task-form input {
  flex: 1;
}

.task-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 0;
  padding: 0;
}

.task-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 6px 4px 12px;
  font-size: 0.875rem;
}

.empty-note {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 8px 0 0;
}

/* ---------- Entries ---------- */

.day {
  margin-bottom: 14px;
}

.day:last-child {
  margin-bottom: 0;
}

.day-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
  margin-bottom: 4px;
}

.day-head h3 {
  margin: 0;
  font-size: 0.9rem;
}

.day-total {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.entry {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  grid-template-areas:
    "task hours edit remove"
    "desc desc desc desc";
  gap: 2px 10px;
  padding: 8px 4px;
}

.entry-task {
  grid-area: task;
  font-weight: 600;
  font-size: 0.925rem;
}

.entry-hours {
  grid-area: hours;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
}

.entry-edit {
  grid-area: edit;
}

.entry-remove {
  grid-area: remove;
}

.entry-desc {
  grid-area: desc;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---------- Footer ---------- */

.site-footer {
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 16px 32px;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

/* ---------- Small screens ---------- */

@media (max-width: 520px) {
  .form-row {
    grid-template-columns: 1fr;
  }

  .form-row > .form-actions {
    align-self: start;
    width: 100%;
  }

  .form-actions .btn {
    flex: 1;
  }
}
