  :root {
    color-scheme: dark;
    --bg: #0b0e13;
    --surface: #141820;
    --surface-2: #1b212b;
    --surface-3: #252d3a;
    --border: rgba(255, 255, 255, 0.12);
    --border-hover: rgba(255, 255, 255, 0.22);
    --text: #edf3fb;
    --muted: #9aa6b5;
    --faint: #566174;
    --accent: #4f9a94;
    --accent-strong: #3f817c;
    --accent-soft: rgba(79, 154, 148, 0.14);
    --accent-border: rgba(79, 154, 148, 0.34);
    --pin: #f59e0b;
    --pin-soft: rgba(245, 158, 11, 0.12);
    --special: #d6b45f;
    --special-soft: rgba(214, 180, 95, 0.14);
    --special-border: rgba(214, 180, 95, 0.4);
    --success: #20b486;
    --danger: #f05262;
    --warning: #eab308;
    --radius: 8px;
    font-family: "Noto Sans Thai", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  }

  body.light {
    color-scheme: light;
    --bg: #f5efe4;
    --surface: #fffaf1;
    --surface-2: #f7efdf;
    --surface-3: #efe4d0;
    --border: rgba(89, 67, 41, 0.14);
    --border-hover: rgba(89, 67, 41, 0.24);
    --text: #2f271d;
    --muted: #746653;
    --faint: #b8aa94;
    --accent-soft: rgba(79, 154, 148, 0.1);
    --accent-border: rgba(79, 154, 148, 0.24);
    --pin-soft: rgba(245, 158, 11, 0.1);
    --special-soft: rgba(181, 134, 39, 0.12);
    --special-border: rgba(181, 134, 39, 0.32);
  }

  * { box-sizing: border-box; letter-spacing: 0; }

  html { width: 100%; overflow-x: hidden; }

  body {
    min-height: 100vh;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
    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); }

  .layout {
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr;
    gap: 18px;
    align-items: start;
    animation: fadeUp 0.35s ease both;
  }

  @media (min-width: 820px) {
    .layout { grid-template-columns: 280px 1fr; }
  }

  @media (min-width: 1140px) {
    .layout { grid-template-columns: 270px 1fr 270px; }
  }

  .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.18);
  }

  .left-panel, .notes-sidebar { display: grid; gap: 14px; }
  .left-panel, main, .notes-sidebar, .card { min-width: 0; }

  /* ── Top projects bar ── */
  .top-projects {
    width: 100%;
    max-width: 1180px;
    margin: 0 auto 18px;
    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: 58px;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    padding: 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.disabled {
    opacity: 0.72;
    border-style: dashed;
    cursor: not-allowed;
  }

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

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

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

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

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

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

  @media (max-width: 820px) {
    .top-projects-inner { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    /* hide future project tiles on tablet too */
    .top-project.disabled { display: none; }
  }

  @media (max-width: 520px) {
    .top-projects-inner { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }

  /* ── เวลา ── */
  .clock-card { text-align: center; }

  #clock {
    font-family: "DM Mono", monospace;
    font-size: 2.65rem;
    font-weight: 500;
    line-height: 1;
    color: var(--accent);
  }

  #clockDate { margin-top: 8px; color: var(--muted); font-size: 0.78rem; }

  /* ── Layout helpers ── */
  .cal-head, .main-header, .โน้ต-header, .progress-label, .modal-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .cal-head { margin-bottom: 14px; font-size: 0.9rem; font-weight: 600; }

  .nav-btn, .icon-btn {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    min-width: 36px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    padding: 0;
    line-height: 1;
    transition: 0.15s ease;
  }

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

  /* NEW: วันนี้ button next to month navigation */
  .today-btn {
    border: 1px solid var(--accent-border);
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    padding: 3px 10px;
    font-size: 0.72rem;
    font-weight: 700;
    transition: 0.15s ease;
  }

  .today-btn:hover {
    background: var(--accent);
    color: #ffffff;
  }

  /* ── Calendar ── */
  .cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    text-align: center;
  }

  .day-name { padding-bottom: 6px; color: var(--faint); font-size: 0.64rem; font-weight: 600; }

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

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

  .cal-day.holiday { color: var(--danger); font-weight: 700; }
  .cal-day.holiday:hover { color: var(--danger); background: rgba(240, 82, 98, 0.1); }
  .cal-day.special-day { color: var(--special); font-weight: 700; }
  .cal-day.special-day:hover { color: var(--special); background: var(--special-soft); }
  .cal-day.today { color: var(--accent); font-weight: 700; }
  .cal-day.today.holiday { color: var(--danger); }
  .cal-day.today.special-day { color: var(--special); }
  .cal-day.today::before {
    content: "";
    position: absolute;
    inset: 0;
    border: 1px solid var(--accent-border);
    border-radius: inherit;
  }
  .cal-day.today.holiday::before { border-color: rgba(240, 82, 98, 0.42); }
  .cal-day.today.special-day::before { border-color: var(--special-border); }

  .cal-day.selected { background: var(--accent); color: #ffffff; font-weight: 700; }
  .cal-day.selected.holiday { background: var(--danger); color: #ffffff; }
  .cal-day.selected.special-day { background: var(--special); color: #111318; }

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

  .cal-task-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
  }
  .cal-task-dot.high { background: var(--danger); }
  .cal-task-dot.medium { background: var(--warning); }
  .cal-task-dot.low { background: var(--success); }

  .cal-hint { margin: 12px 0 0; color: var(--faint); text-align: center; font-size: 0.72rem; }

  .main-header { margin-bottom: 14px; }

  .main-header h1 {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0;
    font-size: 1.22rem;
    line-height: 1.25;
    font-weight: 700;
  }

  .date-badge {
    border: 1px solid var(--accent-border);
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    padding: 4px 10px;
    font-family: "DM Mono", monospace;
    font-size: 0.68rem;
    font-weight: 500;
  }
  .main-header.special-day h1 { color: var(--special); }
  .date-badge.special-day {
    border-color: var(--special-border);
    background: var(--special-soft);
    color: var(--special);
  }
  .date-event {
    display: none;
    align-items: center;
    min-height: 26px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    padding: 4px 10px;
    font-size: 0.72rem;
    font-weight: 800;
  }
  .date-event.show { display: inline-flex; }
  .date-event.holiday {
    border-color: rgba(240, 82, 98, 0.34);
    background: rgba(240, 82, 98, 0.11);
    color: var(--danger);
  }
  .date-event.special-day {
    border-color: var(--special-border);
    background: var(--special-soft);
    color: var(--special);
  }

  .theme-btn, .btn {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--muted);
    min-height: 40px;
    padding: 0 14px;
    transition: 0.15s ease;
  }

  .theme-btn:hover, .btn-secondary:hover {
    border-color: var(--border-hover);
    color: var(--text);
    background: var(--surface-2);
  }

  .btn-primary {
    border-color: var(--accent);
    background: var(--accent);
    color: #ffffff;
    font-weight: 700;
  }

  .btn-primary:hover { border-color: var(--accent-strong); background: var(--accent-strong); }

  .btn-danger {
    border-color: var(--danger);
    background: rgba(240, 82, 98, 0.12);
    color: var(--danger);
    font-weight: 700;
  }

  .btn-danger:hover { background: var(--danger); color: #ffffff; }

  .btn-active {
    border-color: var(--pin);
    background: var(--pin-soft);
    color: var(--pin);
  }

  /* ── Input rows ── */
  .input-row { display: grid; grid-template-columns: 1fr minmax(86px, 112px) auto; gap: 8px; margin-bottom: 8px; }

  .app-actions { display: grid; gap: 8px; margin-bottom: 14px; }
  .tool-row { display: grid; gap: 8px; margin-bottom: 14px; }

  .sync-row, .action-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
  }

  .action-row { justify-content: flex-start; }

  #statsToggleBtn::after {
    content: "⌄";
    display: inline-block;
    margin-left: 6px;
    transition: transform 0.16s ease;
  }

  #statsToggleBtn.expanded::after {
    transform: rotate(180deg);
  }

  .stats-panel {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.025);
  }

  .bulk-action-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    margin: -6px 0 14px;
    padding: 8px;
  }

  .bulk-action-bar span {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
    margin-right: auto;
  }

  .status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    padding: 3px 10px;
    font-size: 0.72rem;
    font-weight: 700;
  }

  .status-pill.online { border-color: var(--accent-border); background: var(--accent-soft); color: var(--accent); }
  .status-pill.warn { border-color: rgba(234, 179, 8, 0.35); background: rgba(234, 179, 8, 0.12); color: var(--warning); }

  .tool-row { grid-template-columns: 1fr auto; }

  select, input[type="datetime-local"] {
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    background-image: url("data:image/svg+xml,%3Csvg width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%237d8795' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 13px center;
    background-size: 14px;
    color: var(--text);
    min-height: 42px;
    padding: 0 38px 0 14px;
    outline: none;
  }

  select:focus, input[type="datetime-local"]:focus {
    border-color: var(--accent-border);
    background: var(--surface-3);
  }

  #taskInput, .modal-input, #searchInput {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--text);
    outline: none;
    min-height: 42px;
    padding: 12px 14px;
    transition: 0.15s ease;
  }

  #taskInput:focus, .modal-input:focus, #searchInput:focus {
    border-color: var(--accent-border);
    background: var(--surface-3);
  }

  #taskInput::placeholder, .modal-input::placeholder, #searchInput::placeholder { color: var(--faint); }

  #taskInput:disabled,
  #addBtn:disabled {
    cursor: not-allowed;
    opacity: 0.58;
  }

  /* ── เลยกำหนด box ── */
  .overdue-box {
    display: none;
    border: 1px solid rgba(240, 82, 98, 0.24);
    border-radius: var(--radius);
    background: rgba(240, 82, 98, 0.08);
    color: var(--text);
    margin-bottom: 16px;
    padding: 12px;
  }

  .overdue-box.show { display: grid; gap: 8px; }
  .overdue-title { color: var(--danger); font-size: 0.78rem; font-weight: 700; }
  .overdue-list { display: grid; gap: 6px; }

  .overdue-item {
    border: 0;
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    min-height: 34px;
    padding: 6px 9px;
    text-align: left;
  }

  body.light .overdue-item { background: rgba(15, 23, 42, 0.05); }

  .progress-label { color: var(--muted); font-size: 0.72rem; margin-bottom: 5px; }

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

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

  /* ── งาน list ── */
  #taskList, .sticky-tasks { list-style: none; margin: 0; padding: 0; }

  .task-item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) minmax(82px, 100px) auto auto auto;
    align-items: center;
    gap: 9px;
    min-height: 48px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    padding: 8px 12px;
    margin-bottom: 6px;
    transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
    cursor: pointer;
  }

  .task-item:hover { border-color: var(--border-hover); background: var(--surface-2); transform: translateX(2px); }
  .task-item.dragging { opacity: 0.45; border-style: dashed; border-color: var(--accent-border); }

  .task-item.pinned { background: var(--pin-soft); box-shadow: inset 4px 0 0 var(--pin); }
  .task-item.high { box-shadow: inset 4px 0 0 var(--danger); }
  .task-item.medium { box-shadow: inset 4px 0 0 var(--warning); }
  .task-item.low { box-shadow: inset 4px 0 0 var(--success); }
  .task-item.pinned.high, .task-item.pinned.medium, .task-item.pinned.low { box-shadow: inset 4px 0 0 var(--pin); }

  .task-item.completed .task-text { color: var(--muted); opacity: 0.58; text-decoration: line-through; }

  /* NEW: Bulk selected state */
  .task-item.bulk-selected {
    border-color: var(--accent-border);
    background: var(--accent-soft);
    transform: translateX(2px);
  }

  /* ── งาน text wrap (holds color dot + text) ── */
  .task-text-wrap { display: flex; align-items: center; gap: 6px; min-width: 0; }

  .task-text { min-width: 0; overflow-wrap: anywhere; font-size: 0.92rem; line-height: 1.45; }

  /* NEW FEATURE: Color dot for color tag */
  .color-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1.5px solid rgba(255,255,255,0.18);
  }

  /* ── Check box ── */
  .check-box {
    display: inline-grid;
    place-items: center;
    width: 20px;
    height: 20px;
    border: 1.5px solid var(--border-hover);
    border-radius: 6px;
    background: transparent;
    color: transparent;
    padding: 0;
    font-size: 11px;
    transition: 0.15s ease;
  }

  .task-item.completed .check-box { border-color: var(--success); background: var(--success); color: #ffffff; }

  /* ── งาน action buttons ── */
  .pin-btn, .priority-btn, .detail-btn, .delete-btn, .ความสำคัญ-btn, .mini-del, .note-delete-btn {
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 0;
    min-width: 32px;
    min-height: 32px;
    border-radius: 6px;
    font-size: 0.82rem;
    transition: 0.15s ease;
  }
  .priority-btn {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-weight: 800;
  }

  .priority-select {
    min-height: 32px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--surface-2);
    color: var(--text);
    padding: 0 8px;
    font-size: 0.72rem;
    font-weight: 800;
  }

  .priority-select:focus {
    border-color: var(--accent-border);
    background: var(--surface-3);
  }

  .task-item.high .priority-select {
    border-color: rgba(240, 82, 98, 0.34);
    background: rgba(240, 82, 98, 0.1);
    color: var(--danger);
  }
  .task-item.medium .priority-select {
    border-color: rgba(234, 179, 8, 0.34);
    background: rgba(234, 179, 8, 0.1);
    color: var(--warning);
  }
  .task-item.low .priority-select {
    border-color: rgba(32, 180, 134, 0.34);
    background: rgba(32, 180, 134, 0.1);
    color: var(--success);
  }

  .pin-btn.active, .pin-btn:hover { color: var(--pin); }
  .priority-btn:hover, .ความสำคัญ-btn:hover, .detail-btn:hover { color: var(--accent); background: var(--accent-soft); }
  .delete-btn:hover, .mini-del:hover, .note-delete-btn:hover { color: var(--danger); background: rgba(240, 82, 98, 0.1); }

  /* ── ความสำคัญ badge ── */
  .ความสำคัญ-badge {
    border-radius: 999px;
    padding: 3px 7px;
    font-size: 0.65rem;
    font-weight: 700;
    white-space: nowrap;
  }

  .ความสำคัญ-high { background: rgba(240, 82, 98, 0.13); color: var(--danger); }
  .ความสำคัญ-medium { background: rgba(234, 179, 8, 0.13); color: var(--warning); }
  .ความสำคัญ-low { background: rgba(32, 180, 134, 0.13); color: var(--success); }

  .task-remark {
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border: 1px solid var(--accent-border);
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    padding: 3px 8px;
    font-size: 0.68rem;
  }

  .task-meta { color: var(--muted); font-size: 0.68rem; white-space: nowrap; }

  .empty-state { padding: 34px 0; color: var(--faint); text-align: center; font-size: 0.9rem; }

  /* ── NEW FEATURE: สถิติ panel ── */
  .stats-panel {
    display: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    padding: 16px;
    margin-bottom: 18px;
    animation: fadeUp 0.2s ease both;
  }

  .stats-panel.show { display: block; }

  .stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 14px;
  }

  .stat-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    padding: 10px;
    text-align: center;
  }

  .stat-value {
    font-family: "DM Mono", monospace;
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--accent);
    line-height: 1;
  }

  .stat-label {
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.68rem;
  }

  .stat-card.danger .stat-value { color: var(--danger); }
  .stat-card.pin .stat-value { color: var(--pin); }
  .stat-card.success .stat-value { color: var(--success); }

  /* Mini bar chart for ความสำคัญ breakdown */
  .stats-chart { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 4px; }

  .stats-chart-title {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--muted);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 14px;
    height: 60px;
  }

  .bar-col { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1; }

  .bar-fill {
    width: 100%;
    border-radius: 4px 4px 0 0;
    min-height: 3px;
    transition: height 0.3s ease;
  }

  .bar-fill.high { background: var(--danger); }
  .bar-fill.medium { background: var(--warning); }
  .bar-fill.low { background: var(--success); }

  .bar-val { font-family: "DM Mono", monospace; font-size: 0.7rem; color: var(--muted); }
  .bar-lbl { font-size: 0.62rem; color: var(--faint); text-transform: uppercase; }

  /* ── Notes sidebar ── */
  .notes-sidebar { max-height: calc(100vh - 40px); }

  .โน้ต-header { padding: 4px 2px; }
  .โน้ต-header h2 { margin: 0; font-size: 0.92rem; }
  .โน้ต-count { color: var(--muted); font-size: 0.68rem; }

  .โน้ต-scroll { display: grid; gap: 10px; overflow-y: auto; padding-right: 3px; }

  .sticky {
    position: relative;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    padding: 14px;
    cursor: pointer;
    transition: 0.18s ease;
  }

  .notes-sidebar {
    position: sticky;
    top: 14px;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 34px);
    min-height: 0;
    padding-bottom: 2px;
  }
  .notes-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex: 0 0 auto;
    padding: 4px 2px 10px;
  }
  .notes-header h2 { margin: 0; font-size: 0.95rem; }
  .notes-count {
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    padding: 3px 8px;
    font-size: 0.68rem;
    font-weight: 700;
    white-space: nowrap;
  }
  .notes-scroll {
    display: grid;
    gap: 8px;
    align-content: start;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0 4px 14px 0;
    min-height: 0;
    scrollbar-gutter: stable;
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 calc(100% - 18px), transparent 100%);
    mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 calc(100% - 18px), transparent 100%);
  }
  .notes-scroll::-webkit-scrollbar { width: 6px; }
  .notes-scroll::-webkit-scrollbar-track { background: transparent; }
  .notes-scroll::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(124, 150, 188, 0.22);
  }
  .deleted-history {
    flex: 0 0 auto;
    margin-top: 4px;
    border-top: 1px solid rgba(255, 255, 255, 0.045);
    padding-top: 7px;
  }
  .deleted-history[hidden] { display: none; }
  .deleted-history summary {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    color: var(--faint);
    font-size: 0.66rem;
    font-weight: 750;
    list-style: none;
    cursor: pointer;
    transition: color 0.18s ease;
  }
  .deleted-history summary::-webkit-details-marker { display: none; }
  .deleted-history summary:hover { color: var(--muted); }
  .deleted-history-count {
    min-width: 18px;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 1px 6px;
    text-align: center;
  }
  .deleted-history-list {
    display: grid;
    gap: 5px;
    margin-top: 7px;
  }
  .deleted-history-item {
    display: grid;
    gap: 1px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.025);
    padding: 6px 8px;
  }
  .deleted-history-text {
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .deleted-history-meta {
    color: var(--faint);
    font-size: 0.6rem;
  }
  body.light .deleted-history { border-top-color: rgba(89, 67, 41, 0.08); }
  body.light .deleted-history-item { background: rgba(89, 67, 41, 0.04); }
  .empty-notes {
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--faint);
    padding: 28px 16px;
    text-align: center;
    font-size: 0.82rem;
  }

  .notes-month {
    display: grid;
    gap: 8px;
    min-width: 0;
  }

  .notes-month-header {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--border-hover);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    text-align: left;
    cursor: pointer;
    transition: 0.18s ease;
  }

  .notes-month-header:hover {
    border-color: var(--border-hover);
    background: var(--surface-2);
  }

  .notes-month-title {
    color: color-mix(in srgb, var(--accent) 82%, var(--text));
    font-size: 0.75rem;
    font-weight: 850;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .notes-month-meta {
    color: color-mix(in srgb, var(--muted) 72%, var(--text));
    font-size: 0.66rem;
    font-weight: 750;
    white-space: nowrap;
  }

  .notes-month-chevron {
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1;
    transition: transform 0.16s ease;
  }

  .notes-month.collapsed .notes-month-chevron {
    transform: rotate(-90deg);
  }

  .notes-month-body {
    display: grid;
    gap: 8px;
  }

  .notes-month-body[hidden] {
    display: none;
  }

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

  .sticky-date { margin-bottom: 9px; color: var(--accent); font-size: 0.72rem; font-weight: 800; }

  .sticky-tasks { display: grid; gap: 5px; }

  .sticky-tasks li {
    display: flex;
    align-items: center;
    gap: 8px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.035);
    padding: 7px 8px;
    color: var(--text);
    font-size: 0.74rem;
    line-height: 1.3;
  }

  body.light .sticky-tasks li { background: rgba(89, 67, 41, 0.05); }

  .sticky-tasks li.done { color: var(--muted); text-decoration: line-through; opacity: 0.58; }

  .prio-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
  .prio-high { background: var(--danger); }
  .prio-medium { background: var(--warning); }
  .prio-low { background: var(--success); }

  .mini-del { margin-left: auto; opacity: 0; }
  .sticky-tasks li:hover .mini-del { opacity: 1; }

  .note-delete-btn { position: absolute; top: 8px; right: 8px; opacity: 0; }
  .sticky:hover .note-delete-btn { opacity: 1; }

  .empty-โน้ต {
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--faint);
    padding: 28px 16px;
    text-align: center;
    font-size: 0.82rem;
  }

  /* ── Modals ── */
  .modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.56);
    backdrop-filter: blur(8px);
    padding: 16px;
  }

  .modal-overlay.show { display: flex; }

  .modal-box {
    width: min(430px, 100%);
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    box-shadow: 0 22px 60px rgba(0, 0, 0, 0.42);
    padding: 24px;
    animation: popIn 0.2s ease both;
  }

  .detail-modal { width: min(500px, 100%); }
  .shortcut-box { width: min(360px, 100%); }

  .modal-box h2 { margin: 0 0 6px; font-size: 1.12rem; }
  .modal-date { margin: 0 0 18px; color: var(--accent); font-size: 0.8rem; }

  .field-group { display: grid; gap: 5px; margin-bottom: 14px; }
  .field-label { color: var(--muted); font-size: 0.74rem; font-weight: 700; }

  textarea.modal-input { min-height: 100px; resize: vertical; }

  .modal-actions { justify-content: flex-end; margin-top: 18px; }

  .shortcut-list {
    display: grid;
    gap: 8px;
    margin-top: 14px;
  }

  .shortcut-list span {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    padding: 8px 10px;
  }

  .shortcut-list kbd {
    border: 1px solid var(--border-hover);
    border-radius: 6px;
    background: var(--surface-3);
    color: var(--accent);
    padding: 2px 8px;
    text-align: center;
    font-family: "DM Mono", monospace;
  }

  /* NEW FEATURE: สีของงาน picker in detail modal */
  .color-tag-picker {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
  }

  /* ── Tooltip ── */
  .tooltip {
    position: fixed;
    z-index: 2000;
    display: none;
    max-width: 220px;
    border: 1px solid var(--border-hover);
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--text);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
    padding: 9px 12px;
    pointer-events: none;
    font-size: 0.78rem;
  }

  .error-msg { margin: 14px 0 0; color: var(--danger); font-size: 0.82rem; }

  .toast {
    position: fixed;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
    z-index: 2200;
    display: none;
    max-width: min(360px, calc(100vw - 32px));
    border: 1px solid var(--border-hover);
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--text);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.3);
    padding: 12px 14px;
    font-size: 0.84rem;
  }

  .toast.show { display: block; }

  .toast-action {
    margin-left: 10px;
    border: 0;
    border-bottom: 1px solid currentColor;
    background: transparent;
    color: var(--accent);
    padding: 0;
    font-weight: 800;
  }

  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

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

    .layout { width: 100%; max-width: 100%; gap: 10px; }
    .card { padding: 12px 14px; }

    /* ── Top nav: hide future projects on mobile ── */
    .top-project.disabled { display: none; }
    .top-projects-inner { grid-template-columns: repeat(2, 1fr) !important; gap: 8px; }
    .top-project { min-height: 44px !important; }
    .top-project-desc { display: none; }

    /* ── Headers & rows stack ── */
    .main-header {
      flex-direction: column;
      align-items: flex-start;
      gap: 8px;
    }
    .main-header > div { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
    .main-header h1 { font-size: 1.08rem !important; }

    .input-row { grid-template-columns: 1fr minmax(72px, 92px) auto !important; gap: 6px; }

    .tool-row { grid-template-columns: 1fr !important; gap: 6px; }

    .theme-btn, .btn { min-height: 36px !important; }

    select { width: 100%; }

    .sync-row { flex-direction: column; align-items: flex-start; gap: 6px; }
    .action-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
    .action-row .btn { width: 100%; }

    .status-pill { width: auto; }

    /* ── Task items: hide decorative meta on small screens ── */
    .task-item {
      grid-template-columns: auto minmax(0, 1fr) minmax(72px, 90px) auto auto auto !important;
      gap: 7px !important;
      padding: 8px 10px !important;
    }
    .ความสำคัญ-badge, .task-remark { display: none; }
    .task-meta { display: none; }

    /* ── Notes sidebar: expand below main ── */
    .notes-sidebar {
      position: static;
      max-height: min(62vh, 520px);
    }
    .notes-scroll {
      padding-right: 2px;
      -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 16px), transparent 100%);
      mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 16px), transparent 100%);
    }
    .notes-month-header {
      grid-template-columns: minmax(0, 1fr) auto;
      row-gap: 2px;
      min-height: 42px;
    }
    .notes-month-meta {
      grid-column: 1;
      grid-row: 2;
    }
    .notes-month-chevron {
      grid-column: 2;
      grid-row: 1 / span 2;
    }

    /* ── Stats ── */
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .stats-panel { padding: 12px !important; }
  }

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

  @keyframes popIn {
    from { opacity: 0; transform: scale(0.96); }
    to   { opacity: 1; transform: scale(1); }
  }

  /* ── แจ้งเตือน custom calendar ── */
  .reminder-picker-row {
    display: grid;
    grid-template-columns: 1fr 120px auto;
    gap: 8px;
    align-items: center;
  }

  .reminder-date-button {
    text-align: left;
    color: var(--text);
  }

  .reminder-time-input {
    min-width: 0;
  }

  .reminder-clear-btn {
    min-height: 42px;
    padding: 0 12px;
  }

  .reminder-calendar {
    margin-top: 10px;
    border: 1px solid var(--accent-border);
    border-radius: var(--radius);
    background: var(--surface-2);
    padding: 12px;
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.22);
  }

  .reminder-cal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
    font-size: 0.86rem;
    font-weight: 700;
  }

  .reminder-weekdays {
    margin-bottom: 4px;
  }

  .reminder-day {
    position: relative;
    min-height: 34px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    font-size: 0.78rem;
    cursor: pointer;
    transition: 0.15s ease;
  }

  .reminder-day:hover {
    background: var(--accent-soft);
    color: var(--accent);
  }

  .reminder-day.today {
    color: var(--accent);
    font-weight: 700;
  }

  .reminder-day.selected {
    background: var(--accent);
    color: #fff;
    font-weight: 700;
  }

  @media (max-width: 560px) {
    .reminder-picker-row {
      grid-template-columns: 1fr;
    }
  }

  /* Phase 6: dashboard and task list polish */
  .task-card {
    border-color: color-mix(in srgb, var(--border) 78%, var(--accent-border));
  }

  .task-card.search-focus {
    border-color: rgba(214, 180, 95, 0.72);
    box-shadow:
      0 0 0 1px rgba(214, 180, 95, 0.38),
      0 0 26px rgba(214, 180, 95, 0.22),
      0 18px 42px rgba(0, 0, 0, 0.28);
  }

  .main-header {
    align-items: flex-start;
    gap: 14px;
    padding-bottom: 2px;
  }

  .main-header h1 {
    font-size: 1.34rem;
  }

  .input-row {
    align-items: stretch;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--surface-2) 72%, transparent);
    padding: 10px;
  }

  #taskInput,
  #searchInput,
  .modal-input {
    background: var(--surface) !important;
  }

  .tool-row {
    align-items: stretch;
  }

  .dashboard-strip {
    gap: 10px;
  }

  .dash-card {
    min-height: 92px;
    display: grid;
    align-content: center;
  }

  .dash-card strong {
    font-size: 1.24rem;
  }

  .progress-wrap {
    height: 6px;
  }

  .task-item {
    min-height: 58px;
    grid-template-columns: auto minmax(0, 1fr) minmax(90px, 112px) auto auto auto;
    gap: 10px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.018), transparent), var(--surface);
  }

  .task-text {
    font-size: 0.96rem;
  }

  .check-box {
    width: 23px;
    height: 23px;
  }

  .priority-select {
    min-height: 34px;
  }

  .pin-btn,
  .priority-btn,
  .detail-btn,
  .delete-btn,
  .mini-del,
  .note-delete-btn {
    min-width: 34px;
    min-height: 34px;
  }

  .empty-state {
    min-height: 72px !important;
  }

  .feature-panel {
    border-color: color-mix(in srgb, var(--border) 82%, var(--accent-border));
  }

  .activity-item {
    min-height: 48px;
  }

  @media (max-width: 640px) {
    .main-header {
      align-items: stretch;
    }

    .input-row {
      grid-template-columns: 1fr !important;
    }

    .task-item {
      grid-template-columns: auto minmax(0, 1fr) auto;
      align-items: start;
    }

    .task-item .priority-select,
    .task-meta {
      grid-column: 2 / -1;
      width: 100%;
    }
  }
