:root {
  color-scheme: light;
  --bg: #111315;
  --page: #edf2f0;
  --surface: #fffdf8;
  --surface-2: #f7f1ea;
  --surface-3: #e7eef5;
  --text: #171716;
  --muted: #706b64;
  --line: #d9d6ce;
  --brand: #0f766e;
  --blue: #2f80ed;
  --green: #16a34a;
  --amber: #d89516;
  --red: #dc2626;
  --violet: #7c3aed;
  --shadow: 0 16px 36px rgba(22, 22, 18, 0.12);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100vh;
}

body {
  background: var(--bg);
  color: var(--text);
}

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

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(100%, 1180px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px calc(96px + env(safe-area-inset-bottom));
  background:
    linear-gradient(180deg, #111315 0, #111315 160px, var(--page) 160px, var(--page) 100%);
}

.topbar,
.brand-lockup,
.topbar-actions,
.section-title,
.section-actions,
.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0 18px;
}

.brand-lockup {
  min-width: 0;
  gap: 12px;
  color: #fffdf8;
}

.app-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
}

.brand-lockup strong {
  display: block;
  font-size: clamp(20px, 3vw, 28px);
  font-weight: 900;
  letter-spacing: 0;
}

.brand-lockup span {
  display: block;
  margin-top: 2px;
  color: rgba(255, 253, 248, 0.68);
  font-size: 12px;
}

.topbar-actions {
  gap: 8px;
}

.icon-button,
.text-button,
.action-tile,
.primary-button,
.secondary-button,
.danger-button,
.mini-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 8px;
  font-weight: 800;
  letter-spacing: 0;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 253, 248, 0.12);
  background: rgba(255, 253, 248, 0.1);
  color: #fffdf8;
}

.icon-button svg,
.text-button svg,
.action-tile svg,
.primary-button svg,
.secondary-button svg,
.danger-button svg,
.mini-button svg,
.nav-item svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.4;
}

.command-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 253, 248, 0.1);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.action-tile {
  min-height: 64px;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
}

.action-tile input,
.file-button input {
  display: none;
}

.sync-strip {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 12px 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #1f2937;
  color: #f9fafb;
  font-size: 12px;
  font-weight: 800;
}

.update-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0;
  padding: 12px;
  border: 1px solid rgba(216, 149, 22, 0.34);
  border-radius: 8px;
  background: #fff7df;
  box-shadow: var(--shadow);
}

.update-notice[hidden] {
  display: none !important;
}

.update-notice strong {
  display: block;
  font-size: 14px;
}

.update-notice p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.stat-card {
  min-height: 86px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-align: left;
}

.stat-card strong {
  display: block;
  font-size: 28px;
  line-height: 1;
}

.stat-card span {
  display: block;
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stat-card.warning {
  border-color: rgba(216, 149, 22, 0.45);
  background: #fff7df;
}

.stat-card.danger {
  border-color: rgba(220, 38, 38, 0.35);
  background: #fff1f1;
}

.stat-card.done {
  border-color: rgba(22, 163, 74, 0.35);
  background: #eefbf2;
}

.filter-panel,
.content-view,
.analytics-panel,
.report-preview,
.milestone-summary,
.summary-card,
.project-card,
.person-card,
.department-card,
.stage-card,
.milestone-card,
.risk-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.filter-panel {
  margin: 12px 0;
  padding: 12px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
}

.filter-grid,
.analytics-controls,
.form-grid {
  display: grid;
  gap: 10px;
}

.filter-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin-top: 10px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: 0;
  padding: 10px 11px;
}

textarea {
  resize: vertical;
}

.content-view {
  display: none;
  padding: 14px;
}

.content-view.active {
  display: block;
}

.section-title {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title h2,
.section-title h3 {
  margin: 0;
  font-size: 18px;
}

.compact-title {
  margin-top: 16px;
  margin-bottom: 8px;
}

.section-actions {
  flex-wrap: wrap;
  gap: 8px;
}

.text-button,
.mini-button {
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font-size: 12px;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 42px;
  padding: 10px 14px;
}

.primary-button {
  background: var(--brand);
  color: #fff;
}

.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
}

.danger-button {
  background: #fff1f1;
  color: var(--red);
}

.project-list,
.people-list,
.milestone-list,
.risk-list,
.log-list,
.attachment-list,
.department-project-list,
.person-project-list {
  display: grid;
  gap: 10px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.summary-card {
  padding: 13px;
}

.summary-card header,
.department-card header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.summary-card strong {
  display: block;
  font-size: 24px;
}

.summary-card p,
.summary-card small {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.project-card {
  padding: 13px;
}

.project-card header,
.person-card header,
.milestone-card header,
.risk-card header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.project-card h3,
.person-card h3,
.milestone-card h3,
.risk-card h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.35;
}

.project-card p,
.person-card p,
.milestone-card p,
.risk-card p,
.department-card p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.badge-row,
.card-actions,
.meta-grid,
.person-stats,
.analytics-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.badge-row {
  margin-top: 10px;
}

.status-badge,
.risk-badge,
.stage-badge,
.meta-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef2f7;
  color: #253040;
  font-size: 12px;
  font-weight: 900;
}

.risk-high {
  background: #fee2e2;
  color: #991b1b;
}

.risk-medium {
  background: #fef3c7;
  color: #92400e;
}

.risk-low {
  background: #dcfce7;
  color: #166534;
}

.status-delay,
.status-paused {
  background: #fee2e2;
  color: #991b1b;
}

.status-complete {
  background: #dcfce7;
  color: #166534;
}

.meta-grid {
  margin-top: 12px;
}

.meta-pill {
  border-radius: 8px;
  background: var(--surface-2);
}

.card-actions {
  margin-top: 12px;
}

.kanban {
  display: grid;
  grid-template-columns: repeat(6, minmax(210px, 1fr));
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
}

.stage-card {
  min-width: 210px;
  padding: 10px;
  background: #f9fafb;
}

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

.stage-card h3 {
  margin: 0;
  font-size: 14px;
}

.stage-card .project-card {
  margin-top: 8px;
  background: #fff;
}

.department-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.department-card,
.person-card,
.milestone-card,
.risk-card {
  padding: 13px;
}

.department-card strong {
  display: block;
  font-size: 24px;
}

.department-project-list,
.person-project-list {
  margin-top: 10px;
}

.mini-project-row {
  display: grid;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.mini-project-row strong {
  font-size: 13px;
}

.mini-project-row span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.person-stats {
  margin-top: 10px;
}

.person-stats span {
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.milestone-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  margin-bottom: 12px;
}

.analytics-panel {
  padding: 12px;
}

.analytics-controls {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 12px;
}

.analytics-panel canvas {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.analytics-legend {
  margin-top: 10px;
}

.analytics-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 800;
}

.analytics-legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.report-preview,
.report-text {
  margin: 12px 0 0;
  padding: 12px;
  white-space: pre-wrap;
  color: #292524;
  font-size: 13px;
  line-height: 1.6;
}

.sheet-dialog {
  width: min(94vw, 860px);
  max-height: 92vh;
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.small-dialog {
  width: min(94vw, 460px);
}

.sheet-dialog::backdrop {
  background: rgba(17, 19, 21, 0.58);
}

.sheet-dialog form,
.sheet-dialog > div,
.sheet-dialog > pre {
  margin: 0;
}

.dialog-header {
  position: sticky;
  top: 0;
  z-index: 1;
  justify-content: space-between;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.dialog-header h3 {
  margin: 0;
}

.dialog-header .icon-button {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

.form-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 14px;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.attachment-panel,
.log-panel {
  padding: 0 14px 14px;
}

.attachment-item,
.log-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.attachment-item strong,
.log-item strong {
  display: block;
  font-size: 13px;
}

.attachment-item span,
.log-item span {
  color: var(--muted);
  font-size: 12px;
}

.dialog-actions {
  position: sticky;
  bottom: 0;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.settings-panel,
.share-fallback-body {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.settings-panel {
  margin: 0 14px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.settings-panel strong {
  font-size: 14px;
}

.settings-panel p,
.share-fallback-body p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.compact-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.share-fallback-body textarea {
  min-height: 150px;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 5;
  display: grid;
  width: min(100%, 1180px);
  grid-template-columns: repeat(5, 1fr);
  transform: translateX(-50%);
  border-top: 1px solid rgba(17, 19, 21, 0.14);
  background: rgba(255, 253, 248, 0.96);
  backdrop-filter: blur(14px);
}

.nav-item {
  display: grid;
  min-height: calc(64px + env(safe-area-inset-bottom));
  padding: 8px 4px max(8px, env(safe-area-inset-bottom));
  place-items: center;
  gap: 2px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.nav-item.active {
  color: var(--brand);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: min(92vw, 460px);
  transform: translateX(-50%);
  padding: 11px 14px;
  border-radius: 8px;
  background: #111315;
  color: #fffdf8;
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 800;
}

.empty-state {
  padding: 20px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  text-align: center;
  font-weight: 800;
}

@media (max-width: 920px) {
  .app-shell {
    width: min(100%, 540px);
    padding-inline: 14px;
    background:
      linear-gradient(180deg, #111315 0, #111315 142px, var(--page) 142px, var(--page) 100%);
  }

  .command-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-grid,
  .analytics-controls,
  .form-grid,
  .department-board,
  .summary-grid,
  .milestone-summary {
    grid-template-columns: 1fr;
  }

  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .update-notice {
    align-items: stretch;
    flex-direction: column;
  }

  .kanban {
    grid-template-columns: repeat(6, 84%);
  }
}

@media (max-width: 420px) {
  .brand-lockup strong {
    font-size: 18px;
  }

  .topbar-actions {
    gap: 5px;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .action-tile {
    min-height: 58px;
    font-size: 13px;
  }
}
