:root {
  --navy: #2A2E70;
  --navy-dark: #1E2154;
  --green: #6BAC2A;
  --orange: #F78F1E;
  --bg: #F7F7FA;
  --card: #ffffff;
  --border: #E2E4EE;
  --text: #22243A;
  --text-muted: #666A80;
  --danger: #C0392B;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#topbar {
  background: var(--navy);
  color: white;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  height: 56px;
}
.brand { color: white; font-weight: 700; text-decoration: none; font-size: 18px; letter-spacing: 0.5px; }
#main-nav { display: flex; gap: 4px; flex: 1; }
#main-nav a {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
}
#main-nav a:hover, #main-nav a.active { background: rgba(255,255,255,0.15); color: white; }
.nav-divider { width: 1px; align-self: stretch; margin: 10px 4px; background: rgba(255,255,255,0.25); }
#main-nav a.nav-standalone { background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.25); }
#main-nav a.nav-standalone:hover, #main-nav a.nav-standalone.active { background: rgba(255,255,255,0.25); border-color: rgba(255,255,255,0.4); }
#user-box { font-size: 13px; color: rgba(255,255,255,0.85); display: flex; align-items: center; gap: 10px; }
#user-box button { background: transparent; border: 1px solid rgba(255,255,255,0.4); color: white; padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; }
#user-box button:hover { border-color: white; }

main#app { max-width: 1400px; margin: 0 auto; padding: 24px 20px 60px; }

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.subtitle { color: var(--text-muted); margin: 0 0 20px; font-size: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
}

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  color: var(--text);
}
textarea { width: 100%; resize: vertical; }
label { font-size: 12px; color: var(--text-muted); display: block; margin-bottom: 4px; }
.field { margin-bottom: 12px; }

button.btn {
  font-family: inherit;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--navy);
  background: var(--navy);
  color: white;
  cursor: pointer;
}
button.btn:hover { background: var(--navy-dark); }
button.btn.secondary { background: white; color: var(--navy); }
button.btn.secondary:hover { background: #EEF0FA; }
button.btn.danger { background: white; color: var(--danger); border-color: var(--danger); }
button.btn.danger:hover { background: #FDECEA; }
button.btn.small { padding: 4px 9px; font-size: 12px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
tr:hover td { background: #FAFAFD; }
a.row-link { color: var(--navy); text-decoration: none; font-weight: 600; }
a.row-link:hover { text-decoration: underline; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.status-awaiting_previous { background: #EDEEF4; color: #55597A; }
.badge.status-open_to_start { background: #E7F0FF; color: #2456B0; }
.badge.status-in_progress { background: #FFF3D9; color: #9A6A00; }
.badge.status-pending_approval { background: #F3E8FF; color: #6E2FB0; }
.badge.status-completed { background: #E4F6E0; color: #2E7D22; }
.badge.status-inactive_branch { background: #F0F0F0; color: #9A9A9A; }
.badge.lifecycle-active { background: #E4F6E0; color: #2E7D22; }
.badge.lifecycle-archived { background: #F0F0F0; color: #777; }
.badge.lifecycle-rejected_ended { background: #FDECEA; color: var(--danger); }
.badge.lifecycle-completed { background: #E7F0FF; color: #2456B0; }
.badge.timeline-on_track { background: #E4F6E0; color: #2E7D22; }
.badge.timeline-due_soon { background: #FFF3D9; color: #9A6A00; }
.badge.timeline-overdue { background: #FDECEA; color: var(--danger); }
.badge.role { background: #EEF0FA; color: var(--navy); }

.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-tile { background: white; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.stat-tile .value { font-size: 24px; font-weight: 700; color: var(--navy); }
.stat-tile .label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.stat-columns { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.stat-columns .card { flex: 1 1 220px; min-width: 220px; }
.stat-list { display: flex; flex-direction: column; }
.stat-list-row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 2px; border-bottom: 1px solid var(--border); font-size: 14px; }
.stat-list-row:last-child { border-bottom: none; }
.stat-list-row .label { color: var(--text-muted); }
.stat-list-row .value { font-weight: 600; color: var(--navy); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button { background: none; border: none; padding: 10px 14px; font-size: 14px; cursor: pointer; color: var(--text-muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--navy); border-color: var(--navy); font-weight: 600; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.error-banner { background: #FDECEA; color: var(--danger); padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; }
.notice-banner { background: #E7F0FF; color: #2456B0; padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; }

.workflow-scroll { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: white; }

/* Gantt view */
.gantt-top-scroll { overflow-x: auto; overflow-y: hidden; height: 16px; margin-bottom: -1px; }
.gantt-top-scroll-spacer { height: 1px; }
.gantt-wrap { border: 1px solid var(--border); border-radius: var(--radius); background: white; overflow-x: auto; position: relative; }
.gantt-row {
  display: grid;
  grid-template-columns: 260px 100px 130px 130px var(--gantt-track-w, 1fr);
  align-items: center;
  min-width: 820px;
  border-bottom: 1px solid var(--border);
}
.gantt-row.header-row {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted);
  font-weight: 600; background: #FAFAFD; position: sticky; top: 0; z-index: 4;
}
.gantt-cell { padding: 8px 10px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gantt-cell.name a { color: var(--text); text-decoration: none; font-weight: 500; }
/* Each phase is a bordered box (gantt-strip-wrap.phase-group) with a vertical
   side label running its full height, built as a flex row: a fixed-width
   label strip + a column of ordinary step rows. Header/ruler rows reuse the
   same wrapper with a blank, unlabeled strip so every row's columns - phase
   label aside - line up in the same place. */
.gantt-strip-wrap { display: flex; align-items: stretch; }
.gantt-strip-wrap > .gantt-row { flex: 1 1 auto; min-width: 0; }
/* No overflow:hidden here deliberately - it would become the sticky
   containing block for the label strip below instead of the real scrolling
   ancestor (.gantt-wrap), freezing the label in place rather than letting it
   track horizontal scroll. The corner radius just won't clip the strip's
   square corners, a minor cosmetic trade-off. */
.gantt-strip-wrap.phase-group { border: 2px solid; border-radius: 8px; margin: 8px 0; }
.gantt-strip-rows { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.gantt-strip {
  flex: 0 0 28px; position: sticky; left: 0; z-index: 4;
  display: flex; align-items: center; justify-content: center;
}
.gantt-strip.blank { background: #FAFAFD; }
.gantt-strip.phase-label {
  color: white; font-weight: 700; font-size: 12px; letter-spacing: 0.3px;
  writing-mode: vertical-rl; transform: rotate(180deg); padding: 10px 0; white-space: nowrap;
}
/* Zoom mode gives the timeline column an explicit pixel width wider than the
   viewport, so the label columns are pinned (sticky) while only the timeline
   scrolls underneath them - like a spreadsheet's frozen columns. The 28px
   offset accounts for the strip every row now sits to the right of. */
.gantt-cell:nth-child(1) { position: sticky; left: 28px; z-index: 3; background: white; }
.gantt-cell:nth-child(2) { position: sticky; left: 288px; z-index: 3; background: white; }
.gantt-cell:nth-child(3) { position: sticky; left: 388px; z-index: 3; background: white; }
.gantt-cell:nth-child(4) { position: sticky; left: 518px; z-index: 3; background: white; }
.header-row .gantt-cell, .ruler-row .gantt-cell { background: #FAFAFD; }
.gantt-zoom-controls { display: flex; gap: 4px; align-items: center; margin-left: auto; }
.gantt-zoom-controls button { padding: 3px 9px; font-size: 13px; border: 1px solid var(--border); background: white; border-radius: 5px; cursor: pointer; }
.gantt-zoom-controls button:hover { background: #F2F2F6; }
.gantt-zoom-label { font-size: 11px; color: var(--text-muted); min-width: 46px; text-align: center; }
.gantt-cell.name a:hover { color: var(--navy); text-decoration: underline; }
.gantt-track { position: relative; height: 32px; margin: 4px 10px 4px 0; background: repeating-linear-gradient(90deg, #F2F2F6 0, #F2F2F6 1px, transparent 1px, transparent 12.5%); border-radius: 4px; }
.gantt-bar { position: absolute; top: 6px; height: 20px; border-radius: 4px; display: flex; align-items: center; justify-content: center; min-width: 6px; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08); color: #fff; font-size: 11px; line-height: 1; overflow: hidden; text-shadow: 0 0 2px rgba(0,0,0,0.5); }
.team-chip {
  display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px;
  border-radius: 50%; color: #fff; font-size: 10px; line-height: 1; margin-right: 6px; flex-shrink: 0;
  text-shadow: 0 0 2px rgba(0,0,0,0.5);
}
.gantt-bar.pending { opacity: 0.55; background-image: repeating-linear-gradient(45deg, rgba(255,255,255,0.35) 0 4px, transparent 4px 8px); }
.gantt-bar.overdue { box-shadow: inset 0 0 0 2px var(--danger); }
.gantt-today-line { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--danger); opacity: 0.6; }
.gantt-legend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-size: 12px; }
.gantt-legend .swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }
.gantt-marker {
  position: absolute; top: 50%; width: 11px; height: 11px; margin-left: -5px; margin-top: -5px;
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); opacity: 0.6;
}
.gantt-marker.overdue { box-shadow: 0 0 0 2px var(--danger); }
.gantt-row.ruler-row { background: #FAFAFD; }
.gantt-ruler-track { position: relative; height: 30px; margin: 0 10px 0 0; }
.gantt-tick { position: absolute; top: 0; bottom: 0; width: 1px; background: #E2E4EE; }
.gantt-tick.major { background: #C5C8DC; }
.gantt-tick-label {
  position: absolute; top: 50%; transform: translate(-50%, -50%); white-space: nowrap;
  font-size: 10px; color: var(--text-muted);
}
.gantt-tick-label.major { font-weight: 700; color: var(--text); font-size: 11px; }
.wf-node { fill: white; stroke: var(--navy); stroke-width: 1.5; rx: 8; }
.wf-node.gate { fill: #FFF3D9; stroke: var(--orange); }
.wf-node.completed { fill: #E4F6E0; stroke: var(--green); }
.wf-node.inactive { fill: #F0F0F0; stroke: #ccc; }
.wf-node-label { font-size: 11px; fill: var(--text); }
.wf-edge { stroke: #9AA0C0; stroke-width: 1.5; fill: none; }
.wf-edge.approved_branch { stroke: var(--green); }
.wf-edge.rejected_branch { stroke: var(--danger); stroke-dasharray: 4 2; }
.wf-edge.return_for_revision { stroke: var(--orange); stroke-dasharray: 2 2; }
.wf-edge.inactive-edge { opacity: 0.25; }

.pill-list { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { background: #EEF0FA; color: var(--navy); border-radius: 100px; padding: 3px 10px; font-size: 12px; display: flex; align-items: center; gap: 6px; }
.pill button { border: none; background: none; cursor: pointer; color: var(--text-muted); font-size: 12px; padding: 0; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,22,50,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal { background: white; border-radius: var(--radius); padding: 20px; width: 480px; max-width: 92vw; max-height: 86vh; overflow: auto; }
.modal.modal-fullscreen { width: 96vw; max-width: 96vw; height: 94vh; max-height: 94vh; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.login-screen { display: flex; align-items: center; justify-content: center; min-height: 70vh; }
.login-card { text-align: center; padding: 40px; }
.login-card h1 { margin-bottom: 6px; }
