/* ============ Planner — styles (light + dark, responsive) ============ */
* { box-sizing: border-box; }

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --surface-3: #e4e9f4;
  --text: #1b2233;
  --muted: #667085;
  --border: #e2e6f0;
  --accent: #4f46e5;
  --accent-strong: #4338ca;
  --accent-soft: #eef2ff;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --ok: #16a34a;
  --pri-high: #ef4444;
  --pri-med: #f59e0b;
  --pri-low: #10b981;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .10);
  --shadow-lg: 0 12px 30px rgba(15, 23, 42, .18);
  --radius: 14px;
  --radius-sm: 9px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html.dark {
  --bg: #0d1119;
  --surface: #161d2c;
  --surface-2: #1f2840;
  --surface-3: #2a3552;
  --text: #e8ecf6;
  --muted: #98a2b8;
  --border: #283350;
  --accent: #6366f1;
  --accent-strong: #818cf8;
  --accent-soft: #1e2a55;
  --danger-soft: #3b1d26;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 1px 3px rgba(0, 0, 0, .35);
  --shadow-lg: 0 14px 34px rgba(0, 0, 0, .5);
}

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }

/* ---------- Header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 18px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.brand-logo { font-size: 20px; }

.view-tabs {
  display: flex; gap: 2px; padding: 3px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.tab {
  border: 0; background: transparent; padding: 6px 16px; border-radius: 999px;
  cursor: pointer; font-weight: 600; font-size: 13.5px; color: var(--muted);
  transition: background .15s, color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }

.nav-controls { display: flex; align-items: center; gap: 6px; }
.date-label {
  font-size: 15px; font-weight: 650; margin: 0 4px; flex: 1; min-width: 150px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.header-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }

/* ---------- Buttons ---------- */
button { cursor: pointer; }
.icon-btn, .ghost-btn, .primary-btn, .danger-btn, .mini-btn {
  border-radius: var(--radius-sm); border: 1px solid transparent;
  transition: background .15s, border-color .15s, transform .05s;
}
.icon-btn:active, .ghost-btn:active, .primary-btn:active, .mini-btn:active { transform: translateY(1px); }
.icon-btn {
  width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface); border-color: var(--border); font-size: 15px; padding: 0;
}
.icon-btn:hover { background: var(--surface-2); }
.ghost-btn { padding: 7px 14px; background: var(--surface); border-color: var(--border); font-weight: 600; font-size: 13.5px; }
.ghost-btn:hover { background: var(--surface-2); }
.primary-btn { padding: 8px 16px; background: var(--accent); color: #fff; font-weight: 650; font-size: 13.5px; }
.primary-btn:hover { background: var(--accent-strong); }
.danger-btn { padding: 8px 14px; background: var(--danger-soft); color: var(--danger); font-weight: 650; font-size: 13.5px; }
.mini-btn {
  width: 26px; height: 26px; border-radius: 7px; background: transparent;
  border-color: transparent; color: var(--muted); font-size: 13px; flex: none; padding: 0;
}
.mini-btn:hover { background: var(--surface-3); color: var(--text); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

/* ---------- Layout ---------- */
main { max-width: 1160px; margin: 0 auto; padding: 18px 18px 90px; }
.view { display: none; }
.view.active { display: block; }

/* ---------- Day view ---------- */
.timeline-wrap { position: relative; }
.timeline {
  display: grid; grid-template-columns: 62px 1fr;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
}
.tl-label {
  border-top: 1px solid var(--border);
  padding: 9px 10px 0 0; text-align: right; font-size: 12px; color: var(--muted);
  font-variant-numeric: tabular-nums; user-select: none;
}
.tl-slot { position: relative; min-height: 58px; border-top: 1px solid var(--border); cursor: pointer; }
.tl-slot:hover { background: var(--accent-soft); }
.timeline > :nth-child(-n+2) { border-top: 0; }

.task-chip {
  position: absolute; left: 8px; right: 8px; display: flex; align-items: flex-start; gap: 6px;
  border: 0; border-left: 3px solid var(--accent); border-radius: 8px;
  background: var(--surface-2); padding: 2px 8px; text-align: left; min-height: 26px;
  overflow: hidden; font-size: 12.5px; box-shadow: var(--shadow);
}
.chip-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; cursor: pointer; }
.task-chip .chip-time { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.task-chip .chip-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-chip.pri-high { border-left-color: var(--pri-high); }
.task-chip.pri-med { border-left-color: var(--pri-med); }
.task-chip.pri-low { border-left-color: var(--pri-low); }
.task-chip.done { opacity: .55; }
.task-chip.done .chip-title { text-decoration: line-through; }

.now-line {
  position: absolute; left: 62px; right: 0; height: 0; z-index: 5; pointer-events: none;
  border-top: 2px solid var(--danger);
}
.now-line::before {
  content: ''; position: absolute; left: -4px; top: -5px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--danger);
}

.unscheduled { margin-top: 20px; }
.unscheduled h2 {
  font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em;
  margin: 0 0 10px;
}
.task-list { display: flex; flex-direction: column; gap: 8px; }

.task-row {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 10px 12px; box-shadow: var(--shadow);
}
.task-row.pri-high { border-left-color: var(--pri-high); }
.task-row.pri-med { border-left-color: var(--pri-med); }
.task-row.pri-low { border-left-color: var(--pri-low); }
.task-row.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-body { flex: 1; min-width: 0; }
.task-title { font-weight: 600; cursor: pointer; }
.task-time {
  font-size: 12px; color: var(--muted); background: var(--surface-2); padding: 1px 8px;
  border-radius: 999px; display: inline-block; margin-top: 4px; font-variant-numeric: tabular-nums;
}
.task-notes { font-size: 12.5px; color: var(--muted); margin-top: 3px; white-space: pre-wrap; word-break: break-word; }

.check {
  flex: none; width: 21px; height: 21px; margin-top: 1px; border-radius: 50%;
  border: 2px solid var(--border); background: var(--surface); color: #fff;
  font-size: 13px; line-height: 1; display: inline-flex; align-items: center; justify-content: center;
  padding: 0; transition: background .12s, border-color .12s;
}
.check:hover { border-color: var(--accent); }
.task-row.done .check, .week-task.done .check { background: var(--ok); border-color: var(--ok); }

.empty { color: var(--muted); font-size: 13.5px; font-style: italic; margin: 4px 0; }

/* ---------- Week view ---------- */
.week-grid {
  display: grid; grid-template-columns: repeat(7, minmax(138px, 1fr));
  gap: 10px; overflow-x: auto; padding-bottom: 6px;
}
.week-col {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; overflow: hidden; min-height: 420px;
}
.week-col.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
.week-col-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px 8px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.week-day { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.week-date { font-size: 17px; font-weight: 700; }
.week-col.today .week-day, .week-col.today .week-date { color: var(--accent); }
.week-col-body { flex: 1; display: flex; flex-direction: column; gap: 6px; padding: 8px; overflow-y: auto; }
.week-task {
  display: flex; gap: 7px; align-items: flex-start;
  background: var(--surface-2); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 7px 8px; font-size: 12.5px;
}
.week-task.pri-high { border-left-color: var(--pri-high); }
.week-task.pri-med { border-left-color: var(--pri-med); }
.week-task.pri-low { border-left-color: var(--pri-low); }
.week-task .check { width: 17px; height: 17px; font-size: 11px; margin-top: 0; }
.week-task-main { flex: 1; min-width: 0; cursor: pointer; }
.week-task .task-title { font-weight: 550; word-break: break-word; }
.week-task.done .task-title { text-decoration: line-through; color: var(--muted); }
.week-task .task-time { margin-top: 0; font-size: 11px; padding: 0 6px; }
.week-add {
  border: 1px dashed var(--border); background: transparent; border-radius: 8px;
  padding: 8px; color: var(--muted); font-size: 14px; flex: 1;
}
.week-add:hover { border-color: var(--accent); color: var(--accent); }
.week-col-add {
  margin-left: auto; width: 24px; height: 24px; flex: none; padding: 0;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  border-radius: 7px; font-size: 14px; line-height: 1; display: inline-flex;
  align-items: center; justify-content: center;
}
.week-col-add:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Drag & drop ---------- */
.dragging { opacity: .4; }
.drag-over { outline: 2px dashed var(--accent); outline-offset: -2px; }
.week-col.drag-over, .month-cell.drag-over { background: var(--accent-soft); }
.tl-slot.drag-over { background: var(--accent-soft); }
.week-task { cursor: grab; }

/* ---------- Month view ---------- */
.month-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  background: var(--surface); box-shadow: var(--shadow);
}
.month-head { display: contents; }
.month-head > div {
  padding: 9px 6px; text-align: center; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.month-cell {
  min-height: 96px; padding: 6px; cursor: pointer; position: relative;
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  transition: background .12s;
}
.month-cell:hover { background: var(--accent-soft); }
.month-cell:nth-child(7n) { border-right: 0; }
.month-cell:nth-child(n+43) { border-bottom: 0; }
.month-cell.outside { background: var(--surface-2); opacity: .55; }
.month-cell.today { box-shadow: inset 0 0 0 2px var(--accent); border-radius: 6px; }
.month-num {
  width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
  font-size: 13.5px; font-weight: 650; border-radius: 50%;
}
.month-cell.today .month-num { background: var(--accent); color: #fff; }
.month-dots { display: flex; align-items: center; gap: 3px; margin-top: 3px; min-height: 9px; flex-wrap: wrap; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-high { background: var(--pri-high); }
.dot-med { background: var(--pri-med); }
.dot-low { background: var(--pri-low); }
.count { font-size: 10.5px; color: var(--muted); font-weight: 700; margin-left: 2px; }
.month-preview { margin-top: 4px; display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.m-task {
  font-size: 11px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: grab; border-left: 2px solid transparent; padding-left: 5px;
}
.m-task.pri-high { border-left-color: var(--pri-high); }
.m-task.pri-med { border-left-color: var(--pri-med); }
.m-task.pri-low { border-left-color: var(--pri-low); }
.m-task.done { text-decoration: line-through; color: var(--muted); }
.m-more { font-size: 10.5px; color: var(--muted); }

/* ---------- Modal ---------- */
.task-modal {
  border: 0; border-radius: 16px; padding: 0; width: min(480px, 92vw);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.task-modal::backdrop { background: rgba(10, 14, 26, .45); backdrop-filter: blur(2px); }
.task-modal.fallback { position: fixed; top: 12vh; left: 50%; transform: translateX(-50%); z-index: 100; }
#task-form { padding: 20px 22px; }
#task-form h2 { margin: 0 0 14px; font-size: 18px; }
#task-form label {
  display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 650;
  color: var(--muted); margin-bottom: 12px;
}
#task-form input, #task-form select, #task-form textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 11px; font-weight: 500;
}
#task-form textarea { resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.spacer { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(16px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 200;
  max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .app-header { padding: 10px 12px; }
  .date-label { order: 10; flex-basis: 100%; margin: 2px 0 0; }
  .week-grid { grid-template-columns: repeat(7, 130px); }
  .form-row { grid-template-columns: 1fr; gap: 0; }
  .month-cell { min-height: 72px; }
  .month-preview { display: none; }
}
