/* ----- Base ----- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: #222;
    background: #f6f7fa;
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
a { color: #0c68d6; text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
    max-width: 1080px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ----- Header / Footer ----- */
.site-header {
    background: #0d1b2a;
    color: #fff;
    padding: 14px 0;
    border-bottom: 3px solid #3388ff;
}
.site-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}
.site-header .brand {
    color: #fff;
    font-weight: 700;
    font-size: 20px;
    letter-spacing: 0.5px;
}
.site-header .brand span {
    color: #3388ff;
    font-weight: 400;
}
.site-header nav {
    display: flex;
    align-items: center;
    gap: 18px;
}
.site-header nav a {
    color: #cfd8e3;
    font-size: 14px;
}
.site-header nav a:hover { color: #fff; text-decoration: none; }
.agent-badge {
    background: #3388ff;
    color: #fff;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.site-footer {
    margin-top: auto;
    background: #0d1b2a;
    color: #8da0b8;
    padding: 16px 0;
    font-size: 13px;
}
.site-footer .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.site-footer a { color: #cfd8e3; }
.site-footer .footer-links { display: inline-flex; gap: 6px; }

.legal-page h3 {
    margin-top: 18px;
    font-size: 15px;
    color: #0d1b2a;
}
.legal-page h3:first-of-type { margin-top: 4px; }
.legal-page p, .legal-page ul { margin: 6px 0 10px; }
.legal-page ul { padding-left: 20px; }
.legal-page .muted { color: #94a3b8; font-style: italic; }

main.container {
    flex: 1;
    padding-top: 36px;
    padding-bottom: 48px;
}

/* ----- Login / Hero ----- */
.hero {
    text-align: center;
    padding: 40px 20px 48px;
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e2e8ef;
    margin-bottom: 32px;
}
.hero h1 {
    font-size: 32px;
    margin: 0 0 16px;
    line-height: 1.2;
}
.hero .lead {
    max-width: 640px;
    margin: 0 auto 24px;
    font-size: 17px;
    color: #475569;
}
.hero .hint {
    max-width: 560px;
    margin: 20px auto 0;
    font-size: 13px;
    color: #64748b;
}

.btn-primary {
    display: inline-block;
    background: #3388ff;
    color: #fff;
    padding: 12px 28px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 16px;
    border: 0;
    cursor: pointer;
    transition: background .15s;
}
.btn-primary:hover { background: #2673e0; text-decoration: none; }
.btn-primary:disabled {
    background: #9bb4d1;
    cursor: not-allowed;
}

/* ----- Feature grid on login ----- */
.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 18px;
}
.feature {
    background: #fff;
    border: 1px solid #e2e8ef;
    border-radius: 10px;
    padding: 20px;
}
.feature h3 {
    margin: 0 0 8px;
    font-size: 16px;
    color: #0d1b2a;
}
.feature p {
    margin: 0;
    font-size: 14px;
    color: #475569;
}

/* ----- Page head ----- */
.page-head {
    margin-bottom: 24px;
}
.page-head h1 {
    margin: 0 0 6px;
    font-size: 26px;
}
.page-head p {
    margin: 0;
    color: #64748b;
}
.back-link {
    display: inline-block;
    margin-bottom: 8px;
    color: #64748b;
    font-size: 14px;
}

/* ----- Ops grid ----- */
.ops-grid {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}
.op-card {
    background: #fff;
    border: 1px solid #e2e8ef;
    border-radius: 10px;
    transition: border-color .15s, transform .15s;
}
.op-card:hover {
    border-color: #3388ff;
    transform: translateY(-2px);
}
.op-card-link {
    display: block;
    padding: 20px;
    color: inherit;
}
.op-card-link:hover { text-decoration: none; }
.op-card h2 {
    margin: 0 0 8px;
    font-size: 18px;
    color: #0d1b2a;
}
.op-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    margin-top: 8px;
}
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: #e2e8ef;
    color: #334155;
}
.badge.type { background: #dbeafe; color: #1e40af; }
.badge.role { background: #ecfccb; color: #3f6212; }
.owner { font-size: 13px; color: #64748b; }
.updated { font-size: 12px; color: #94a3b8; margin-top: 8px; }

.onboarding {
    margin-bottom: 20px;
}
.onboarding h3 {
    margin: 0 0 8px;
    font-size: 15px;
    color: #0d1b2a;
}
.onboarding p {
    margin: 0;
    color: #475569;
    font-size: 14px;
    line-height: 1.5;
}

/* ----- Empty state ----- */
.empty-state {
    background: #fff;
    border: 1px dashed #cbd5e1;
    border-radius: 10px;
    padding: 40px;
    text-align: center;
    color: #64748b;
}

/* ----- Op detail ----- */
.op-status {
    margin: 24px 0;
}
.notice {
    padding: 14px 18px;
    border-radius: 8px;
    margin-bottom: 12px;
}
.notice.info { background: #eff6ff; border-left: 4px solid #3388ff; color: #1e3a8a; }
.notice.warn { background: #fef3c7; border-left: 4px solid #f59e0b; color: #7c2d12; }
.notice.danger { background: #fee2e2; border-left: 4px solid #dc2626; color: #7f1d1d; }

.long-links-details {
    margin-top: 8px;
}
.long-links-details summary {
    cursor: pointer;
    font-size: 13px;
    color: #991b1b;
    padding: 4px 0;
}
.long-links-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 6px;
    background: #fff;
    font-size: 13px;
    color: #334155;
}
.long-links-table th, .long-links-table td {
    padding: 4px 8px;
    border-bottom: 1px solid #fee2e2;
    text-align: left;
}
.long-links-table th { background: #fef2f2; font-weight: 600; color: #7f1d1d; }
.long-links-table .num { text-align: right; font-family: Consolas, monospace; }
.long-links-table .outer-row { background: #fef2f2; }
.long-links-table .outer-row em { color: #991b1b; font-style: normal; font-size: 11px; }
.actions { margin-top: 10px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.actions .hint { color: #64748b; font-size: 13px; }

.agents-section {
    background: #fff;
    border: 1px solid #e2e8ef;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
}
.agents-section h3 {
    margin: 0 0 14px;
    font-size: 15px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #64748b;
}
.agents-section .notice.compact { padding: 10px 14px; font-size: 14px; margin-bottom: 14px; }
.agents-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.agent-row {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: #eef2f7;
    border-radius: 999px;
    font-size: 13px;
    color: #0d1b2a;
}
.agent-name { font-weight: 600; }

.portal-preview {
    background: #fff;
    border: 1px solid #e2e8ef;
    border-radius: 10px;
    padding: 20px;
}
.portal-preview h3 {
    margin: 0 0 14px;
    font-size: 15px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #64748b;
}
.portal-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid #f1f5f9;
    font-size: 14px;
}
.portal-row:last-child { border-bottom: 0; }
.portal-name { color: #0d1b2a; }
.portal-coords { color: #94a3b8; font-family: Consolas, monospace; font-size: 12px; }
.more { margin-top: 12px; color: #94a3b8; font-size: 13px; text-align: center; }

/* ---- Anchor picker ---- */
.picker {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 20px;
    align-items: stretch;
}
.anchor-map {
    height: 520px;
    border-radius: 10px;
    border: 1px solid #cbd5e1;
    background: #e2e8ef;
}
.picker-side {
    background: #fff;
    border: 1px solid #e2e8ef;
    border-radius: 10px;
    padding: 18px;
    display: flex;
    flex-direction: column;
}
.picker-side h3 {
    margin: 0 0 10px;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #64748b;
}
.selection-list {
    padding-left: 18px;
    margin: 0 0 14px 0;
    min-height: 86px;
    font-size: 14px;
}
.selection-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}
.drop-btn {
    border: 0;
    background: #e2e8ef;
    border-radius: 999px;
    width: 22px;
    height: 22px;
    cursor: pointer;
    color: #475569;
    font-weight: 700;
}
.drop-btn:hover { background: #cbd5e1; }
.picker-stats {
    margin: 8px 0 14px;
    padding: 10px;
    background: #f1f5f9;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.6;
}
.picker-stats.hidden { display: none; }
.picker-stats strong { color: #0d1b2a; }

.picker-score {
    margin: 8px 0 14px;
    padding: 12px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.5;
    text-align: center;
}
.picker-score.hidden { display: none; }
.picker-score .score-value {
    font-size: 24px;
    font-weight: 700;
    color: #0d1b2a;
    margin: 4px 0 10px;
}
.medal {
    padding: 2px 10px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.medal-gold   { background: #fde68a; color: #78350f; }
.medal-silver { background: #e5e7eb; color: #374151; }
.medal-bronze { background: #fed7aa; color: #7c2d12; }
.medal-none   { background: #fee2e2; color: #7f1d1d; }

/* ---- Scheme picker ---- */
.scheme-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.scheme-option {
    display: flex;
    gap: 14px;
    padding: 16px;
    background: #fff;
    border: 1px solid #e2e8ef;
    border-radius: 10px;
    cursor: pointer;
    align-items: flex-start;
}
.scheme-option:hover { border-color: #3388ff; }
.scheme-option input[type="radio"] {
    margin-top: 4px;
    transform: scale(1.2);
}
.scheme-option strong {
    display: block;
    font-size: 16px;
    margin-bottom: 4px;
}
.scheme-option p {
    margin: 0 0 8px;
    color: #475569;
    font-size: 14px;
}
.z-select {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
}
.z-select select {
    padding: 6px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 14px;
    flex: 1;
    max-width: 380px;
}

.build-order,
.agent-names {
    background: #fff;
    border: 1px solid #e2e8ef;
    border-radius: 10px;
    padding: 16px 18px;
    margin: 0;
}
.build-order legend {
    padding: 0 6px;
    font-weight: 600;
    color: #0d1b2a;
}
.build-order .hint { margin: 6px 0 14px; }
.build-order-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.build-order-option {
    display: flex;
    gap: 10px;
    padding: 12px 14px;
    background: #f8fafc;
    border: 1px solid #e2e8ef;
    border-radius: 8px;
    cursor: pointer;
    align-items: flex-start;
}
.build-order-option:hover { border-color: #3388ff; }
.build-order-option input[type="radio"] {
    margin-top: 3px;
    transform: scale(1.1);
}
.build-order-option strong {
    display: block;
    font-size: 14px;
    margin-bottom: 2px;
}
.build-order-option p {
    margin: 0;
    color: #475569;
    font-size: 12.5px;
    line-height: 1.4;
}
@media (max-width: 600px) {
    .build-order-grid { grid-template-columns: 1fr; }
}


.agent-names legend {
    padding: 0 6px;
    font-weight: 600;
    color: #0d1b2a;
}
.agent-names .hint {
    margin: 6px 0 12px;
}
.agent-name-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}
.agent-name-grid label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
    color: #475569;
}
.agent-name-grid input,
.agent-name-grid select {
    padding: 6px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
}
.agent-name-grid input:focus,
.agent-name-grid select:focus {
    border-color: #3388ff;
    outline: none;
    box-shadow: 0 0 0 2px #3388ff33;
}
@media (max-width: 600px) {
    .agent-name-grid { grid-template-columns: 1fr; }
}

.muted { color: #94a3b8; }

/* ---- Result page ---- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.stat-card {
    background: #fff;
    border: 1px solid #e2e8ef;
    border-radius: 10px;
    padding: 16px;
    text-align: center;
}
.stat-card.highlight {
    border-color: #3388ff;
    box-shadow: 0 0 0 2px #3388ff22;
}
.stat-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #64748b;
}
.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: #0d1b2a;
    margin: 4px 0;
}
.stat-hint { font-size: 12px; color: #94a3b8; }

.row-two {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 18px;
}
.card {
    background: #fff;
    border: 1px solid #e2e8ef;
    border-radius: 10px;
    padding: 18px;
}
.card h3 {
    margin: 0 0 12px;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #64748b;
}
.kv-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.kv-list li {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid #f1f5f9;
    font-size: 14px;
}
.kv-list li:last-child { border-bottom: 0; }
.kv-list strong { color: #0d1b2a; }

.estimate-card .estimate-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.estimate-card .estimate-table th,
.estimate-card .estimate-table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid #f1f5f9;
}
.estimate-card .estimate-table thead th {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #64748b;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8ef;
}
.estimate-card .estimate-table td .sub {
    color: #94a3b8;
    font-size: 12px;
    margin-left: 4px;
}
.estimate-card .estimate-table .total-row td {
    border-top: 2px solid #cbd5e1;
    border-bottom: 0;
    background: #eff6ff;
    font-weight: 600;
}
.estimate-card .estimate-table .total-row strong {
    color: #0d1b2a;
}
.estimate-card .hint {
    margin-top: 10px;
}

.map-card .plan-map {
    height: 420px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    background: #e2e8ef;
    margin-top: 8px;
}
.map-card .legend {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    font-size: 13px;
    color: #475569;
    margin-bottom: 10px;
}
.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.legend-sep {
    flex: 0 0 100%;
    height: 0;
    margin: 0;
}
.legend .swatch {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}
.legend .swatch.anchor { background: #dc2626; border: 1px solid #991b1b; }
.legend .swatch.zhub   { background: #7c3aed; border: 1px solid #4c1d95; }
.legend .swatch.inner  { background: #64748b; border: 1px solid #334155; width: 8px; height: 8px; }
.legend .swatch.walk-start { background: #10b981; border: 1px solid #065f46; }
.legend .swatch.walk-end   { background: #dc2626; border: 1px solid #7f1d1d; }

/* Numbered markers on the walk-route map. Leaflet divIcon-styled bubbles. */
.walk-marker {
    background: #64748b;
    color: #fff;
    border: 2px solid #fff;
    border-radius: 50%;
    text-align: center;
    font: 600 11px/18px "Segoe UI", Arial, sans-serif;
    box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.walk-marker.start  { background: #10b981; border-color: #065f46; }
.walk-marker.end    { background: #dc2626; border-color: #7f1d1d; }
.walk-marker.anchor { background: #dc2626; border-color: #991b1b; }
.legend .line {
    display: inline-block;
    width: 22px;
    height: 3px;
    border-radius: 2px;
}
.legend .line.alice   { background: #3388ff; }
.legend .line.bob     { background: #8b5cf6; }
.legend .line.charlie { background: #f59e0b; }

.actions-card .actions {
    flex-wrap: wrap;
    gap: 10px;
}
.btn-secondary {
    display: inline-block;
    background: #e2e8ef;
    color: #0d1b2a;
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: 600;
    border: 0;
    cursor: pointer;
}
.btn-secondary:hover { background: #cbd5e1; }
.btn-secondary:disabled {
    background: #f1f5f9;
    color: #94a3b8;
    cursor: not-allowed;
}
.btn-danger {
    display: inline-block;
    background: #dc2626;
    color: #fff;
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 15px;
    border: 0;
    cursor: pointer;
    transition: background .15s;
}
.btn-danger:hover { background: #b91c1c; }
.btn-danger:disabled {
    background: #fca5a5;
    color: #fff;
    cursor: not-allowed;
}

.cleanup-card {
    border-left: 3px solid #dc2626;
}
.outside-list {
    columns: 2;
    column-gap: 20px;
    list-style: disc inside;
    margin: 10px 0;
    padding: 0;
    font-size: 13px;
    color: #475569;
}
.outside-list li { break-inside: avoid; padding: 2px 0; }
.outside-list li.more { color: #94a3b8; font-style: italic; list-style: none; }
.anchor-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.anchor-list li {
    padding: 6px 0;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    justify-content: space-between;
    font-size: 14px;
}
.anchor-list li:last-child { border-bottom: 0; }
.coords { color: #94a3b8; font-family: Consolas, monospace; font-size: 12px; }

/* ---- Push progress ---- */
.push-status { margin-top: 14px; }
.push-status.hidden { display: none; }
.push-bar-outer {
    height: 12px;
    background: #e2e8ef;
    border-radius: 6px;
    overflow: hidden;
}
.push-bar-inner {
    height: 100%;
    background: #3388ff;
    transition: width .4s ease;
}
.push-meta {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    font-size: 13px;
    color: #475569;
}
.push-meta #push-count { font-family: Consolas, monospace; color: #94a3b8; }

/* ==================================================================
   Responsive layout
   ================================================================== */

/* Tablet portrait & below: single-column stacks */
@media (max-width: 820px) {
    .picker { grid-template-columns: 1fr; }
    .row-two { grid-template-columns: 1fr; }
    .anchor-map { height: 440px; }
}

/* Phone portrait: tighten every bit of chrome, shrink grids, widen tap
   targets, prevent iOS zoom on input focus, and let wide tables scroll
   horizontally instead of blowing out the layout. */
@media (max-width: 600px) {
    .container { padding: 0 12px; }

    /* CSS grid cells default to min-width: min-content, which lets inner
       text blocks force the whole grid wider than the viewport. Reset
       every grid item on this page so 1fr columns actually track the
       container width. */
    .stats-grid > *,
    .row-two > *,
    .features > *,
    .ops-grid > *,
    .picker > *,
    .agent-name-grid > * { min-width: 0; }

    /* Header: pack tighter, let the nav wrap under the brand if needed. */
    .site-header { padding: 10px 0; border-bottom-width: 2px; }
    .site-header .container { flex-wrap: wrap; gap: 8px; }
    .site-header .brand { font-size: 18px; }
    .site-header nav { gap: 10px; flex-wrap: wrap; }
    .site-header nav a { font-size: 13px; }
    .agent-badge { font-size: 11px; padding: 2px 8px; }

    main.container { padding-top: 20px; padding-bottom: 28px; }

    /* Hero + page headers */
    .hero { padding: 28px 18px 32px; }
    .hero h1 { font-size: 22px; }
    .hero .lead { font-size: 15px; }
    .page-head h1 { font-size: 21px; }
    .page-head p { font-size: 14px; }

    /* Landing feature grid */
    .features { grid-template-columns: 1fr; }

    /* Stat grids: 2-up on phone rather than trying to fit 4. */
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-card { padding: 12px; }
    .stat-value { font-size: 22px; }

    /* Anchor picker: bigger tap targets, narrower map still usable. */
    .anchor-map { height: 380px; }
    .picker-side { padding: 14px; }

    /* Scheme picker */
    .agent-name-grid { grid-template-columns: 1fr; }
    .scheme-option { padding: 14px; gap: 10px; }
    .scheme-option strong { font-size: 15px; }
    .scheme-option p { font-size: 13px; }
    .z-select { flex-direction: column; align-items: flex-start; }
    .z-select select { max-width: 100%; width: 100%; }

    /* Plan result */
    .map-card .plan-map { height: 340px; }
    .map-card .legend { font-size: 12px; gap: 10px; }
    .outside-list { columns: 1; }

    /* Summary tables: shrink to fit the card instead of overflowing it.
       Narrower padding + font, and wrap within cells are enough to avoid
       horizontal scroll at phone widths. The (keys) sub-hint breaks
       onto its own line inside the Phase 1 cell. */
    .estimate-card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .estimate-table,
    .long-links-table {
        font-size: 11px;
        table-layout: fixed;
        width: 100%;
    }
    .estimate-table th,
    .estimate-table td,
    .long-links-table th,
    .long-links-table td {
        padding: 4px 3px;
        white-space: normal;
        overflow-wrap: anywhere;
    }
    .estimate-table .sub { display: block; font-size: 10px; }

    /* Cards: slightly tighter padding, consistent with narrower container. */
    .card, .cleanup-card, .onboarding, .agents-section { padding: 14px; }

    /* Portal preview rows: allow names to wrap, coords drop to a new line. */
    .portal-row { flex-direction: column; align-items: flex-start; gap: 2px; }
    .portal-coords, .coords { font-size: 11px; }

    /* Long portal names in the anchor + key-destination lists pushed the
       number column off the right edge on 375 px viewports. Let the label
       take the full row and the count sit underneath. */
    .kv-list li,
    .anchor-list li {
        flex-wrap: wrap;
        gap: 2px 8px;
    }
    .kv-list li > span,
    .anchor-list li > strong,
    .anchor-list li > span {
        overflow-wrap: anywhere;
    }

    /* Global safety net: nothing should force the viewport wider than the
       phone's content area. Any cell / card content with a huge unbroken
       string now wraps instead of stretching the page. */
    body { overflow-x: hidden; }
    .card, .notice { overflow-wrap: anywhere; word-break: break-word; }
    .notice.danger { padding: 12px 14px; }
    .notice.danger strong { display: block; margin-bottom: 4px; }

    /* Form inputs: 16 px is the threshold below which iOS Safari auto-zooms
       when an input is focused. Bump everything up to avoid that UX hit. */
    .agent-name-grid input,
    .agent-name-grid select,
    .z-select select { font-size: 16px; }

    /* Buttons: make sure they clear the 44 px tap-target guideline. */
    .btn-primary, .btn-secondary, .btn-danger {
        min-height: 44px;
        padding: 10px 18px;
        font-size: 15px;
    }

    /* Result page action rows can stack when the button labels are long. */
    .actions-card .actions,
    .cleanup-card .actions { flex-direction: column; align-items: stretch; }
    .actions-card .actions > * { width: 100%; text-align: center; }

    /* Footer: stack brand line and links. */
    .site-footer .container {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 6px;
    }
}
