/* ============================================================================
   RMBIO eQMS — Application stylesheet
   A clean, dense, regulated-software UI: green sidebar, neutral content canvas,
   status pills, data tables, cards, modals and toasts. No external CSS deps.
   ========================================================================== */

:root {
    --brand:        #0f6e4f;   /* RMBIO green */
    --brand-dark:   #0c5740;
    --brand-darker: #0a3d2e;
    --brand-accent: #b6e14b;   /* lime highlight (active nav) */
    --ink:          #1f2933;
    --ink-soft:     #52606d;
    --muted:        #7b8794;
    --line:         #e4e7eb;
    --bg:           #f4f6f8;
    --card:         #ffffff;
    --danger:       #cf1124;
    --warn:         #b44d12;
    --ok:           #0b8043;
    --info:         #1f6feb;
    --radius:       10px;
    --shadow:       0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.06);
    --shadow-lg:    0 12px 32px rgba(16,24,40,.18);
    --sidebar-w:    232px;
    --font:         system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 14px; line-height: 1.45; }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { margin: 0 0 .4em; font-weight: 650; color: var(--ink); }
button { font-family: inherit; }
.muted { color: var(--muted); }
.hidden, [hidden] { display: none !important; }

/* ---- Boot spinner -------------------------------------------------------- */
.app-loading { display: flex; align-items: center; justify-content: center; height: 100vh; }
.boot-spinner { text-align: center; color: var(--muted); }
.spinner { width: 38px; height: 38px; border: 4px solid var(--line); border-top-color: var(--brand);
           border-radius: 50%; margin: 0 auto 12px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- App shell ----------------------------------------------------------- */
.layout { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar { background: linear-gradient(180deg, var(--brand-dark), var(--brand-darker));
           color: #d9f2e6; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { padding: 18px 20px; font-weight: 800; font-size: 18px; letter-spacing: .5px; color: #fff;
                  border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar .brand small { display: block; font-size: 10px; font-weight: 500; opacity: .7; letter-spacing: 1px; }
.nav { list-style: none; margin: 0; padding: 10px 8px; overflow-y: auto; flex: 1; }
.nav li { margin: 1px 0; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
         color: #c7e6d7; font-weight: 500; cursor: pointer; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav a.active { background: var(--brand-accent); color: #14361f; font-weight: 650; }
.nav a .ico { width: 18px; text-align: center; opacity: .95; }
.nav .section { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: #7fbfa3;
                padding: 14px 14px 4px; }
.sidebar .userbox { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.sidebar .userbox .name { color: #fff; font-weight: 600; }
.sidebar .userbox a { color: #9ae6b4; }

/* ---- Top bar + content --------------------------------------------------- */
.content { display: flex; flex-direction: column; min-width: 0; }
.topbar { background: var(--card); border-bottom: 1px solid var(--line); padding: 12px 24px;
          display: flex; align-items: center; gap: 16px; position: sticky; top: 0; z-index: 5; }
.topbar h2 { margin: 0; font-size: 18px; }
.topbar .spacer { flex: 1; }
.page { padding: 22px 24px; }

/* ---- Cards & grids ------------------------------------------------------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
        box-shadow: var(--shadow); padding: 18px; }
.card h3 { font-size: 14px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .grid.cols-4 { grid-template-columns: repeat(2,1fr); } .grid.cols-3 { grid-template-columns: 1fr; } }
@media (max-width: 820px) { .layout { grid-template-columns: 1fr; } .sidebar { position: fixed; z-index: 30; transform: translateX(-100%); transition: .2s; } .sidebar.open { transform: none; } .grid.cols-2, .grid.cols-4 { grid-template-columns: 1fr; } }

/* KPI tiles */
.kpi { display: flex; flex-direction: column; gap: 2px; }
.kpi .num { font-size: 28px; font-weight: 750; color: var(--brand-dark); line-height: 1; }
.kpi .label { color: var(--muted); font-size: 12px; }

/* ---- Tables -------------------------------------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th { background: #fafbfc; color: var(--ink-soft); font-weight: 600; font-size: 12px;
                text-transform: uppercase; letter-spacing: .3px; position: sticky; top: 0; }
table.data tbody tr:hover { background: #f8fbfa; cursor: pointer; }
table.data td.wrap { white-space: normal; max-width: 360px; }

/* ---- Status pills -------------------------------------------------------- */
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 11px; font-weight: 650;
        line-height: 1.6; border: 1px solid transparent; }
.pill.gray   { background:#eef1f4; color:#52606d; }
.pill.blue   { background:#e3effd; color:#1c4f9c; }
.pill.green  { background:#dff5e6; color:#0b6b35; }
.pill.amber  { background:#fdf0d5; color:#8a5a00; }
.pill.red    { background:#fde2e4; color:#a01521; }
.pill.purple { background:#efe5fb; color:#5b21b6; }
.pill.teal   { background:#d7f3ef; color:#0a6b5e; }

/* ---- Buttons ------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
       border: 1px solid var(--line); background: #fff; color: var(--ink); font-weight: 600; cursor: pointer;
       font-size: 13px; transition: .12s; }
.btn:hover { background: #f3f5f7; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand-dark); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Forms --------------------------------------------------------------- */
label { display: block; font-weight: 600; font-size: 12.5px; color: var(--ink-soft); margin-bottom: 12px; }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
        font: inherit; margin-top: 5px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand);
        box-shadow: 0 0 0 3px rgba(15,110,79,.12); }
textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-error { color: var(--danger); font-size: 11.5px; font-weight: 500; margin-top: 3px; }
.form-error { background: #fde2e4; color: #a01521; border: 1px solid #f5c2c7; padding: 10px 12px;
              border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; margin-top: 0; }
.toolbar .spacer { flex: 1; }

/* ---- Login --------------------------------------------------------------- */
.login-body { background: radial-gradient(1200px 600px at 70% -10%, #15805d, var(--brand-darker));
              display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card { background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 400px;
              padding: 30px 30px 22px; }
.login-brand { text-align: center; margin-bottom: 18px; }
.brand-mark { font-weight: 850; font-size: 26px; color: var(--brand); letter-spacing: 1px; display: block; }
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: .5px; }
.login-card h1 { font-size: 18px; text-align: center; margin: 6px 0 18px; }
.login-foot { text-align: center; font-size: 11px; color: var(--ink-soft); margin: 18px 0 0; line-height: 1.5; }

/* ---- Modal --------------------------------------------------------------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,24,33,.5); display: flex; align-items: flex-start;
                 justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; box-shadow: var(--shadow-lg); width: 100%; max-width: 620px; }
.modal.lg { max-width: 920px; }
.modal.xl { max-width: 1150px; }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-head .close { margin-left: auto; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }

/* Signature box */
.sig-box { border: 1px dashed var(--brand); background: #f3faf6; border-radius: 8px; padding: 14px; margin-top: 6px; }
.sig-box .sig-meaning { font-weight: 650; color: var(--brand-dark); }

/* Detail layout */
.detail-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }
@media (max-width: 900px){ .detail-grid { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0 8px 16px; border-left: 2px solid var(--line); position: relative; font-size: 12.5px; }
.timeline li::before { content:''; position:absolute; left:-5px; top:12px; width:8px; height:8px; border-radius:50%; background: var(--brand); }
.timeline .when { color: var(--muted); font-size: 11px; }

/* Matrix */
.matrix { border-collapse: collapse; font-size: 12px; }
.matrix th, .matrix td { border: 1px solid var(--line); padding: 6px 8px; text-align: center; }
.matrix th.rot { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; height: 120px; vertical-align: bottom; }
.matrix td.name { text-align: left; white-space: nowrap; font-weight: 600; }
.cell-ok { background:#dff5e6; color:#0b6b35; }
.cell-no { background:#fdf0d5; color:#8a5a00; }
.cell-over { background:#fde2e4; color:#a01521; }
.cell-none { color:#cbd2d9; }

/* Bars */
.bar { height: 8px; border-radius: 6px; background: var(--line); overflow: hidden; display: flex; }
.bar > span { height: 100%; }

/* Toasts */
.toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: #1f2933; color: #fff; padding: 11px 16px; border-radius: 8px; box-shadow: var(--shadow-lg);
         font-size: 13px; min-width: 220px; animation: toastin .2s ease; }
.toast.ok { background: #0b6b35; } .toast.err { background: #a01521; }
@keyframes toastin { from { opacity: 0; transform: translateY(8px);} }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.spin-inline { display:inline-block; width:16px; height:16px; border:2px solid var(--line); border-top-color: var(--brand); border-radius:50%; animation: spin .7s linear infinite; vertical-align: middle; }
.editor-frame { width: 100%; height: 72vh; border: 1px solid var(--line); border-radius: 8px; }
.badge-count { background: var(--brand-accent); color:#14361f; border-radius: 999px; padding: 0 7px; font-size: 11px; font-weight: 700; margin-left: auto; }
