
:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #dbe3ef;
  --primary: #2563eb;
  --primary-2: #1d4ed8;
  --danger: #dc2626;
  --warning: #d97706;
  --success: #059669;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

[data-theme="dark"] {
  --bg: #0b1220;
  --panel: #111827;
  --panel-2: #0f172a;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: #243043;
  --primary: #60a5fa;
  --primary-2: #3b82f6;
  --danger: #f87171;
  --warning: #fbbf24;
  --success: #34d399;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overflow-x: clip;
}
body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, var(--bg), var(--panel-2));
  color: var(--text);
}

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

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  padding: 20px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: white;
  font-weight: 800;
}
.brand h1 { margin: 0; font-size: 1.1rem; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }

.nav-tabs {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
}
.nav-tab, .btn, .select, input, textarea {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
}
.nav-tab {
  padding: 12px 14px;
  text-align: left;
}
.nav-tab.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: white;
  border-color: transparent;
}

.sidebar-card, .toolbar, .dashboard-card, .task-card, .calendar-card, .settings-card, .modal-dialog {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.sidebar-card { padding: 16px; margin-bottom: 16px; }
.quick-stats { display: grid; gap: 8px; margin-top: 10px; }
.quick-stats .stat-line { display: flex; justify-content: space-between; gap: 8px; }
.sidebar-actions { display: grid; gap: 10px; }
.sidebar-mobile-controls { display: none; }
.sidebar-backdrop { display: none; }

.content {
  padding: 22px;
  overflow: visible;
  min-width: 0;
}
.content,
.sidebar,
.toolbar,
.dashboard-card,
.task-card,
.calendar-card,
.settings-card,
.modal-dialog {
  min-width: 0;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.topbar h2 { margin: 4px 0 0; font-size: 1.6rem; }
.eyebrow { margin: 0; color: var(--primary); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; font-size: .78rem; }
.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.menu-toggle { display: none; }
.search-wrap input, .select, input, textarea {
  padding: 10px 12px;
  outline: none;
}
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-wrap input { width: min(360px, 70vw); padding-right: 42px; }
.search-clear {
  position: absolute;
  right: 8px;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  line-height: 1;
}
.select { min-width: 150px; }

.view-section { display: none; }
.view-section.active { display: block; }

.grid {
  display: grid;
  gap: 14px;
}
.dashboard-grid { grid-template-columns: repeat(12, 1fr); }
.dashboard-card { padding: 16px; }
.span-4 { grid-column: span 4; }
.span-6 { grid-column: span 6; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }

.section-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.section-header,
.topbar,
.calendar-header-row,
.toolbar-footer,
.toolbar-footer-actions,
.task-card-head,
.task-actions {
  min-width: 0;
}
.section-header h3, .section-header h4 { margin: 0; }
.muted { color: var(--muted); }

.task-list { display: grid; gap: 12px; }
.task-card { padding: 16px; }
.task-card.overdue { border-color: rgba(220, 38, 38, .35); background: rgba(220, 38, 38, .06); }
.task-card.high-priority {
  border-color: rgba(220, 38, 38, .28);
  background:
    linear-gradient(90deg, rgba(220, 38, 38, .08), rgba(220, 38, 38, .02) 34%, transparent 100%),
    var(--panel);
  box-shadow: inset 4px 0 0 rgba(220, 38, 38, .85), var(--shadow);
}
.task-card.high-priority .task-title {
  font-weight: 800;
}
.task-card.completed { opacity: .72; }
.task-card.completed .task-title { text-decoration: line-through; }
.task-card.focus-target {
  outline: 3px solid rgba(37, 99, 235, .42);
  outline-offset: 2px;
}
.task-card.search-hit, .calendar-event.search-hit, .calendar-day-event.search-hit {
  border-color: rgba(37, 99, 235, .35);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, .08), var(--shadow);
}
.task-card.search-focus, .calendar-event.search-focus, .calendar-day-event.search-focus {
  outline: 3px solid rgba(245, 158, 11, .72);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(245, 158, 11, .16), var(--shadow);
}
.task-card-head { display: flex; justify-content: space-between; gap: 10px; align-items: start; }
.task-card-head > div,
.task-badges {
  min-width: 0;
}
.task-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.task-card.compact {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 14px;
}
.task-card.compact .task-card-head,
.task-card.compact .task-actions {
  grid-column: 1 / -1;
}
.task-card.compact .task-description,
.task-card.compact .task-memo {
  display: none;
}
.task-card.compact .task-actions {
  margin-top: 0;
}
.task-title,
.task-meta,
.task-description,
.task-memo,
.calendar-month-title,
.filter-chip,
.badge {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.task-title { margin: 0 0 4px; font-size: 1.05rem; }
.task-meta { margin: 0; color: var(--muted); font-size: .9rem; }
.task-description, .task-memo { margin: 10px 0 0; white-space: pre-wrap; }
.task-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 700;
  border: 1px solid transparent;
  margin-left: 6px;
}
.badge.high { background: rgba(220,38,38,.1); color: var(--danger); border-color: rgba(220,38,38,.2); }
.badge.medium { background: rgba(217,119,6,.1); color: var(--warning); border-color: rgba(217,119,6,.2); }
.badge.low { background: rgba(5,150,105,.1); color: var(--success); border-color: rgba(5,150,105,.2); }
.badge.done { background: rgba(100,116,139,.12); color: var(--muted); }
.badge.pause { background: rgba(100,116,139,.12); color: var(--muted); }
.badge.progress { background: rgba(37,99,235,.12); color: var(--primary); }
.badge.overdue { background: rgba(220,38,38,.1); color: var(--danger); border-color: rgba(220,38,38,.2); }
.badge.today { background: rgba(37,99,235,.12); color: var(--primary); border-color: rgba(37,99,235,.2); }
.badge.soon { background: rgba(217,119,6,.1); color: var(--warning); border-color: rgba(217,119,6,.2); }
.badge.repeat-auto { background: rgba(2,132,199,.12); color: #0369a1; border-color: rgba(2,132,199,.18); }
.field-help { margin-top: 6px; font-size: .82rem; line-height: 1.3; }

.toast-host {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  display: grid;
  gap: 10px;
  width: min(92vw, 360px);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.toast-success { background: rgba(5, 150, 105, 0.95); }
.toast-error { background: rgba(220, 38, 38, 0.95); }
.toast-info { background: rgba(37, 99, 235, 0.95); }

.btn:hover, .nav-tab:hover { transform: translateY(-1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  border-color: transparent;
  color: white;
}
.btn-danger { background: rgba(220,38,38,.1); color: var(--danger); }
.btn-success { background: rgba(5,150,105,.1); color: var(--success); }
.btn-secondary { background: rgba(100,116,139,.08); }
.icon-btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 10px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.toolbar .filters { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar-footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.toolbar-summary { display: grid; gap: 8px; }
.toolbar-footer-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-chip {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(37,99,235,.1);
  color: var(--primary);
  font-size: .78rem;
  border: 1px solid rgba(37,99,235,.2);
}
.filter-chip.neutral {
  background: rgba(100,116,139,.08);
  color: var(--muted);
  border-color: rgba(100,116,139,.15);
}
.calendar-card {
  padding: 20px;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 14px;
}
.calendar-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.calendar-month-nav {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.calendar-month-title {
  margin: 0;
  text-align: center;
  font-size: 1.3rem;
}
.calendar-nav-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  font-size: 1.1rem;
  font-weight: 800;
  line-height: 1;
}
.calendar-today-btn {
  white-space: nowrap;
}
.calendar-month {
  gap: 14px;
}
.calendar-head { text-align: center; color: var(--muted); font-weight: 700; }
.calendar-week {
  display: grid;
  grid-column: 1 / -1;
  gap: 0;
}
.calendar-day-events {
  display: grid;
  gap: 4px;
  margin-top: 4px;
}
.calendar-day-event {
  width: 100%;
  min-height: 18px;
  padding: 0 7px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
  box-shadow: 0 4px 10px rgba(15, 23, 42, .08);
}
.calendar-day-more {
  color: var(--muted);
  font-size: .68rem;
  padding-left: 4px;
}
.calendar-week-events {
  display: none;
}
.calendar-event {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 18px;
  padding: 0 7px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
  box-shadow: 0 4px 10px rgba(15, 23, 42, .08);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-align: left;
}
.calendar-event-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.calendar-event.high { background: linear-gradient(135deg, rgba(220, 38, 38, .96), rgba(185, 28, 28, .96)); }
.calendar-event.medium { background: linear-gradient(135deg, rgba(217, 119, 6, .96), rgba(180, 83, 9, .96)); }
.calendar-event.low { background: linear-gradient(135deg, rgba(5, 150, 105, .96), rgba(4, 120, 87, .96)); }
.calendar-event.done { background: linear-gradient(135deg, rgba(100, 116, 139, .94), rgba(71, 85, 105, .94)); }
.calendar-event.pause { background: linear-gradient(135deg, rgba(148, 163, 184, .94), rgba(100, 116, 139, .94)); }
.calendar-event.progress { background: linear-gradient(135deg, rgba(37, 99, 235, .94), rgba(29, 78, 216, .94)); }
.calendar-event.overdue { box-shadow: 0 0 0 2px rgba(220, 38, 38, .18), 0 6px 16px rgba(15, 23, 42, .12); }
.calendar-event.today { box-shadow: 0 0 0 2px rgba(37, 99, 235, .18), 0 6px 16px rgba(15, 23, 42, .12); }
.calendar-event.soon { box-shadow: 0 0 0 2px rgba(217, 119, 6, .18), 0 6px 16px rgba(15, 23, 42, .12); }
.calendar-event.search-hit {
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .4), 0 6px 16px rgba(15, 23, 42, .14);
}
.calendar-event.search-focus {
  outline: 2px solid rgba(37, 99, 235, .5);
  outline-offset: 2px;
}
.search-mark {
  background: rgba(250, 204, 21, .45);
  color: inherit;
  border-radius: .25em;
  padding: 0 .08em;
}
.calendar-week-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}
.calendar-day {
  min-height: 102px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
}
.calendar-day.outside { opacity: .45; }
.calendar-day.today { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.08); }
.calendar-day.selected { outline: 2px solid var(--primary); }
.calendar-day-header { display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.calendar-task-count { margin-top: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.calendar-task-count .count { font-size: .76rem; padding: 3px 7px; border-radius: 999px; background: rgba(37,99,235,.1); color: var(--primary); }
.calendar-selected-panel { margin-top: 14px; }

.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid label { display: grid; gap: 6px; font-size: .92rem; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid input, .form-grid textarea, .form-grid select { width: 100%; }
.inline-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, .45);
  padding: 20px;
  z-index: 40;
}
.modal.hidden { display: none; }
.modal-dialog {
  width: min(760px, 100%);
  padding: 18px;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }

.settings-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.settings-card { padding: 16px; }
.settings-card.full { grid-column: 1 / -1; }
.settings-card label { display: grid; gap: 6px; margin-bottom: 10px; }

.progress-bar {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: rgba(148,163,184,.2);
  overflow: hidden;
  margin-top: 10px;
}
.progress-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(135deg, var(--primary), var(--success));
}
.summary-tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.summary-tile {
  padding: 15px 13px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.35);
  display: flex;
  flex-direction: column;
  min-height: 108px;
}
.summary-label {
  display: block;
  color: var(--muted);
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .02em;
  margin-bottom: 7px;
}
.summary-value {
  display: block;
  font-size: 1.72rem;
  line-height: 1;
  letter-spacing: -0.03em;
  font-weight: 800;
}
.summary-note {
  margin-top: auto;
  padding-top: 8px;
  color: var(--muted);
  font-size: .74rem;
  line-height: 1.2;
  font-weight: 700;
}
.summary-label,
.summary-note {
  overflow-wrap: anywhere;
}
.summary-tile-todo {
  border-color: rgba(37,99,235,.28);
  background: linear-gradient(180deg, rgba(37,99,235,.11), rgba(37,99,235,.04));
  box-shadow: inset 0 4px 0 rgba(37,99,235,.82), inset 0 1px 0 rgba(255,255,255,.35);
}
.summary-tile-incomplete {
  border-color: rgba(217,119,6,.28);
  background: linear-gradient(180deg, rgba(217,119,6,.11), rgba(217,119,6,.04));
  box-shadow: inset 0 4px 0 rgba(217,119,6,.82), inset 0 1px 0 rgba(255,255,255,.35);
}
.summary-tile-overdue {
  border-color: rgba(220,38,38,.38);
  background: linear-gradient(180deg, rgba(220,38,38,.16), rgba(220,38,38,.06));
  box-shadow: inset 0 4px 0 rgba(220,38,38,.95), inset 0 1px 0 rgba(255,255,255,.35);
}
.summary-tile-overdue .summary-label,
.summary-tile-overdue .summary-value {
  color: var(--danger);
}
.summary-tile.is-zero {
  opacity: .64;
}
.summary-tile.is-zero .summary-value {
  color: var(--muted);
}
.summary-tile.is-zero .summary-note {
  opacity: .8;
}

.empty-state {
  padding: 22px;
  border: 1px dashed var(--border);
  border-radius: 18px;
  color: var(--muted);
  text-align: center;
  background: rgba(148,163,184,.05);
}

.split {
  display: grid;
  gap: 14px;
  grid-template-columns: 1.4fr .9fr;
}

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(320px, 82vw);
    height: 100vh;
    transform: translateX(-105%);
    transition: transform .24s ease;
    z-index: 60;
    box-shadow: 18px 0 40px rgba(15, 23, 42, .22);
  }
  body.sidebar-open { overflow: hidden; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .45);
    backdrop-filter: blur(1px);
    z-index: 55;
  }
  .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .topbar-actions { width: 100%; }
  .topbar-actions > :not(.menu-toggle) { display: none; }
  .topbar-actions .menu-toggle { margin-left: auto; }
  .sidebar-mobile-controls {
    display: grid;
    gap: 10px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
  }
  .sidebar-mobile-controls .mobile-control-row {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .sidebar-mobile-controls .search-wrap input,
  .sidebar-mobile-controls .select {
    width: 100%;
  }
  .sidebar-mobile-controls .search-clear {
    flex: 0 0 auto;
  }
  .dashboard-grid, .settings-grid, .split { grid-template-columns: 1fr; }
  .span-4, .span-6, .span-8, .span-12 { grid-column: auto; }
  .summary-tiles { grid-template-columns: 1fr; gap: 8px; }
  .summary-tile {
    padding: 13px 11px;
    min-height: 96px;
  }
  .summary-value {
    font-size: 1.34rem;
  }
}

@media (max-width: 720px) {
  .content { padding: 14px; }
  .topbar-actions { width: 100%; }
  .search-wrap, .search-wrap input, .select { width: 100%; }
  .toolbar-footer, .toolbar-footer-actions { width: 100%; }
  .toolbar-footer-actions { justify-content: stretch; }
  .toolbar-footer-actions .btn { flex: 1 1 0; }
  .form-grid { grid-template-columns: 1fr; }
  .calendar-grid { gap: 6px; }
  .calendar-week-events { gap: 3px; grid-auto-rows: 22px; }
  .calendar-week-days { gap: 4px; }
  .calendar-day { min-height: 88px; padding: 8px; }
  .task-card-head { flex-direction: column; }
}

/* Drag and drop on calendar */
.calendar-day.drag-over {
  outline: 2px dashed var(--primary, #2563eb);
  outline-offset: -4px;
  background: color-mix(in srgb, var(--primary, #2563eb) 8%, transparent);
}

.calendar-event[draggable="true"],
.calendar-day-event[draggable="true"] {
  cursor: grab;
}

.calendar-event.dragging,
.calendar-day-event.dragging {
  opacity: 0.55;
}
