/* Fill Plan additions to css/app.css (the shared ClearView stylesheet). */

.flash { margin-bottom: 14px; }
.toast-box { position: fixed; right: 16px; bottom: 72px; display: grid; gap: 8px; z-index: 60; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 10px 14px; border-radius: 10px; background: var(--text); color: #fff; box-shadow: var(--shadow); font-size: 14px; }
.toast-error { background: var(--danger); }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.gap { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn.active { background: var(--brand-soft); border-color: var(--brand); color: #065f46; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: #fef2f2; border-color: #fecaca; }
.input-sm { min-height: 32px; padding: 4px 8px; }
textarea.input { resize: vertical; }
select.input { padding-right: 28px; }

/* Site sub-navigation under the top bar */
.site-bar { position: sticky; top: 61px; z-index: 19; background: var(--card); border-bottom: 1px solid var(--border); }
.site-tabs { display: flex; gap: 2px; padding: 0 12px; overflow-x: auto; scrollbar-width: none; max-width: 1400px; margin: 0 auto; }
.site-tabs::-webkit-scrollbar { display: none; }
.site-tab { padding: 11px 12px; font-weight: 700; font-size: 14px; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.site-tab:hover { color: var(--text); }
.site-tab.active { color: #065f46; border-bottom-color: var(--brand); }

/* Tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; font-weight: 700; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: #fafafa; }
.tbl th.num, .tbl td.num { text-align: right; }
.tbl .input { min-height: 34px; padding: 5px 8px; }
.tbl tfoot td { font-weight: 800; border-top: 2px solid var(--border); }
.card-flush { padding: 0; overflow: hidden; }
.card-flush .tbl th:first-child, .card-flush .tbl td:first-child { padding-left: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.card-head h2, .card-head h3 { margin: 0; font-size: 15px; font-weight: 800; }

.page-head { margin-bottom: 14px; }
.page-head h2 { margin: 0; font-size: 20px; font-weight: 800; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* Stats row */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { padding: 12px 14px; }
.kpi .k { font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.kpi .v { margin-top: 4px; font-size: 24px; font-weight: 800; line-height: 1.15; }
.kpi .s { margin-top: 2px; font-size: 12px; color: var(--muted); }

/* Status chips */
.st { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--hover); color: var(--muted); }
.st::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.st-planned { color: #6b7280; }
.st-constructed { color: #1d4ed8; background: #eff6ff; }
.st-active { color: #047857; background: var(--brand-soft); }
.st-full { color: #b45309; background: #fff7ed; }
.st-closed { color: #374151; background: #e5e7eb; }

/* Site cards on the home page */
.site-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.site-card { display: flex; flex-direction: column; padding: 0; overflow: hidden; transition: box-shadow .15s; }
.site-card:hover { box-shadow: 0 8px 22px rgba(17, 24, 39, .14); }
.site-thumb { aspect-ratio: 16 / 9; background: #e5e7eb center / cover no-repeat; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
.site-card-body { padding: 12px 14px 14px; display: grid; gap: 8px; }
.site-card-body h3 { margin: 0; font-size: 16px; font-weight: 800; }
.site-card .meta { font-size: 13px; color: var(--muted); }
.fill-bar { height: 8px; border-radius: 999px; background: var(--hover); overflow: hidden; }
.fill-bar span { display: block; height: 100%; background: linear-gradient(90deg, #00cd8a, #f59e0b 80%, #dc2626); background-size: 400px 100%; }
.site-add { align-items: center; justify-content: center; min-height: 220px; border: 2px dashed var(--border); box-shadow: none; color: var(--muted); font-weight: 700; }
.site-add:hover { border-color: var(--brand); color: #065f46; }

/* ---------- Image viewer (js/viewer.js) ---------- */
.viewer { position: relative; overflow: hidden; background: #1f2937; border-radius: var(--radius); height: min(72vh, 760px); min-height: 360px; touch-action: none; user-select: none; cursor: grab; }
.viewer.dragging { cursor: grabbing; }
.viewer.mode-draw, .viewer.mode-measure { cursor: crosshair; }
.viewer-stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.viewer-stage img { display: block; max-width: none; pointer-events: none; }
.viewer-stage svg { position: absolute; left: 0; top: 0; overflow: visible; }
.viewer-tools { position: absolute; right: 10px; top: 10px; display: flex; flex-direction: column; gap: 6px; z-index: 2; }
.viewer-tools .btn { min-height: 36px; width: 36px; padding: 0; background: rgba(255, 255, 255, .95); font-size: 18px; }
.viewer-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #d1d5db; text-align: center; padding: 20px; }
.viewer-hint { position: absolute; left: 10px; bottom: 10px; z-index: 2; padding: 6px 10px; border-radius: 8px; background: rgba(17, 24, 39, .85); color: #fff; font-size: 13px; max-width: calc(100% - 20px); }
.viewer-legend { position: absolute; left: 10px; top: 10px; z-index: 2; display: flex; flex-wrap: wrap; gap: 6px; max-width: calc(100% - 70px); }
.viewer-legend span { padding: 3px 8px; border-radius: 999px; background: rgba(255, 255, 255, .92); font-size: 12px; font-weight: 700; display: inline-flex; gap: 6px; align-items: center; }
.viewer-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* Area shapes on the SVG overlay */
.ar { stroke: #fff; vector-effect: non-scaling-stroke; stroke-width: 2; fill-opacity: .45; cursor: pointer; }
.ar:hover { fill-opacity: .6; }
.ar.sel { stroke: #facc15; stroke-width: 3; fill-opacity: .55; }
.ar-label { font-weight: 800; fill: #fff; paint-order: stroke; stroke: rgba(0, 0, 0, .65); stroke-linejoin: round; pointer-events: none; text-anchor: middle; dominant-baseline: middle; }
.vtx { fill: #fff; stroke: #111827; vector-effect: non-scaling-stroke; stroke-width: 1.5; cursor: move; }
.vtx.first { fill: #facc15; }
.draft { fill: rgba(250, 204, 21, .25); stroke: #facc15; stroke-width: 2.5; vector-effect: non-scaling-stroke; stroke-dasharray: 6 4; pointer-events: none; }
.measure-line { stroke: #f43f5e; stroke-width: 3; vector-effect: non-scaling-stroke; }
.measure-pt { fill: #f43f5e; stroke: #fff; stroke-width: 1.5; vector-effect: non-scaling-stroke; }

/* Areas editor layout */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 14px; align-items: start; }
.editor-side { display: grid; gap: 12px; position: sticky; top: 120px; max-height: calc(100vh - 136px); overflow: auto; }
.area-list { display: grid; gap: 4px; }
.area-row { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 7px 8px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; }
.area-row:hover { background: var(--hover); }
.area-row.sel { background: var(--brand-soft); border-color: #a7f3d0; }
.area-row .sw { width: 14px; height: 14px; border-radius: 4px; }
.area-row .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.area-row .sub { font-size: 12px; color: var(--muted); }
.area-row.child { margin-left: 18px; }
.area-row.no-geom .nm::after { content: " (no outline)"; font-weight: 500; color: var(--muted); font-size: 12px; }
.area-form .form-grid { grid-template-columns: 1fr 1fr; }
.area-form .field-wide { grid-column: 1 / -1; }

/* Progression */
.timeline { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 14px; }
.timeline input[type=range] { width: 100%; accent-color: var(--brand-dark); }
.timeline .when { font-size: 20px; font-weight: 800; min-width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
.prog-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 14px; align-items: start; }
.chart { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--border); }
.chart text { font-size: 11px; fill: var(--muted); }
.chart .used { fill: rgba(0, 205, 138, .25); stroke: #00a06c; stroke-width: 2; }
.chart .cap { stroke: #dc2626; stroke-dasharray: 5 4; stroke-width: 1.5; }
.chart .cursor { stroke: #111827; stroke-width: 1.5; }
.chart .actual { fill: none; stroke: #1d4ed8; stroke-width: 2; }
.ramp { height: 10px; border-radius: 999px; background: linear-gradient(90deg, #22c55e, #eab308, #f97316, #dc2626); }

/* Images */
.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.img-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.img-card .thumb { aspect-ratio: 4 / 3; background: #e5e7eb center / cover no-repeat; display: block; }
.img-card .body { padding: 10px 12px; display: grid; gap: 6px; font-size: 13px; }
.img-card .body strong { font-size: 14px; }
.img-card.is-base { outline: 3px solid var(--brand); }
.drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted); }
.drop.over { border-color: var(--brand); background: var(--brand-soft); }

/* Scenario page */
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.order-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.order-list li { display: grid; grid-template-columns: 28px 14px minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 6px 8px; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.order-list li.dragging { opacity: .5; }
.order-list .handle { cursor: grab; color: var(--muted); text-align: center; }
.order-list .sw { width: 14px; height: 14px; border-radius: 4px; }
.order-list li.off { opacity: .5; }

@media (max-width: 1100px) {
  .editor, .prog-layout { grid-template-columns: 1fr; }
  .editor-side { position: static; max-height: none; }
}
@media (max-width: 980px) {
  .site-bar { top: 67px; }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .timeline { grid-template-columns: auto minmax(0, 1fr); }
  .timeline .when { grid-column: 1 / -1; text-align: left; }
  .area-form .form-grid { grid-template-columns: 1fr; }
  .viewer { height: 60vh; }
}

/* Buttons inside stacked forms keep their natural width (app.css .stack .btn is full width for sign-in). */
.card.stack .btn, form.stack .btn, .area-form .btn { width: auto; }
.auth-card .stack .btn { width: 100%; }

/* Users page: temporary password while the user hasn't set their own */
.temp-pw { display: flex; align-items: center; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.temp-pw code { padding: 3px 8px; border-radius: 6px; background: #fff7ed; border: 1px solid #fed7aa; font-size: 13px; user-select: all; }

/* Image cards: link area + delete row */
.img-card .img-link { display: flex; flex-direction: column; color: inherit; }
.img-del { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px 10px; border-top: 1px solid var(--border); margin-top: auto; }
/* Cell list: delete button per row */
.area-row { grid-template-columns: 14px minmax(0, 1fr) auto auto; }
.area-row .row-del { min-height: 28px; width: 28px; padding: 0; font-size: 16px; line-height: 1; color: var(--muted); border-color: transparent; background: transparent; }
.area-row .row-del:hover { color: var(--danger); background: #fef2f2; border-color: #fecaca; }
