/* ===== 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: 24px; padding: 48px; max-width: 800px; width: 100%;
  box-shadow: 0 30px 100px rgba(0,0,0,.5); text-align: center; }
.login-logo { font-size: 40px; letter-spacing: 8px; margin-bottom: 16px; }
.login-card h1 { font-size: 32px; margin: 0 0 12px; color: var(--brand); line-height: 1.1; font-weight: 800; }
.login-sub { color: var(--ink); font-weight: 700; font-size: 16px; }
.login-hint { color: var(--muted); font-size: 14.5px; margin: 8px 0 32px; }
.role-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.role-btn { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; text-align: left;
  background: #f8fafc; border: 2px solid var(--line); border-radius: 16px; padding: 20px 24px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); cursor: pointer; }
.role-btn:hover { border-color: var(--brand2); background: #f0f9ff; transform: translateY(-3px); box-shadow: 0 12px 24px rgba(15,23,42,0.06); }
.role-icon { font-size: 28px; }
.role-name { font-weight: 800; color: var(--bg); font-size: 15px; }
.role-desc { font-size: 13px; color: #64748b; line-height: 1.4; }
.tech-picker { margin-top: 24px; padding-top: 32px; border-top: 1.5px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 16px; }
.tech-picker label { font-weight: 600; }

/* ===== App shell ===== */
.topbar { display: flex; align-items: center; justify-content: space-between; background: var(--bg); color: #fff;
  padding: 0 32px; height: 64px; position: sticky; top: 0; z-index: 20; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.brand { font-weight: 800; font-size: 1.1rem; white-space: nowrap; margin-right: 32px; color: var(--brand2); }
.nav { display: flex; gap: 8px; flex: 1; align-items: center; }
.nav a { background: transparent; text-decoration: none; color: #cbd5e1; padding: 8px 16px; border-radius: 999px;
  font-weight: 600; font-size: 14px; white-space: nowrap; transition: all 0.2s ease; border: 1px solid transparent; }
.nav a:hover { background: rgba(255,255,255,0.1); color: #fff; }
.nav a.active { background: rgba(14, 165, 233, 0.15); color: var(--brand2); border-color: rgba(14, 165, 233, 0.3); }
.user-box { display: flex; align-items: center; gap: 20px; white-space: nowrap; margin-left: 24px; }
.current-user { font-size: 13px; color: #94a3b8; border-right: 1px solid #334155; padding-right: 20px; }
.btn-ghost { background: transparent; color: #cbd5e1; border: 1px solid #334155; padding: 6px 14px; border-radius: 8px; font-size: 13px; font-weight: 600; transition: all 0.2s; }
.btn-ghost:hover { background: #334155; color: #fff; border-color: #475569; }
.view { max-width: 1200px; margin: 0 auto; padding: 32px 32px 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: 8px; margin-bottom: 24px; flex-wrap: wrap; }
.tabs button { background: var(--panel); border: 1.5px solid var(--line); border-radius: 999px; padding: 8px 20px;
  font-weight: 700; color: #64748b; font-size: 14px; transition: all 0.2s ease; cursor: pointer; }
.tabs button:hover { background: #f8fafc; border-color: #cbd5e1; color: var(--ink); }
.tabs button.active { background: var(--brand); color: #fff; border-color: var(--brand); box-shadow: 0 4px 12px rgba(3, 105, 161, 0.2); }

.btn-primary { background: var(--brand); color: #fff; border: none; padding: 10px 20px; border-radius: 10px; font-weight: 700; font-size: 14px; box-shadow: 0 2px 4px rgba(3, 105, 161, 0.2); transition: all 0.2s; }
.btn-primary:hover { background: #075985; transform: translateY(-1px); box-shadow: 0 4px 8px rgba(3, 105, 161, 0.3); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { background: #94a3b8; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-sm { padding: 8px 16px; font-size: 13px; border-radius: 8px; border: 1.5px solid var(--line); background: #fff;
  font-weight: 700; color: #475569; transition: all 0.2s; cursor: pointer; }
.btn-sm:hover { background: #f8fafc; border-color: #cbd5e1; color: var(--ink); }
.btn-sm.green { color: #15803d; border-color: #bbf7d0; background: #f0fdf4; }
.btn-sm.green:hover { background: #dcfce7; border-color: #86efac; }
.btn-sm.red { color: #b91c1c; border-color: #fecaca; background: #fef2f2; }
.btn-sm.red:hover { background: #fee2e2; border-color: #fca5a5; }
.btn-sm.blue { color: #1d4ed8; border-color: #bfdbfe; background: #eff6ff; }
.btn-sm.blue:hover { background: #dbeafe; border-color: #93c5fd; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.toolbar { display: flex; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; align-items: center; }
input:not([type=checkbox]):not([type=radio]), select, textarea {
  display: block; font: inherit; padding: 10px 14px; border: 1.5px solid var(--line); border-radius: 8px; background: #fff; width: 100%; 
  transition: border-color 0.2s, box-shadow 0.2s; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(3, 105, 161, 0.1); }
input::placeholder, textarea::placeholder { color: #94a3b8; }
input:disabled, select:disabled, textarea:disabled { background: #f1f5f9; color: #64748b; cursor: not-allowed; }

textarea { resize: vertical; min-height: 100px; line-height: 1.6; }

.field { margin-bottom: 20px; }
.field label { display: block; font-size: 13.5px; font-weight: 700; margin-bottom: 8px; color: #334155; }
.field .helper { font-size: 12px; color: var(--muted); margin-top: 4px; }
.field .error { font-size: 12.5px; color: var(--danger); margin-top: 6px; font-weight: 600; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

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

/* checklist */
.check-item { border: 1.5px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; background: #fff; }
.check-item .ci-head { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 12px; }
.check-item .ci-name { font-weight: 700; color: #1e293b; font-size: 15px; }
.ci-toggle { display: flex; gap: 8px; }
.ci-toggle button { border: 1.5px solid var(--line); background: #fff; padding: 6px 14px; border-radius: 8px; font-weight: 700; font-size: 13px; transition: all 0.2s; }
.ci-toggle button:disabled { opacity: 0.8; }
.ci-toggle button.sel-normal { background: var(--ok); color: #fff; border-color: var(--ok); box-shadow: 0 2px 4px rgba(22, 163, 74, 0.2); }
.ci-toggle button.sel-abnormal { background: var(--danger); color: #fff; border-color: var(--danger); box-shadow: 0 2px 4px rgba(220, 38, 38, 0.2); }
.ci-note { margin-top: 0; }
.ci-evidence { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--line); }
.ci-ev-label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 4px; color: #475569; }
.ci-ev-help { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.ci-file { width: auto; font-size: 13px; padding: 8px; border: 1.5px dashed var(--line); border-radius: 8px; width: 100%; cursor: pointer; }
.ci-preview { display: flex; align-items: flex-start; gap: 12px; margin-top: 12px; }
.ci-preview img { width: 120px; height: 120px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); box-shadow: var(--shadow); }
.ci-preview img.clickable { cursor: pointer; transition: transform 0.2s, ring 0.2s; }
.ci-preview img.clickable:hover { transform: scale(1.02); }

/* full-size photo lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(15,23,42,.9); display: grid; place-items: center; z-index: 100; padding: 40px; }
.lightbox-inner { background: #fff; border-radius: 16px; max-width: 95vw; max-height: 95vh; display: flex; flex-direction: column;
  overflow: hidden; box-shadow: 0 40px 100px rgba(0,0,0,.6); }
.lightbox-head { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 16px 24px; border-bottom: 1px solid var(--line); }
.lightbox-title { font-weight: 800; font-size: 17px; color: var(--bg); }
.lightbox-close { background: #f1f5f9; border: none; font-size: 28px; line-height: 1; color: var(--muted); cursor: pointer; width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.lightbox-close:hover { background: #e2e8f0; color: var(--bg); }
.lightbox-img { max-width: 90vw; max-height: 75vh; object-fit: contain; display: block; background: #000; }
.lightbox-cap { padding: 14px 24px; font-size: 14px; color: var(--muted); border-top: 1px solid var(--line); background: #f8fafc; font-weight: 500; }

/* bars */
.bar-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.bar-label { width: 180px; font-size: 13.5px; color: #475569; flex-shrink: 0; font-weight: 600; }
.bar-track { flex: 1; background: #f1f5f9; border-radius: 10px; height: 20px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--brand2), var(--brand)); border-radius: 10px; }
.bar-val { width: 40px; text-align: right; font-weight: 800; font-size: 14px; color: var(--bg); }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 32px; margin-bottom: 24px; padding: 4px; }
.detail-grid .k { font-size: 11px; color: #64748b; text-transform: uppercase; font-weight: 800; letter-spacing: 0.05em; margin-bottom: 4px; }
.detail-grid .v { font-weight: 700; margin-bottom: 8px; color: #1e293b; font-size: 15px; }
.note-box { background: #fffbeb; border: 1.5px solid #fef3c7; border-radius: 10px; padding: 14px 18px; margin: 16px 0;
  color: #92400e; font-size: 14.5px; line-height: 1.6; }

/* buttons */
.btn-primary { background: var(--brand); color: #fff; border: none; padding: 10px 20px; border-radius: 10px; font-weight: 700; font-size: 14px; box-shadow: 0 2px 4px rgba(3, 105, 161, 0.2); transition: all 0.2s; }
.btn-primary:hover { background: #075985; transform: translateY(-1px); box-shadow: 0 4px 8px rgba(3, 105, 161, 0.3); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { background: #94a3b8; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-sm { padding: 6px 14px; font-size: 13px; border-radius: 8px; border: 1.5px solid var(--line); background: #fff;
  font-weight: 700; color: #475569; transition: all 0.2s; }
.btn-sm:hover { background: #f8fafc; border-color: #cbd5e1; color: var(--ink); }
.btn-sm.green { color: #15803d; border-color: #bbf7d0; background: #f0fdf4; }
.btn-sm.green:hover { background: #dcfce7; border-color: #86efac; }
.btn-sm.red { color: #b91c1c; border-color: #fecaca; background: #fef2f2; }
.btn-sm.red:hover { background: #fee2e2; border-color: #fca5a5; }
.btn-sm.blue { color: #1d4ed8; border-color: #bfdbfe; background: #eff6ff; }
.btn-sm.blue:hover { background: #dbeafe; border-color: #93c5fd; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.65); display: grid; place-items: center; z-index: 50; padding: 24px; backdrop-filter: blur(2px); }
.modal-card { background: #fff; border-radius: 20px; width: 100%; max-width: 680px; max-height: 90vh; overflow: auto;
  box-shadow: 0 40px 100px rgba(0,0,0,.45); border: 1px solid rgba(255,255,255,0.1); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 20px 28px; border-bottom: 1.5px solid var(--line);
  position: sticky; top: 0; background: rgba(255,255,255,0.95); backdrop-filter: blur(8px); z-index: 10; }
.modal-head h2 { font-size: 1.25rem; font-weight: 800; color: var(--bg); }
.modal-close { background: #f1f5f9; border: none; font-size: 24px; line-height: 1; color: var(--muted); width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: all 0.2s; }
.modal-close:hover { background: #e2e8f0; color: var(--bg); }
.modal-body { padding: 28px; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 32px; padding-top: 20px; border-top: 1.5px solid var(--line); 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: 1024px) {
  .topbar { height: auto; padding: 12px 24px; flex-direction: column; align-items: stretch; gap: 16px; }
  .brand { margin-right: 0; text-align: center; }
  .nav { justify-content: center; flex-wrap: wrap; }
  .user-box { margin-left: 0; justify-content: center; border-top: 1px solid #334155; padding-top: 16px; }
}

@media (max-width: 720px) {
  .role-buttons, .grid2, .detail-grid { grid-template-columns: 1fr; }
  .view { padding: 20px 16px; }
}

/* ===== Enhanced Components ===== */
.badge { padding: 4px 12px; font-weight: 700; letter-spacing: 0.025em; box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.card { transition: transform 0.2s, box-shadow 0.2s; border: 1px solid var(--line); }
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(15,23,42,0.08); }
.card .num { line-height: 1; margin-bottom: 4px; }
.card .lbl { font-weight: 700; color: var(--muted); }

.panel-head { background: #fcfdfe; }
table th { font-weight: 700; color: #475569; border-bottom: 2px solid var(--line); }
table td { padding: 12px 14px; }
tr.clickable:hover td { background: #f8fafc; }
