/* Tekhne Web Inspections — no external CSS framework, by design. Mobile first. */

:root {
    --green: #009150;
    --green-dark: #007a43;
    --green-tint: #e8f5ee;
    --green-border: #b2dfc5;
    --text: #2b2b2b;
    --muted: #666;
    --faint: #999;
    --bg: #f4f5f4;
    --card: #fff;
    --line: #e2e4e2;
    --input-border: #c8ccc8;
    --danger: #c62828;
    --danger-tint: #fdecea;
    --warning: #8a5a00;
    --warning-tint: #fff4dc;
    --info-tint: #eef4fb;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    color: var(--text);
    background: var(--bg);
}

a { color: var(--green-dark); }
a:hover { color: var(--green); }

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: 1.45rem; color: var(--green); }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.75em; }

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

.topbar {
    background: #fff;
    border-bottom: 3px solid var(--green);
    padding: 8px 16px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 18px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--green);
    font-weight: 700;
    font-size: 1.05rem;
}
.brand img { height: 30px; width: auto; }

.nav {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    flex: 1;
}
.nav a {
    text-decoration: none;
    color: #444;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.95rem;
}
.nav a:hover { background: var(--green-tint); color: var(--green-dark); }
.nav a.active { background: var(--green); color: #fff; }

.user-menu {
    font-size: 0.85rem;
    color: var(--muted);
    display: flex;
    gap: 10px;
    align-items: center;
}

.dev-banner {
    background: var(--warning-tint);
    color: var(--warning);
    font-size: 0.8rem;
    text-align: center;
    padding: 3px 8px;
    border-bottom: 1px solid #f0d9a8;
}

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

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 16px;
}
.container.wide { max-width: 1600px; }

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px 16px;
    margin-bottom: 14px;
}
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); font-size: 0.92rem; margin-top: 2px; }

.breadcrumbs { font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
.breadcrumbs a { color: var(--muted); }

.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.card-head h2 { margin: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 900px) {
    .grid-2 { grid-template-columns: 1fr 1fr; align-items: start; }
}

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.hidden { display: none !important; }

/* ---------- Tiles (home) ---------- */

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.tile {
    display: block;
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    text-decoration: none;
    color: var(--text);
    border-left: 5px solid var(--green);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.tile:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); color: var(--text); }
.tile strong { display: block; font-size: 1.05rem; color: var(--green-dark); margin-bottom: 4px; }
.tile span { font-size: 0.88rem; color: var(--muted); }
.tile .count {
    float: right;
    background: var(--danger);
    color: #fff;
    border-radius: 12px;
    padding: 1px 9px;
    font-size: 0.8rem;
    font-weight: 700;
}

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    min-height: 40px;
    border: 1px solid var(--green);
    border-radius: 6px;
    background: var(--green);
    color: #fff;
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { background: var(--green-dark); border-color: var(--green-dark); color: #fff; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--green-dark); }
.btn.secondary:hover { background: var(--green-tint); color: var(--green-dark); }
.btn.danger { background: #fff; color: var(--danger); border-color: #e3a4a4; }
.btn.danger:hover { background: var(--danger-tint); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--green-dark); padding-left: 8px; padding-right: 8px; }
.btn.ghost:hover { background: var(--green-tint); }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: 0.85rem; }
.btn.block { display: flex; width: 100%; }
.btn.big { padding: 12px 22px; font-size: 1.05rem; }

.link-button {
    background: none;
    border: none;
    padding: 0;
    color: var(--green-dark);
    font: inherit;
    text-decoration: underline;
    cursor: pointer;
}

/* ---------- Forms ---------- */

.field { margin-bottom: 14px; }
.field label, .label {
    display: block;
    font-weight: 600;
    margin-bottom: 5px;
    color: #3a3a3a;
    font-size: 0.93rem;
}
.field .hint { font-size: 0.82rem; color: var(--muted); margin-top: 4px; }

input[type="text"], input[type="email"], input[type="date"], input[type="search"], input[type="number"],
select, textarea {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--input-border);
    border-radius: 6px;
    font: inherit;
    font-size: 16px; /* stops iOS zooming into inputs */
    background: #fff;
    color: var(--text);
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--green-border);
    border-color: var(--green);
}

.field-row { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 640px) {
    .field-row { grid-template-columns: 1fr 1fr; }
    .field-row.three { grid-template-columns: 1fr 1fr 1fr; }
}

.check {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    font-weight: normal;
    margin: 6px 0;
    cursor: pointer;
}
.check input { width: 18px; height: 18px; margin-top: 2px; flex-shrink: 0; accent-color: var(--green); }

.inline-form { display: inline; }

.file-button { position: relative; overflow: hidden; }
.file-button input[type="file"] {
    position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 100px;
}

/* ---------- Flash messages ---------- */

.flashes { margin-bottom: 14px; }
.flash {
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 8px;
    border: 1px solid;
    font-size: 0.93rem;
}
.flash.success { background: var(--green-tint); border-color: var(--green-border); color: #145c36; }
.flash.error { background: var(--danger-tint); border-color: #f1b7b7; color: #8e1c1c; }
.flash.warning { background: var(--warning-tint); border-color: #f0d9a8; color: var(--warning); }
.flash.info { background: var(--info-tint); border-color: #c7daf0; color: #28486f; }

.notice {
    padding: 12px 14px;
    border-radius: 6px;
    margin-bottom: 14px;
    background: var(--info-tint);
    border: 1px solid #c7daf0;
    font-size: 0.93rem;
}
.notice.warning { background: var(--warning-tint); border-color: #f0d9a8; color: var(--warning); }
.notice.danger { background: var(--danger-tint); border-color: #f1b7b7; color: #8e1c1c; }
.notice.success { background: var(--green-tint); border-color: var(--green-border); color: #145c36; }

/* ---------- Badges ---------- */

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    vertical-align: middle;
    background: #eee;
    color: #555;
    white-space: nowrap;
}
.badge.draft { background: #e7eef8; color: #2d5a8c; }
.badge.failed { background: var(--danger-tint); color: var(--danger); }
.badge.queued, .badge.generating { background: var(--warning-tint); color: var(--warning); }
.badge.issued { background: var(--green-tint); color: #145c36; }
.badge.superseded { background: #eee; color: #777; }
.badge.open, .badge.rectified { background: var(--danger-tint); color: var(--danger); }
.badge.closed { background: var(--green-tint); color: #145c36; }
.badge.rev { background: #fff3cd; color: #856404; }
.badge.count { background: var(--danger); color: #fff; }
.badge.muted { background: #f0f0f0; color: #777; }

.chip {
    display: inline-block;
    background: var(--green-tint);
    border: 1px solid var(--green-border);
    color: #245c3d;
    border-radius: 12px;
    padding: 1px 8px;
    font-size: 0.78rem;
    margin: 2px 2px 0 0;
}

/* ---------- Lists & tables ---------- */

.list { list-style: none; margin: 0; padding: 0; }
.list > li {
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}
.list > li:last-child { border-bottom: none; }
.list .item-title { font-weight: 600; }
.list .item-meta { font-size: 0.85rem; color: var(--muted); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th {
    text-align: left;
    background: var(--green);
    color: #fff;
    padding: 8px 10px;
    font-weight: 600;
    white-space: nowrap;
}
.table td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:hover td { background: #f7fbf8; }
.table .actions { text-align: right; white-space: nowrap; }

.dl { display: grid; grid-template-columns: 1fr; gap: 2px 16px; margin: 0; }
.dl dt { font-weight: 600; color: #555; font-size: 0.85rem; margin-top: 8px; }
.dl dd { margin: 0; }
@media (min-width: 640px) {
    .dl { grid-template-columns: 190px 1fr; }
    .dl dt { margin-top: 0; }
    .dl dt, .dl dd { padding: 5px 0; border-bottom: 1px solid var(--line); }
}

.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }

.group-title {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin: 18px 0 4px;
}

details.more { margin-top: 12px; }
details.more > summary { cursor: pointer; color: var(--green-dark); font-weight: 600; padding: 4px 0; }
details.more[open] > summary { margin-bottom: 8px; }

.empty { color: var(--muted); padding: 14px 0; text-align: center; font-style: italic; }

/* ---------- Photos ---------- */

.photo-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.photo-card {
    display: flex;
    gap: 10px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px;
    background: #fff;
}
.photo-card img { width: 110px; height: 82px; object-fit: cover; border-radius: 4px; flex-shrink: 0; background: #eee; }
.photo-card input { flex: 1; min-width: 0; }
.photo-card.uploading { opacity: 0.6; }

.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.thumbs a, .thumbs .thumb { display: block; position: relative; }
.thumbs img { width: 96px; height: 72px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); display: block; }
.thumbs .caption { font-size: 0.72rem; color: var(--muted); text-align: center; }

.attachment-list { list-style: none; padding: 0; margin: 8px 0 0; }
.attachment-list li {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 6px 10px; border: 1px solid var(--green-border); background: var(--green-tint);
    border-radius: 6px; margin-bottom: 6px; font-size: 0.9rem;
}

/* ---------- Signature ---------- */

.signature-pad {
    display: block;
    width: 100%;
    height: 170px;
    border: 1px solid #555;
    border-radius: 6px;
    background: #fff;
    touch-action: none;
    cursor: crosshair;
}
.signature-existing { border: 1px dashed var(--input-border); border-radius: 6px; padding: 8px; background: #fff; }
.signature-existing img { max-height: 110px; max-width: 100%; }

/* ---------- Sticky action bar (long forms) ---------- */

.action-bar {
    position: sticky;
    bottom: 0;
    z-index: 40;
    background: rgba(255, 255, 255, 0.97);
    border-top: 1px solid var(--line);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
    padding: 10px 16px;
    margin: 0 -16px -16px;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    flex-wrap: wrap;
}
.action-bar .status-text { margin-right: auto; align-self: center; font-size: 0.85rem; color: var(--muted); }

/* ---------- Progress ---------- */

.steps { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.step { display: flex; align-items: center; gap: 10px; color: var(--faint); }
.step .dot {
    width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--green-border); flex-shrink: 0;
}
.step.done { color: var(--text); }
.step.done .dot { background: var(--green); border-color: var(--green); }
.step.active { color: var(--green-dark); font-weight: 600; }
.step.active .dot { border-color: var(--green); border-top-color: transparent; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.spinner {
    display: inline-block; width: 18px; height: 18px; border: 3px solid var(--green-border);
    border-top-color: var(--green); border-radius: 50%; animation: spin 0.9s linear infinite; vertical-align: middle;
}

/* ---------- Drawing viewer ---------- */

.viewer-layout { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 1000px) {
    .viewer-layout { grid-template-columns: minmax(0, 1fr) 320px; }
}

.viewer-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    background: #fff;
    padding: 8px;
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 52px;
    z-index: 30;
}
.viewer-toolbar .sep { width: 1px; height: 26px; background: var(--line); margin: 0 4px; }
.viewer-toolbar .page-label { font-size: 0.88rem; min-width: 70px; text-align: center; }

.btn.toggle-on { background: var(--danger); border-color: var(--danger); color: #fff; }

.viewer-stage {
    position: relative;
    overflow: auto;
    background: #6b716d;
    /* Shrinks to the drawing (e.g. a landscape sheet on a phone), scrolls once zoomed in. */
    max-height: calc(100vh - 190px);
    min-height: 240px;
    border-radius: 0 0 var(--radius) var(--radius);
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
}
.viewer-page {
    position: relative;
    margin: 12px auto;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
    background: #fff;
}
.viewer-page canvas { display: block; }
.viewer-page.placing { cursor: crosshair; }
.viewer-loading {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    color: #fff; gap: 10px; font-size: 0.95rem;
}

.pin {
    position: absolute;
    transform: translate(-50%, -50%);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid #fff;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    padding: 0;
    z-index: 5;
}
.pin.closed { background: var(--green); }
.pin.other { opacity: 0.55; }
.pin.focus { outline: 3px solid #ffd54f; outline-offset: 2px; z-index: 6; }
.pin.pending { background: #444; }

.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 0.82rem; color: var(--muted); }
.legend span::before {
    content: ""; display: inline-block; width: 11px; height: 11px; border-radius: 50%;
    margin-right: 5px; vertical-align: -1px; background: var(--danger);
}
.legend .l-closed::before { background: var(--green); }
.legend .l-other::before { opacity: 0.55; }

.defect-list { list-style: none; margin: 0; padding: 0; max-height: calc(100vh - 260px); overflow-y: auto; }
.defect-list li {
    display: flex; gap: 8px; align-items: flex-start; padding: 8px; border-bottom: 1px solid var(--line);
    cursor: pointer; border-radius: 6px;
}
.defect-list li:hover { background: var(--green-tint); }
.defect-list .desc { font-size: 0.87rem; }

/* ---------- Dialogs ---------- */

dialog {
    border: none;
    border-radius: 10px;
    padding: 0;
    width: min(560px, calc(100vw - 20px));
    max-height: calc(100vh - 30px);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog .dialog-body { padding: 16px; overflow-y: auto; max-height: calc(100vh - 110px); }
dialog .dialog-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 16px; border-bottom: 1px solid var(--line); background: #fafafa;
    border-radius: 10px 10px 0 0;
}
dialog .dialog-head h2 { margin: 0; font-size: 1.1rem; }
dialog .dialog-foot {
    display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap;
    padding: 12px 16px; border-top: 1px solid var(--line); background: #fafafa;
    border-radius: 0 0 10px 10px;
}

/* ---------- Defect cards (close-out) ---------- */

.defect-card {
    border: 1px solid var(--line);
    border-left: 5px solid var(--danger);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
    background: #fff;
}
.defect-card.closed { border-left-color: var(--green); }
.defect-card .head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.defect-card .label { font-weight: 700; font-size: 1.05rem; }
.defect-card form { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }

/* ---------- Login ---------- */

.login-box {
    max-width: 420px;
    margin: 8vh auto;
    background: #fff;
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 28px;
    text-align: center;
}
.login-box img { max-width: 160px; margin-bottom: 10px; }
.login-box form { text-align: left; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--faint); font-size: 0.8rem; margin: 20px 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

@media (max-width: 600px) {
    body { font-size: 14.5px; }
    .container { padding: 12px; }
    .card { padding: 13px; }
    .topbar { padding: 6px 12px; }
    .user-menu .name { display: none; }
    .action-bar { margin: 0 -13px -13px; padding: 10px 12px; }
    .viewer-toolbar { top: 86px; }
    .viewer-stage { max-height: calc(100vh - 230px); }
}
