/* ===== Base ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f172a; --bg2: #1e293b; --panel: #ffffff; --ink: #1e293b; --muted: #64748b;
  --line: #e2e8f0; --brand: #0369a1; --brand2: #0ea5e9; --accent: #f1f5f9;
  --ok: #16a34a; --warn: #d97706; --danger: #dc2626; --crit: #b91c1c; --info: #2563eb;
  --radius: 12px; --shadow: 0 1px 3px rgba(15,23,42,.08), 0 6px 20px rgba(15,23,42,.06);
}
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink); background: #f8fafc; line-height: 1.5; }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
a { color: var(--brand); }

/* ===== Login ===== */
.login-screen { min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #1e3a5f, var(--bg)); padding: 24px; }
.login-card { background: var(--panel); border-radius: 20px; padding: 40px; max-width: 720px; width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,.4); text-align: center; }
.login-logo { font-size: 34px; letter-spacing: 6px; }
.login-card h1 { font-size: 30px; margin: 12px 0 6px; color: var(--brand); line-height: 1.15; }
.login-sub { color: var(--ink); font-weight: 600; }
.login-hint { color: var(--muted); font-size: 14px; margin: 6px 0 24px; }
.role-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.role-btn { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left;
  background: var(--accent); border: 2px solid transparent; border-radius: var(--radius); padding: 18px 20px;
  transition: .15s; }
.role-btn:hover { border-color: var(--brand2); background: #eff6ff; transform: translateY(-2px); }
.role-icon { font-size: 26px; }
.role-name { font-weight: 700; color: var(--ink); }
.role-desc { font-size: 13px; color: var(--muted); }
.tech-picker { margin-top: 22px; padding-top: 22px; border-top: 1px solid var(--line);
  display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
.tech-picker label { font-weight: 600; }

/* ===== App shell ===== */
.topbar { display: flex; align-items: center; gap: 18px; background: var(--bg); color: #fff;
  padding: 0 20px; height: 58px; position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; white-space: nowrap; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav button { background: transparent; border: none; color: #cbd5e1; padding: 8px 14px; border-radius: 8px;
  font-weight: 600; white-space: nowrap; }
.nav button:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav button.active { background: var(--brand2); color: #fff; }
.user-box { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.current-user { font-size: 13px; color: #cbd5e1; }
.btn-ghost { background: rgba(255,255,255,.12); color: #fff; border: none; padding: 7px 12px; border-radius: 8px; }
.btn-ghost:hover { background: rgba(255,255,255,.22); }
.view { max-width: 1180px; margin: 0 auto; padding: 24px 20px 60px; }

/* ===== Generic ===== */
h2.page-title { font-size: 22px; margin-bottom: 4px; }
.page-sub { color: var(--muted); margin-bottom: 20px; font-size: 14px; }
.section { margin-bottom: 28px; }
.section h3 { font-size: 15px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted);
  margin-bottom: 12px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); }
.card .num { font-size: 28px; font-weight: 800; }
.card .lbl { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.card.alert .num { color: var(--danger); }
.card.warn .num { color: var(--warn); }
.card.ok .num { color: var(--ok); }
.card.info .num { color: var(--info); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; }
.panel-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between;
  align-items: center; gap: 10px; flex-wrap: wrap; }
.panel-head h3 { margin: 0; color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 16px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; font-size: 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: #f8fafc; }
tr:last-child td { border-bottom: none; }
tr.clickable:hover { background: #f1f5f9; cursor: pointer; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  border: 1px solid transparent; white-space: nowrap; }
.b-grey { background: #f1f5f9; color: #475569; }
.b-blue { background: #dbeafe; color: #1d4ed8; }
.b-amber { background: #fef3c7; color: #b45309; }
.b-green { background: #dcfce7; color: #15803d; }
.b-red { background: #fee2e2; color: #b91c1c; }
.b-purple { background: #ede9fe; color: #6d28d9; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 16px;
  font-weight: 600; color: var(--muted); }
.tabs button.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.btn-primary { background: var(--brand); color: #fff; border: none; padding: 9px 16px; border-radius: 8px; font-weight: 600; }
.btn-primary:hover { background: #075985; }
.btn-sm { padding: 5px 11px; font-size: 13px; border-radius: 7px; border: 1px solid var(--line); background: #fff;
  font-weight: 600; color: var(--ink); }
.btn-sm:hover { background: #f1f5f9; }
.btn-sm.green { color: var(--ok); border-color: #bbf7d0; }
.btn-sm.red { color: var(--danger); border-color: #fecaca; }
.btn-sm.blue { color: var(--info); border-color: #bfdbfe; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
input[type=text], input[type=date], input[type=search], select, textarea {
  font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; width: 100%; }
textarea { resize: vertical; min-height: 70px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.state { text-align: center; padding: 40px 20px; color: var(--muted); }
.state .big { font-size: 32px; }
.spinner { width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--brand);
  border-radius: 50%; margin: 0 auto 10px; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-state { color: var(--danger); }

/* checklist */
.check-item { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; }
.check-item .ci-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.check-item .ci-name { font-weight: 600; }
.ci-toggle { display: flex; gap: 6px; }
.ci-toggle button { border: 1px solid var(--line); background: #fff; padding: 5px 12px; border-radius: 7px; font-weight: 600; }
.ci-toggle button.sel-normal { background: var(--ok); color: #fff; border-color: var(--ok); }
.ci-toggle button.sel-abnormal { background: var(--danger); color: #fff; border-color: var(--danger); }
.ci-note { margin-top: 8px; }
.ci-evidence { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.ci-ev-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.ci-ev-help { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.ci-file { width: auto; font-size: 13px; padding: 6px; }
.ci-preview { display: flex; align-items: flex-start; gap: 10px; margin-top: 8px; }
.ci-preview img { width: 92px; height: 92px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.ci-preview img.clickable { cursor: pointer; transition: opacity .15s, box-shadow .15s; }
.ci-preview img.clickable:hover { opacity: .9; box-shadow: 0 0 0 2px var(--brand2); }

/* full-size photo lightbox (layered above the inspection modal) */
.lightbox { position: fixed; inset: 0; background: rgba(15,23,42,.8); display: grid; place-items: center; z-index: 70; padding: 24px; }
.lightbox-inner { background: #fff; border-radius: 14px; max-width: 92vw; max-height: 92vh; display: flex; flex-direction: column;
  overflow: hidden; box-shadow: 0 30px 80px rgba(0,0,0,.55); }
.lightbox-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.lightbox-title { font-weight: 700; font-size: 15px; }
.lightbox-close { background: none; border: none; font-size: 26px; line-height: 1; color: var(--muted); cursor: pointer; }
.lightbox-close:hover { color: var(--ink); }
.lightbox-img { max-width: 88vw; max-height: 74vh; object-fit: contain; display: block; background: #0f172a; }
.lightbox-cap { padding: 10px 16px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); }

/* bars */
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.bar-label { width: 160px; font-size: 13px; color: var(--ink); flex-shrink: 0; }
.bar-track { flex: 1; background: #f1f5f9; border-radius: 6px; height: 18px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--brand2), var(--brand)); }
.bar-val { width: 34px; text-align: right; font-weight: 700; font-size: 13px; }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px; margin-bottom: 18px; }
.detail-grid .k { font-size: 12px; color: var(--muted); text-transform: uppercase; }
.detail-grid .v { font-weight: 600; margin-bottom: 6px; }
.note-box { background: #fff7ed; border: 1px solid #fed7aa; border-radius: 8px; padding: 10px 12px; margin: 12px 0;
  color: #9a3412; font-size: 14px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal-card { background: #fff; border-radius: 16px; width: 100%; max-width: 640px; max-height: 90vh; overflow: auto;
  box-shadow: 0 30px 80px rgba(0,0,0,.4); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: #fff; }
.modal-head h2 { font-size: 18px; }
.modal-close { background: none; border: none; font-size: 26px; line-height: 1; color: var(--muted); }
.modal-body { padding: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }

/* toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 12px 20px; border-radius: 10px; z-index: 60; box-shadow: var(--shadow); font-weight: 600; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

@media (max-width: 720px) {
  .role-buttons, .grid2, .detail-grid { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 14px; }
  .nav { order: 3; width: 100%; }
}
