:root {
  color-scheme: dark;
  --bg: #0d0e11;
  --rail: #15161a;
  --surface: #191b20;
  --raised: #212329;
  --hover: #25272e;
  --line: #34363d;
  --text: #f5f5f7;
  --muted: #b0b3bf;
  --accent: #f8ce3b;
  --accent-text: #171208;
  --selected: #2b271b;
  --danger: #ff7b84;
  --green: #58c989;
  --shadow: #0008;
  --topbar-height: 57px;
  font: 15px/1.45 Inter, "Segoe UI", "Malgun Gothic", system-ui, sans-serif;
}

:root[data-theme="dark-sky"] {
  --bg: #131923;
  --rail: #1b2331;
  --surface: #202a39;
  --raised: #28364a;
  --hover: #2a374b;
  --line: #41516a;
  --muted: #b2c2d7;
  --accent: #8dd8ff;
  --accent-text: #10202c;
  --selected: #263f55;
}

:root[data-theme="light-violet"] {
  color-scheme: light;
  --bg: #faf9fd;
  --rail: #f2eff9;
  --surface: #ffffff;
  --raised: #eeeafa;
  --hover: #eae5f8;
  --line: #dcd5eb;
  --text: #242036;
  --muted: #645d75;
  --accent: #6846c6;
  --accent-text: #fff;
  --selected: #ede5ff;
  --danger: #a7293e;
  --green: #147d43;
  --shadow: #38286f33;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button { color: inherit; cursor: pointer; }
button[disabled] { opacity: .65; cursor: wait; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button, a { -webkit-tap-highlight-color: transparent; }
input, textarea, select { min-width: 0; color: var(--text); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input[type=checkbox] { accent-color: var(--accent); }
.icon { display: block; width: 20px; height: 20px; flex: 0 0 auto; }
.icon-button, .plain-button, .primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 36px;
  background: transparent;
  white-space: nowrap;
}
.icon-button { width: 36px; padding: 6px; color: var(--muted); flex: 0 0 auto; }
.icon-button:hover, .plain-button:hover { background: var(--hover); color: var(--text); }
.plain-button, .primary { padding: 7px 13px; font-weight: 650; }
.plain-button { border-color: var(--line); }
.primary { background: var(--accent); color: var(--accent-text); }
.primary:hover { filter: brightness(1.08); }
.danger { color: var(--danger); }
.mobile-only, .mobile-brand, .mobile-add, .mobile-nav, .sidebar-close { display: none; }

.workspace { display: grid; grid-template-columns: 245px minmax(0, 1fr); height: 100vh; height: 100dvh; }
.sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--rail);
  border-right: 1px solid var(--line);
  overflow: auto;
}
.sidebar-brand { min-height: 73px; padding: 14px 19px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: 12px; font-weight: 740; font-size: 23px; white-space: nowrap; }
.brand-button { padding: 0; border: 0; background: none; text-align: left; }
.brand-icon {
  display: inline-grid;
  width: 31px;
  height: 31px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 23px;
  font-weight: 800;
  line-height: 1;
}
.navigation { padding: 0 12px 24px; flex: 1; }
.nav-link {
  display: flex;
  width: 100%;
  gap: 12px;
  align-items: center;
  min-height: 44px;
  padding: 8px 12px;
  margin: 1px 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  text-align: left;
}
.nav-link .nav-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.nav-link .count { margin-left: auto; color: var(--muted); font-size: 13px; }
.nav-link:hover { background: var(--hover); }
.nav-link[aria-current=page] { background: var(--selected); color: var(--accent); font-weight: 670; }
.nav-link[aria-current=page] .count { color: var(--accent); }
.nav-section { margin: 17px 7px 4px; padding: 12px 4px 0; border-top: 1px solid var(--line); }
.nav-section-head { display: flex; align-items: center; justify-content: space-between; min-height: 30px; gap: 8px; }
.nav-section h2 { margin: 0; font-size: 13px; font-weight: 710; }
.nav-section .icon-button { min-height: 29px; width: 29px; }
.nav-section .icon-button .icon { width: 17px; height: 17px; }
.nav-section .nav-link { min-height: 36px; padding: 6px; }
.sidebar-settings {
  margin: 0 12px max(12px, env(safe-area-inset-bottom));
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: 0;
  border-radius: 7px;
  text-align: left;
  color: var(--muted);
}
.sidebar-settings:hover { background: var(--hover); color: var(--text); }
.drawer-overlay { display: none; }

.application { min-width: 0; min-height: 0; display: grid; grid-template-rows: var(--topbar-height) minmax(0, 1fr); }
.topbar {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
  padding: 0 21px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.search { display: flex; align-items: center; gap: 8px; max-width: 300px; min-width: 0; color: var(--muted); }
.search input {
  width: 100%;
  padding: 6px 9px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.search .icon { width: 18px; height: 18px; }
.sync-status { margin-left: auto; display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.sync-dot { display: block; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.sync-status[data-state=synced] .sync-dot { background: var(--green); }
.sync-status[data-state=pending] .sync-dot { background: var(--accent); }
.sync-status[data-state=conflict] .sync-dot { background: var(--danger); }
.work-body { display: flex; min-width: 0; min-height: 0; }
.main-view {
  flex: 1;
  min-width: 0;
  overflow: auto;
  padding: 24px clamp(22px, 4.1vw, 70px) 34px;
  scrollbar-gutter: stable;
}
.main-view > * { max-width: 1120px; margin-inline: auto; }
.viewbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.view-title { min-width: 0; }
.view-title h1 { margin: 0; overflow-wrap: anywhere; line-height: 1.18; font-size: clamp(29px, 3.4vw, 43px); letter-spacing: -.045em; }
.view-title p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.quick-button { min-height: 43px; flex: 0 0 auto; }
.view-tools { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 18px; }
.view-options { display: inline-flex; align-items: center; gap: 2px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: var(--surface); }
.view-options button { display: flex; gap: 6px; align-items: center; justify-content: center; min-height: 30px; padding: 2px 10px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 13px; }
.view-options button:hover { background: var(--hover); }
.view-options button[aria-pressed=true] { background: var(--selected); color: var(--accent); }
.view-options .icon { width: 15px; height: 15px; }
.task-content { margin-top: 19px; }
.task-group + .task-group { margin-top: 20px; }
.task-group h2 {
  margin: 0;
  padding: 7px 12px;
  background: var(--surface);
  border-radius: 7px;
  font-size: 15px;
  font-weight: 700;
}
.task-group.overdue h2 { color: var(--danger); }
.task-list, .board-list, .calendar-tasks { padding: 0; margin: 0; list-style: none; }
.task-row { display: flex; align-items: center; min-height: 59px; gap: 10px; padding: 4px 9px 4px 10px; border-bottom: 1px solid var(--line); position: relative; }
.task-row:last-child { border-bottom-color: transparent; }
.task-row[data-selected=true] { background: var(--selected); border-radius: 7px; border-bottom-color: transparent; box-shadow: inset 3px 0 var(--accent); }
.task-row[data-child=true] { margin-left: 19px; }
.task-row:hover:not([data-selected=true]) { background: var(--surface); border-radius: 7px; }
.task-open { background: transparent; border: 0; padding: 5px 1px; text-align: left; color: var(--text); flex: 1; min-width: 0; min-height: 43px; }
.task-name { display: block; overflow-wrap: anywhere; font-size: 16px; font-weight: 650; }
.task-row[data-complete=true] .task-name { color: var(--muted); text-decoration: line-through; }
.check {
  position: relative;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 50%;
  color: var(--text);
}
.check::before { content: ""; display: block; width: 21px; height: 21px; border: 1.75px solid currentColor; border-radius: 50%; }
.check:hover { color: var(--accent); background: var(--hover); }
.check[data-done=true]::before { background: var(--accent); border-color: var(--accent); }
.check .icon { position: absolute; width: 16px; height: 16px; color: var(--accent-text); }
.task-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 3px; color: var(--muted); font-size: 12px; }
.task-meta span { display: inline-flex; gap: 4px; align-items: center; max-width: 100%; overflow-wrap: anywhere; }
.task-meta .icon { width: 14px; height: 14px; }
.priority-dot, .color-dot { flex: 0 0 auto; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.priority-dot { vertical-align: .16em; margin-right: 6px; }
.priority-dot[data-priority="3"] { background: var(--danger); }
.priority-dot[data-priority="2"] { background: #f49d57; }
.priority-dot[data-priority="1"] { background: #79aef8; }
.color-dot[data-color="#7d858f"] { background: #7d858f; }
.color-dot[data-color="#e56576"] { background: #e56576; }
.color-dot[data-color="#f19e64"] { background: #f19e64; }
.color-dot[data-color="#e6b524"] { background: #e6b524; }
.color-dot[data-color="#64bb91"] { background: #64bb91; }
.color-dot[data-color="#79aef8"] { background: #79aef8; }
.color-dot[data-color="#b292f7"] { background: #b292f7; }
.empty { margin: 26px 0; padding: 23px 14px; color: var(--muted); text-align: center; border: 1px dashed var(--line); border-radius: 8px; }
.board { display: grid; grid-template-columns: repeat(3, minmax(172px, 1fr)); gap: 12px; overflow: auto; padding-bottom: 8px; }
.board-column { min-height: 130px; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 8px; }
.board-column[data-drop=true] { outline: 2px solid var(--accent); outline-offset: -2px; }
.board-title { margin: 3px 7px 7px; font-size: 14px; }
.board-title span { color: var(--muted); font-weight: 400; margin-left: 5px; }
.board .task-row { padding: 1px 4px; }
.board .task-name { font-size: 14px; }
.board-empty { color: var(--muted); padding: 12px 8px; margin: 0; font-size: 13px; }
.calendar-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.calendar-heading h2 { margin: 0; font-size: 19px; }
.calendar-arrows { display: flex; gap: 3px; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-bottom: 0; border-right: 0; }
.calendar-weekday, .calendar-day { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.calendar-weekday { text-align: center; padding: 6px; background: var(--surface); font-size: 12px; color: var(--muted); }
.calendar-day { min-height: 69px; padding: 2px; min-width: 0; }
.calendar-day[data-selected=true] { background: var(--selected); }
.calendar-day[data-outside=true] .calendar-date { color: var(--muted); opacity: .72; }
.calendar-date { width: 100%; text-align: left; min-height: 25px; border: 0; border-radius: 3px; background: transparent; padding: 3px 5px; font-size: 13px; }
.calendar-date[aria-current=date] { color: var(--accent); font-weight: 730; }
.calendar-date:hover { background: var(--hover); }
.calendar-count { float: right; font-size: 11px; color: var(--muted); }
.calendar-event { display: block; width: 100%; border: 0; border-radius: 3px; background: var(--surface); text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 2px 4px; margin: 2px 0; font-size: 11px; }
.calendar-event:hover { background: var(--hover); }
.calendar-agenda { margin-top: 15px; }
.calendar-agenda-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.calendar-agenda-head h2 { font-size: 15px; margin: 0; }

.detail {
  flex: 0 0 clamp(286px, 29vw, 340px);
  min-width: 0;
  padding: 19px 16px 27px;
  overflow: auto;
  background: var(--surface);
  border-left: 1px solid var(--line);
}
.detail-head { display: flex; align-items: flex-start; gap: 4px; margin-bottom: 14px; }
.detail-head label { flex: 1; min-width: 0; }
.detail-head input { width: 100%; background: transparent; border: 1px solid transparent; border-radius: 5px; padding: 5px 3px; font-size: 21px; font-weight: 730; }
.detail-head input:hover, .detail-head input:focus { border-color: var(--line); }
.detail-field { display: grid; gap: 5px; padding: 11px 1px; border-top: 1px solid var(--line); }
.detail-field legend, .detail-label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.detail-label .icon { width: 17px; height: 17px; }
.detail-pair { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 6px; }
.detail-field input:not([type=checkbox]), .detail-field select, .detail-field textarea { width: 100%; }
.detail-field textarea { resize: vertical; min-height: 60px; }
.detail-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; margin-top: 9px; }
.detail-actions button { font-size: 13px; }
.detail-subtasks { margin-top: 15px; border-top: 1px solid var(--line); padding-top: 10px; }
.detail-subtasks h2 { margin: 0 0 5px; font-size: 14px; }
.detail-subtasks .task-row { min-height: 41px; padding-inline: 0; margin-left: 0; }
.detail-subtasks .task-open { min-height: 35px; }
.detail-subtasks .task-name { font-size: 13px; }
.detail-subtasks .plain-button { margin-top: 7px; width: 100%; font-size: 13px; }
.label-options { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 2px 0; }
.label-options label { display: inline-flex; align-items: center; gap: 4px; padding: 4px 7px; background: var(--bg); border: 1px solid var(--line); border-radius: 5px; font-size: 12px; overflow-wrap: anywhere; }
.label-options input { margin: 0; }
.field-hint { color: var(--muted); font-size: 12px; }
.reminder-field { display: grid; gap: 4px; min-width: 0; }
.field-error { margin: 4px 0; color: var(--danger); font-size: 13px; }
.conflicts { background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--danger); border-radius: 7px; margin-top: 13px; padding: 10px; }
.conflicts h2 { margin: 0 0 6px; font-size: 14px; }
.conflict-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 7px 0; border-top: 1px solid var(--line); }
.conflict-copy { flex: 1; min-width: 145px; overflow-wrap: anywhere; font-size: 13px; }
.conflict-row .plain-button { font-size: 12px; min-height: 30px; }

.gate { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.gate-card { width: min(100%, 390px); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px; }
.gate-card h1 { font-size: 25px; margin: 0; }
.gate-card p { color: var(--muted); }
.gate-card form { display: grid; gap: 13px; margin-top: 20px; }
.gate-card form .field-error { color: var(--danger); }
.gate-card label, .dialog label, .detail-field > label { display: grid; gap: 5px; min-width: 0; }
.gate-card label, .dialog label { color: var(--muted); font-size: 13px; }
.gate-card input, .dialog input, .dialog select, .dialog textarea,
.detail-field input:not([type=checkbox]), .detail-field select, .detail-field textarea {
  padding: 7px 8px;
  min-height: 36px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.dialog { width: min(490px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 18px; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 11px; box-shadow: 0 17px 65px var(--shadow); }
.dialog::backdrop { background: #0008; }
.dialog h2 { margin: 0; font-size: 19px; }
.dialog-head, .dialog-actions { display: flex; align-items: center; gap: 8px; }
.dialog-head { justify-content: space-between; margin-bottom: 13px; }
.dialog-actions { justify-content: flex-end; margin-top: 11px; flex-wrap: wrap; }
.dialog form { display: grid; gap: 11px; }
.dialog-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.dialog input[name=title] { min-height: 45px; font-size: 17px; }
.quick-parse { margin: 0; font-size: 12px; color: var(--accent); }
.preset-list { display: grid; gap: 7px; }
.preset { min-height: 42px; border: 1px solid var(--line); border-radius: 7px; display: flex; align-items: center; gap: 8px; padding: 6px 9px; background: var(--bg); text-align: left; }
.preset[aria-pressed=true] { border-color: var(--accent); }
.preset-swatch { display: inline-block; width: 24px; height: 19px; border: 1px solid #788; border-radius: 4px; background: linear-gradient(90deg, #0d0e11 50%, #f8ce3b 50%); }
.preset[data-theme=dark-sky] .preset-swatch { background: linear-gradient(90deg, #202a39 50%, #8dd8ff 50%); }
.preset[data-theme=light-violet] .preset-swatch { background: linear-gradient(90deg, #faf9fd 50%, #6846c6 50%); }
.settings-section + .settings-section { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 10px; }
.settings-section h3 { margin: 0 0 7px; font-size: 14px; }
.settings-section p { color: var(--muted); margin: 5px 0; font-size: 13px; }
.settings-section .plain-button { margin: 3px 3px 0 0; }
.notice { position: fixed; z-index: 22; right: 20px; bottom: 20px; max-width: min(390px, calc(100vw - 40px)); border: 1px solid var(--line); background: var(--raised); border-radius: 8px; padding: 9px 13px; box-shadow: 0 10px 30px var(--shadow); overflow-wrap: anywhere; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

@media (max-width: 1030px) and (min-width: 801px) {
  .workspace { grid-template-columns: 195px minmax(0, 1fr); }
  .main-view { padding-inline: 20px; }
  .detail { flex-basis: 277px; }
  .task-meta { gap: 3px 6px; }
}

@media (max-width: 800px) {
  :root { --topbar-height: 54px; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .application { padding-bottom: calc(58px + env(safe-area-inset-bottom)); }
  .sidebar { position: fixed; z-index: 20; inset: 0 auto 0 0; width: min(290px, 86vw); visibility: hidden; transform: translateX(-100%); transition: transform .15s, visibility .15s; }
  .workspace[data-drawer=open] .sidebar { transform: none; visibility: visible; }
  .workspace[data-drawer=open] .drawer-overlay { display: block; }
  .drawer-overlay { position: fixed; z-index: 19; inset: 0; border: 0; padding: 0; background: #0009; }
  .sidebar-brand { min-height: 61px; }
  .sidebar-close, .mobile-only { display: inline-flex; }
  .topbar { position: relative; gap: 7px; padding: 0 12px; }
  .mobile-brand { display: inline-flex; gap: 8px; font-size: 17px; }
  .mobile-brand .brand-icon { width: 24px; height: 24px; font-size: 19px; border-radius: 6px; }
  .topbar .search { display: none; }
  .topbar[data-search=open] .search { display: flex; max-width: none; flex: 1; }
  .topbar[data-search=open] .mobile-brand { display: none; }
  .topbar .icon-button { width: 42px; min-height: 42px; }
  .topbar .settings-shortcut { display: none; }
  .mobile-search { margin-left: auto; }
  .sync-status { margin-left: 0; }
  .sync-status .sync-label { display: none; }
  .main-view { padding: 17px 13px 76px; scrollbar-gutter: auto; }
  .view-title h1 { font-size: 33px; }
  .quick-button { display: none; }
  .view-tools { margin-top: 14px; }
  .view-options button { min-height: 34px; }
  .task-content { margin-top: 13px; }
  .task-row { padding: 5px 3px; min-height: 58px; }
  .task-row[data-child=true] { margin-left: 14px; }
  .check { width: 44px; height: 44px; }
  .task-name { font-size: 15px; }
  .mobile-add { display: grid; place-items: center; position: fixed; right: 15px; bottom: calc(73px + env(safe-area-inset-bottom)); z-index: 3; width: 55px; min-height: 55px; height: 55px; padding: 0; border-radius: 50%; box-shadow: 0 5px 17px var(--shadow); }
  .mobile-add .icon { width: 26px; height: 26px; }
  .mobile-nav { display: grid; grid-template-columns: repeat(3, 1fr); position: fixed; z-index: 4; inset: auto 0 0; padding: 3px 7px env(safe-area-inset-bottom); min-height: calc(58px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--rail); }
  .mobile-nav button { display: grid; justify-items: center; align-content: center; gap: 2px; min-height: 47px; color: var(--muted); border: 0; border-radius: 6px; background: transparent; font-size: 12px; }
  .mobile-nav button[aria-current=page] { color: var(--accent); background: var(--selected); }
  .detail { position: fixed; z-index: 11; inset: var(--topbar-height) 0 0; padding: 14px 15px max(22px, env(safe-area-inset-bottom)); border: 0; }
  .detail-head input { font-size: 22px; }
  .detail-field input:not([type=checkbox]), .detail-field select, .detail-field textarea, .dialog input, .dialog select, .dialog textarea { min-height: 43px; }
  .detail .icon-button, .detail .plain-button, .detail .primary, .dialog .icon-button { min-height: 42px; }
  .notice { left: 12px; right: 12px; bottom: calc(73px + env(safe-area-inset-bottom)); max-width: none; }
  .calendar-day { min-height: 38px; }
  .calendar-date { min-height: 33px; padding: 3px; text-align: center; }
  .calendar-count { float: none; display: block; line-height: 10px; }
  .calendar-event { display: none; }
  .board { grid-template-columns: repeat(3, minmax(155px, 64vw)); scroll-snap-type: x proximity; }
  .board-column { scroll-snap-align: start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
