/* Datonet CMS
 *
 * A support tool, not a marketing site (D30). Datonet's identity sets the
 * accent; the layout prioritises information density and legibility because
 * staff read this all day, often while on a call.
 *
 * Brand colours are placeholders until extracted from datonet.co.za (D36).
 * Only --brand and --brand-dark should need changing.
 *
 * Health colours are deliberately SEPARATE from brand colours - if a red brand
 * accent were reused, it would start reading as an alarm.
 */

:root {
    --brand:        #0b6ab0;
    --brand-dark:   #084d80;
    --brand-tint:   #e8f2f9;

    --bg:           #f5f6f8;
    --surface:      #ffffff;
    --surface-2:    #fafbfc;
    --border:       #dde1e6;
    --text:         #1a1d21;
    --text-dim:     #5c6570;
    --text-faint:   #8b949e;

    --green:        #1a7f43;
    --green-bg:     #e6f4ec;
    --amber:        #9a6700;
    --amber-bg:     #fdf3d9;
    --red:          #b3261e;
    --red-bg:       #fbeae9;
    --neutral:      #5c6570;
    --neutral-bg:   #eef0f2;

    --radius:       6px;
    --gap:          16px;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:         #14171a;
        --surface:    #1c2024;
        --surface-2:  #22272b;
        --border:     #30363d;
        --text:       #e6edf3;
        --text-dim:   #9aa4ae;
        --text-faint: #6e7781;

        --brand-tint: #10283a;
        --green-bg:   #12281c;
        --amber-bg:   #2b2210;
        --red-bg:     #2d1614;
        --neutral-bg: #262b30;

        --green:      #4ac776;
        --amber:      #d9a400;
        --red:        #ef6b60;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--sans);
    font-size: 14px;
    line-height: 1.45;
    color: var(--text);
    background: var(--bg);
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Top bar ---------- */

.topbar {
    display: flex;
    align-items: center;
    gap: var(--gap);
    padding: 10px 18px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.brand { display: flex; align-items: center; gap: 9px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
    display: grid;
    place-items: center;
    width: 28px; height: 28px;
    background: var(--brand);
    color: #fff;
    border-radius: var(--radius);
    font-weight: 700;
}
.brand-name { font-size: 15px; letter-spacing: -0.01em; white-space: nowrap; }
.brand-name strong { color: var(--brand); }

.search { flex: 1; max-width: 620px; position: relative; }
.search input {
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.search input:focus {
    outline: 2px solid var(--brand);
    outline-offset: -1px;
    background: var(--surface);
}

.suggest {
    position: absolute;
    top: calc(100% + 4px); left: 0; right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,.12);
    overflow: hidden;
    z-index: 60;
}
.suggest a {
    display: flex; justify-content: space-between; gap: 12px;
    padding: 8px 12px;
    color: var(--text);
    border-bottom: 1px solid var(--border);
}
.suggest a:last-child { border-bottom: 0; }
.suggest a:hover, .suggest a.sel { background: var(--brand-tint); text-decoration: none; }
.suggest .code { font-family: var(--mono); color: var(--brand); font-size: 12px; }

.nav { display: flex; gap: 4px; }
.nav a {
    padding: 6px 11px;
    border-radius: var(--radius);
    color: var(--text-dim);
    white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--brand-tint); color: var(--brand); font-weight: 600; }

.user { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.user-name { color: var(--text-dim); font-size: 13px; white-space: nowrap; }
a.user-name:hover { color: var(--brand); text-decoration: none; }

/* Per-permission results under "Test connection" */
.test-checks { list-style: none; margin: 6px 0 0; padding: 0; font-size: 12.5px; }
.test-checks li { margin-bottom: 2px; }
.test-checks li.ok   { color: var(--green); }
.test-checks li.fail { color: var(--red); }
.link {
    background: none; border: 0; padding: 0;
    color: var(--brand); cursor: pointer; font: inherit;
}

/* ---------- Layout ---------- */

.page { padding: 18px; max-width: 1500px; margin: 0 auto; }

.grid { display: grid; gap: var(--gap); }
.grid.cols-2 { grid-template-columns: 2fr 1fr; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 1000px) {
    .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
    .topbar { flex-wrap: wrap; }
    .search { order: 3; flex-basis: 100%; max-width: none; }
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.card + .card { margin-top: var(--gap); }
.card-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}
.card-head h2 { margin: 0; font-size: 13px; text-transform: uppercase;
                letter-spacing: .05em; color: var(--text-dim); }
.card-body { padding: 14px; }
.card-body.tight { padding: 0; }

h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
h3 { font-size: 14px; margin: 0 0 8px; }

.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.mono  { font-family: var(--mono); font-size: 12.5px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- Tables ---------- */

table { width: 100%; border-collapse: collapse; }
th {
    text-align: left; padding: 8px 14px;
    font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-dim); background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0;
}
td { padding: 8px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }

.scroll-x { overflow-x: auto; }

/* ---------- Status ---------- */

.pill {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px; font-weight: 600;
    white-space: nowrap;
}
/* Status is never colour alone (D30) - each pill carries a glyph too. */
.pill::before { font-family: var(--mono); font-size: 10px; }
.pill.green   { background: var(--green-bg);   color: var(--green); }
.pill.green::before { content: "\25CF"; }
.pill.amber   { background: var(--amber-bg);   color: var(--amber); }
.pill.amber::before { content: "\25B2"; }
.pill.red     { background: var(--red-bg);     color: var(--red); }
.pill.red::before { content: "\2715"; }
.pill.neutral { background: var(--neutral-bg); color: var(--neutral); }
.pill.neutral::before { content: "\2013"; }

/* ---------- Health tiles (D35) ---------- */

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }

.tile {
    padding: 11px 13px;
    border: 1px solid var(--border);
    border-left-width: 3px;
    border-radius: var(--radius);
    background: var(--surface);
}
.tile.green   { border-left-color: var(--green);   background: var(--green-bg); }
.tile.amber   { border-left-color: var(--amber);   background: var(--amber-bg); }
.tile.red     { border-left-color: var(--red);     background: var(--red-bg); }
.tile.neutral { border-left-color: var(--neutral); }

.tile-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.tile-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
              color: var(--text-dim); }
.tile-value { font-size: 19px; font-weight: 600; font-family: var(--mono); }
/* The plain-English meaning - the whole point of the tile (D35). */
.tile-meaning { margin-top: 5px; font-size: 12.5px; line-height: 1.4; color: var(--text-dim); }

/* ---------- First glance: verdict + topology (Q71) ----------
 * The top of the customer page answers "are they online" and "what is between
 * us and them", and nothing else. Everything else is in a drawer below.
 */

.glance {
    display: grid; grid-template-columns: 230px 1fr; gap: var(--gap);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: var(--gap);
}
@media (max-width: 900px) { .glance { grid-template-columns: 1fr; } }

.glance-verdict {
    display: flex; flex-direction: column; justify-content: center;
    padding: 12px 14px; border-radius: var(--radius);
    border-left: 4px solid var(--neutral); background: var(--neutral-bg);
}
.glance-verdict.green { border-left-color: var(--green); background: var(--green-bg); }
.glance-verdict.amber { border-left-color: var(--amber); background: var(--amber-bg); }
.glance-verdict.red   { border-left-color: var(--red);   background: var(--red-bg); }

/* The word carries the meaning - the colour only reinforces it (D30). */
.glance-label { font-size: 25px; font-weight: 700; line-height: 1.1; letter-spacing: -0.01em; }
.glance-verdict.green .glance-label { color: var(--green); }
.glance-verdict.amber .glance-label { color: var(--amber); }
.glance-verdict.red   .glance-label { color: var(--red); }
.glance-verdict.neutral .glance-label { color: var(--neutral); }
.glance-detail { margin-top: 5px; font-size: 12.5px; color: var(--text-dim); }

.glance-topology { display: flex; flex-direction: column; gap: 8px;
                   justify-content: center; min-width: 0; }

/* Same renderer and same visual language as the /topology graph, just smaller -
   an agent should not have to learn two topology views (D24). */
/* Boxed nodes need more room than bare dots did. The site page's map is the main
   navigation view (D41), so it opens taller than an embedded panel. */
#site-graph {
    width: 100%; height: 420px;
    background: var(--surface-2);
    border: 1px solid var(--border); border-radius: var(--radius);
}
#customer-graph, #device-graph {
    width: 100%; height: 320px;
    background: var(--surface-2);
    border: 1px solid var(--border); border-radius: var(--radius);
}
@media (max-width: 900px) { #customer-graph, #device-graph { height: 240px; } }

.chain-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chain { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.chain-arrow { color: var(--text-faint); }
.chain-note { font-size: 12px; color: var(--amber); }
.chain-legend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center;
                font-size: 12px; margin-top: 2px; }
.chain-legend span { display: flex; align-items: center; gap: 6px; }

.hop {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 5px 10px;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface-2); color: var(--text);
    max-width: 100%;
}
.hop:hover { text-decoration: none; border-color: var(--brand); }
.hop.amber { border-color: var(--amber); background: var(--amber-bg); }
.hop.red   { border-color: var(--red);   background: var(--red-bg); }
/* The customer's own device, so an agent can see at a glance which end is theirs. */
.hop.theirs { outline: 2px solid var(--brand); outline-offset: 1px; font-weight: 600; }

.hop-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 24ch; }
.hop-role { font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
            color: var(--text-faint); }

/* Status is never colour alone (D30) - the dot carries the same glyph as a pill. */
.hop-dot { font-family: var(--mono); font-size: 10px; line-height: 1; }
.hop-dot.green::before   { content: "\25CF"; color: var(--green); }
.hop-dot.amber::before   { content: "\25B2"; color: var(--amber); }
.hop-dot.red::before     { content: "\2715"; color: var(--red); }
.hop-dot.neutral::before { content: "\2013"; color: var(--neutral); }

/* Detail on demand: a card that opens. The chevron replaces the browser's own
   marker so the head keeps the same layout as a plain card head. */
.drawer > summary { cursor: pointer; list-style: none; justify-content: flex-start; }
.drawer > summary > h2 { margin-right: auto; }
.drawer > summary::-webkit-details-marker { display: none; }
.drawer > summary::after { content: "\25BE"; color: var(--text-faint); font-size: 11px; }
.drawer[open] > summary::after { content: "\25B4"; }
.drawer > summary:hover { background: var(--brand-tint); }

/* ---------- Customer page ---------- */

.customer-head {
    display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap;
    margin-bottom: var(--gap);
}
.customer-code {
    font-family: var(--mono); font-size: 13px; font-weight: 600;
    color: var(--brand); background: var(--brand-tint);
    padding: 3px 9px; border-radius: var(--radius);
}
.actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
    display: inline-block;
    padding: 6px 13px;
    font: inherit; font-size: 13px;
    color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius);
    cursor: pointer;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { background: var(--red-bg); border-color: var(--red); color: var(--red); }
.btn.danger:hover { background: var(--red); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

dl.facts { display: grid; grid-template-columns: minmax(110px, auto) 1fr;
           gap: 5px 14px; margin: 0; }
dl.facts dt { color: var(--text-dim); font-size: 12.5px; }
dl.facts dd { margin: 0; }

.device {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    background: var(--surface);
}
.device-head {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 10px 13px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}
.device-name { font-weight: 600; }
.device-meta { color: var(--text-dim); font-size: 12.5px; }
.device-body { padding: 13px; }

/* Capability notice - never leave an agent guessing whether an empty list
   means "nothing there" or "we cannot see in" (D16). */
.capability {
    margin-top: 10px; padding: 9px 12px;
    border-radius: var(--radius); font-size: 12.5px;
    border: 1px dashed var(--border);
    color: var(--text-dim);
}
.capability.none    { border-color: var(--amber); background: var(--amber-bg); color: var(--amber); }
.capability.partial { border-color: var(--border); }

.banner {
    padding: 11px 14px; border-radius: var(--radius); margin-bottom: var(--gap);
    border: 1px solid transparent;
}
.banner.info  { background: var(--brand-tint); border-color: var(--brand); }
.banner.warn  { background: var(--amber-bg);   border-color: var(--amber); color: var(--amber); }
.banner.error { background: var(--red-bg);     border-color: var(--red);   color: var(--red); }
.banner.ok    { background: var(--green-bg);   border-color: var(--green); color: var(--green); }

.stat { text-align: center; padding: 6px 0; }
.stat-value { font-size: 26px; font-weight: 600; line-height: 1.1; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
              color: var(--text-dim); margin-top: 3px; }

.stale {
    display: inline-block; font-size: 11px; padding: 1px 7px;
    background: var(--amber-bg); color: var(--amber);
    border-radius: 999px; font-weight: 600;
}

/* ---------- Auth ---------- */

.auth-wrap { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface);
             border: 1px solid var(--border); border-radius: var(--radius); padding: 26px; }
.auth-card h1 { text-align: center; margin-bottom: 20px; }
/* Relative so a type-ahead dropdown inside a form field anchors to the field
   rather than to the page (the device pickers on a site page). */
.field { margin-bottom: 13px; position: relative; }
.field label { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 4px; }
.field input, .field select, .field textarea {
    width: 100%; padding: 8px 11px; font: inherit;
    color: var(--text); background: var(--surface-2);
    border: 1px solid var(--border); border-radius: var(--radius);
}
.field input:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.code-input { font-family: var(--mono); font-size: 22px !important;
              text-align: center; letter-spacing: .3em; }
.totp-secret {
    font-family: var(--mono); font-size: 15px; word-break: break-all;
    background: var(--surface-2); padding: 11px; border-radius: var(--radius);
    border: 1px solid var(--border); text-align: center; user-select: all;
}

/* ---------- Wallboard (D12) ---------- */

body.wallboard {
    background: #0a0d10; color: #e6edf3;
    font-size: 17px; padding: 22px; overflow: hidden;
}
.wb-head { display: flex; align-items: baseline; justify-content: space-between;
           margin-bottom: 18px; }
.wb-head h1 { font-size: 30px; }
.wb-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 22px; }
.wb-panel { background: #12171c; border: 1px solid #232b33; border-radius: 8px; padding: 16px; }
.wb-panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .12em;
               color: #7d8894; margin: 0 0 12px; }
.wb-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 22px; }
.wb-stat { background: #12171c; border: 1px solid #232b33; border-radius: 8px;
           padding: 16px; text-align: center; }
.wb-stat .v { font-size: 42px; font-weight: 700; line-height: 1; }
.wb-stat .l { font-size: 12px; text-transform: uppercase; letter-spacing: .12em;
              color: #7d8894; margin-top: 7px; }
.wb-stat.down .v { color: #ef6b60; }
.wb-stat.up .v   { color: #4ac776; }
.wb-row { display: flex; justify-content: space-between; gap: 12px;
          padding: 8px 0; border-bottom: 1px solid #1d242b; }
.wb-row:last-child { border-bottom: 0; }
.wb-affected { font-weight: 700; color: #ef6b60; }

/* A stale wallboard showing all-green because polling died is worse than no
   wallboard at all. So it says so, loudly (D12). */
.wb-stale {
    background: #3d1a17; border: 2px solid #ef6b60; color: #ff9d94;
    padding: 14px 18px; border-radius: 8px; margin-bottom: 18px;
    font-size: 19px; font-weight: 700; text-align: center;
}

/* ---------- Topology ---------- */

#graph { width: 100%; height: 720px; background: var(--surface);
         border: 1px solid var(--border); border-radius: var(--radius); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 10px;
          font-size: 12.5px; color: var(--text-dim); }
.legend span { display: flex; align-items: center; gap: 6px; }
.swatch { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }

.empty { padding: 34px 18px; text-align: center; color: var(--text-dim); }
.empty strong { display: block; margin-bottom: 5px; color: var(--text); }

/* ---------- Photos (D43) ----------
 *
 * The CMS is the only copy of these, so the grid is built to be read rather
 * than skimmed: a real thumbnail, what it shows, and who put it there.
 */

.photo-upload {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: var(--gap);
}

.photo-upload-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.photo-upload-row input[type="text"],
.photo-upload-row select {
    padding: 8px 10px;
    font: inherit;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.photo-upload-row input[type="text"] { flex: 1; min-width: 180px; }

.photo-pick { cursor: pointer; }

/* Thumb-sized targets: this is used one-handed, on a roof. */
.photo-actions { display: flex; gap: 8px; margin-bottom: 10px; }
.photo-actions .btn.big,
.btn.big {
    flex: 1;
    padding: 14px 16px;
    font-size: 16px;
    text-align: center;
}

.photo-queue { margin-top: 10px; display: grid; gap: 4px; }

.photo-queue-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
}

.photo-queue-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.photo-queue-state { color: var(--text-dim); }
.photo-queue-row.done   { border-color: var(--green); }
.photo-queue-row.done   .photo-queue-state { color: var(--green); }
.photo-queue-row.failed { border-color: var(--red); background: var(--red-bg); }
.photo-queue-row.failed .photo-queue-state { color: var(--red); }

.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}

.photo-tile {
    margin: 0;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.photo-open {
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    background: var(--neutral-bg);
    cursor: zoom-in;
}

.photo-open img {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
}

.photo-tile figcaption { padding: 8px 10px; }
.photo-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.photo-caption { margin-top: 4px; }
.photo-sub { margin-top: 2px; font-size: 12px; }

.photo-edit { border-top: 1px solid var(--border); }
.photo-edit summary {
    padding: 6px 10px;
    cursor: pointer;
    color: var(--text-dim);
    font-size: 12px;
}
.photo-edit form { padding: 0 10px 10px; }

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 20px;
    background: rgba(0, 0, 0, .88);
}

.lightbox img {
    max-width: 100%;
    max-height: calc(100vh - 90px);
    object-fit: contain;
    border-radius: var(--radius);
}

.lightbox-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    max-width: 100%;
    flex-wrap: wrap;
    justify-content: center;
}

/* The field app is a phone screen first. */
.field-app .page { max-width: 680px; }
.field-app .photo-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }

@media (max-width: 600px) {
    .photo-upload-row { flex-direction: column; align-items: stretch; }
    .photo-upload-row input[type="text"] { min-width: 0; }
}

/* "Don't ask for a code on this device" (D44). A checkbox on the auth cards,
   which are otherwise all full-width fields. */
.remember {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 0 14px;
    font-size: 13px;
    color: var(--text-dim);
    cursor: pointer;
}
.remember input { margin: 0; }
