:root {
  color-scheme: light;
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-2: #eef3f2;
  --ink: #172026;
  --muted: #66727b;
  --line: #d8dee3;
  --line-strong: #b8c2cc;
  --accent: #0f766e;
  --accent-2: #2563eb;
  --critical: #c2413a;
  --critical-dark: #8f2925;
  --warn: #a86412;
  --good: #257a45;
  --blocked: #7c3aed;
  --row: #f9fbfc;
  --shadow: 0 10px 24px rgba(29, 42, 53, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden],
.is-hidden {
  display: none !important;
}

html,
body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
.file-button {
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #ffffff;
  min-height: 32px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
  white-space: nowrap;
  font-size: 14px;
}

button:hover,
.file-button:hover {
  filter: brightness(0.97);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

svg {
  width: 15px;
  height: 15px;
  flex: 0 0 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.ghost-button,
.tab-button {
  background: #ffffff;
  color: var(--ink);
  border-color: var(--line);
}

.ghost-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.danger-button {
  background: #ffffff;
  color: var(--critical);
  border-color: #e8b7b1;
}

.app-shell {
  width: min(1580px, 100%);
  margin: 0 auto;
  padding: 7px 10px 10px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 48px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 260px;
  min-width: 0;
}

.brand > div {
  min-width: 0;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #17443f;
  color: #ffffff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 20px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 19px;
  line-height: 1.2;
}

h2 {
  font-size: 15px;
  line-height: 1.2;
  margin-bottom: 10px;
}

.brand p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar {
  display: flex;
  flex: 0 1 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
}

.toolbar button,
.toolbar .file-button {
  min-height: 30px;
  padding: 0 8px;
  font-size: 13px;
}

.toolbar-check {
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  font-size: 13px;
}

.toolbar-check input {
  width: auto;
  min-height: 0;
  padding: 0;
}

.project-strip,
.metrics-grid,
.workspace {
  margin-top: 7px;
}

.project-strip {
  display: grid;
  grid-template-columns: minmax(210px, 1.25fr) minmax(118px, 0.42fr) minmax(118px, 0.42fr) minmax(86px, 0.3fr) minmax(132px, 0.48fr) minmax(145px, 0.55fr);
  gap: 6px;
  align-items: end;
}

label {
  color: var(--muted);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  min-height: 30px;
  padding: 4px 8px;
}

textarea {
  min-height: 78px;
  resize: vertical;
}

.server-status {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--muted);
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-size: 12px;
}

.server-status.ok {
  color: var(--good);
  border-color: #b8dac8;
  background: #f0faf4;
}

.server-status.offline {
  color: var(--warn);
  border-color: #ead3aa;
  background: #fff8ec;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(96px, 1fr));
  gap: 6px;
}

.metric-card {
  min-height: 48px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  box-shadow: var(--shadow);
}

.metric-card span {
  color: var(--muted);
  font-size: 11px;
}

.metric-card strong {
  font-size: 18px;
  line-height: 1.1;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

body.side-panel-open .workspace {
  grid-template-columns: minmax(0, 1fr) 330px;
}

.main-panel,
.side-panel,
.side-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.main-panel {
  min-width: 0;
  overflow: hidden;
}

.side-panel {
  padding: 10px;
  display: none;
  gap: 10px;
  background: #f9fbfc;
}

body.side-panel-open .side-panel {
  display: grid;
}

.side-section {
  padding: 12px;
  box-shadow: none;
}

.tabs {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-bottom: 1px solid var(--line);
  background: #f8fafb;
}

.tab-button {
  min-height: 30px;
  padding: 0 12px;
}

.tab-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.tab-page {
  display: none;
  min-height: 0;
}

.tab-page.active {
  display: block;
}

.panel-tools {
  min-height: 42px;
  padding: 6px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  border-bottom: 1px solid var(--line);
}

.panel-tools input[type="search"] {
  max-width: 220px;
}

.panel-tools select {
  max-width: 130px;
}

.panel-tools button {
  min-height: 30px;
  padding: 0 8px;
  font-size: 12px;
}

.icon-only-button {
  min-width: 32px;
  width: 32px;
  padding: 0;
}

.replace-tools {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  flex: 0 1 270px;
  min-width: 270px;
}

.replace-tools input {
  flex: 1 1 0;
  min-width: 88px;
  width: auto;
}

.replace-tools button {
  flex: 0 0 auto;
}

.table-wrap {
  max-height: clamp(340px, calc(100vh - 315px), 640px);
  overflow: auto;
}

.top-scroll {
  height: 18px;
  overflow-x: auto;
  overflow-y: hidden;
  border-bottom: 1px solid var(--line);
  background: #f8fafb;
}

.top-scroll > div {
  height: 1px;
}

table {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  width: auto;
  min-width: 1380px;
  font-size: 12px;
}

body.detail-columns-open table {
  min-width: 1650px;
}

body:not(.detail-columns-open) .detail-col {
  display: none;
}

body:not(.estimate-columns-open) .estimate-col {
  display: none;
}

body:not(.estimate-columns-open) col.estimate-col {
  width: 0 !important;
  min-width: 0 !important;
  max-width: 0 !important;
}

th,
td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 5px;
  vertical-align: middle;
  background: #ffffff;
  overflow: hidden;
}

th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #e9eff2;
  color: #24313b;
  font-weight: 700;
  text-align: left;
  height: 34px;
  white-space: nowrap;
  text-overflow: ellipsis;
  user-select: none;
}

.column-resizer {
  position: absolute;
  top: 0;
  right: -4px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
  z-index: 5;
}

.column-resizer::after {
  content: "";
  position: absolute;
  top: 7px;
  bottom: 7px;
  left: 3px;
  width: 2px;
  border-radius: 999px;
  background: transparent;
}

.column-resizer:hover::after,
body.resizing-column .column-resizer::after {
  background: var(--accent-2);
}

body.resizing-column {
  cursor: col-resize;
  user-select: none;
}

tr:nth-child(even) td {
  background: var(--row);
}

tr.selected td {
  background: #eaf3ff;
}

tr.critical-row td:first-child {
  border-left: 4px solid var(--critical);
}

td input,
td select,
td textarea {
  min-height: 28px;
  padding: 3px 6px;
  border-color: transparent;
  background: transparent;
}

td input:focus,
td select:focus,
td textarea:focus {
  border-color: var(--accent-2);
  background: #ffffff;
  outline: none;
}

.task-id-cell {
  width: 78px;
}

.section-cell {
  width: 116px;
}

.activity-cell {
  width: 380px;
  vertical-align: top;
}

.activity-input {
  display: block;
  min-height: 32px;
  line-height: 1.35;
  resize: none;
  overflow: hidden;
  white-space: normal;
  word-break: break-word;
}

.owner-cell {
  width: 112px;
}

.pred-cell {
  width: 96px;
}

.number-cell {
  width: 68px;
}

.duration-input {
  text-align: center;
}

.date-cell {
  width: 122px;
}

.status-cell {
  width: 132px;
}

.progress-cell {
  width: 98px;
}

.notes-cell {
  width: 220px;
}

.task-id-cell,
.section-cell,
.activity-cell,
.owner-cell,
.pred-cell,
.number-cell,
.date-cell,
.status-cell,
.progress-cell,
.notes-cell {
  width: auto;
  min-width: 0;
}

.readonly-value {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 6px;
  color: #2b3740;
}

.critical-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 700;
}

.critical-pill {
  color: #ffffff;
  background: var(--critical);
}

.critical-pill.float {
  color: var(--muted);
  background: #edf1f4;
}

.status-pill.not-started {
  background: #edf1f4;
  color: #42515c;
}

.status-pill.in-progress {
  background: #e8f1ff;
  color: #1d56a9;
}

.status-pill.blocked {
  background: #efe7ff;
  color: #6d28d9;
}

.status-pill.delayed {
  background: #fff0df;
  color: #a3500f;
}

.status-pill.complete {
  background: #e7f6ed;
  color: #237246;
}

.row-action {
  width: 34px;
  min-width: 34px;
  min-height: 28px;
  padding: 0;
}

.gantt {
  overflow: auto;
  min-height: 590px;
  background: #ffffff;
}

.gantt-empty,
.empty-state {
  min-height: 120px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 18px;
}

.gantt-grid {
  display: grid;
  grid-template-columns: 300px 1fr;
  min-width: 900px;
}

.gantt-label-header,
.gantt-date-header {
  position: sticky;
  top: 0;
  z-index: 4;
  min-height: 42px;
  background: #e9eff2;
  border-bottom: 1px solid var(--line);
}

.gantt-label-header {
  left: 0;
  padding: 10px;
  font-weight: 700;
  border-right: 1px solid var(--line);
}

.gantt-date-header {
  display: flex;
  overflow: hidden;
}

.gantt-date-cell {
  flex: 0 0 var(--unit-width);
  border-right: 1px solid #dce3e8;
  padding-top: 4px;
  text-align: center;
  font-size: 11px;
  color: #41505c;
}

.gantt-row-label,
.gantt-row-line {
  min-height: 38px;
  border-bottom: 1px solid var(--line);
}

.gantt-row-label {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #ffffff;
  border-right: 1px solid var(--line);
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.gantt-row-label strong {
  font-size: 12px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gantt-row-label span {
  color: var(--muted);
  font-size: 11px;
}

.gantt-row-line {
  position: relative;
  min-width: var(--timeline-width);
  background-image: linear-gradient(to right, #eef2f4 1px, transparent 1px);
  background-size: var(--unit-width) 100%;
}

.gantt-bar {
  position: absolute;
  top: 8px;
  height: 20px;
  border-radius: 5px;
  background: var(--accent-2);
  border: 1px solid rgba(0, 0, 0, 0.12);
  overflow: hidden;
}

.gantt-bar.critical {
  background: var(--critical);
}

.gantt-bar.complete {
  background: var(--good);
}

.gantt-bar.blocked {
  background: var(--blocked);
}

.gantt-progress {
  height: 100%;
  background: rgba(255, 255, 255, 0.33);
}

.today-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #101820;
  opacity: 0.45;
}

.critical-layout,
.tracking-grid {
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(280px, 0.45fr) minmax(0, 1fr);
  gap: 14px;
}

.path-list,
.compact-list,
.analysis-notes,
.saved-projects {
  display: grid;
  gap: 8px;
}

.path-step,
.list-row,
.saved-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #ffffff;
}

.saved-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.saved-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.saved-actions button {
  min-height: 30px;
  padding: 0 8px;
}

.revision-block {
  border-top: 1px solid var(--line);
  margin-top: 12px;
  padding-top: 10px;
}

.revision-heading {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 8px;
}

.revision-heading strong {
  font-size: 13px;
}

.revision-heading span {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.revision-row {
  background: #fbfcfd;
}

.path-step {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 8px;
  align-items: center;
}

.path-step .badge {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: var(--critical);
  color: #ffffff;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.list-row strong,
.path-step strong,
.saved-row strong {
  display: block;
  font-size: 13px;
}

.list-row span,
.path-step span,
.saved-row span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.network-view {
  position: relative;
  min-height: 460px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.network-canvas {
  position: relative;
  min-width: 780px;
  min-height: 430px;
}

.network-canvas svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.network-node {
  position: absolute;
  width: 154px;
  min-height: 58px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  padding: 8px;
  box-shadow: 0 4px 12px rgba(29, 42, 53, 0.08);
}

.network-node.critical {
  border-color: var(--critical);
  box-shadow: 0 0 0 2px rgba(194, 65, 58, 0.16);
}

.network-node strong {
  display: block;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.network-node span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-top: 3px;
}

.selected-task {
  display: grid;
  gap: 8px;
}

.selected-task.empty-state {
  display: flex;
}

.task-detail-summary {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: #f8fafb;
}

.task-detail-summary strong {
  font-size: 13px;
  line-height: 1.25;
}

.task-detail-summary span {
  color: var(--muted);
  font-size: 12px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

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

.saved-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.saved-row button {
  min-height: 30px;
  padding: 0 9px;
}

.analysis-notes .note {
  border-left: 4px solid var(--accent-2);
  padding: 8px 9px;
  background: #f4f8ff;
  border-radius: 6px;
  color: #26333c;
  font-size: 12px;
}

.analysis-notes .note.warn {
  border-left-color: var(--warn);
  background: #fff8ec;
}

.analysis-notes .note.bad {
  border-left-color: var(--critical);
  background: #fff1ef;
}

.toast {
  position: fixed;
  right: 14px;
  bottom: 14px;
  max-width: min(420px, calc(100vw - 28px));
  background: #14212b;
  color: #ffffff;
  border-radius: 8px;
  padding: 11px 13px;
  box-shadow: 0 12px 30px rgba(16, 24, 33, 0.2);
  font-size: 13px;
  z-index: 20;
}

@media (max-width: 1180px) {
  .topbar,
  .workspace {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    justify-content: flex-start;
  }

  .brand {
    flex: 0 0 auto;
    width: 100%;
  }

  .toolbar {
    justify-content: flex-start;
  }

  .project-strip {
    grid-template-columns: minmax(180px, 1.2fr) minmax(108px, 0.45fr) minmax(108px, 0.45fr) minmax(78px, 0.32fr) minmax(124px, 0.55fr) minmax(130px, 0.6fr);
  }

  .metrics-grid {
    grid-template-columns: repeat(6, minmax(86px, 1fr));
  }
}

@media (max-width: 900px) {
  .project-strip {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }

  .metrics-grid {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 8px;
  }

  .toolbar,
  .panel-tools {
    align-items: stretch;
  }

  .toolbar button,
  .toolbar .file-button,
  .toolbar .toolbar-check,
  .panel-tools button,
  .panel-tools select,
  .panel-tools input {
    flex: 1 1 150px;
  }

  .project-strip,
  .metrics-grid,
  .critical-layout,
  .tracking-grid,
  .field-grid {
    grid-template-columns: 1fr;
  }

  .tabs {
    overflow-x: auto;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }
}
