:root {
  --bg: #f2f3f5;
  --panel: #ffffff;
  --sidebar: #ffffff;
  --line: #e5e6eb;
  --line-strong: #c9cdd4;
  --text: #1f2329;
  --text-secondary: #646a73;
  --muted: #8f959e;
  --blue: #3370ff;
  --blue-hover: #245bdb;
  --blue-active: #1a4acb;
  --blue-soft: #e8f3ff;
  --blue-soft-2: #f0f4ff;
  --ok: #34c724;
  --ok-soft: #e8ffea;
  --warn: #ff8800;
  --warn-soft: #fff7e8;
  --danger: #f54a45;
  --danger-soft: #fff2f1;
  --radius-sm: 4px;
  --radius: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(31, 35, 41, 0.04);
  --shadow: 0 1px 4px rgba(31, 35, 41, 0.06);
  --shadow-md: 0 4px 16px rgba(31, 35, 41, 0.08);
  --shadow-lg: 0 12px 32px rgba(31, 35, 41, 0.14);
  --font: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --sidebar-w: 220px;
  --topbar-h: 56px;
  --focus-ring: 0 0 0 2px rgba(51, 112, 255, 0.2);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
body.nav-open,
body.modal-open { overflow: hidden; }

a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--blue-hover); }

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
button:focus:not(:focus-visible),
a:focus:not(:focus-visible),
select:focus:not(:focus-visible),
input:focus:not(:focus-visible),
textarea:focus:not(:focus-visible) {
  outline: none;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb {
  background: #c9cdd4;
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: #8f959e; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

.bg-grid, .bg-orb { display: none; }

/* ---- Shell ---- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  min-width: 0;
}

.sidebar-backdrop { display: none; }
.menu-btn { display: none; }

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 12px 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 30;
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 10px 14px;
  position: relative;
}
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #4e83fd 0%, #3370ff 55%, #245bdb 100%);
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(51, 112, 255, 0.28);
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 3px;
  background: #fff;
  opacity: 0.95;
}
.brand-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
}
.brand-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; min-height: 0; }
.nav-group { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; }
.nav-group-label {
  font-size: 12px;
  color: var(--muted);
  padding: 4px 12px 6px;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.nav-link {
  text-decoration: none;
  color: var(--text-secondary);
  padding: 8px 12px;
  border-radius: var(--radius);
  font-weight: 400;
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.nav-link:hover {
  background: #f5f6f7;
  color: var(--text);
}
.nav-link.active {
  color: var(--blue);
  background: var(--blue-soft);
  font-weight: 500;
}
.nav-link.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--blue);
}
.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
}
.nav-icon svg {
  width: 16px;
  height: 16px;
  display: block;
}
.nav-link.active .nav-icon { opacity: 1; }

.sidebar-foot {
  margin-top: auto;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  border-top: 1px solid var(--line);
  position: relative;
  z-index: 5;
}
.sidebar-project { position: relative; }
.sidebar-project-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fafbfc;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.sidebar-project-btn:hover,
.sidebar-project.is-open .sidebar-project-btn {
  border-color: #9db7ff;
  background: #fff;
  box-shadow: var(--shadow-sm);
}
.sidebar-project-meta {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 2px;
}
.sidebar-project-label {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.2;
}
.sidebar-project-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-project-caret {
  flex-shrink: 0;
  color: var(--muted);
  transition: transform 0.15s var(--ease);
}
.sidebar-project.is-open .sidebar-project-caret {
  transform: rotate(180deg);
}
.sidebar-project-menu {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 6px);
  max-height: min(280px, 50vh);
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
  box-shadow: var(--shadow-md);
  display: grid;
  gap: 2px;
}
.sidebar-project-menu[hidden] { display: none; }
.sidebar-project-option {
  appearance: none;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: left;
  padding: 8px 10px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-project-option:hover {
  background: #f5f6f7;
}
.sidebar-project-option.active {
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 600;
}
.sidebar-project-empty {
  padding: 4px 2px;
  font-size: 12px;
}

.main {
  padding: 0;
  min-width: 0;
  width: 100%;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.main-body {
  padding: 16px 24px 36px;
  flex: 1;
  min-width: 0;
}
.main-material-task .main-body {
  padding-top: 12px;
  padding-bottom: 16px;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  min-height: var(--topbar-h);
  padding: 10px 24px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-compact {
  min-height: 48px;
  padding-top: 8px;
  padding-bottom: 8px;
}
.topbar-compact h1 {
  font-size: 16px;
  line-height: 1.3;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
.topbar-title { min-width: 0; }
.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  word-break: break-word;
  letter-spacing: 0.01em;
}
.muted {
  color: var(--muted);
  margin: 4px 0 0;
  word-break: break-word;
  font-size: 13px;
}
.topbar .muted { margin-top: 2px; font-size: 12px; }
.topbar-right {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.menu-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
  padding: 9px 8px;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease);
}
.menu-btn:hover { background: #f5f6f7; border-color: var(--line-strong); }
.menu-btn span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}

/* ---- Forms / Inputs ---- */
.project-form { display: flex; gap: 8px; }
.project-form input,
.form-grid input,
.form-grid select,
.form-grid textarea,
.inline-form input,
.inline-form select,
.inline-form textarea,
.child-form input {
  width: 100%;
  background: #fff;
  border: 1px solid var(--line-strong);
  color: var(--text);
  border-radius: var(--radius);
  padding: 7px 10px;
  outline: none;
  font: inherit;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.form-grid textarea,
.inline-form textarea {
  resize: vertical;
  min-height: 72px;
}
.project-form input::placeholder,
.form-grid input::placeholder,
.form-grid textarea::placeholder,
.inline-form input::placeholder,
.inline-form textarea::placeholder,
.child-form input::placeholder {
  color: #bbbfc4;
}
.project-form input:hover,
.form-grid input:hover,
.form-grid select:hover,
.form-grid textarea:hover,
.inline-form input:hover,
.inline-form select:hover,
.inline-form textarea:hover,
.child-form input:hover {
  border-color: #a0a5ad;
}
.project-form input:focus,
.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus,
.inline-form input:focus,
.inline-form select:focus,
.inline-form textarea:focus,
.child-form input:focus {
  border-color: var(--blue);
  box-shadow: var(--focus-ring);
}
.project-form button {
  width: 36px;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--blue);
  color: #fff;
  font-size: 18px;
}
.project-form button:hover { background: var(--blue-hover); }

/* ---- Alerts / Toast ---- */
.alert {
  margin: 0 24px 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
}
.alert.ok {
  background: var(--ok-soft);
  color: #2ea121;
  border: 1px solid #bbf2c1;
}
.alert.err {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #fddad8;
}
.alert.leaving {
  opacity: 0;
  transform: translateY(-6px);
}
.toast-host {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: min(360px, calc(100vw - 24px));
}
.toast {
  pointer-events: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  animation: toast-in 0.2s var(--ease);
}
.toast.ok { border-left: 3px solid var(--ok); }
.toast.err { border-left: 3px solid var(--danger); }
.toast.warn { border-left: 3px solid var(--warn); }
.toast.leaving {
  animation: toast-out 0.18s var(--ease) forwards;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(-4px); }
}

.import-hint a { color: var(--blue); text-decoration: none; }
.import-hint a:hover { text-decoration: underline; }

/* ---- Stats ---- */
.stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin: 16px 24px 14px;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.stat-card:hover {
  border-color: #d0d3d9;
  box-shadow: var(--shadow);
}
.stat-card span { color: var(--muted); font-size: 12px; }
.stat-card strong { font-size: 22px; font-weight: 600; color: var(--text); letter-spacing: -0.02em; }
.stat-card.wide {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
}
.warn { color: var(--warn); }

.progress-track {
  height: 6px;
  border-radius: 999px;
  background: #eff0f1;
  overflow: hidden;
}
.progress-track.thin { height: 4px; margin-top: 10px; }
.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #4e83fd, var(--blue));
  transition: width 0.25s var(--ease);
}

/* ---- Panel / Buttons ---- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 18px 20px;
  min-width: 0;
  overflow: hidden;
}
.panel-head { margin-bottom: 16px; }
.panel-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.panel-head .muted { margin-top: 4px; }

.btn {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 0 14px;
  height: 32px;
  cursor: pointer;
  font-weight: 500;
  color: var(--text);
  background: #fff;
  font: inherit;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease), box-shadow 0.15s var(--ease);
  white-space: nowrap;
  user-select: none;
}
.btn:hover { background: #f5f6f7; color: var(--text); }
.btn:active { background: #eff0f1; }
.btn.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  box-shadow: 0 1px 2px rgba(51, 112, 255, 0.2);
}
.btn.primary:hover {
  background: var(--blue-hover);
  border-color: var(--blue-hover);
  color: #fff;
}
.btn.primary:active {
  background: var(--blue-active);
  border-color: var(--blue-active);
}
.btn.ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--line);
}
.btn.ghost:hover {
  background: #f5f6f7;
  color: var(--text);
  border-color: var(--line-strong);
}
.btn.danger {
  background: #fff;
  color: var(--danger);
  border-color: #f8c9c7;
}
.btn.danger:hover { background: var(--danger-soft); }
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}
.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
}
.icon-btn {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.icon-btn:hover {
  background: #f5f6f7;
  color: var(--text);
}

/* ---- Kanban ---- */
.kanban {
  display: grid;
  grid-template-columns: repeat(5, minmax(220px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
}
.kanban-col {
  background: #f7f8fa;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  min-height: 360px;
  min-width: 220px;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
}
.kanban-col-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 10px;
}
.kanban-col-head strong {
  font-size: 13px;
  font-weight: 600;
}
.kanban-col-head em {
  margin-left: auto;
  font-style: normal;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  padding: 0 7px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--blue); flex-shrink: 0; }
.kanban-list {
  padding: 0 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 300px;
  flex: 1;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  transition: background 0.15s var(--ease), outline-color 0.15s var(--ease);
}
.kanban-list.drag-over {
  background: var(--blue-soft);
  outline: 1px dashed var(--blue);
  outline-offset: -4px;
}

.task-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), transform 0.15s var(--ease);
}
.task-card:hover {
  border-color: #c9cdd4;
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.task-card.dragging {
  cursor: grabbing;
  opacity: 0.55;
  transform: none;
  box-shadow: var(--shadow-sm);
}
.task-card h3 {
  margin: 8px 0 6px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
}
.task-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.task-card-top,
.task-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.task-card-top .tiny { margin-left: auto; margin-right: 4px; }
.card-delete { margin: 0; }
.card-del-btn {
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.card-del-btn:hover {
  background: var(--danger-soft);
  color: var(--danger);
}
.edit-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.task-meta { margin-top: 10px; color: var(--muted); font-size: 12px; }
.tiny { color: var(--muted); font-size: 12px; }

.empty-hint,
.empty-block {
  color: var(--muted);
  text-align: center;
  padding: 28px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  background: #fafbfc;
}
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  padding: 40px 20px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  background: #fafbfc;
  color: var(--muted);
}
.empty-state-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--blue-soft);
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}
.empty-state-icon svg { width: 24px; height: 24px; }
.empty-state strong {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}
.empty-state p {
  margin: 0;
  font-size: 13px;
  max-width: 320px;
  line-height: 1.55;
}
.empty-state .btn { margin-top: 8px; }
.kanban-list .empty-hint {
  padding: 16px 10px;
  font-size: 12px;
  background: transparent;
  border-style: dashed;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  height: 20px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  border: 1px solid transparent;
  white-space: nowrap;
}
.pri-high { background: var(--danger-soft); color: #f54a45; border-color: #fddad8; }
.pri-mid { background: var(--warn-soft); color: #de7802; border-color: #ffe1b8; }
.pri-low { background: var(--ok-soft); color: #2ea121; border-color: #bbf2c1; }
.st-backlog { background: #f5f6f7; color: #646a73; }
.st-todo { background: var(--blue-soft); color: var(--blue); }
.st-in_progress { background: #e8f3ff; color: #245bdb; }
.st-review { background: var(--warn-soft); color: #de7802; }
.st-done { background: var(--ok-soft); color: #2ea121; }
.dot.st-backlog { background: #8f959e; }
.dot.st-todo { background: #3370ff; }
.dot.st-in_progress { background: #4e83fd; }
.dot.st-review { background: #ff8800; }
.dot.st-done { background: #34c724; }

/* ---- Gantt ---- */
.gantt-wrap {
  --day-w: 48px;
  display: grid;
  grid-template-columns: 220px 1fr;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #fff;
}
.gantt-side-head {
  background: #fafbfc;
  border-bottom: 1px solid var(--line);
  height: 40px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-weight: 600;
  font-size: 13px;
  box-sizing: border-box;
  position: sticky;
  top: 0;
  z-index: 1;
}
.gantt-label {
  height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-bottom: 1px solid #f0f1f2;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-sizing: border-box;
}
.tree-mark { color: var(--blue); opacity: 0.7; }
.gantt-timeline {
  overflow-x: auto;
  overflow-y: hidden;
}
.gantt-scroll {
  --track-w: calc(var(--days) * var(--day-w));
  width: var(--track-w);
}
.gantt-days {
  display: grid;
  grid-template-columns: repeat(var(--days), var(--day-w));
  width: var(--track-w);
  height: 40px;
  background: #fafbfc;
  border-bottom: 1px solid var(--line);
  box-sizing: border-box;
  position: sticky;
  top: 0;
  z-index: 1;
}
.gantt-day {
  width: var(--day-w);
  box-sizing: border-box;
  border-right: 1px solid #f0f1f2;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.gantt-rows { width: var(--track-w); }
.gantt-row {
  position: relative;
  height: 44px;
  width: var(--track-w);
  border-bottom: 1px solid #f0f1f2;
  box-sizing: border-box;
}
.gantt-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--days), var(--day-w));
  pointer-events: none;
  z-index: 0;
}
.gantt-cell {
  box-sizing: border-box;
  border-right: 1px solid #f5f6f7;
}
.gantt-panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.gantt-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}
.gantt-legend .lg {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: -1px;
}
.gantt-bar {
  position: absolute;
  top: 10px;
  height: 24px;
  border-radius: 4px;
  overflow: visible;
  display: flex;
  align-items: center;
  min-width: 0;
  z-index: 1;
  box-sizing: border-box;
  cursor: grab;
  user-select: none;
  touch-action: none;
  background: #8f959e;
  box-shadow: 0 1px 2px rgba(31, 35, 41, 0.12);
}
.gantt-bar.dragging-bar { cursor: grabbing; opacity: 0.92; z-index: 2; }
.gantt-bar.tone-pending { background: #8f959e; }
.gantt-bar.tone-active { background: #3370ff; }
.gantt-bar.tone-due_soon { background: #ff8800; }
.gantt-bar.tone-overdue { background: #f54a45; }
.gantt-bar.tone-done { background: #34c724; }
.gantt-legend .tone-pending { background: #8f959e; }
.gantt-legend .tone-active { background: #3370ff; }
.gantt-legend .tone-due_soon { background: #ff8800; }
.gantt-legend .tone-overdue { background: #f54a45; }
.gantt-handle {
  position: absolute;
  top: 0;
  width: 8px;
  height: 100%;
  z-index: 3;
  cursor: ew-resize;
}
.gantt-handle.left { left: 0; border-radius: 4px 0 0 4px; }
.gantt-handle.right { right: 0; border-radius: 0 4px 4px 0; }
.gantt-handle:hover { background: rgba(255, 255, 255, 0.28); }
.gantt-empty {
  height: 44px;
  display: flex;
  align-items: center;
  padding-left: 12px;
  font-size: 12px;
}
.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: rgba(255, 255, 255, 0.28);
  border-radius: 4px 0 0 4px;
  pointer-events: none;
}
.bar-text {
  position: relative;
  z-index: 1;
  font-size: 12px;
  padding: 0 10px;
  color: #fff;
  pointer-events: none;
  font-weight: 500;
}

/* ---- WBS ---- */
.wbs-panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.wbs-toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.wbs { display: flex; flex-direction: column; gap: 8px; }
.wbs-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
  overflow: hidden;
}
.wbs-children {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 10px 10px 18px;
  border-top: 1px solid #f0f1f2;
  background: #fafbfc;
}
.wbs-children .wbs-item { background: #fff; }
.wbs-item summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  user-select: none;
  transition: background 0.15s var(--ease);
}
.wbs-item summary::-webkit-details-marker { display: none; }
.wbs-item summary:hover { background: #fafbfc; }
.wbs-toggle {
  width: 7px;
  height: 7px;
  border-right: 2px solid #8f959e;
  border-bottom: 2px solid #8f959e;
  transform: rotate(45deg);
  flex-shrink: 0;
  transition: transform 0.15s var(--ease);
}
.wbs-item[open] > summary .wbs-toggle { transform: rotate(-135deg); }
.wbs-child-count { color: var(--muted); }
.wbs-progress {
  margin-left: auto;
  color: var(--blue);
  font-size: 13px;
  font-weight: 500;
}
.wbs-body {
  padding: 0 14px 14px;
  display: grid;
  gap: 10px;
  border-top: 1px solid #f0f1f2;
  padding-top: 12px;
}
.inline-form,
.child-form {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.inline-form textarea,
.child-form { grid-column: 1 / -1; }
.inline-form .form-actions { grid-column: 1 / -1; }
.child-form {
  grid-template-columns: 1fr auto;
  align-items: center;
}

/* ---- Workbench ---- */
.workbench-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.workbench-quick {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.workbench-hero {
  display: block;
  text-decoration: none;
  color: inherit;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: #fff;
  padding: 18px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.workbench-hero::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--blue);
}
.workbench-hero:hover {
  border-color: #9db7ff;
  box-shadow: var(--shadow-md);
  color: inherit;
}
.workbench-hero-label {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  color: var(--blue);
  background: var(--blue-soft);
  padding: 0 8px;
  height: 22px;
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  font-weight: 500;
}
.workbench-hero-main {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: center;
}
.workbench-hero h3 {
  margin: 8px 0 6px;
  font-size: 18px;
  font-weight: 600;
}
.workbench-hero p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}
.workbench-hero-progress {
  display: grid;
  gap: 8px;
  justify-items: end;
  min-width: 120px;
}
.workbench-hero-progress strong {
  font-size: 28px;
  color: var(--blue);
  letter-spacing: -0.03em;
}
.workbench-hero-progress .progress-track { width: 120px; }
.workbench-section { margin-top: 8px; }
.workbench-section h3 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
}
.workbench-projects {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}
.workbench-project-chip {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fafbfc;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.workbench-project-chip:hover {
  border-color: #9db7ff;
  background: #fff;
  color: inherit;
}
.workbench-project-chip.active {
  border-color: var(--blue);
  background: var(--blue-soft);
}
.workbench-empty { padding: 28px 16px; }

/* ---- Projects ---- */
.project-create, .project-list { margin-top: 8px; }
.project-create {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fafbfc;
}
.project-create h3, .project-list h3 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
}
.project-list { margin-top: 20px; display: grid; gap: 12px; }
.project-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px;
  background: #fff;
  position: relative;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.project-card:hover {
  border-color: #d0d3d9;
  box-shadow: var(--shadow);
}
.project-card-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.project-delete { margin-top: 10px; padding-top: 10px; border-top: 1px solid #f0f1f2; }

/* ---- Materials ---- */
.material-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.material-card {
  position: relative;
  display: block;
  text-decoration: none;
  color: inherit;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), transform 0.15s var(--ease);
}
.material-card:hover {
  border-color: #9db7ff;
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  color: inherit;
}
.material-card.is-recent {
  border-color: #9db7ff;
  background: linear-gradient(180deg, #f7faff 0%, #fff 50%);
}
.material-ribbon {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 11px;
  font-weight: 500;
  padding: 0 8px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-sm);
  border: 1px solid #c6d8ff;
}
.material-card h3 {
  margin: 8px 0 6px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  padding-right: 64px;
}
.material-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 36px;
}
.material-card-top {
  display: flex;
  gap: 8px;
  align-items: center;
}
.material-opened {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}
.material-task-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.material-task-head a { color: var(--blue); text-decoration: none; }
.material-task-head a:hover { text-decoration: underline; }
.material-task-panel {
  display: flex;
  flex-direction: column;
  padding: 0;
  min-height: calc(100vh - 120px);
  border: 0;
  box-shadow: none;
  background: transparent;
  flex: 1;
}
.material-task-panel > .material-viewer {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  flex: 1;
  min-height: 0;
}
.material-task-toolbar {
  display: flex;
  align-items: center;
  gap: 8px 10px;
  flex-wrap: wrap;
  min-height: 40px;
  margin-bottom: 10px;
  padding: 0 2px;
}
.material-back {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px 4px 4px;
  border-radius: var(--radius);
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.material-back:hover {
  background: #fff;
  color: var(--blue);
}
.material-task-title {
  font-size: 15px;
  font-weight: 600;
  max-width: min(420px, 46vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.material-task-meta {
  font-size: 12px;
  white-space: nowrap;
}
.material-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}
.material-toolbar-actions form { margin: 0; }
.material-upload,
.material-files,
.material-viewer {
  margin-top: 0;
  padding-top: 0;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.material-upload {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.material-upload h3,
.material-files h3,
.material-viewer h3 {
  margin: 0 0 12px;
  font-size: 14px;
}
.material-files { display: grid; gap: 10px; }
.material-tabs {
  display: flex;
  flex-wrap: nowrap;
  gap: 0;
  align-items: stretch;
  border-bottom: 1px solid var(--line);
  padding: 0 8px;
  flex-shrink: 0;
  background: #fafbfc;
  overflow-x: auto;
}
.material-tab {
  appearance: none;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 10px 14px;
  margin-bottom: -1px;
  cursor: pointer;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.material-tab:hover {
  color: var(--text);
  background: rgba(31, 35, 41, 0.03);
}
.material-tab.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
  background: transparent;
}
.material-tab[draggable="true"] { cursor: grab; }
.material-tab.dragging {
  opacity: 0.45;
  cursor: grabbing;
}
.material-tab.drag-over-tab {
  box-shadow: inset 2px 0 0 var(--blue);
}
.material-tabs.is-reordering {
  cursor: grabbing;
}
.material-tab-add {
  width: 36px;
  min-width: 36px;
  padding: 8px 0;
  text-align: center;
  font-size: 18px;
  line-height: 1;
  color: var(--blue);
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  margin-left: 0;
}
.material-tab-add:hover,
.material-tab-add.active {
  background: var(--blue-soft);
  border-bottom-color: transparent;
}
.material-active-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.material-upload-empty {
  border: 0;
  border-radius: 0;
  background: #fafbfc;
  padding: 40px 24px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.material-upload-empty-title {
  color: var(--text);
  font-size: 16px;
  margin: 0 0 6px;
}
.material-upload-empty > .muted {
  margin: 0 0 20px;
  text-align: center;
  max-width: 360px;
}
.material-upload-empty .material-upload-form {
  width: min(460px, 100%);
  text-align: left;
}
.material-dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 168px;
  padding: 28px 20px;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius-md);
  background: #fff;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease), box-shadow 0.15s var(--ease);
  text-align: center;
  user-select: none;
}
.material-dropzone:hover,
.material-dropzone:focus-visible {
  border-color: var(--blue);
  background: var(--blue-soft-2);
  box-shadow: var(--focus-ring);
  outline: none;
}
.material-dropzone.is-dragover {
  border-color: var(--blue);
  background: var(--blue-soft);
  box-shadow: var(--focus-ring);
}
.material-dropzone.has-file {
  border-style: solid;
  border-color: var(--blue);
  background: var(--blue-soft-2);
}
.material-dropzone-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 0;
}
.material-dropzone-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--blue-soft);
  color: var(--blue);
  pointer-events: none;
}
.material-dropzone-icon svg {
  width: 22px;
  height: 22px;
}
.material-dropzone-text {
  display: grid;
  gap: 4px;
  pointer-events: none;
}
.material-dropzone-text strong {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}
.material-dropzone-text span {
  font-size: 13px;
}
.material-dropzone-text em {
  font-style: normal;
  color: var(--blue);
  font-weight: 500;
}
.material-dropzone-file {
  pointer-events: none;
  margin-top: 2px;
  padding: 6px 12px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.material-dropzone.has-file .material-dropzone-text { display: none; }
.material-upload-modal-panel {
  width: min(480px, 100%);
}
.material-upload-form { margin: 0; }
.material-fs-exit {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(31, 35, 41, 0.72);
  color: #fff;
  border-radius: var(--radius);
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.material-fs-exit:hover { background: rgba(31, 35, 41, 0.9); }
.material-frame-wrap:fullscreen,
.material-frame-wrap:-webkit-full-screen {
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
  background: #fff;
}
.material-frame-wrap:fullscreen .material-frame,
.material-frame-wrap:-webkit-full-screen .material-frame {
  height: 100%;
  min-height: 100%;
}
.material-frame-wrap:fullscreen .material-fs-exit,
.material-frame-wrap:-webkit-full-screen .material-fs-exit {
  display: inline-flex;
}
.material-file-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px;
  background: #fafbfc;
}
.material-file-info {
  display: grid;
  gap: 4px;
  min-width: 0;
}
.material-file-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.material-file-actions form { margin: 0; }
.material-browse-panel { padding: 0; border: 0; box-shadow: none; background: transparent; }
.material-browse-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 0;
  min-height: 70vh;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow-sm);
}
.material-side-list {
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: #fafbfc;
  overflow: auto;
  max-height: 70vh;
}
.material-side-title {
  padding: 12px 14px;
  font-weight: 600;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  position: sticky;
  top: 0;
}
.material-side-item {
  display: block;
  padding: 10px 14px;
  color: var(--text-secondary);
  text-decoration: none;
  border-bottom: 1px solid #f0f1f2;
  font-size: 13px;
  word-break: break-word;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.material-side-item:hover { background: #fff; color: var(--text); }
.material-side-item.active {
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 500;
}
.material-frame-wrap {
  position: relative;
  border: 0;
  border-radius: 0;
  overflow: hidden;
  background: #fff;
  flex: 1;
  min-height: calc(100vh - 210px);
  display: flex;
  flex-direction: column;
}
.material-frame {
  width: 100%;
  height: 100%;
  min-height: calc(100vh - 210px);
  border: 0;
  display: block;
  background: #fff;
  flex: 1;
}

/* ---- AI ---- */
.ai-panel {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 120px);
  padding: 0;
  overflow: hidden;
}
.ai-shell,
.ai-chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(51, 112, 255, 0.06), transparent 60%),
    #f7f8fa;
}
.ai-shell-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
  flex-shrink: 0;
}
.ai-shell-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.ai-shell-title strong {
  display: block;
  font-size: 15px;
  font-weight: 600;
}
.ai-shell-title .muted {
  margin: 2px 0 0;
  font-size: 12px;
}
.ai-shell-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #4e83fd, #3370ff);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(51, 112, 255, 0.28);
}
.ai-shell-avatar svg { width: 18px; height: 18px; }
.ai-banner {
  margin: 12px 16px 0;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #fddad8;
  font-size: 13px;
}
.ai-banner code {
  background: rgba(255, 255, 255, 0.7);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
}
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 320px;
}
.ai-msg {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: min(760px, 100%);
  animation: ai-msg-in 0.18s var(--ease);
}
.ai-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.ai-msg.assistant,
.ai-msg.error,
.ai-msg.thinking {
  align-self: flex-start;
}
@keyframes ai-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.ai-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  background: #fff;
  color: var(--blue);
  border: 1px solid #d6e4ff;
}
.ai-msg.user .ai-avatar {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}
.ai-bubble {
  max-width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
}
.ai-bubble.md {
  white-space: normal;
}
.ai-bubble.md > *:first-child { margin-top: 0; }
.ai-bubble.md > *:last-child { margin-bottom: 0; }
.ai-bubble.md p {
  margin: 0 0 0.65em;
}
.ai-bubble.md p:last-child { margin-bottom: 0; }
.ai-bubble.md h1,
.ai-bubble.md h2,
.ai-bubble.md h3,
.ai-bubble.md h4 {
  margin: 0.85em 0 0.45em;
  font-weight: 600;
  line-height: 1.35;
  color: inherit;
}
.ai-bubble.md h1 { font-size: 1.2em; }
.ai-bubble.md h2 { font-size: 1.1em; }
.ai-bubble.md h3,
.ai-bubble.md h4 { font-size: 1em; }
.ai-bubble.md ul,
.ai-bubble.md ol {
  margin: 0.4em 0 0.7em;
  padding-left: 1.35em;
}
.ai-bubble.md li { margin: 0.2em 0; }
.ai-bubble.md li > p { margin: 0.2em 0; }
.ai-bubble.md blockquote {
  margin: 0.5em 0;
  padding: 0.35em 0 0.35em 0.85em;
  border-left: 3px solid #c6d8ff;
  color: var(--text-secondary);
  background: rgba(51, 112, 255, 0.04);
}
.ai-bubble.md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: #f2f3f5;
  color: #c41d7f;
  padding: 0.1em 0.4em;
  border-radius: 4px;
}
.ai-bubble.md pre {
  margin: 0.55em 0;
  padding: 10px 12px;
  overflow-x: auto;
  background: #1f2329;
  color: #f5f6f7;
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.55;
}
.ai-bubble.md pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}
.ai-bubble.md a {
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.ai-bubble.md table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.6em 0;
  font-size: 13px;
  overflow-x: auto;
  display: block;
}
.ai-bubble.md th,
.ai-bubble.md td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
}
.ai-bubble.md th {
  background: #f5f6f7;
  font-weight: 600;
}
.ai-bubble.md hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 0.8em 0;
}
.ai-bubble.assistant {
  background: #fff;
  border: 1px solid var(--line);
  border-top-left-radius: 4px;
  box-shadow: var(--shadow-sm);
  color: var(--text);
}
.ai-bubble.user {
  background: var(--blue);
  color: #fff;
  border-top-right-radius: 4px;
  box-shadow: 0 4px 12px rgba(51, 112, 255, 0.22);
}
.ai-bubble.error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #fddad8;
  border-top-left-radius: 4px;
}
.ai-bubble.thinking {
  color: var(--muted);
  font-style: italic;
  background: transparent;
  border: 0;
  padding: 8px 4px;
  box-shadow: none;
}
.ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-left: 42px;
  margin-top: -4px;
}
.ai-chip {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), color 0.15s var(--ease), background 0.15s var(--ease);
}
.ai-chip:hover {
  border-color: #9db7ff;
  color: var(--blue);
  background: var(--blue-soft);
}
.ai-composer {
  padding: 12px 16px 16px;
  background: linear-gradient(180deg, transparent, #f7f8fa 24%);
  flex-shrink: 0;
}
.ai-composer-box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  padding: 10px 12px 10px;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.ai-composer-box:focus-within {
  border-color: #9db7ff;
  box-shadow: 0 0 0 3px rgba(51, 112, 255, 0.12), var(--shadow-md);
}
.ai-composer-box textarea {
  width: 100%;
  border: 0;
  resize: none;
  min-height: 52px;
  max-height: 160px;
  padding: 4px 4px 8px;
  font: inherit;
  outline: none;
  background: transparent;
  color: var(--text);
}
.ai-composer-box textarea::placeholder { color: #bbbfc4; }
.ai-composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.ai-composer-hint { font-size: 12px; margin: 0; }
.ai-send {
  min-width: 72px;
  border-radius: 8px;
}
.ai-input-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  background: #fff;
  align-items: end;
}
.ai-input-bar textarea {
  width: 100%;
  resize: vertical;
  min-height: 44px;
  max-height: 160px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font: inherit;
  outline: none;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.ai-input-bar textarea:focus {
  border-color: var(--blue);
  box-shadow: var(--focus-ring);
}
.ai-panel code {
  background: #f5f6f7;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.ai-fab {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 60;
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(51, 112, 255, 0.35);
  transition: background 0.15s var(--ease), transform 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.ai-fab:hover {
  background: var(--blue-hover);
  transform: translateY(-1px);
}
.ai-fab.is-open {
  background: #1f2329;
  box-shadow: 0 8px 20px rgba(31, 35, 41, 0.25);
}
.ai-dock {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(84px, calc(72px + env(safe-area-inset-bottom)));
  z-index: 61;
  width: min(380px, calc(100vw - 24px));
  height: min(520px, calc(100vh - 120px));
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: dock-in 0.2s var(--ease);
}
.ai-dock[hidden] { display: none; }
@keyframes dock-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.ai-dock-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
}
.ai-dock-head strong { display: block; font-size: 14px; }
.ai-dock-head .muted { display: block; margin: 4px 0 0; font-size: 12px; }
.ai-dock-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f7f8fa;
}
.ai-dock-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: #fff;
  align-items: end;
}
.ai-dock-form textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  font: inherit;
  resize: none;
  outline: none;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.ai-dock-form textarea:focus {
  border-color: var(--blue);
  box-shadow: var(--focus-ring);
}
.ai-dock-tip {
  padding: 0 12px 10px;
  font-size: 12px;
  color: var(--danger);
}

/* ---- Modal ---- */
.modal[hidden] { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(31, 35, 41, 0.45);
  display: grid;
  place-items: center;
  padding: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  opacity: 0;
  transition: opacity 0.18s var(--ease);
}
.modal.is-open { opacity: 1; }
.modal-panel {
  width: min(680px, 100%);
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 0;
  max-height: calc(100vh - 40px);
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  transform: translateY(8px) scale(0.98);
  transition: transform 0.2s var(--ease);
}
.modal.is-open .modal-panel {
  transform: translateY(0) scale(1);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  gap: 8px;
  flex-shrink: 0;
}
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-body {
  padding: 16px 20px 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-panel > .form-grid,
.modal-panel > .import-hint,
.modal-panel > p {
  margin-left: 20px;
  margin-right: 20px;
}
.modal-panel > .form-grid {
  margin-bottom: 20px;
  padding-bottom: 4px;
  overflow-y: auto;
}
.modal-panel > .import-hint { margin-top: 0; margin-bottom: 12px; }
.modal-panel > #edit-delete-form { display: none; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-grid label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  min-width: 0;
}
.form-grid .full { grid-column: 1 / -1; }
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---- Responsive ---- */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .stat-card.wide { grid-column: 1 / -1; }
  .gantt-wrap { grid-template-columns: 140px 1fr; --day-w: 44px; }
  .inline-form { grid-template-columns: 1fr 1fr; }
  .kanban { grid-template-columns: repeat(5, minmax(200px, 240px)); }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; height: 100%; }
  .menu-btn { display: flex; }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 45;
    background: rgba(31, 35, 41, 0.4);
  }
  .sidebar-backdrop[hidden] { display: none; }
  .sidebar {
    top: 0;
    left: 0;
    bottom: 0;
    width: min(280px, 86vw);
    z-index: 46;
    transform: translateX(-105%);
    transition: transform 0.22s var(--ease);
    box-shadow: 8px 0 24px rgba(31, 35, 41, 0.12);
    border-right: 1px solid var(--line);
    height: 100vh;
  }
  body.nav-open .sidebar { transform: translateX(0); }

  .topbar { padding: 10px 12px; }
  .main-body { padding: 12px 12px 72px; }
  .stats { margin-left: 12px; margin-right: 12px; }
  .alert { margin-left: 12px; margin-right: 12px; }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .topbar-right { justify-content: stretch; }
  .topbar-right .btn { flex: 1 1 auto; }
  .topbar h1 { font-size: 17px; }

  .stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .stat-card { padding: 12px; }
  .stat-card strong { font-size: 18px; }
  .stat-card.wide {
    grid-column: 1 / -1;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .panel { padding: 14px; border-radius: var(--radius-md); }
  .panel-head h2 { font-size: 15px; }
  .gantt-panel-head,
  .wbs-panel-head {
    flex-direction: column;
    align-items: stretch;
  }
  .gantt-legend,
  .wbs-toolbar { width: 100%; }
  .wbs-toolbar .btn { flex: 1; }

  .kanban {
    grid-auto-flow: column;
    grid-template-columns: none;
    grid-auto-columns: minmax(260px, 78vw);
    gap: 10px;
    margin: 0 -12px;
    padding: 0 12px 10px;
  }
  .kanban-col {
    min-width: 260px;
    min-height: 280px;
  }
  .kanban-list { min-height: 220px; }

  .gantt-wrap {
    grid-template-columns: 96px 1fr;
    border-radius: var(--radius-md);
    --day-w: 40px;
  }
  .gantt-label { font-size: 12px; padding: 0 6px; }
  .gantt-side-head { padding: 0 6px; font-size: 12px; }
  .gantt-day { font-size: 11px; }

  .inline-form,
  .form-grid { grid-template-columns: 1fr; }
  .child-form { grid-template-columns: 1fr; }
  .child-form .btn { width: 100%; }

  .wbs-children { padding-left: 10px; }
  .wbs-item summary {
    flex-wrap: wrap;
    gap: 6px 8px;
    padding: 10px 12px;
  }
  .wbs-progress { margin-left: 0; width: 100%; text-align: right; }
  .wbs-body { padding: 0 10px 12px; }

  .project-card-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .project-card-actions .form-actions {
    width: 100%;
    justify-content: stretch;
  }
  .project-card-actions .btn { flex: 1; text-align: center; }

  .modal { padding: 0; align-items: end; }
  .modal-panel {
    width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
  }
  .modal-head { padding: 14px 16px; }
  .modal-body,
  .modal-panel > .form-grid,
  .modal-panel > .import-hint,
  .modal-panel > p {
    margin-left: 14px;
    margin-right: 14px;
  }
  .modal-panel > .form-grid {
    margin-bottom: calc(14px + env(safe-area-inset-bottom));
  }
  .edit-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .edit-actions .form-actions {
    width: 100%;
    justify-content: stretch;
  }
  .edit-actions .btn,
  .form-actions .btn {
    flex: 1;
    text-align: center;
  }

  .btn {
    min-height: 36px;
    height: auto;
    padding: 8px 12px;
  }
  .btn-sm {
    min-height: 32px;
    height: auto;
  }
}

@media (max-width: 480px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .topbar-right .btn.ghost {
    order: 3;
    flex: 1 1 100%;
  }
  .kanban { grid-auto-columns: minmax(240px, 85vw); }
  .gantt-wrap {
    grid-template-columns: 72px 1fr;
    --day-w: 36px;
  }
  .gantt-label {
    height: 40px;
    font-size: 11px;
    padding: 0 4px;
  }
  .gantt-side-head {
    height: 36px;
    font-size: 11px;
    padding: 0 4px;
  }
  .gantt-days { height: 36px; }
  .gantt-row { height: 40px; }
  .gantt-bar { top: 8px; height: 22px; font-size: 11px; }
  .bar-text { padding: 0 4px; font-size: 11px; }
  .import-hint { font-size: 12px; line-height: 1.6; }
  .brand-sub { display: none; }
  .material-browse-layout {
    grid-template-columns: 1fr;
    min-height: 0;
  }
  .material-side-list {
    max-height: 160px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .material-task-panel { min-height: calc(100vh - 150px); }
  .material-task-title { max-width: 46vw; }
  .material-frame-wrap,
  .material-frame {
    min-height: calc(100vh - 240px);
  }
  .material-file-actions { width: 100%; }
  .material-file-actions .btn,
  .material-file-actions form { flex: 1; }
  .material-file-actions .btn { text-align: center; }
  .workbench-hero-main { grid-template-columns: 1fr; }
  .workbench-hero-progress {
    justify-items: start;
    width: 100%;
  }
  .workbench-hero-progress .progress-track { width: 100%; }
  .workbench-quick { width: 100%; }
  .workbench-quick .btn { flex: 1; text-align: center; }
  .ai-panel { min-height: calc(100vh - 140px); }
  .ai-shell-head { padding: 12px 14px; }
  .ai-messages { min-height: 240px; padding: 16px 12px 8px; }
  .ai-suggestions { padding-left: 0; }
  .ai-composer { padding: 10px 12px 14px; }
  .ai-composer-hint { display: none; }
  .ai-send { flex: 1; }
  .ai-dock {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: max(80px, calc(68px + env(safe-area-inset-bottom)));
    height: min(60vh, 480px);
  }
  .ai-dock-form { grid-template-columns: 1fr; }
  .ai-dock-form .btn { width: 100%; }
  .toast-host {
    left: 12px;
    right: 12px;
    max-width: none;
  }
}

@supports (padding: max(0px)) {
  .main-body {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  @media (max-width: 900px) {
    .main-body {
      padding-bottom: max(72px, calc(24px + env(safe-area-inset-bottom)));
    }
  }
}
