:root {
    --bg:      #f4f6f9;
    --bg2:     #ffffff;
    --accent:  #1a5c9e;
    --accent2: #2272c3;
    --navy:    #1a2332;
    --text:    #1a2332;
    --muted:   #5a6a7a;
    --border:  #d0d7e0;
    --danger:  #c0392b;
    --success: #1e8449;
    --warn:    #c8820a;
    --zero:    #b8c2ce;
    --shadow:  0 1px 3px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Barlow', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Nav ---- */
nav {
    background: var(--navy);
    border-bottom: 3px solid var(--accent);
    display: flex; align-items: stretch; padding: 0; min-height: 64px;
    position: sticky; top: 0; z-index: 50;
}
.nav-brand {
    display: flex; align-items: center; gap: 14px;
    padding: 10px 24px; background: #ffffff;
    border-right: 3px solid var(--accent); text-decoration: none;
}
.nav-brand:hover { text-decoration: none; }
.nav-brand img { height: 42px; width: auto; display: block; }
.nav-brand-text {
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 0.95rem; font-weight: 700; color: var(--navy);
    letter-spacing: 0.08em; text-transform: uppercase;
}
nav a.nav-link {
    color: #ffffff; text-decoration: none; padding: 0 18px;
    font-size: 0.85rem; font-weight: 700; letter-spacing: 0.05em;
    text-transform: uppercase; transition: color 0.15s, background 0.15s;
    border-right: 1px solid #2e3d55; display: flex; align-items: center;
}
nav a.nav-link:hover, nav a.nav-link.active {
    color: #ffffff; background: var(--accent2); text-decoration: none;
}
.nav-user { display: flex; margin-left: auto; align-items: stretch; }
.nav-user .nav-link { gap: 8px; border-right: none; border-left: 1px solid #2e3d55; }
.role-tag {
    font-size: 0.62rem; padding: 2px 6px; border-radius: 3px;
    background: #2e3d55; color: #aeb9c7; letter-spacing: 0.08em;
}
.role-tag.role-admin   { background: #7fe0a4; color: #123a24; }
.role-tag.role-quality { background: #ffd47f; color: #4a3400; }

.container { max-width: 1800px; margin: 0 auto; padding: 28px 24px; }
.container.narrow { max-width: 1100px; }

/* ---- Page header ---- */
.page-header {
    display: flex; align-items: flex-end; justify-content: space-between;
    margin-bottom: 24px; padding-bottom: 16px; border-bottom: 2px solid var(--border);
    flex-wrap: wrap; gap: 16px;
}
.page-title {
    font-family: 'Barlow Condensed', sans-serif; font-size: 1.8rem;
    font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text);
}
.page-title span { color: var(--accent); }
.page-sub { color: var(--muted); font-size: 0.9rem; margin-top: 4px; }
.page-sub strong { color: var(--text); }
.head-actions { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; gap: 6px; padding: 8px 18px;
    border: none; border-radius: 4px; font-family: 'Barlow', sans-serif;
    font-size: 0.85rem; font-weight: 500; letter-spacing: 0.04em;
    text-transform: uppercase; cursor: pointer; text-decoration: none; transition: all 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); color: #fff; text-decoration: none; }
.btn-secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); background: #f0f5fc; text-decoration: none; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #e74c3c; color: #fff; text-decoration: none; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #27ae60; color: #fff; text-decoration: none; }
.btn-sm { padding: 5px 12px; font-size: 0.78rem; }

.icon-btn {
    border: none; background: none; cursor: pointer; font-size: 15px;
    padding: 4px 7px; border-radius: 4px; color: var(--muted); line-height: 1;
}
.icon-btn:hover { background: #f0f5fc; color: var(--accent); }
.del-btn:hover { background: #fdf0ee; color: var(--danger); }

/* ---- Alerts ---- */
.alert { padding: 12px 18px; border-radius: 4px; margin-bottom: 20px; font-size: 0.9rem; border-left: 4px solid; }
.alert-success { background: #eafaf1; border-color: var(--success); color: #1a6e3c; }
.alert-warning { background: #fef9ec; border-color: var(--warn); color: #7d5a00; }
.alert-error,
.alert-danger { background: #fdf0ee; border-color: var(--danger); color: #922b21; }
.alert-info { background: #eaf4fb; border-color: #2980b9; color: #1a5276; }

/* ---- Stat pills ---- */
.stat-row { display: flex; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.stat-pill {
    flex: 1; min-width: 130px;
    background: #fff; border: 1px solid var(--border); border-radius: 6px;
    padding: 14px 20px; font-family: 'Barlow Condensed', sans-serif; box-shadow: var(--shadow);
}
a.stat-pill:hover { border-color: var(--accent); text-decoration: none; box-shadow: 0 0 0 3px rgba(26,92,158,0.10); }
.stat-pill.accent { background: var(--navy); border-color: var(--navy); }
.stat-pill.accent .stat-num { color: #fff; }
.stat-pill.accent .stat-lbl { color: #aeb9c7; }
.stat-pill.alarm { border-color: var(--danger); }
.stat-pill.alarm .stat-num { color: var(--danger); }
.stat-pill.good .stat-num { color: var(--success); }
.stat-num { font-size: 1.8rem; font-weight: 700; color: var(--accent); line-height: 1; }
.stat-num.small { font-size: 1.1rem; }
.stat-lbl { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-top: 4px; }
.stat-sub { font-size: 0.82rem; font-weight: 600; color: var(--success); margin-top: 3px; }
.stat-pill.accent .stat-sub { color: #7fe0a4; }

/* ---- Table ---- */
.table-wrap { background: var(--bg2); border: 1px solid var(--border); border-radius: 6px; box-shadow: var(--shadow); }
@media (max-width: 1200px) { .table-wrap { overflow-x: auto; } }
table.grid { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.grid thead tr { background: #f8f9fb; }
table.grid th {
    padding: 12px 14px; text-align: left; font-family: 'Barlow Condensed', sans-serif;
    font-size: 1rem; font-weight: 700; letter-spacing: 0.08em;
    text-transform: uppercase; color: var(--navy); border-bottom: 2px solid var(--border);
    white-space: nowrap; position: sticky; top: 67px; background: #f8f9fb; z-index: 20;
}
table.grid td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
table.grid td.wrap { white-space: normal; min-width: 280px; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid tbody tr:hover td { background: #f0f5fc; }
table.grid tbody tr.row-overdue td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.zero { color: var(--zero); }
.actions-col { text-align: center; width: 90px; }

/* A plain, non-sticky table for use inside cards */
table.mini { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
table.mini th {
    text-align: left; padding: 8px 10px; font-family: 'Barlow Condensed', sans-serif;
    font-size: 0.85rem; letter-spacing: 0.06em; text-transform: uppercase;
    color: var(--muted); border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.mini td { padding: 8px 10px; border-bottom: 1px solid #eef1f5; vertical-align: top; }
table.mini tr:last-child td { border-bottom: none; }

/* ---- Cards ---- */
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: 6px; box-shadow: var(--shadow); margin-bottom: 20px; }
.card-header {
    padding: 14px 20px; border-bottom: 1px solid var(--border);
    font-family: 'Barlow Condensed', sans-serif; font-size: 0.9rem; font-weight: 600;
    letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
    background: #f8f9fb; border-radius: 6px 6px 0 0;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-body { padding: 20px; }
.card-body.tight { padding: 8px 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; align-items: start; }
@media (max-width: 1100px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---- Badges ---- */
.badge {
    display: inline-block; padding: 3px 9px; border-radius: 3px;
    font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em;
    text-transform: uppercase; white-space: nowrap;
}
.st-Draft                { background: #eceff3; color: #5a6a7a; }
.st-Open                 { background: #eaf4fb; color: #1a5276; }
.st-InProgress           { background: #e6f0fb; color: #1a5c9e; }
.st-PendingVerification  { background: #fef9ec; color: #7d5a00; }
.st-Closed               { background: #eafaf1; color: #1a6e3c; }
.st-Cancelled            { background: #eceff3; color: #96a2ae; text-decoration: line-through; }
/* Training states */
.st-Outstanding { background: #eaf4fb; color: #1a5276; }
.st-DueSoon     { background: #fef9ec; color: #7d5a00; }
.st-Overdue     { background: var(--danger); color: #fff; }
.st-Expired     { background: #fdf0ee; color: #922b21; }
.st-Current     { background: #eafaf1; color: #1a6e3c; }
.st-Complete    { background: #eafaf1; color: #1a6e3c; }

.sev-Minor    { background: #eceff3; color: #5a6a7a; }
.sev-Major    { background: #fef9ec; color: #7d5a00; }
.sev-Critical { background: #fdf0ee; color: #922b21; }
.badge-overdue { background: var(--danger); color: #fff; }
.badge-flag    { background: #fdf0ee; color: #922b21; }

/* ---- Discipline chips (D1..D8 progress) ---- */
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
    display: inline-flex; flex-direction: column; align-items: center;
    min-width: 44px; padding: 5px 8px; border-radius: 4px;
    border: 1px solid var(--border); background: #f8f9fb; color: var(--zero);
    font-family: 'Barlow Condensed', sans-serif; font-weight: 700;
    font-size: 0.85rem; letter-spacing: 0.06em; text-decoration: none;
}
.chip:hover { text-decoration: none; border-color: var(--accent); }
.chip.done { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip small { font-size: 0.6rem; font-weight: 400; letter-spacing: 0; text-transform: none; opacity: .85; }
.chip-mini { display: inline-flex; gap: 2px; }
.chip-mini i {
    display: block; width: 9px; height: 14px; border-radius: 2px;
    background: #e2e7ee; font-style: normal;
}
.chip-mini i.done { background: var(--accent); }

/* ---- Simple horizontal bar chart ---- */
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 190px 1fr 44px; gap: 12px; align-items: center; font-size: 0.85rem; }
.bar-track { background: #eef1f5; border-radius: 3px; height: 16px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; border-radius: 3px; min-width: 2px; }
.bar-fill.warn { background: var(--warn); }
.bar-fill.danger { background: var(--danger); }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
@media (max-width: 700px) { .bar-row { grid-template-columns: 120px 1fr 40px; } }

/* ---- Forms ---- */
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px 18px; }
.form-grid .span2 { grid-column: span 2; }
.form-grid .span3 { grid-column: span 3; }
.form-grid .span4 { grid-column: span 4; }
@media (max-width: 1100px) {
    .form-grid { grid-template-columns: repeat(2, 1fr); }
    .form-grid .span3, .form-grid .span4 { grid-column: span 2; }
}
@media (max-width: 640px) {
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .span2, .form-grid .span3, .form-grid .span4 { grid-column: span 1; }
}
.field { display: block; margin-bottom: 0; }
.field-label {
    display: block; margin-bottom: 6px; font-size: 0.75rem; font-weight: 600;
    letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
}
.field-label .req { color: var(--danger); }
.field-help { font-size: 0.78rem; color: var(--muted); margin-top: 5px; line-height: 1.45; }
.field input, .field select, .field textarea, input.minput, select.minput, textarea.minput {
    width: 100%; padding: 9px 13px; background: #fff; color: var(--text);
    border: 1px solid var(--border); border-radius: 4px;
    font-family: 'Barlow', sans-serif; font-size: 0.92rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.field textarea, textarea.minput { resize: vertical; min-height: 84px; line-height: 1.5; }
.field textarea.tall { min-height: 150px; }
.field input:focus, .field select:focus, .field textarea:focus,
input.minput:focus, select.minput:focus, textarea.minput:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(26,92,158,0.12);
}
.field input[readonly] { background: #f4f6f9; color: var(--muted); }
.check-row { display: flex; align-items: center; gap: 9px; font-size: 0.9rem; margin-bottom: 10px; }
.check-row input { width: auto; }
.form-actions {
    display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px;
    border-top: 1px solid var(--border); background: #f8f9fb; border-radius: 0 0 6px 6px;
}
.form-actions.sticky { position: sticky; bottom: 0; z-index: 30; box-shadow: 0 -2px 8px rgba(0,0,0,.06); }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { flex: 1; min-width: 130px; }

/* ---- Filter bar ---- */
.filter-bar {
    display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end;
    background: #fff; border: 1px solid var(--border); border-radius: 6px;
    padding: 14px 18px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.filter-bar .field { min-width: 150px; }
.filter-bar .field.wide { min-width: 260px; flex: 1; }

/* ---- 8D discipline sections ---- */
.d-nav {
    display: flex; gap: 4px; flex-wrap: wrap; background: #fff;
    border: 1px solid var(--border); border-radius: 6px; padding: 8px;
    margin-bottom: 20px; position: sticky; top: 67px; z-index: 40; box-shadow: var(--shadow);
}
.d-nav a {
    padding: 7px 13px; border-radius: 4px; font-family: 'Barlow Condensed', sans-serif;
    font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
    font-size: 0.85rem; color: var(--muted); border: 1px solid transparent;
}
.d-nav a:hover { background: #f0f5fc; color: var(--accent); text-decoration: none; }
.d-nav a.done { color: var(--accent); }
.d-nav a.done::before { content: "\2713 "; color: var(--success); }

.d-card { scroll-margin-top: 140px; }
.d-card .card-header { color: var(--navy); font-size: 1rem; }
.d-code {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; border-radius: 4px; margin-right: 10px;
    background: var(--navy); color: #fff; font-weight: 700; font-size: 0.8rem;
}
.d-card.is-done .d-code { background: var(--success); }
.d-hint { font-size: 0.82rem; color: var(--muted); font-weight: 400;
          text-transform: none; letter-spacing: 0; font-family: 'Barlow', sans-serif; }

/* ---- Key/value display ---- */
.kv { display: grid; grid-template-columns: 190px 1fr; gap: 9px 16px; font-size: 0.9rem; }
.kv dt { color: var(--muted); font-size: 0.75rem; text-transform: uppercase;
         letter-spacing: 0.06em; font-weight: 600; padding-top: 2px; }
.kv dd { color: var(--text); }
@media (max-width: 640px) { .kv { grid-template-columns: 1fr; gap: 2px 0; } .kv dd { margin-bottom: 10px; } }
.prose { white-space: pre-wrap; line-height: 1.55; font-size: 0.92rem; }
.prose.empty, .muted { color: var(--muted); }
.muted-i { color: var(--zero); font-style: italic; }

/* ---- Why chain ---- */
.why-chain { display: flex; flex-direction: column; gap: 10px; }
.why-row { display: grid; grid-template-columns: 74px 1fr; gap: 12px; align-items: start; }
.why-lbl {
    font-family: 'Barlow Condensed', sans-serif; font-weight: 700; font-size: 0.8rem;
    letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
    background: #f8f9fb; border: 1px solid var(--border); border-radius: 4px;
    padding: 9px 6px; text-align: center;
}

/* ---- Comments ---- */
.comment { border-left: 3px solid var(--border); padding: 4px 0 4px 14px; margin-bottom: 16px; }
.comment-head { font-size: 0.78rem; color: var(--muted); margin-bottom: 4px; }
.comment-head strong { color: var(--text); }
.comment-body { white-space: pre-wrap; font-size: 0.9rem; line-height: 1.5; }

/* ---- Empty state ---- */
.empty { padding: 26px; text-align: center; color: var(--muted); font-size: 0.9rem; }

/* ---- Modal ---- */
.modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(26,35,50,.55);
    align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal { background: #fff; border-radius: 6px; width: 100%; max-width: 560px;
    box-shadow: 0 20px 60px rgba(0,0,0,.3); border-top: 4px solid var(--accent);
    max-height: 90vh; overflow-y: auto; }
.modal-head {
    padding: 16px 22px; border-bottom: 1px solid var(--border);
    font-family: 'Barlow Condensed', sans-serif; font-size: 1.15rem; font-weight: 700;
    letter-spacing: 0.05em; text-transform: uppercase; color: var(--text);
}
.modal-body { padding: 22px; }
.modal-body .field { margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); }

/* ---- Login ---- */
.login-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 20px; background: var(--bg);
}
.login-card {
    background: #fff; border: 1px solid var(--border); border-radius: 8px;
    border-top: 4px solid var(--accent); box-shadow: 0 6px 24px rgba(0,0,0,.10);
    padding: 34px 32px; width: 100%; max-width: 380px; text-align: center;
}
.login-logo { height: 46px; width: auto; margin: 0 auto 14px; display: block; }
.login-title {
    font-family: 'Barlow Condensed', sans-serif; font-size: 1.15rem; font-weight: 700;
    letter-spacing: 0.08em; text-transform: uppercase; color: var(--navy);
    margin-bottom: 22px; padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.login-hint { color: var(--muted); font-size: 0.85rem; margin-bottom: 14px; }
.login-card input {
    width: 100%; padding: 11px 14px; border: 1px solid var(--border); border-radius: 5px;
    font-size: 1rem; margin-bottom: 14px; font-family: 'Barlow', sans-serif;
}
.login-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(26,92,158,0.12); }
.login-card .btn { width: 100%; justify-content: center; padding: 11px; font-size: 0.95rem; }
.login-card .alert { text-align: left; }

/* ---- Footer ---- */
.foot {
    display: flex; justify-content: space-between; align-items: center;
    max-width: 1800px; margin: 20px auto 0; padding: 20px 24px 30px;
    border-top: 1px solid var(--border); color: var(--muted); font-size: 0.8rem;
}
.foot .mono { font-family: 'Barlow Condensed', sans-serif; letter-spacing: 0.05em; text-transform: uppercase; }
@media (max-width: 640px) { .foot { flex-direction: column; gap: 6px; text-align: center; } }

/* ---- Training matrix ---- */
.matrix-wrap { background: var(--bg2); border: 1px solid var(--border);
               border-radius: 6px; box-shadow: var(--shadow); overflow-x: auto; }
table.matrix { border-collapse: collapse; font-size: 0.82rem; }
table.matrix th, table.matrix td { border: 1px solid var(--border); padding: 7px 9px; }
table.matrix thead th {
    background: #f8f9fb; font-family: 'Barlow Condensed', sans-serif;
    font-weight: 700; letter-spacing: 0.04em; color: var(--navy);
    vertical-align: bottom; min-width: 108px; max-width: 150px;
}
table.matrix th.who {
    position: sticky; left: 0; z-index: 2; background: #f8f9fb;
    text-align: left; min-width: 210px;
}
table.matrix td.who {
    position: sticky; left: 0; z-index: 1; background: #fff;
    text-align: left; white-space: nowrap; font-weight: 500;
}
table.matrix td.who small { display: block; color: var(--muted); font-weight: 400; }
table.matrix tbody tr:hover td { background: #f0f5fc; }
table.matrix tbody tr:hover td.who { background: #f0f5fc; }
table.matrix td.cell { text-align: center; white-space: nowrap; }
table.matrix td.na { background: #fafbfc; color: var(--zero); }

/* ---- Training material viewer ---- */
.material-frame {
    width: 100%; height: 70vh; min-height: 420px; border: 1px solid var(--border);
    border-radius: 5px; background: #fff;
}
.ack-box {
    border: 2px solid var(--accent); border-radius: 6px; padding: 20px;
    background: #f4f8fd; margin-top: 22px;
}
.ack-statement {
    font-size: 0.95rem; line-height: 1.55; padding: 14px 16px; background: #fff;
    border: 1px solid var(--border); border-radius: 4px; margin-bottom: 16px;
}

.no-print { }
@media print {
    nav, .foot, .no-print, .d-nav { display: none !important; }
    body { background: #fff; }
    .container { max-width: none; padding: 0; }
}
