:root {
  --bg: #f4f1ea;
  --bg-soft: #ebe6dc;
  --panel: #ffffff;
  --ink: #1d1b18;
  --muted: #7b756b;
  --line: #e2dcd1;
  --line-strong: #d3ccbf;
  --accent: #2f4fdb;
  --accent-soft: #e9edfc;
  --danger: #cf3d3d;
  --danger-soft: #fbeaea;
  --green: #2f9e44;
  --p1: #d14343;
  --p1-bg: #fdeeee;
  --p2: #b7791f;
  --p2-bg: #fdf4e4;
  --p3: #5b7282;
  --p3-bg: #eef2f4;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(40, 33, 20, .08);
  --shadow-lg: 0 24px 70px rgba(30, 24, 12, .18);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "Inter", system-ui, sans-serif;
  background:
    radial-gradient(1200px 600px at 8% -12%, #fff8ea 0%, transparent 60%),
    radial-gradient(900px 520px at 100% 0%, #e9edfc 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

body.locked { overflow: hidden; }

button { font-family: inherit; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d5cec1; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------------------------------------------ topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 26px;
  background: rgba(244, 241, 234, .82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(226, 220, 209, .9);
}

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

.logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 18px;
  color: #fff;
  background: linear-gradient(145deg, #4a67ea, #2f4fdb 60%, #233bb0);
  box-shadow: 0 6px 16px rgba(47, 79, 219, .28);
}

.brand-text h1 {
  margin: 0;
  font-size: 17px;
  letter-spacing: -.02em;
}

.brand-text p {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--muted);
  text-transform: capitalize;
}

.toolbar {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.segmented {
  display: flex;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 3px;
}

.segmented button {
  border: 0;
  background: transparent;
  padding: 7px 14px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}

.segmented button.active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .08);
}

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

.nav .icon { width: 34px; height: 34px; font-size: 20px; }

.today-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}

.today-btn:hover { background: var(--bg-soft); }

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  min-width: 200px;
}

.search svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  flex: none;
}

.search input {
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  font-size: 13px;
  width: 100%;
  color: var(--ink);
}

.search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ----------------------------------------------------------------- buttons */
.primary {
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  box-shadow: 0 4px 14px rgba(47, 79, 219, .22);
  transition: filter .15s, transform .12s;
}

.primary:hover { filter: brightness(1.07); }
.primary:active { transform: translateY(1px); }

.add-btn span { font-size: 16px; line-height: 1; }

.ghost {
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  transition: background .15s;
}

.ghost:hover { background: var(--bg-soft); }
.ghost.danger { color: var(--danger); border-color: #edcaca; }
.ghost.danger:hover { background: var(--danger-soft); }
.ghost.small { padding: 6px 11px; font-size: 12px; margin-top: 6px; }

.icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background .15s;
}

.icon:hover { background: var(--bg-soft); }

.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ------------------------------------------------------------------ layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 22px;
  padding: 22px 26px 48px;
  max-width: 1600px;
  margin: 0 auto;
}

.main { min-width: 0; }

.range {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 2px 2px 14px;
}

.range h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -.02em;
}

.range .muted { font-size: 12px; }

.welcome {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  background: linear-gradient(135deg, #ffffff, #eef2ff);
  border: 1px solid #dbe2ff;
  border-radius: 16px;
  padding: 18px 20px;
  margin-bottom: 14px;
}

.welcome[hidden] { display: none; }

.welcome-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--accent-soft);
  display: grid;
  place-items: center;
  font-size: 20px;
  flex: none;
}

.welcome h3 { margin: 0 0 4px; font-size: 16px; letter-spacing: -.01em; }
.welcome p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.5; }

.welcome code {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 12px;
}

/* -------------------------------------------------------------- week view */
.calendar.week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
  align-items: stretch;
}

.day-col {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 520px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(40, 33, 20, .03);
}

.day-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  user-select: none;
}

.day-head:hover { background: var(--bg-soft); }

.day-head .dow {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  font-weight: 700;
}

.day-head .dnum {
  font-size: 20px;
  font-weight: 700;
  margin-left: 6px;
  letter-spacing: -.02em;
}

.day-head .dmon {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.day-col.today {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow);
}

.day-col.today .day-head { background: var(--accent); color: #fff; }
.day-col.today .day-head .dow,
.day-col.today .day-head .dmon { color: rgba(255, 255, 255, .78); }
.day-col.today .day-head:hover { background: #2743c4; }

.day-body {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  max-height: calc(100vh - 250px);
}

.empty-day {
  border: 1px dashed var(--line);
  border-radius: 9px;
  padding: 16px 8px;
  text-align: center;
  font-size: 11px;
  color: #b3aca0;
  margin-top: 2px;
}

/* -------------------------------------------------------------- task chips */
.p1 { --p-color: var(--p1); --p-bg: var(--p1-bg); }
.p2 { --p-color: var(--p2); --p-bg: var(--p2-bg); }
.p3 { --p-color: var(--p3); --p-bg: var(--p3-bg); }

.task-chip {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-left: 3px solid var(--p-color);
  background: var(--p-bg);
  color: var(--ink);
  padding: 7px 8px;
  border-radius: 9px;
  font: inherit;
  font-size: 12.5px;
  line-height: 1.32;
  cursor: pointer;
  transition: transform .12s, box-shadow .12s;
}

.task-chip:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 14px rgba(40, 33, 20, .1);
}

.task-chip.done { opacity: .55; }
.task-chip.done .chip-title { text-decoration: line-through; }

.task-chip.overdue { box-shadow: inset 0 0 0 1px rgba(207, 61, 61, .4); }

.chip-time {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 10.5px;
  flex: none;
  padding-top: 2px;
}

.chip-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }

.chip-title {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

.chip-tag { font-size: 10px; color: var(--p-color); opacity: .9; }

.chip-comment { font-size: 10px; color: var(--muted); flex: none; padding-top: 1px; }

.chip-repeat { font-size: 10px; flex: none; padding-top: 1px; opacity: .8; }
.mini-repeat { font-size: 9px; flex: none; }

/* ------------------------------------------------------------- month view */
.calendar.month { min-width: 0; }

.month-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

.month-weekdays div {
  text-align: center;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  font-weight: 700;
  padding: 4px;
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.month-cell {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  min-height: 118px;
  padding: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 5px;
  transition: border-color .15s, box-shadow .15s;
}

.month-cell:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.month-cell.outside { background: rgba(255, 255, 255, .45); opacity: .62; }

.month-cell.today {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.mday {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  flex: none;
}

.month-cell.today .mday { background: var(--accent); color: #fff; }

.mtasks { display: flex; flex-direction: column; gap: 3px; min-height: 0; overflow: hidden; }

.mini-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  border: 0;
  background: transparent;
  padding: 2px 3px;
  border-radius: 5px;
  font: inherit;
  font-size: 11px;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
  overflow: hidden;
}

.mini-chip:hover { background: var(--bg-soft); }
.mini-chip.done { opacity: .5; text-decoration: line-through; }

.mini-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--p-color);
  flex: none;
}

.mini-time { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.mini-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.more { font-size: 10px; color: var(--muted); padding-left: 10px; }

/* ---------------------------------------------------------------- agenda */
.agenda { display: flex; flex-direction: column; gap: 12px; }

.agenda-day {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}

.agenda-day.today { border-color: var(--accent); }

.agenda-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg-soft);
  cursor: pointer;
  user-select: none;
}

.agenda-day.today .agenda-head { background: var(--accent-soft); }

.agenda-dow { font-size: 12px; font-weight: 700; text-transform: capitalize; }
.agenda-date { font-size: 12px; color: var(--muted); }

.agenda-body { padding: 10px; display: flex; flex-direction: column; gap: 6px; }

/* --------------------------------------------------------------- search */
.search-results { display: flex; flex-direction: column; gap: 8px; max-width: 780px; }

.search-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  font: inherit;
  transition: border-color .15s, box-shadow .15s;
}

.search-item:hover { border-color: var(--accent); box-shadow: var(--shadow); }

.search-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.search-title { font-weight: 600; font-size: 14px; }
.search-sub { font-size: 12px; color: var(--muted); }

.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.p1 { background: var(--p1); }
.dot.p2 { background: var(--p2); }
.dot.p3 { background: var(--p3); }

.empty-state {
  border: 1px dashed var(--line-strong);
  border-radius: 16px;
  padding: 60px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  max-width: 780px;
}

/* ------------------------------------------------------------------ rail */
.rail { display: flex; flex-direction: column; gap: 16px; }

.rail-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.rail-section h3 {
  margin: 0 0 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.count {
  background: var(--bg-soft);
  border-radius: 20px;
  padding: 1px 8px;
  font-size: 11px;
  color: var(--muted);
}

.rail-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 7px 6px;
  cursor: pointer;
  font: inherit;
}

.rail-item:hover { background: var(--bg-soft); }

.rail-title { font-size: 12.5px; line-height: 1.35; flex: 1; min-width: 0; word-break: break-word; }
.rail-date { font-size: 11px; color: var(--danger); white-space: nowrap; padding-top: 1px; }

.empty-mini { font-size: 12px; color: var(--muted); padding: 4px 6px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  font-size: 11px;
  color: var(--muted);
}

.stat span {
  display: block;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--ink);
  letter-spacing: -.02em;
}

/* ---------------------------------------------------------------- drawer */
.drawer { position: fixed; inset: 0; z-index: 60; pointer-events: none; }

.drawer .scrim {
  position: absolute;
  inset: 0;
  background: rgba(29, 27, 24, .34);
  opacity: 0;
  transition: opacity .22s;
  backdrop-filter: blur(2px);
}

.drawer .panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(460px, 100%);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  transform: translateX(102%);
  transition: transform .26s cubic-bezier(.2, .8, .2, 1);
  display: flex;
  flex-direction: column;
}

.drawer.open { pointer-events: auto; }
.drawer.open .scrim { opacity: 1; }
.drawer.open .panel { transform: translateX(0); }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.pill {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg-soft);
  border-radius: 20px;
  padding: 4px 10px;
}

.panel-body {
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
}

.panel-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.done-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  align-self: flex-start;
}

.done-toggle input { position: absolute; opacity: 0; pointer-events: none; }

.checkbox {
  width: 20px;
  height: 20px;
  border: 1.5px solid var(--line-strong);
  border-radius: 6px;
  display: grid;
  place-items: center;
  transition: background .15s, border-color .15s;
}

.checkbox::after { content: "✓"; color: #fff; font-size: 13px; opacity: 0; }
.done-toggle input:checked + .checkbox { background: var(--green); border-color: var(--green); }
.done-toggle input:checked + .checkbox::after { opacity: 1; }
.done-toggle input:focus-visible + .checkbox { box-shadow: 0 0 0 3px var(--accent-soft); }

.title-input {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 6px 2px 10px;
  font: inherit;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -.01em;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

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

.recurrence-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-soft);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 12.5px;
  color: var(--accent);
}

.recurrence-row[hidden] { display: none; }
.recurrence-icon { font-size: 13px; }

.link-btn {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.link-btn:hover { color: var(--danger); }

.row { display: flex; gap: 12px; }
.row .field { flex: 1; min-width: 0; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
}

.field input,
.field select,
.field textarea {
  font: inherit;
  font-size: 13px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 10px;
  outline: 0;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}

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

.field textarea { resize: vertical; min-height: 72px; }

.field small {
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}

.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.check-line input { accent-color: var(--accent); }

/* -------------------------------------------------------------- comments */
.comments { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 2px; }

.comments-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.comments-head h4 {
  margin: 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}

.comment-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 240px;
  overflow-y: auto;
  padding-right: 2px;
}

.comment { background: var(--bg); border-radius: 10px; padding: 8px 10px; }

.comment-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10.5px;
  color: var(--muted);
  margin-bottom: 3px;
}

.comment-head time { margin-left: auto; }

.comment-del {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
}

.comment-del:hover { color: var(--danger); }

.comment-body { font-size: 13px; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }

.comment-form { display: flex; gap: 8px; margin-top: 10px; }

.comment-form input {
  flex: 1;
  font: inherit;
  font-size: 13px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 10px;
  outline: 0;
}

.comment-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.send {
  background: var(--accent);
  color: #fff;
  border: 0;
  width: 38px;
  height: 38px;
  border-radius: 9px;
  font-size: 16px;
}

.send:hover { filter: brightness(1.07); background: var(--accent); }

/* ----------------------------------------------------------------- modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 18px;
  pointer-events: none;
}

.modal .scrim {
  position: absolute;
  inset: 0;
  background: rgba(29, 27, 24, .38);
  opacity: 0;
  transition: opacity .2s;
  backdrop-filter: blur(3px);
}

.modal-card {
  position: relative;
  width: min(560px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  background: var(--panel);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 22px;
  transform: translateY(14px) scale(.985);
  opacity: 0;
  transition: transform .22s, opacity .22s;
  pointer-events: none;
}

.modal.open { pointer-events: auto; }
.modal.open .scrim { opacity: 1; }
.modal.open .modal-card { transform: none; opacity: 1; pointer-events: auto; }

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

.modal-card h3 { margin: 0; font-size: 19px; letter-spacing: -.02em; }

.modal-card .hint {
  margin: 0 0 12px;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--muted);
}

.modal-card textarea {
  width: 100%;
  font: inherit;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  outline: 0;
  resize: vertical;
  min-height: 96px;
}

.modal-card textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.preview {
  margin-top: 12px;
  background: var(--bg);
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  padding: 12px;
  min-height: 54px;
  font-size: 13px;
  color: var(--muted);
}

.preview-title { font-weight: 700; color: var(--ink); font-size: 15px; margin-bottom: 4px; }
.preview-meta { font-size: 12px; color: var(--muted); }
.preview-llm {
  margin-top: 6px;
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--accent);
}

.modal-card footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.mini-date {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--muted);
}

.mini-date input {
  font: inherit;
  font-size: 12px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  outline: 0;
}

.modal-card.settings { width: min(600px, 100%); }
.modal-card.settings hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.modal-card.settings .field { margin-bottom: 12px; }
.modal-card.settings .row .field { margin-bottom: 12px; }

.settings-status {
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--ink);
  margin-bottom: 14px;
}

.settings-status b { font-weight: 700; }

/* ----------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: #fff;
  padding: 11px 18px;
  border-radius: 12px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 90;
  box-shadow: var(--shadow-lg);
  max-width: 90vw;
  text-align: center;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

/* ------------------------------------------------------------ responsive */
@media (max-width: 1200px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .rail { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .stats { grid-column: 1 / -1; grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; gap: 12px; padding: 12px 16px; }
  .toolbar { width: 100%; }
  .search { flex: 1; min-width: 160px; }
  .layout { padding: 16px 16px 40px; }
  .calendar.week { grid-template-columns: repeat(7, minmax(150px, 1fr)); overflow-x: auto; padding-bottom: 6px; }
  .day-body { max-height: none; }
}

@media (max-width: 760px) {
  .brand-text p { display: none; }
  .brand-text h1 { font-size: 16px; }
  .logo { width: 34px; height: 34px; border-radius: 10px; font-size: 16px; }

  .segmented button { padding: 6px 10px; font-size: 12px; }
  .today-btn { padding: 7px 10px; font-size: 12px; }
  .primary { padding: 8px 12px; font-size: 12px; }

  .range h2 { font-size: 18px; }

  .agenda-head { padding: 9px 12px; }
  .task-chip { font-size: 13px; padding: 9px 10px; }

  .month-cell { min-height: 76px; padding: 5px; border-radius: 9px; gap: 3px; }
  .month-cell .mtasks { flex-direction: row; gap: 2px; flex-wrap: wrap; }
  .mini-chip { padding: 0; }
  .mini-title, .mini-time { display: none; }
  .mini-dot { width: 5px; height: 5px; }
  .more { padding-left: 2px; }
  .month-weekdays { gap: 4px; }
  .month-grid { gap: 4px; }

  .rail { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }

  .drawer .panel { width: 100%; }
  .modal { padding: 10px; }
  .modal-card { padding: 16px; border-radius: 16px; }
  .panel-body { padding: 14px; }
  .panel-foot { padding: 12px 14px; }

  .row { flex-direction: column; gap: 10px; }
}

@media (max-width: 520px) {
  .toolbar { gap: 8px; }
  .nav { order: 2; }
  .segmented { order: 1; }
  .add-btn { order: 3; margin-left: auto; }
  #settingsBtn { order: 4; }
  .search { order: 5; flex-basis: 100%; }
  .layout { padding: 12px 10px 34px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
