:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #17191d;
  --muted: #626a73;
  --line: #d9dee6;
  --carbon: #101216;
  --red: #e10618;
  --yellow: #ffd400;
  --blue: #1269d3;
  --green: #16a34a;
  --shadow: 0 18px 45px rgba(13, 16, 21, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

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

button,
.file-action {
  cursor: pointer;
  touch-action: manipulation;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.access-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(135deg, rgba(16, 18, 22, 0.98), rgba(23, 25, 29, 0.94)),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0 18px, transparent 18px 36px);
}

.access-gate.is-unlocked {
  display: none;
}

.access-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 32px 90px rgba(0, 0, 0, 0.42);
}

.access-card img {
  width: 108px;
  height: 108px;
  object-fit: contain;
  justify-self: center;
}

.access-card h1 {
  text-align: center;
}

.access-error {
  min-height: 20px;
  margin: 0;
  color: var(--red);
  font-weight: 800;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  background: var(--carbon);
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow: auto;
}

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

.brand img {
  width: 58px;
  height: 58px;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
  border: 2px solid var(--yellow);
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 1.15rem;
}

.brand span,
.sidebar-panel small {
  color: rgba(255, 255, 255, 0.68);
}

.nav {
  display: grid;
  gap: 6px;
}

.nav a {
  color: rgba(255, 255, 255, 0.78);
  text-decoration: none;
  padding: 11px 12px;
  border-left: 3px solid transparent;
}

.nav a:hover,
.nav a.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  border-left-color: var(--red);
}

.sidebar-panel {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
}

.sidebar-panel strong {
  font-size: 1.8rem;
  color: var(--yellow);
}

main {
  padding: 26px;
  display: grid;
  gap: 22px;
}

.topbar,
.panel-title,
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  padding-bottom: 4px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--red);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.65rem, 3vw, 3rem);
}

h2 {
  margin-bottom: 0;
  font-size: 1.2rem;
}

.top-actions,
menu {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.primary-action,
.icon-button,
.ghost-button {
  border: 0;
  border-radius: 6px;
  min-height: 40px;
  padding: 0 14px;
  font-weight: 800;
}

.primary-action {
  background: var(--red);
  color: #fff;
  box-shadow: 0 8px 20px rgba(225, 6, 24, 0.2);
}

.icon-button,
.ghost-button {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

.file-action input {
  display: none;
}

.hero-grid,
.grid {
  display: grid;
  gap: 22px;
}

.quick-dashboard {
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(420px, 1.45fr) minmax(230px, 0.75fr);
  gap: 14px;
  align-items: stretch;
  padding: 16px;
  border: 1px solid var(--carbon);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.quick-total {
  display: grid;
  align-content: center;
  gap: 12px;
  padding: 16px;
  border-radius: 8px;
  background: var(--carbon);
  color: #fff;
}

.quick-total h2 {
  font-size: clamp(2rem, 4vw, 3.2rem);
  color: var(--yellow);
  overflow-wrap: anywhere;
}

.quick-summary {
  display: grid;
  gap: 7px;
}

.quick-summary span {
  color: rgba(255, 255, 255, 0.74);
  font-size: 0.86rem;
}

.quick-summary strong {
  color: #fff;
}

.quick-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
}

.quick-form label {
  min-width: 0;
}

.quick-breakdown {
  display: grid;
  gap: 8px;
  align-content: center;
}

.quick-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.quick-row span {
  color: var(--muted);
}

.hero-grid {
  grid-template-columns: minmax(0, 1.55fr) minmax(280px, 0.85fr);
}

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

.panel,
.command-panel,
.visual-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.command-panel {
  min-height: 280px;
  padding: 28px;
  display: grid;
  align-content: space-between;
  position: relative;
  overflow: hidden;
}

.command-panel::after {
  content: "";
  position: absolute;
  inset: auto -40px -70px 30%;
  height: 150px;
  background:
    linear-gradient(90deg, transparent 0 42%, rgba(225, 6, 24, 0.12) 42% 52%, transparent 52% 100%),
    repeating-linear-gradient(135deg, rgba(16, 18, 22, 0.08) 0 18px, transparent 18px 36px);
  transform: skewY(-7deg);
}

.command-panel h2 {
  max-width: 760px;
  font-size: clamp(1.6rem, 4vw, 3.6rem);
  line-height: 0.95;
}

.hero-stats {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
}

.hero-stats div,
.ops-item,
.person,
.idea,
.phase-card,
.vehicle-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.hero-stats div {
  padding: 14px;
}

.hero-stats span,
.meta,
th,
.terrain-result span,
.ops-item span,
.person span,
.idea span {
  color: var(--muted);
  font-size: 0.82rem;
}

.hero-stats strong {
  display: block;
  margin-top: 6px;
  font-size: 1.35rem;
}

.visual-panel {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 280px;
  overflow: hidden;
}

.visual-panel img {
  width: min(82%, 360px);
  position: relative;
  z-index: 1;
}

.speed-strip {
  position: absolute;
  inset: auto 0 30px 0;
  display: flex;
  justify-content: center;
  gap: 9px;
}

.speed-strip span {
  width: 46px;
  height: 12px;
  background: var(--yellow);
  transform: skewX(-26deg);
}

.speed-strip span:nth-child(2) {
  background: var(--red);
}

.speed-strip span:nth-child(3) {
  background: var(--carbon);
}

.speed-strip span:nth-child(4) {
  background: var(--blue);
}

.panel {
  padding: 20px;
  min-width: 0;
}

.timeline {
  margin-top: 18px;
  display: grid;
  gap: 14px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 12px;
  align-items: center;
}

.dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 5px solid var(--line);
  background: #fff;
}

.timeline-item.done .dot {
  border-color: var(--green);
}

.timeline-item.active .dot {
  border-color: var(--red);
}

.progress-track {
  height: 10px;
  background: #eef1f5;
  border-radius: 999px;
  overflow: hidden;
}

.progress-track i,
.bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--red), var(--yellow));
}

.bars {
  margin-top: 18px;
  display: grid;
  gap: 14px;
}

.bar-row {
  display: grid;
  gap: 7px;
}

.bar-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.bar {
  height: 12px;
  border-radius: 999px;
  background: #eef1f5;
  overflow: hidden;
}

.phase-board {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 14px;
}

.phase-card {
  padding: 14px;
  display: grid;
  gap: 10px;
}

.phase-card header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.status-pill {
  border-radius: 999px;
  padding: 4px 8px;
  background: #eef1f5;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.status-pill.active {
  background: rgba(225, 6, 24, 0.12);
  color: var(--red);
}

.status-pill.done {
  background: rgba(22, 163, 74, 0.12);
  color: var(--green);
}

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

.small-button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  min-height: 32px;
  padding: 0 10px;
  font-weight: 750;
}

.delete-button {
  color: var(--red);
}

.table-wrap {
  margin-top: 14px;
  overflow: auto;
}

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

th,
td {
  padding: 12px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

td:last-child {
  text-align: right;
}

.ops-list,
.people-list,
.ideas-list {
  margin-top: 14px;
  display: grid;
  gap: 10px;
}

.ops-item,
.person,
.idea {
  padding: 13px;
  display: grid;
  gap: 6px;
}

.ops-item {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.vehicle-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 14px;
}

.vehicle-card {
  overflow: hidden;
  display: grid;
}

.vehicle-card img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  background: #eef1f5;
}

.vehicle-body {
  padding: 13px;
  display: grid;
  gap: 9px;
}

.form-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
}

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

.terrain-result {
  align-content: center;
}

.terrain-result h2 {
  font-size: clamp(2rem, 5vw, 4rem);
  color: var(--red);
}

#terrainBreakdown {
  margin-top: 16px;
  display: grid;
  gap: 10px;
}

.break-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

dialog {
  width: min(620px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.28);
}

dialog::backdrop {
  background: rgba(13, 16, 21, 0.56);
}

.dialog-fields {
  margin-top: 18px;
  display: grid;
  gap: 12px;
}

menu {
  justify-content: flex-end;
  margin: 18px 0 0;
  padding: 0;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

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

  .hero-grid,
  .two-col,
  .quick-dashboard {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 760px) {
  html {
    scroll-padding-top: 12px;
  }

  body {
    padding-bottom: calc(82px + env(safe-area-inset-bottom));
  }

  main {
    padding: 14px;
    gap: 14px;
  }

  .sidebar {
    padding: 12px 14px;
    gap: 10px;
    overflow: visible;
  }

  .brand img {
    width: 46px;
    height: 46px;
  }

  .brand strong {
    font-size: 1rem;
  }

  .brand span {
    font-size: 0.78rem;
  }

  .sidebar-panel {
    display: none;
  }

  .nav {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(7, minmax(58px, 1fr));
    gap: 4px;
    padding: 8px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    background: rgba(16, 18, 22, 0.96);
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.28);
    overflow-x: auto;
    scrollbar-width: none;
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  .nav a {
    min-height: 52px;
    padding: 7px 6px;
    display: grid;
    place-items: center;
    border-left: 0;
    border-bottom: 3px solid transparent;
    border-radius: 6px;
    font-size: 0.72rem;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
  }

  .nav a:hover,
  .nav a.active {
    border-left-color: transparent;
    border-bottom-color: var(--yellow);
    background: rgba(255, 255, 255, 0.11);
  }

  .topbar {
    gap: 12px;
    padding-bottom: 0;
  }

  .topbar,
  .panel-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .top-actions .primary-action,
  .top-actions .icon-button {
    width: 100%;
    min-height: 44px;
    padding-inline: 8px;
    justify-content: center;
    text-align: center;
  }

  h1 {
    font-size: 1.45rem;
    line-height: 1.05;
  }

  h2 {
    font-size: 1.05rem;
  }

  .hero-stats,
  .phase-board,
  .vehicle-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .hero-grid,
  .grid {
    gap: 14px;
  }

  .quick-dashboard {
    gap: 10px;
    padding: 12px;
  }

  .quick-total {
    padding: 14px;
  }

  .quick-total h2 {
    font-size: 2rem;
  }

  .quick-form {
    grid-template-columns: 1fr;
    gap: 9px;
  }

  .quick-row {
    padding: 8px 0;
  }

  .panel,
  .command-panel,
  .visual-panel {
    border-radius: 8px;
    box-shadow: 0 10px 24px rgba(13, 16, 21, 0.06);
  }

  .panel {
    padding: 14px;
  }

  .command-panel {
    min-height: auto;
    padding: 18px;
    gap: 20px;
  }

  .command-panel h2 {
    font-size: 1.75rem;
    line-height: 1;
  }

  .command-panel::after {
    inset: auto -80px -82px 12%;
    height: 122px;
  }

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

  .hero-stats div {
    min-height: 92px;
    padding: 11px;
  }

  .hero-stats strong {
    font-size: 1.08rem;
    line-height: 1.05;
    overflow-wrap: anywhere;
  }

  .visual-panel {
    min-height: 190px;
  }

  .visual-panel img {
    width: min(76%, 260px);
  }

  .speed-strip {
    bottom: 18px;
  }

  .speed-strip span {
    width: 34px;
    height: 10px;
  }

  .timeline {
    gap: 12px;
  }

  .timeline-item {
    grid-template-columns: 24px 1fr 42px;
    gap: 9px;
  }

  .dot {
    width: 22px;
    height: 22px;
    border-width: 4px;
  }

  .phase-card,
  .vehicle-card,
  .person,
  .idea,
  .ops-item {
    padding: 12px;
  }

  .phase-card header {
    align-items: flex-start;
  }

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

  .small-button {
    min-height: 40px;
  }

  .table-wrap {
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  #costRows {
    display: grid;
    gap: 10px;
  }

  #costRows tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 10px;
  }

  #costRows td {
    display: grid;
    grid-template-columns: 92px 1fr;
    gap: 10px;
    align-items: center;
    padding: 7px 0;
    border-bottom: 1px solid #eef1f5;
    text-align: left;
  }

  #costRows td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 800;
    text-transform: uppercase;
  }

  #costRows td:last-child {
    border-bottom: 0;
  }

  #costRows td:last-child .small-button {
    width: 100%;
    margin-top: 6px;
  }

  .ops-item {
    grid-template-columns: 1fr;
  }

  .vehicle-card img {
    aspect-ratio: 4 / 3;
  }

  .terrain-result h2 {
    font-size: 2.2rem;
    overflow-wrap: anywhere;
  }

  .break-row {
    align-items: flex-start;
  }

  dialog {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 28px);
    padding: 14px;
    overflow: auto;
  }

  .dialog-head {
    align-items: flex-start;
  }

  menu {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  menu button {
    width: 100%;
  }
}
