:root {
  color-scheme: dark;
  --bg: #0f1318;
  --surface: #171d24;
  --surface-2: #202832;
  --surface-3: #2a3441;
  --border: rgba(255, 255, 255, 0.12);
  --border-hover: rgba(255, 255, 255, 0.22);
  --text: #edf3fb;
  --muted: #a2adbb;
  --faint: #657184;
  --accent: #4f9a94;
  --accent-strong: #3f817c;
  --accent-soft: rgba(79, 154, 148, 0.14);
  --accent-border: rgba(79, 154, 148, 0.34);
  --success: #20b486;
  --danger: #f05262;
  --warning: #eab308;
  --special: #d6b45f;
  --special-soft: rgba(214, 180, 95, 0.14);
  --special-border: rgba(214, 180, 95, 0.34);
  --radius: 8px;
  font-family: "Noto Sans Thai", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.light {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-3: #e6edf5;
  --border: rgba(20, 34, 48, 0.12);
  --border-hover: rgba(20, 34, 48, 0.22);
  --text: #1f2937;
  --muted: #667085;
  --faint: #98a2b3;
  --accent-soft: rgba(79, 154, 148, 0.1);
  --accent-border: rgba(79, 154, 148, 0.24);
}

* { box-sizing: border-box; letter-spacing: 0; }
html { width: 100%; overflow-x: hidden; }

body {
  min-height: 100vh;
  margin: 0;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  transition: background 0.25s ease, color 0.25s ease;
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:active { transform: scale(0.98); }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.4rem, 2vw, 2rem); }
h2 { font-size: 1.02rem; }

.top-projects {
  width: 100%;
  max-width: 1760px;
  margin: 0 auto 12px;
  animation: fadeUp 0.35s ease both;
}

.top-projects-inner {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.top-project {
  min-width: 0;
  min-height: 52px;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 8px 10px;
  text-align: left;
  text-decoration: none;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.18);
  transition: 0.15s ease;
}

.top-project:hover {
  border-color: var(--accent-border);
  background: var(--surface-2);
  transform: translateY(-1px);
}

.top-project.active {
  border-color: var(--accent-border);
  background: var(--accent-soft);
}

.top-project-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--accent);
  font-size: 0.9rem;
}

.top-project-text {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.top-project-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8rem;
  font-weight: 800;
}

.top-project-desc {
  color: var(--muted);
  font-size: 0.72rem;
}

.top-project-pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  padding: 2px 7px;
  font-size: 0.68rem;
  font-weight: 800;
  white-space: nowrap;
}

.top-project.active .top-project-pill {
  color: var(--accent);
  border-color: var(--accent-border);
  background: var(--accent-soft);
}

.overview-shell {
  width: 100%;
  max-width: 1760px;
  margin: 0 auto;
  display: grid;
  gap: 14px;
  animation: fadeUp 0.35s ease both;
}

.overview-shell .card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius) !important;
  background: var(--surface);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.18);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
  font-size: 0.82rem;
}

.btn, .theme-btn, .nav-btn, .today-btn, .segment {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  transition: 0.15s ease;
}

.btn, .theme-btn {
  min-height: 36px;
  padding: 7px 11px;
  font-weight: 800;
}

.btn:hover, .theme-btn:hover, .nav-btn:hover, .today-btn:hover, .segment:hover {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-btn {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  padding: 0;
  color: var(--muted);
  font-weight: 800;
}

.today-btn {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-color: var(--accent-border);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 4px 12px;
  font-weight: 800;
  white-space: nowrap;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.86fr) minmax(420px, 1.45fr) minmax(320px, 0.95fr);
  gap: 12px;
  align-items: start;
}

.left-stack, .center-stack, .right-stack {
  min-width: 0;
  display: grid;
  gap: 12px;
}

.calendar-panel,
.selected-task-panel,
.finance-overview-card,
.panel-card,
.hourly-panel {
  display: grid;
  gap: 12px;
  padding: 14px !important;
}

.panel-head,
.cal-head,
.progress-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-head a {
  border: 1px solid var(--accent-border);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 4px 9px;
  font-size: 0.75rem;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.panel-actions {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.selected-date-line {
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
}

.selected-day-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.day-stat {
  min-width: 0;
  min-height: 62px;
  display: grid;
  align-content: center;
  gap: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 9px;
}

.day-stat strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 0.98rem;
}

.day-stat small {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
}

.day-stat.task strong { color: #60a5fa; }
.day-stat.schedule strong { color: #a78bfa; }
.day-stat.finance strong { color: var(--success); }

.cal-head {
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 800;
}

.calendar-panel .cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
  text-align: center;
}

.calendar-panel .day-name {
  padding-bottom: 6px;
  color: var(--faint);
  font-size: 0.7rem;
  font-weight: 800;
}

.calendar-panel .cal-spacer {
  min-height: var(--calendar-day-size, 35px);
}

.calendar-panel .cal-day {
  position: relative;
  min-height: var(--calendar-day-size, 35px);
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: var(--calendar-day-font, 0.86rem);
  cursor: pointer;
  transition: 0.15s ease;
}

.calendar-panel .cal-day:hover {
  background: var(--surface-2);
  color: var(--accent);
}

.calendar-panel .cal-day.holiday {
  color: var(--danger);
  font-weight: 800;
}

.calendar-panel .cal-day.special-day {
  color: var(--special);
  font-weight: 800;
}

.calendar-panel .cal-day.today {
  color: var(--accent);
  font-weight: 800;
}

.calendar-panel .cal-day.today::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid var(--accent-border);
  border-radius: inherit;
}

.calendar-panel .cal-day.selected {
  background: var(--accent);
  color: #ffffff;
  font-weight: 900;
  box-shadow: 0 10px 20px rgba(79, 154, 148, 0.24);
}

.calendar-panel .cal-day.selected.holiday {
  background: var(--danger);
  color: #ffffff;
}

.calendar-panel .cal-day.selected.special-day {
  background: var(--special);
  color: #111318;
}

.cal-dots {
  position: absolute;
  bottom: 4px;
  left: 50%;
  display: flex;
  gap: 3px;
  transform: translateX(-50%);
  pointer-events: none;
}

.cal-dots span,
.calendar-legend i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
}

.cal-dots .task,
.calendar-legend .task { background: #60a5fa; }
.cal-dots .schedule,
.calendar-legend .schedule { background: #a78bfa; }
.cal-dots .finance,
.calendar-legend .finance { background: var(--success); }

.calendar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  color: var(--muted);
  font-size: 0.7rem;
}

.calendar-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.compact-list,
.hourly-list {
  display: grid;
  gap: 8px;
}

.list-item,
.hourly-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 9px;
}

.list-item.done,
.hourly-item.done {
  opacity: 0.72;
}

.list-dot {
  width: 9px;
  height: 32px;
  border-radius: 999px;
  background: var(--accent);
}

.list-dot.task { background: #60a5fa; }
.list-dot.finance { background: var(--success); }
.list-dot.expense { background: var(--danger); }

.item-main {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.item-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.85rem;
}

.item-main small,
.item-meta,
.empty-state {
  color: var(--muted);
  font-size: 0.72rem;
}

.item-meta {
  white-space: nowrap;
  font-weight: 800;
}

.count-pill {
  border: 1px solid var(--accent-border);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
}

.empty-state {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}

.segmented-control {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  padding: 4px;
}

.segment {
  position: relative;
  min-height: 30px;
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
}

.segment + .segment::before {
  content: "";
  position: absolute;
  left: -3px;
  top: 7px;
  bottom: 7px;
  width: 1px;
  background: var(--border);
}

.segment.active {
  border-color: var(--accent-border);
  background: var(--accent);
  color: #ffffff;
}

.finance-visual {
  display: grid;
  grid-template-columns: minmax(230px, 0.92fr) minmax(0, 1fr);
  gap: 18px;
  align-items: center;
}

.donut-wrap {
  display: grid;
  place-items: center;
  min-height: 280px;
}

.finance-donut {
  width: min(280px, 100%);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--surface-3) 0deg 360deg);
  transition: background 0.2s ease;
}

.donut-hole {
  width: 68%;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 5px;
  background: var(--surface);
  border: 10px solid var(--surface);
  text-align: center;
}

.donut-hole span,
.donut-hole small {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.donut-hole strong {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  font-size: clamp(1.25rem, 2.3vw, 2rem);
  white-space: nowrap;
}

.finance-bars {
  display: grid;
  gap: 9px;
}

.finance-bar-row {
  display: grid;
  grid-template-columns: minmax(96px, 0.75fr) minmax(120px, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.finance-bar-row strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.82rem;
}

.finance-bar-row small {
  color: var(--muted);
  font-size: 0.68rem;
}

.finance-bar-row b {
  font-size: 0.78rem;
  white-space: nowrap;
}

.bar-track {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.bar-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--success);
}

.finance-bar-row.expense .bar-track span {
  background: var(--danger);
}

.finance-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.finance-summary-card {
  min-width: 0;
  min-height: 72px;
  display: grid;
  align-content: center;
  gap: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 10px;
}

.finance-summary-card span,
.finance-summary-card small {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
}

.finance-summary-card strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1rem;
}

.finance-summary-card.income strong { color: var(--success); }
.finance-summary-card.expense strong { color: var(--danger); }
.finance-summary-card.net strong { color: var(--accent); }

.split-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.split-stats span {
  min-width: 0;
  min-height: 68px;
  display: grid;
  align-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 9px;
}

.split-stats strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--accent);
  font-size: 1rem;
}

.split-stats small {
  color: var(--muted);
  font-size: 0.68rem;
}

.progress-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.progress-wrap {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.2s ease;
}

.hourly-list {
  position: relative;
}

.hourly-item {
  grid-template-columns: 52px auto minmax(0, 1fr) auto;
}

.hour-range {
  display: grid;
  gap: 2px;
  color: var(--accent);
  font-family: "DM Mono", monospace;
  font-size: 0.76rem;
  font-weight: 800;
}

.hour-range small {
  color: var(--muted);
  font-size: 0.68rem;
}

.hourly-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.hourly-dot.work { background: #60a5fa; box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.14); }
.hourly-dot.study { background: #a78bfa; box-shadow: 0 0 0 4px rgba(167, 139, 250, 0.14); }
.hourly-dot.exercise { background: var(--success); box-shadow: 0 0 0 4px rgba(32, 180, 134, 0.14); }
.hourly-dot.rest { background: var(--warning); box-shadow: 0 0 0 4px rgba(234, 179, 8, 0.14); }
.hourly-dot.travel { background: #38bdf8; box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.14); }

.next-focus-card {
  display: grid;
  gap: 5px;
  border: 1px solid var(--accent-border);
  border-radius: var(--radius);
  background: var(--accent-soft);
  padding: 12px;
}

.next-focus-card strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.next-focus-card small {
  color: var(--muted);
  font-size: 0.74rem;
}

.cal-dot-tooltip {
  position: fixed;
  z-index: 50;
  min-width: 180px;
  max-width: 250px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 8px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: 0.15s ease;
}

.cal-dot-tooltip.show {
  opacity: 1;
  transform: translateY(0);
}

.cal-dot-tooltip-row {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
}

.cal-dot-tooltip-row + .cal-dot-tooltip-row {
  margin-top: 5px;
}

.cal-dot-tooltip-row i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100vw - 36px));
  border: 1px solid var(--accent-border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 12px 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: 0.18s ease;
  z-index: 60;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1180px) {
  .dashboard-grid {
    grid-template-columns: minmax(280px, 0.9fr) minmax(0, 1.25fr);
  }

  .right-stack {
    grid-column: 1 / -1;
    grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  }
}

@media (max-width: 860px) {
  .top-projects-inner,
  .dashboard-grid,
  .right-stack,
  .finance-visual {
    grid-template-columns: 1fr;
  }

  .selected-task-panel {
    order: -1;
  }

  .calendar-panel {
    gap: 8px;
    padding: 12px !important;
  }

  .calendar-panel .cal-grid {
    gap: 5px;
  }

  .calendar-panel .day-name {
    padding-bottom: 2px;
  }

  .calendar-panel .cal-spacer,
  .calendar-panel .cal-day {
    min-height: var(--calendar-day-size, 35px);
  }

  .calendar-panel .cal-day {
    font-size: var(--calendar-day-font, 0.86rem);
  }

  .cal-dots {
    bottom: 3px;
  }
}

@media (max-width: 640px) {
  body { padding: 12px; }

  .finance-summary-grid,
  .split-stats {
    grid-template-columns: 1fr;
  }

  .selected-day-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .segmented-control {
    width: 100%;
  }

  .segment {
    flex: 1;
  }

  .hourly-item {
    grid-template-columns: 48px auto minmax(0, 1fr);
  }

  .hourly-item .item-meta {
    grid-column: 3;
  }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
