:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --ink: #0c1324;
  --muted: #5c6680;
  --brand: #1a66ff;
  --line: #dfe5f2;
  --ok: #1d8f3a;
  --bad: #c0392b;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif; color: var(--ink); background: var(--bg); }
.view { display: none; }
.view.active { display: block; }
#login-view { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 1rem; }
.login-card { width: min(100%, 380px); padding: 1.5rem; text-align: center; }
.logo-login { margin: 0 auto 0.5rem; width: min(238px, 100%); }
label { display: block; margin: 0.9rem 0 0.3rem; font-weight: 600; text-align: left; }
input, button, select, textarea { width: 100%; border-radius: 10px; padding: 0.75rem; border: 1px solid var(--line); font: inherit; background: #fff; }
button { border: 0; margin-top: 1rem; background: var(--brand); color: #fff; font-weight: 600; cursor: pointer; }
button.secondary { background: #e7ecf8; color: var(--ink); }

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

.msg { min-height: 1.25rem; color: var(--bad); margin-top: 0.6rem; }

#portal-view.view.active { min-height: 100vh; display: grid; grid-template-columns: 240px 1fr; }
.mobile-header { display: none; }
.sidebar { border-right: 1px solid var(--line); padding: 1rem; background: #fff; display: flex; flex-direction: column; gap: 0.75rem; align-items: center; }
.logo { width: min(145px, 100%); height: auto; object-fit: contain; display: block; margin: 0 auto; }
.sidebar nav { flex: 1; width: 100%; }
.logout-button { margin-top: auto; background: #0f172a; color: #fff; width: 100%; }
.logout-button:hover { background: #1f2937; }

.nav-item { display: block; text-decoration: none; color: var(--ink); padding: 0.65rem 0.75rem; border-radius: 10px; margin-bottom: 0.35rem; }
.nav-item.active, .nav-item:hover { background: #e8efff; color: #0638a6; }
.content { padding: 1rem; }
.panel { display: none; }
.panel.active { display: block; }

.order-selector { margin-bottom: 1rem; }
.choice-group { display: flex; gap: 0.75rem; }
.choice-btn { margin-top: 0; background: #f3f6ff; color: #11337f; }
.choice-btn.active { background: var(--brand); color: #fff; }

.order-flow { display: none; }
.order-flow.active { display: block; }
.broadband-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; align-items: start; }
.map-pane { position: sticky; top: 1rem; }
.mobile-map-wrap { display: none; margin-top: 1rem; }

.step { display: none; }
.step.active { display: block; }
.diagram { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 0.75rem; margin: 0.75rem 0 1rem; }
.endpoint { border: 1px solid var(--line); border-radius: 10px; padding: 0.8rem; text-align: center; }
.cloud { background: #eef5ff; }
.site { background: #f8f9fc; }
.link { font-size: 1.2rem; color: var(--muted); }
.mobile-arrow { display: none; }

.loader-wrap { margin-top: 0.8rem; }
.loader-bar { width: 100%; height: 12px; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: #f2f5fd; }
.loader-bar span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, #78a5ff, #1a66ff); animation: load 3s ease forwards; }
@keyframes load { from { width: 0; } to { width: 100%; } }

.availability-list { list-style: none; padding: 0; }
.availability-list li { display: grid; grid-template-columns: auto 1fr auto; gap: 0.75rem; align-items: center; padding: 0.45rem 0; border-bottom: 1px solid #f0f2f7; }
.availability-tag { font-size: 0.9rem; }
.availability-tag.available { color: var(--ok); }
.availability-tag.unavailable { color: var(--bad); }
.mini { width: auto; margin: 0; padding: 0.35rem 0.6rem; }


.autocomplete-field { position: relative; }
.autocomplete-dropdown {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 24px rgba(12, 19, 36, 0.12);
  max-height: 220px;
  overflow-y: auto;
  z-index: 40;
  display: none;
}
.autocomplete-dropdown.open { display: block; }
.autocomplete-option {
  display: block;
  width: 100%;
  border: 0;
  background: #fff;
  color: var(--ink);
  text-align: left;
  padding: 0.65rem 0.75rem;
  margin: 0;
  border-radius: 0;
  font-weight: 500;
}
.autocomplete-option:hover { background: #eef3ff; }

.unavailable-item { opacity: 0.45; }
.unavailable-item .mini { background: #e5e7eb; color: #7c8797; cursor: not-allowed; }
.is-locked { background: #f5f7fb; color: #677086; }

.price-grid, .summary-grid { display: grid; grid-template-columns: 1fr auto; gap: 0.5rem 1rem; margin-top: 1rem; align-items: center; }
.summary-grid p { margin: 0; }
.actions { display: flex; gap: 0.75rem; margin-top: 1rem; }
.actions button { margin-top: 0; }
.radio { display: block; margin-top: 0.65rem; font-weight: 500; }
.radio input { width: auto; margin-right: 0.4rem; }
.map { height: 320px; margin-top: 0.6rem; border-radius: 10px; overflow: hidden; }
.map-mobile { height: 260px; margin-top: 0.3rem; }
.hint, .muted { color: var(--muted); }
.confirmation { margin-top: 1rem; color: var(--ok); font-weight: 600; }
.error-text { color: var(--bad); }

.consent-check {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  margin-top: 1rem;
  font-weight: 500;
  color: var(--ink);
}

.consent-check input {
  width: auto;
  margin-top: 0.18rem;
  flex: 0 0 auto;
}

.order-row-highlight {
  animation: orderFlash 2.5s ease;
}

.order-row-highlight td {
  background: #fff9d8;
}

@keyframes orderFlash {
  0% { box-shadow: inset 0 0 0 9999px rgba(255, 236, 133, 0.8); }
  100% { box-shadow: inset 0 0 0 9999px rgba(255, 236, 133, 0); }
}

.filters { display: flex; flex-wrap: wrap; gap: 0.45rem; margin: 0.5rem 0 0.8rem; }
.filter { width: auto; margin: 0; padding: 0.4rem 0.6rem; border: 1px solid var(--line); background: #fff; color: var(--ink); }
.filter.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 980px; }
th, td { border: 1px solid var(--line); padding: 0.6rem; text-align: left; font-size: 0.9rem; }
th { background: #eef3ff; }


.order-link {
  width: auto;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--brand);
  text-decoration: underline;
  font-weight: 600;
  cursor: pointer;
}

.modal[hidden] { display: none; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(12, 19, 36, 0.45);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 1400;
}

.modal-card {
  width: min(900px, 96vw);
  max-height: 92vh;
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-close {
  width: auto;
  margin: 0;
  padding: 0.35rem 0.6rem;
  background: #e7ecf8;
  color: var(--ink);
}

.order-detail-grid {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 0.35rem 0.75rem;
  margin-bottom: 0.8rem;
}

.order-detail-grid p,
.order-detail-grid strong {
  margin: 0;
}

.metadata-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.65rem;
  margin-bottom: 0.8rem;
}

.meta-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  background: #f8faff;
}

.meta-label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.meta-value {
  font-size: 0.95rem;
}

.meta-empty {
  margin: 0 0 0.8rem;
  color: var(--muted);
}


.fault-history {
  margin-top: 1.25rem;
  border-top: 1px solid var(--line);
  padding-top: 1rem;
}

.fault-list {
  display: grid;
  gap: 0.7rem;
  margin-top: 0.65rem;
}

.fault-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem;
  background: #f8faff;
}

.fault-item.compact {
  background: #fff;
}

.fault-item-head {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  align-items: baseline;
}

.fault-item-head strong {
  color: var(--ink);
}

.fault-item-head span,
.fault-item-meta {
  color: var(--muted);
  margin: 0.2rem 0;
  font-size: 0.9rem;
}

.fault-item-details {
  margin: 0.45rem 0 0;
  white-space: pre-wrap;
}

.order-faults {
  margin-bottom: 0.8rem;
}


.fault-item-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
}

.fault-status-badge {
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.8rem;
}

.fault-comments-title {
  margin: 0.75rem 0 0.4rem;
}

.fault-comments-list {
  list-style: none;
  padding: 0;
  margin: 0 0 0.75rem;
  display: grid;
  gap: 0.35rem;
}

.fault-comment-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  background: #fff;
}

.fault-comment-item strong {
  display: inline-block;
  margin-right: 0.45rem;
}

.fault-comment-item span {
  color: var(--muted);
  font-size: 0.85rem;
}

.fault-comment-item p {
  margin: 0.35rem 0 0;
  white-space: pre-wrap;
}

.fault-comment-item.empty {
  color: var(--muted);
}

.fault-actions {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  margin-top: 0.55rem;
}

.fault-actions label {
  display: grid;
  gap: 0.25rem;
  margin: 0;
  font-weight: 500;
}

.fault-actions select,
.fault-actions textarea {
  margin-top: 0;
}

.fault-actions.comment-box {
  align-items: stretch;
}

.fault-actions.comment-box textarea {
  flex: 1;
  min-height: 78px;
}

.fault-actions button {
  width: auto;
  margin: 0;
}
.order-details-map {
  height: 280px;
}

.order-status {
  display: inline-block;
  font-weight: 600;
}

.status-active { color: #1d8f3a; }
.status-in-progress { color: #b7791f; }
.status-resolved { color: #1d8f3a; }
.status-ceased { color: #c0392b; }

.menu-toggle { display: none; border: 1px solid #d0dbf8; background: #fff; color: #11337f; border-radius: 10px; width: auto; padding: 0.5rem 0.7rem; margin: 0; }

@media (max-width: 1000px) {
  .broadband-layout { grid-template-columns: 1fr; }
  .map-pane { position: static; }
}

@media (max-width: 860px) {
  #portal-view.view.active { grid-template-columns: 1fr; }
  .mobile-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 0.75rem;
    background: #fff;
    border-bottom: 1px solid var(--line);
  }
  .logo-mobile { width: min(156px, 70vw); margin: 0 auto; }
  .menu-toggle {
    display: inline-block;
    position: absolute;
    top: 50%;
    left: 0.75rem;
    right: auto;
    transform: translateY(-50%);
  }

  .sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    width: 240px;
    height: auto;
    min-height: 0;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
    background: #fff;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 1099;
    align-items: stretch;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar .logo { display: none; }
  .content { padding: 4.5rem 0.75rem 1rem; }

  .choice-group, .actions, .diagram, .price-grid { grid-template-columns: 1fr; display: grid; }
  .diagram .link { text-align: center; justify-self: center; width: 100%; }
  .desktop-arrow { display: none; }
  .mobile-arrow { display: inline; }
  .map-pane { display: none; }
  .mobile-map-wrap { display: block; }

  .filters {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 0.55rem;
    align-items: stretch;
  }
  .filter { width: 100%; margin: 0; text-align: center; padding: 0.55rem 0.6rem; font-size: 0.95rem; border-radius: 12px; }

  /* Keep both mobile stacks top-aligned: status (left) and service (right). */
  .filters .filter:nth-child(1) { grid-column: 2; grid-row: 1; }
  .filters .filter:nth-child(2) { grid-column: 2; grid-row: 2; }
  .filters .filter:nth-child(3) { grid-column: 2; grid-row: 3; }
  .filters .filter:nth-child(4) { grid-column: 1; grid-row: 1; }
  .filters .filter:nth-child(5) { grid-column: 1; grid-row: 2; }
  .filters .filter:nth-child(6) { grid-column: 1; grid-row: 3; }
  .filters .filter:nth-child(7) { grid-column: 1; grid-row: 4; }

  .table-wrap { max-width: 100%; overflow: visible; margin-top: 0.75rem; }
  table { width: 100%; min-width: 0; border-collapse: separate; border-spacing: 0; }
  thead { display: none; }
  tbody { display: grid; gap: 0.7rem; }

  .order-data-row {
    display: block;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.25rem 0;
    box-shadow: 0 2px 6px rgba(12, 19, 36, 0.04);
  }

  .order-data-row td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.9rem;
    border: 0;
    border-bottom: 1px solid #edf1f9;
    padding: 0.55rem 0.7rem;
    font-size: 0.9rem;
    text-align: right;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .order-data-row td:last-child { border-bottom: 0; }
  .order-data-row td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
    text-align: left;
    flex: 0 0 42%;
  }

  .order-data-row td:first-child {
    background: #f7f9ff;
    border-radius: 12px 12px 0 0;
  }

  .order-data-row .order-link { font-size: 0.95rem; }

  .orders-empty-row td {
    border: 1px dashed var(--line);
    border-radius: 12px;
    background: #fafbff;
    padding: 0.9rem;
    font-size: 0.95rem;
  }


  .modal { padding: 0.6rem; }
  .modal-card {
    width: 100%;
    max-height: calc(100vh - 1.2rem);
    padding: 0.85rem;
  }
  .modal-header { align-items: flex-start; }
  .order-detail-grid {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }
  .order-detail-grid p {
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 0.35rem;
  }
  .order-detail-grid strong,
  .meta-value {
    font-size: 0.95rem;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
  .metadata-grid { grid-template-columns: 1fr; }
  .order-details-map { height: 220px; }
}
