:root {
  color-scheme: light;
  --bg: #f0f5f4;
  --panel: #ffffff;
  --panel-hover: #f6fbf9;
  --ink: #1a2e35;
  --muted: #5a6b75;
  --line: #dce4e6;
  --line-strong: #b8c6ca;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --teal-light: #e8f5f3;
  --blue: #2563eb;
  --blue-light: #eef4ff;
  --amber: #d97706;
  --amber-light: #fffbeb;
  --red: #dc2626;
  --red-light: #fef2f2;
  --green: #15803d;
  --green-light: #f0fdf4;
  --violet: #6d28d9;
  --violet-light: #f5f3ff;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 12px 32px rgba(26, 46, 53, 0.07);
  --shadow-lg: 0 24px 64px rgba(26, 46, 53, 0.12);
  --transition: 180ms cubic-bezier(0.22, 1, 0.36, 1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

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

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

/* ========== TOPBAR ========== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  gap: 16px;
  align-items: center;
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

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

.brand-mark {
  display: inline-grid; width: 38px; height: 38px; place-items: center;
  background: linear-gradient(135deg, #0f766e, #0d9488);
  color: #fff; border-radius: var(--radius-sm); font-weight: 800; font-size: 13px;
}

.brand h1 { margin: 0; font-size: 17px; line-height: 1.2; font-weight: 700; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 12px; line-height: 1.3; }

.view-tabs {
  display: flex; gap: 3px; padding: 3px;
  background: #eef3f2; border: 1px solid var(--line); border-radius: var(--radius);
  min-width: 0; max-width: 100%; overflow-x: auto;
  scrollbar-width: thin;
}

.tab {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 11px; border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; color: #51616c; cursor: pointer; font-weight: 600; font-size: 13px;
  white-space: nowrap; transition: var(--transition);
}

.tab.active { background: var(--panel); color: var(--teal-dark); box-shadow: 0 4px 12px rgba(15,118,110,0.1); }
.tab:hover:not(.active) { background: rgba(255,255,255,0.6); color: #2a4048; }
.tab span { font-size: 12px; }
@media (max-width: 860px) { .tab span { display: none; } }

.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; }

/* Role toggle */
.role-toggle {
  display: flex; align-items: center; gap: 6px; cursor: pointer;
  padding: 3px 8px; border-radius: var(--radius-sm); background: #eef3f2; border: 1px solid var(--line);
  user-select: none;
}
.role-toggle input { display: none; }
.role-slider {
  width: 32px; height: 18px; background: var(--line-strong); border-radius: 999px;
  position: relative; transition: var(--transition);
}
.role-slider::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px;
  background: #fff; border-radius: 50%; transition: var(--transition);
}
.role-toggle input:checked + .role-slider { background: var(--teal); }
.role-toggle input:checked + .role-slider::after { left: 16px; }
.role-label { font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--muted); }

.icon-button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; padding: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm);
  color: #52606b; cursor: pointer; transition: var(--transition);
}
.icon-button:hover { border-color: var(--line-strong); background: #f7faf9; }
.icon-button.danger:hover { color: var(--red); border-color: var(--red); }

/* ========== MAIN ========== */
main { width: min(1500px, calc(100vw - 28px)); margin: 18px auto 48px; }
.view { display: none; }
.view.active { display: block; animation: fadeSlideIn 250ms ease; }
@keyframes fadeSlideIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ========== FILTER BAR ========== */
.filter-bar {
  display: grid; grid-template-columns: minmax(150px, 0.85fr) minmax(130px, 0.7fr) minmax(130px, 0.7fr) minmax(220px, 1.4fr);
  gap: 10px; align-items: end; margin-bottom: 16px;
}
label { display: grid; gap: 5px; color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px; }

input, select, textarea {
  width: 100%; min-height: 36px; padding: 7px 10px;
  color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  transition: var(--transition); text-transform: none;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(15,118,110,0.15);
}
textarea { resize: vertical; min-height: 60px; }

/* ========== KPI STRIP ========== */
.kpi-strip {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-bottom: 16px;
}
.kpi {
  min-width: 0;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 14px 16px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  border-left: 4px solid var(--teal);
}
.kpi span { display: block; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.4px; }
.kpi strong { display: block; margin-top: 6px; font-size: 26px; line-height: 1.1; letter-spacing: -0.3px; }
.kpi small { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }
.kpi.accent-red { border-left-color: var(--red); }
.kpi.accent-amber { border-left-color: var(--amber); }
.kpi.accent-blue { border-left-color: var(--blue); }
.kpi.accent-green { border-left-color: var(--green); }
.kpi.accent-violet { border-left-color: var(--violet); }

/* ========== EQUIPMENT CLASHES ========== */
.equipment-conflict-panel {
  margin-bottom: 14px;
  border-left: 4px solid var(--amber);
}
.equipment-conflict-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 10px;
  padding: 12px;
}
.equipment-conflict-card {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fffdf7;
}
.equipment-conflict-head,
.equipment-activity {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}
.equipment-conflict-head > div,
.equipment-activity > div {
  min-width: 0;
}
.equipment-conflict-head strong,
.equipment-activity strong {
  display: block;
  font-size: 13px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.equipment-conflict-head span,
.equipment-activity span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}
.equipment-activity {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
}
.equipment-activity.recommended {
  border-color: #f2c36b;
  background: var(--amber-light);
}
.equipment-activity .primary-button,
.equipment-activity .secondary-button {
  flex: 0 0 auto;
  min-width: 86px;
  justify-content: center;
}
.equipment-scheduler-grid,
.equipment-view-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(360px, 1.1fr);
  gap: 14px;
  margin-bottom: 14px;
}
.equipment-usage-panel,
.equipment-schedule-panel {
  min-height: clamp(310px, 32vh, 380px);
}
.equipment-schedule-panel {
  display: flex;
  flex-direction: column;
}
.equipment-schedule-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
  padding: 12px;
  max-height: clamp(260px, 36vh, 360px);
  overflow-y: auto;
}
.asset-card {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--teal);
  border-radius: var(--radius-sm);
  background: var(--panel);
}
.asset-card.warn { border-left-color: var(--amber); }
.asset-card.bad { border-left-color: var(--red); }
.asset-card.good { border-left-color: var(--green); }
.asset-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}
.asset-card-head > div { min-width: 0; }
.asset-card-head strong,
.asset-booking strong {
  display: block;
  font-size: 13px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.asset-card-head span,
.asset-booking span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}
.asset-meter {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7edf0;
}
.asset-meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
}
.asset-card.warn .asset-meter span { background: var(--amber); }
.asset-card.bad .asset-meter span { background: var(--red); }
.asset-booking {
  padding: 7px 8px;
  border: 1px solid #edf1f2;
  border-radius: var(--radius-sm);
  background: #fbfdfc;
  cursor: pointer;
}
.asset-booking:hover { background: var(--panel-hover); }

/* ========== DASHBOARD GRID ========== */
.dashboard-grid {
  display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(260px, 1fr);
  gap: 14px; align-items: start; min-width: 0;
}
.panel {
  min-width: 0;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: clip; transition: var(--transition);
}
.dashboard-grid > *,
.analytics-grid > *,
.template-actions > *,
.equipment-scheduler-grid > *,
.kpi-strip > * { min-width: 0; }
.panel:hover { box-shadow: 0 16px 40px rgba(26,46,53,0.09); }
.panel + .panel, .dashboard-grid + .panel { margin-top: 14px; }
.panel.wide { grid-row: span 3; }
.management-chart-panel {
  min-height: clamp(310px, 31vh, 360px);
  display: flex;
  flex-direction: column;
}
.management-chart-panel canvas { flex: 1 1 auto; }
.management-critical-panel {
  min-height: clamp(270px, 28vh, 330px);
  display: flex;
  flex-direction: column;
}
.management-critical-panel .stack-list {
  flex: 1 1 auto;
  max-height: clamp(220px, 30vh, 320px);
  overflow-y: auto;
}
.management-summary-panel .table-wrap {
  max-height: clamp(360px, 54vh, 620px);
  overflow: auto;
}

.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.panel-header > div { min-width: 0; }
.panel-header.compact { padding-bottom: 10px; }
.panel-header h2 { margin: 0; font-size: 15px; font-weight: 700; }
.panel-header p { margin: 3px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; overflow-wrap: anywhere; }

/* Timeline legend */
.timeline-legend { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: 11px; color: var(--muted); }
.legend-plan, .legend-actual, .legend-forecast { display: inline-block; width: 14px; height: 8px; border-radius: 4px; }
.legend-plan { background: #d1d9dc; }
.legend-actual { background: var(--teal); }
.legend-forecast { background: repeating-linear-gradient(90deg, var(--amber) 0 5px, transparent 5px 8px); border: 1px solid var(--amber); }

/* ========== TIMELINE (Gantt-style) ========== */
#timelineChart, #activityGantt { overflow-x: auto; scrollbar-width: thin; }
#managementView .management-timeline {
  min-height: 0;
  max-height: clamp(360px, 50vh, 520px);
  padding: 12px 16px;
  overflow: auto;
}
.timeline-wrap { min-width: 700px; padding: 6px 0; position: relative; }
.timeline-months { display: flex; border-bottom: 1px solid var(--line); margin-bottom: 4px; position: relative; height: 28px; flex-shrink: 0; }
.timeline-month { position: absolute; font-size: 10px; font-weight: 800; text-transform: uppercase; color: var(--muted); letter-spacing: 0.5px; white-space: nowrap; }
.timeline-label-col { width: 180px; flex-shrink: 0; padding-right: 10px; }
.timeline-track-col { flex: 1; position: relative; min-height: 36px; min-width: 400px; }

.timeline-row {
  display: flex; align-items: center; padding: 5px 0;
  border-bottom: 1px solid #edf1f2; cursor: pointer; transition: var(--transition);
  border-radius: var(--radius-sm); position: relative;
}
.timeline-row:hover { background: var(--panel-hover); }
.timeline-row:last-child { border-bottom: none; }

#timelineChart .timeline-label-col,
#activityGantt .timeline-label-col {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--panel);
  box-shadow: 8px 0 12px rgba(255, 255, 255, 0.88);
}
#timelineChart .timeline-row:hover .timeline-label-col,
#activityGantt .timeline-row:hover .timeline-label-col { background: var(--panel-hover); }

.timeline-label strong { display: block; font-size: 13px; line-height: 1.2; }
.timeline-label span { display: block; margin-top: 1px; color: var(--muted); font-size: 11px; }

.timeline-track { position: relative; height: 30px; background: repeating-linear-gradient(to right, transparent 0, transparent calc(8.33% - 1px), #f0f4f3 calc(8.33% - 1px), #f0f4f3 8.33%); border-radius: var(--radius-sm); }

.timeline-bar { position: absolute; height: 9px; border-radius: 999px; transition: var(--transition); }
.timeline-bar.plan { background: #d1d9dc; top: 2px; height: 10px; }
.timeline-bar.actual { top: 17px; height: 10px; background: var(--teal); }
.timeline-bar.forecast {
  top: 17px; height: 10px; background: rgba(245, 158, 11, 0.14);
  border: 1px dashed var(--amber);
}
.timeline-bar.marker { height: 30px; width: 2px; background: var(--red); top: 0; opacity: 0.4; z-index: 2; pointer-events: none; }

.timeline-row.delayed .timeline-label strong { color: var(--red); }
.timeline-row.atrisk .timeline-label strong { color: var(--amber); }

.activity-gantt { padding: 12px 16px; }
.activity-gantt .timeline-wrap { min-width: 840px; }
.activity-gantt .timeline-label-col { width: 250px; }
.activity-gantt .timeline-row.has-delay .timeline-label strong { color: var(--red); }
.activity-gantt .timeline-row.blocked .timeline-label strong { color: var(--red); }
.activity-gantt .timeline-row.completed .timeline-label strong { color: var(--green); }

/* ========== CHARTS ========== */
canvas { display: block; width: 100%; height: 250px; min-height: 220px; max-height: 280px; padding: 4px 8px; box-sizing: border-box; cursor: pointer; }
#managementView canvas { height: clamp(220px, 25vh, 270px); }

/* ========== TABLE ========== */
.table-wrap { width: 100%; overflow-x: auto; }
.table-wrap.tall { max-height: calc(100vh - 240px); overflow-y: auto; }

table { width: 100%; border-collapse: collapse; min-width: 800px; }

th, td { padding: 10px 12px; border-bottom: 1px solid #edf1f2; text-align: left; vertical-align: middle; font-size: 13px; }

th {
  position: sticky; top: 0; z-index: 2;
  background: #f6faf9; font-size: 11px; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.4px; color: #52606b;
  cursor: pointer; user-select: none; white-space: nowrap;
}
th:hover { color: var(--teal-dark); }
th::after { content: ' ↕'; font-size: 10px; opacity: 0.3; }
th[data-sort].asc::after { content: ' ↑'; opacity: 1; }
th[data-sort].desc::after { content: ' ↓'; opacity: 1; }

tbody tr { transition: background 120ms ease; cursor: pointer; }
tbody tr:hover { background: var(--panel-hover); }
tbody tr:last-child td { border-bottom: none; }

.project-link { display: grid; gap: 2px; }
.project-link strong { color: var(--teal-dark); }
.project-link span { color: var(--muted); font-size: 11px; }

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

/* ========== PILLS & BADGES ========== */
.pill {
  display: inline-flex; align-items: center; min-height: 22px;
  padding: 3px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; white-space: nowrap;
  background: #edf1f2; color: #334155;
}
.pill.good { background: var(--green-light); color: #0f5132; }
.pill.warn { background: var(--amber-light); color: #7c4a03; }
.pill.bad { background: var(--red-light); color: #7f1d1d; }
.pill.info { background: var(--blue-light); color: #1e3a8a; }
.pill.violet { background: var(--violet-light); color: #4c1d95; }

/* ========== PROGRESS BAR ========== */
.progress-bar {
  width: 120px; height: 8px; overflow: hidden;
  background: #e7edf0; border-radius: 999px;
}
.progress-bar span { display: block; height: 100%; border-radius: inherit; background: var(--teal); transition: width 400ms ease; }
.progress-bar span.warn { background: var(--amber); }
.progress-bar span.bad { background: var(--red); }
.progress-bar span.good { background: var(--green); }
.progress-cell { display: flex; align-items: center; gap: 8px; min-width: 140px; }
.progress-cell > span { color: var(--muted); font-size: 12px; font-weight: 700; min-width: 36px; }

/* ========== STACK LIST ========== */
.stack-list { display: grid; gap: 8px; padding: 12px; }
.stack-item {
  padding: 10px 12px; border: 1px solid var(--line);
  border-left: 3px solid var(--amber); border-radius: var(--radius-sm);
  background: var(--panel-soft, #fafcfb); transition: var(--transition);
}
.stack-item strong { display: block; font-size: 13px; }
.stack-item span, .stack-item p { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.stack-item.bad { border-left-color: var(--red); }
.stack-item.info { border-left-color: var(--blue); }
.stack-item.good { border-left-color: var(--green); }
.stack-item:hover { background: var(--panel-hover); }

/* ========== SORT CONTROLS ========== */
.sort-controls select { width: auto; min-width: 120px; }

/* ========== INPUT LAYOUT ========== */
.input-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 14px; }
.input-sidebar { position: sticky; top: 90px; align-self: start; }
.field { padding: 0 14px; }
.quick-filters { padding: 0 14px 12px; }

.mini-stats { display: grid; gap: 4px; padding: 10px 14px; }
.mini-stat { display: flex; justify-content: space-between; gap: 8px; padding: 7px 0; border-bottom: 1px solid #edf1f2; font-size: 13px; }
.mini-stat:last-child { border-bottom: none; }
.mini-stat strong { font-weight: 700; }

.button-row { display: flex; gap: 8px; padding: 12px 14px; }
.batch-actions { display: flex; gap: 6px; }

.primary-button, .secondary-button {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; min-height: 34px;
  font-weight: 700; font-size: 12px; border-radius: var(--radius-sm);
  cursor: pointer; transition: var(--transition); white-space: nowrap;
}
.primary-button {
  background: var(--teal); color: #fff; border: 1px solid var(--teal);
}
.primary-button:hover { background: var(--teal-dark); border-color: var(--teal-dark); }
.secondary-button {
  background: var(--panel); color: #344650;
  border: 1px solid var(--line);
}
.secondary-button:hover { border-color: var(--line-strong); background: #f7faf9; }
.secondary-button.danger { color: var(--red); }
.secondary-button.danger:hover { border-color: var(--red); color: var(--red); }

.import-box {
  margin: 0 14px 12px; padding: 12px;
  display: grid; place-items: center; gap: 6px;
  color: var(--teal-dark); background: var(--teal-light);
  border: 1px dashed #99c7c2; border-radius: var(--radius-sm);
  cursor: pointer; text-align: center; font-weight: 600;
  transition: var(--transition);
}
.import-box:hover { background: #ddf0ec; }
.import-box input { display: none; }
.import-box svg { width: 22px; height: 22px; }

/* ========== PROJECT DETAIL HEADER ========== */
.project-detail-header {
  display: grid; grid-template-columns: minmax(0, 1.5fr) repeat(5, 1fr);
  gap: 10px; margin-bottom: 14px;
}
.detail-tile {
  padding: 14px 16px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  border-left: 4px solid var(--teal);
}
.detail-tile h2 { margin: 0; font-size: 20px; line-height: 1.2; }
.detail-tile span { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; text-transform: uppercase; font-weight: 700; letter-spacing: 0.4px; }

/* ========== PHASE TIMELINE ========== */
.phase-timeline { display: grid; gap: 10px; padding: 14px 18px; }
.phase-row {
  display: grid; grid-template-columns: 160px 1fr 60px;
  gap: 10px; align-items: center; padding: 5px 6px; border-radius: var(--radius-sm); cursor: pointer;
  transition: var(--transition);
}
.phase-row:hover { background: var(--panel-hover); }
.phase-row.active { background: var(--teal-light); }
.phase-label { font-weight: 700; font-size: 13px; }
.phase-bar-track { height: 10px; overflow: hidden; background: #e7edf0; border-radius: 999px; }
.phase-bar-fill { display: block; height: 100%; border-radius: inherit; background: var(--blue); transition: width 500ms ease; }
.phase-pct { font-size: 12px; font-weight: 700; text-align: right; color: var(--muted); }

/* ========== ANALYTICS GRID ========== */
.analytics-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px;
}
.analytics-grid .wide-row { grid-column: 1 / -1; }

.health-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; padding: 14px 18px; }
.health-card { padding: 12px; border-radius: var(--radius-sm); text-align: center; }
.health-card strong { display: block; font-size: 28px; }
.health-card span { display: block; margin-top: 4px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px; }
.health-card.good { background: var(--green-light); color: #0f5132; }
.health-card.warn { background: var(--amber-light); color: #7c4a03; }
.health-card.bad { background: var(--red-light); color: #7f1d1d; }
.health-card.info { background: var(--blue-light); color: #1e3a8a; }

/* ========== TEMPLATE ========== */
.template-actions {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 14px;
}
.download-card {
  display: flex; align-items: center; gap: 12px;
  min-height: 64px; padding: 14px;
  color: var(--teal-dark); text-decoration: none;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  transition: var(--transition);
}
.download-card:hover { border-color: var(--teal); background: var(--teal-light); }
.download-card strong { display: block; font-size: 13px; }
.download-card span { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }

.instruction-list { padding: 16px 18px 16px 40px; display: grid; gap: 8px; }
.instruction-list li { font-size: 13px; line-height: 1.5; color: var(--ink); }
.instruction-list code { background: #eef3f2; padding: 2px 5px; border-radius: 3px; font-size: 12px; }

/* ========== MODAL ========== */
.modal {
  width: min(860px, calc(100vw - 28px));
  padding: 0; border: none; border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.modal::backdrop { background: rgba(26, 46, 53, 0.5); backdrop-filter: blur(4px); }
.modal.narrow { width: min(640px, calc(100vw - 28px)); }
.modal:focus-visible { outline: none; }

.modal-header, .modal-actions {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.modal-actions { border-top: 1px solid var(--line); border-bottom: none; }
.modal-header h2 { font-size: 16px; font-weight: 700; }
.modal-header p { margin-top: 3px; color: var(--muted); font-size: 12px; }

.spacer { flex: 1; }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 16px 18px; }
.span-2 { grid-column: 1 / -1; }

/* ========== TOAST ========== */
.toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 50;
  min-width: 220px; max-width: 400px; padding: 12px 14px;
  color: #fff; background: #1a2e35;
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(12px); pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
  font-size: 13px; font-weight: 600;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ========== DRILL DOWN DRAWER ========== */
.drilldown-drawer {
  position: fixed;
  top: 76px;
  right: 18px;
  z-index: 45;
  width: min(440px, calc(100vw - 28px));
  max-height: calc(100vh - 104px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform: translateX(calc(100% + 24px));
  opacity: 0;
  pointer-events: none;
  transition: transform 220ms ease, opacity 220ms ease;
}
.drilldown-drawer.open {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}
.drilldown-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.drilldown-header h2 { font-size: 16px; margin: 0; }
.drilldown-header p { margin-top: 3px; color: var(--muted); font-size: 12px; line-height: 1.35; }
.drilldown-list {
  display: grid;
  gap: 8px;
  padding: 12px;
  overflow-y: auto;
}
.drilldown-item {
  display: grid;
  gap: 4px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--teal);
  border-radius: var(--radius-sm);
  background: #fbfdfc;
  cursor: pointer;
  transition: var(--transition);
}
.drilldown-item:hover { background: var(--panel-hover); border-color: var(--line-strong); }
.drilldown-item.bad { border-left-color: var(--red); }
.drilldown-item.warn { border-left-color: var(--amber); }
.drilldown-item.good { border-left-color: var(--green); }
.drilldown-item.info { border-left-color: var(--blue); }
.drilldown-item strong { font-size: 13px; line-height: 1.25; }
.drilldown-item span, .drilldown-item p { color: var(--muted); font-size: 12px; line-height: 1.35; }
.drilldown-item .drilldown-action {
  margin-top: 2px;
  color: var(--teal-dark);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* ========== EMPTY / LOADING ========== */
.empty-state { padding: 24px; color: var(--muted); text-align: center; font-size: 13px; }
.loading-pulse { display: inline-block; width: 24px; height: 24px; border: 3px solid var(--line); border-top-color: var(--teal); border-radius: 50%; animation: spin 600ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Row actions */
.row-actions { display: flex; justify-content: flex-end; gap: 4px; white-space: nowrap; }

/* ========== RESPONSIVE ========== */
@media (max-width: 1300px) {
  .dashboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid .panel.wide { grid-column: 1 / -1; grid-row: auto; }
  #managementView .management-timeline { max-height: 500px; }
}

@media (max-width: 1100px) {
  .kpi-strip { grid-template-columns: repeat(3, 1fr); }
  .project-detail-header { grid-template-columns: repeat(3, 1fr); }
  .analytics-grid { grid-template-columns: 1fr; }
  .equipment-scheduler-grid { grid-template-columns: 1fr; }
  .topbar { grid-template-columns: minmax(220px, 1fr) minmax(0, auto); }
  .top-actions { grid-column: 1 / -1; justify-content: flex-end; }
}

@media (max-width: 860px) {
  .topbar { grid-template-columns: 1fr; gap: 8px; padding: 10px 16px; }
  .view-tabs { overflow-x: auto; }
  .filter-bar { grid-template-columns: 1fr 1fr; }
  .input-layout { grid-template-columns: 1fr; }
  .input-sidebar { position: static; }
  .kpi-strip { grid-template-columns: repeat(2, 1fr); }
  .template-actions { grid-template-columns: 1fr; }
  .project-detail-header { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  main { width: calc(100vw - 20px); }
  input, select, textarea { min-height: 40px; }
  .icon-button { width: 40px; height: 40px; }
  .panel-header { align-items: flex-start; flex-direction: column; }
  .panel-header > div { width: 100%; }
  .sort-controls, .sort-controls select { width: 100%; }
  .management-chart-panel { min-height: 300px; }
  .management-critical-panel { min-height: 280px; }
  .management-summary-panel .table-wrap { max-height: 580px; }
  #managementView .management-timeline { max-height: 460px; }
  .timeline-label-col { width: 140px; }
  .activity-gantt .timeline-label-col { width: 180px; }
  .tab span { display: none; }
  .drilldown-drawer {
    top: 118px;
    left: 10px;
    right: auto;
    width: calc(100vw - 20px);
    max-height: calc(100vh - 138px);
    transform: translateY(18px);
  }
  .drilldown-drawer.open { transform: translateY(0); }
}

@media (max-width: 700px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .equipment-conflict-list { grid-template-columns: 1fr; }
  .equipment-schedule-list { grid-template-columns: 1fr; max-height: none; }
  #timelineChart { padding: 10px 10px 12px !important; }
  #managementView .management-timeline { max-height: 390px; }
  .management-chart-panel { min-height: 280px; }
  .management-critical-panel { min-height: 260px; }
  .management-critical-panel .stack-list { max-height: 300px; }
  .management-summary-panel .table-wrap { max-height: 560px; }
  .timeline-wrap { min-width: 620px; }
  .timeline-track-col { min-width: 320px; }
  .project-summary-table {
    display: grid;
    gap: 10px;
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0;
  }
  .project-summary-table thead { display: none; }
  .project-summary-table tbody { display: grid; gap: 10px; width: 100%; }
  .project-summary-table tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; width: 100%; }
  .project-summary-table td { display: block; width: 100%; }
  .project-summary-table tr {
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-left: 4px solid var(--teal);
    border-radius: var(--radius-sm);
    background: var(--panel);
    box-shadow: 0 8px 18px rgba(26, 46, 53, 0.05);
  }
  .project-summary-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    min-height: 34px;
    padding: 5px 0;
    border-bottom: 1px solid #edf1f2;
    text-align: left;
  }
  .project-summary-table td:first-child {
    display: block;
    grid-column: 1 / -1;
    text-align: left;
    padding-top: 0;
  }
  .project-summary-table td:nth-last-child(-n + 2) { border-bottom: none; }
  .project-summary-table td:last-child { border-bottom: none; padding-bottom: 0; }
  .project-summary-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.35px;
  }
  .project-summary-table td:first-child::before { display: none; }
  .project-summary-table td[data-label="Owner"],
  .project-summary-table td[data-label="Priority"],
  .project-summary-table td[data-label="Planned Finish"] { display: none; }
  .project-summary-table td[data-label="Progress"] { grid-column: 1 / -1; }
  .project-summary-table .progress-cell { justify-content: flex-end; min-width: 0; }
  .project-summary-table .progress-bar { width: 110px; }
}

@media (max-width: 600px) {
  .filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi { min-height: 94px; padding: 12px; }
  .kpi strong { font-size: 22px; }
  .kpi small { font-size: 11px; }
  .project-detail-header { grid-template-columns: 1fr; }
  .tab svg { width: 20px; height: 20px; }
  .brand h1 { font-size: 15px; }
  .brand p { font-size: 11px; }
  .role-label { display: none; }
  .top-actions { justify-content: flex-start; }
  canvas { height: 220px; min-height: 210px; }
  #managementView canvas { height: 220px; }
}

@media (max-width: 430px) {
  .topbar { padding: 10px; }
  main { width: calc(100vw - 14px); margin-top: 12px; }
  .brand-mark { width: 34px; height: 34px; }
  .tab { padding: 8px 10px; }
  .filter-bar, .kpi-strip, .dashboard-grid { gap: 8px; }
  .equipment-scheduler-grid { gap: 8px; }
  .equipment-conflict-list { padding: 10px; gap: 8px; }
  .equipment-schedule-list { padding: 10px; gap: 8px; }
  .equipment-conflict-head,
  .asset-card-head,
  .equipment-activity {
    align-items: flex-start;
    flex-direction: column;
  }
  .equipment-activity .primary-button,
  .equipment-activity .secondary-button {
    width: 100%;
  }
  .kpi-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi { min-height: 78px; padding: 9px 8px; }
  .kpi span { font-size: 9px; line-height: 1.2; letter-spacing: 0.25px; }
  .kpi strong { margin-top: 4px; font-size: 20px; }
  .kpi small { display: none; }
  .management-chart-panel { min-height: 258px; }
  .management-critical-panel { min-height: 250px; }
  .management-critical-panel .stack-list { max-height: 280px; }
  .management-summary-panel .table-wrap { max-height: 520px; }
  #managementView .management-timeline { max-height: 350px; }
  .timeline-wrap { min-width: 580px; }
  .timeline-label-col { width: 126px; }
  .timeline-track-col { min-width: 300px; }
  .project-summary-table td {
    gap: 6px;
  }
  .project-summary-table .progress-cell { width: 100%; }
  .progress-bar { width: min(150px, 58vw); }
  .project-summary-table .progress-bar { width: 98px; }
}
