:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --line: #e5e7eb;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --success: #047857;
    --sidebar: #0f172a;
    --sidebar-text: #cbd5e1;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--text);
}

a { color: inherit; text-decoration: none; }

.app-shell {
    min-height: 100vh;
    display: flex;
}

.sidebar {
    width: 270px;
    background: var(--sidebar);
    color: var(--sidebar-text);
    padding: 22px 16px;
    position: fixed;
    inset: 0 auto 0 0;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 8px 22px;
    border-bottom: 1px solid rgba(255,255,255,.12);
    margin-bottom: 18px;
}

.brand strong { display: block; color: white; font-size: 20px; letter-spacing: .5px; }
.brand span { display: block; font-size: 12px; color: #94a3b8; margin-top: 3px; }
.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: var(--primary);
    display: grid;
    place-items: center;
    color: white;
    font-weight: 700;
    font-size: 20px;
}

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a, .nav-section {
    padding: 11px 12px;
    border-radius: 10px;
    font-size: 14px;
}
.nav a:hover { background: rgba(255,255,255,.09); color: white; }
.nav-section {
    color: #64748b;
    font-size: 11px;
    letter-spacing: .08em;
    text-transform: uppercase;
    margin-top: 12px;
}

.main {
    margin-left: 270px;
    width: calc(100% - 270px);
    min-height: 100vh;
}

.topbar {
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    padding: 20px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}
.topbar h1 { margin: 0; font-size: 24px; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.userbox { display: flex; align-items: center; gap: 12px; color: var(--muted); }

.content { padding: 28px; }
.grid { display: grid; gap: 18px; }
.stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 18px; }
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 22px;
    box-shadow: 0 10px 25px rgba(15, 23, 42, .04);
}
.stat-card span { color: var(--muted); font-size: 13px; }
.stat-card strong { display: block; margin-top: 10px; font-size: 34px; }
.stat-card.danger strong { color: var(--danger); }

.btn {
    border: 0;
    border-radius: 10px;
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-light { background: #eef2ff; color: #3730a3; }
.full { width: 100%; }

.alert {
    padding: 12px 14px;
    border-radius: 12px;
    margin-bottom: 16px;
    font-size: 14px;
}
.alert-success { background: #ecfdf5; color: var(--success); border: 1px solid #a7f3d0; }
.alert-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }

.form { display: grid; gap: 11px; }
.form label { font-size: 13px; color: var(--muted); font-weight: 700; }
.form input, .form textarea, .form select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px 13px;
    font-size: 14px;
    outline: none;
}
.form input:focus, .form textarea:focus, .form select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.auth-page, .public-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 18px;
    background: radial-gradient(circle at top left, #dbeafe, transparent 35%), var(--bg);
}
.auth-card, .public-shell { width: min(440px, 100%); }
.auth-card {
    background: var(--panel);
    border-radius: 20px;
    border: 1px solid var(--line);
    padding: 28px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, .12);
}
.auth-header { text-align: center; margin-bottom: 24px; }
.auth-header h1 { margin: 12px 0 4px; }
.auth-header p, .auth-note { color: var(--muted); font-size: 13px; }
.auth-mark { margin: 0 auto; }
.auth-note { margin-top: 18px; line-height: 1.5; }
.public-card h1 { margin-top: 0; }

.flow-box {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
}
.flow-box span {
    background: #eef2ff;
    color: #3730a3;
    padding: 9px 12px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
}
.check-list { line-height: 1.9; color: var(--muted); }
.error-card { text-align: center; }

@media (max-width: 900px) {
    .sidebar { position: static; width: 100%; inset: auto; }
    .app-shell { display: block; }
    .main { width: 100%; margin-left: 0; }
    .topbar { align-items: flex-start; flex-direction: column; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
    .content, .topbar { padding: 18px; }
    .stats-grid { grid-template-columns: 1fr; }
    .userbox { width: 100%; justify-content: space-between; }
}

/* Release 002 additions */
.two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.detail-grid { align-items: start; margin-bottom: 18px; }
.page-actions, .card-header, .form-actions, .button-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 18px;
}
.page-actions h2, .card-header h2 { margin: 0; }
.page-actions p, .card-header p { margin: 5px 0 0; }
.muted { color: var(--muted); }
.link { color: var(--primary); font-weight: 700; }
.link:hover { text-decoration: underline; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td {
    text-align: left;
    border-bottom: 1px solid var(--line);
    padding: 12px 10px;
    vertical-align: top;
}
.table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 5px 9px;
    font-size: 12px;
    font-weight: 700;
    background: #e5e7eb;
    color: #374151;
    white-space: nowrap;
}
.badge-success { background: #ecfdf5; color: #047857; }
.badge-warning { background: #fffbeb; color: #92400e; }
.badge-danger { background: #fef2f2; color: #dc2626; }
.btn-sm { padding: 7px 10px; font-size: 12px; }
.form-grid { display: grid; gap: 14px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.check-option {
    display: flex !important;
    align-items: center;
    gap: 8px;
    color: var(--text) !important;
    font-weight: 600 !important;
    line-height: 1.4;
}
.check-option input { width: auto !important; }
.detail-list {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 9px 14px;
    margin: 0 0 18px;
}
.detail-list dt { color: var(--muted); font-weight: 700; }
.detail-list dd { margin: 0; }
.preline { white-space: pre-line; line-height: 1.65; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
.timeline-list { display: grid; gap: 12px; }
.timeline-item {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px;
    background: #fbfdff;
}
.timeline-item strong { display: block; }
.timeline-item span { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
.timeline-item p { margin-bottom: 0; }
.compact-form { margin-bottom: 14px; }
.inline-edit {
    margin-top: 12px;
    padding: 12px;
    border-radius: 12px;
    background: #f8fafc;
}
.role-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 14px;
    border: 1px solid var(--line);
    padding: 12px;
    border-radius: 12px;
}
.stack-mobile { justify-content: flex-start; }

@media (max-width: 1100px) {
    .two-col, .form-grid.three, .form-grid.four { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
    .page-actions, .card-header, .form-actions, .button-row { align-items: flex-start; flex-direction: column; }
    .form-grid.two, .role-grid { grid-template-columns: 1fr; }
    .detail-list { grid-template-columns: 1fr; }
}

/* Patch 003 additions */
.badge-info { background: #eff6ff; color: #1d4ed8; }
.filter-action {
    display: flex;
    align-items: end;
    gap: 10px;
    padding-top: 22px;
}
.security-note {
    border: 1px solid #bfdbfe;
    background: #eff6ff;
    border-radius: 14px;
    padding: 14px;
}
.security-note strong { color: #1d4ed8; }
.security-note p { margin: 6px 0 0; color: var(--muted); }
.milestone-list { display: grid; gap: 14px; }
.milestone-item {
    display: grid;
    grid-template-columns: 38px 1fr;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px;
    background: #f8fafc;
}
.milestone-item.active { border-color: #93c5fd; background: #eff6ff; }
.milestone-item.completed { border-color: #a7f3d0; background: #ecfdf5; }
.milestone-item.locked { opacity: .72; }
.milestone-number {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    background: var(--primary);
    color: white;
    display: grid;
    place-items: center;
    font-weight: 700;
}
.milestone-item strong { display: block; margin-bottom: 4px; }
.milestone-item span, .milestone-item small { color: var(--muted); font-size: 12px; }
.milestone-item p { margin: 8px 0; line-height: 1.5; }

@media (max-width: 700px) {
    .filter-action { align-items: stretch; flex-direction: column; padding-top: 0; }
    .milestone-item { grid-template-columns: 1fr; }
}

/* Patch 004 additions */
.milestone-item { color: inherit; text-decoration: none; transition: transform .15s ease, box-shadow .15s ease; }
.milestone-item:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(15, 23, 42, .08); }
.completion-box {
    border: 1px solid var(--line);
    background: #f8fafc;
    border-radius: 14px;
    padding: 14px;
    margin-top: 16px;
}
.completion-box strong { display: block; margin-bottom: 10px; }
.progress-line {
    height: 10px;
    border-radius: 999px;
    background: #e5e7eb;
    overflow: hidden;
}
.progress-line span {
    display: block;
    height: 100%;
    background: var(--primary);
    border-radius: 999px;
}
.completion-box p { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.empty-state {
    border: 1px dashed var(--line);
    border-radius: 14px;
    padding: 18px;
    background: #fbfdff;
    color: var(--muted);
}
.empty-state strong { display: block; color: var(--text); margin-bottom: 4px; }
.empty-state p { margin: 0; }
.task-list { display: grid; gap: 14px; }
.task-item {
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    padding: 14px;
}
.task-item.in-progress { border-color: #93c5fd; background: #eff6ff; }
.task-item.completed { border-color: #a7f3d0; background: #ecfdf5; }
.task-item.blocked, .task-item.rejected { border-color: #fecaca; background: #fef2f2; }
.task-item strong { display: block; margin-bottom: 4px; }
.task-item span, .task-item small { display: block; color: var(--muted); font-size: 12px; }
.task-item p { margin: 8px 0; line-height: 1.5; }

/* Patch 005 additions */
.small-text { font-size: 12px; }
.evidence-box {
    border: 1px solid var(--line);
    background: #f8fafc;
    border-radius: 14px;
    padding: 12px;
    margin-top: 12px;
}
.evidence-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}
.evidence-header span { color: var(--muted); font-size: 12px; }
.evidence-list { display: grid; gap: 8px; }
.evidence-item {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px;
    background: #fff;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: flex-start;
}
.evidence-item strong { display: block; margin-bottom: 3px; }
.evidence-item span { display: block; color: var(--muted); font-size: 12px; }
.evidence-item.voided { opacity: .65; background: #f9fafb; }
.void-form {
    display: flex;
    gap: 8px;
    align-items: center;
    min-width: 260px;
}
.void-form input {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 9px 10px;
    width: 100%;
}
.public-task-summary {
    border: 1px solid #bfdbfe;
    background: #eff6ff;
    border-radius: 14px;
    padding: 14px;
    margin: 16px 0;
}
.public-task-summary strong { display: block; margin-bottom: 6px; }
.public-task-summary span { display: block; color: var(--muted); font-size: 13px; margin-top: 4px; }

@media (max-width: 700px) {
    .evidence-item { flex-direction: column; }
    .void-form { width: 100%; min-width: 0; }
}

/* Patch 006 additions */
.btn-success { background: #16a34a; color: #fff; border-color: #16a34a; }
.btn-danger { background: #dc2626; color: #fff; border-color: #dc2626; }
.action-cell { min-width: 240px; }
.stacked-form { display: grid; gap: 8px; margin-bottom: 10px; }
.stacked-form textarea {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 9px 10px;
    width: 100%;
    resize: vertical;
}
.mini-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin: 12px 0;
}
.mini-stats div {
    border: 1px solid var(--line);
    background: #f8fafc;
    border-radius: 14px;
    padding: 14px;
}
.mini-stats strong { display: block; font-size: 22px; margin-bottom: 4px; }
.mini-stats span { color: var(--muted); font-size: 12px; }
.required { color: #dc2626; }
@media (max-width: 700px) {
    .mini-stats { grid-template-columns: 1fr; }
    .action-cell { min-width: 0; }
}

/* Patch 007 additions */
.mt-18 { margin-top: 18px; }
.text-danger { color: var(--danger); }
.stat-card.warning strong { color: #d97706; }
.stat-card.success strong { color: var(--success); }
.dashboard-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.three-col { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.summary-bars { display: grid; gap: 12px; }
.summary-bar-row { display: grid; gap: 6px; }
.summary-bar-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.summary-bar {
    height: 9px;
    background: #e5e7eb;
    border-radius: 999px;
    overflow: hidden;
}
.summary-bar span {
    display: block;
    height: 100%;
    background: var(--primary);
    border-radius: 999px;
}
.compact-list { display: grid; gap: 10px; }
.compact-list > div {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 11px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: #fbfdff;
}
.compact-list strong { font-size: 18px; }
.report-list { max-height: 360px; overflow: auto; padding-right: 4px; }
.timeline-list { display: grid; gap: 10px; }
.timeline-card {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px;
    display: grid;
    gap: 7px;
    background: #fff;
}
.timeline-card:hover { border-color: #bfdbfe; background: #eff6ff; }
.timeline-card strong { color: var(--text); }
.timeline-card small { color: var(--muted); }
.filter-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-top: 16px;
}
.filter-grid label {
    font-size: 13px;
    color: var(--muted);
    font-weight: 700;
    display: grid;
    gap: 6px;
}
.filter-grid input, .filter-grid select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 11px;
    font-size: 14px;
    background: #fff;
}
.filter-actions {
    display: flex;
    align-items: end;
    gap: 8px;
}
@media (max-width: 1050px) {
    .dashboard-stats, .three-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
    .dashboard-stats, .three-col, .filter-grid { grid-template-columns: 1fr; }
    .filter-actions { align-items: stretch; flex-direction: column; }
}

/* Patch 008 additions */
.inline-form {
    display: flex;
    align-items: end;
    gap: 10px;
    flex-wrap: wrap;
}
.inline-form label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 700; }
.inline-form input {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 9px 10px;
}
.checkbox-line {
    display: flex !important;
    align-items: center;
    gap: 8px;
    color: var(--text) !important;
    font-weight: 700 !important;
}
.checkbox-line input { width: auto !important; }
.code-block {
    background: #0f172a;
    color: #e5e7eb;
    border-radius: 12px;
    padding: 12px;
    overflow-x: auto;
    font-size: 13px;
}
.wa-message-preview {
    display: block;
    max-width: 360px;
    white-space: pre-line;
}
.action-stack {
    display: grid;
    gap: 6px;
    min-width: 120px;
}
.btn-small { padding: 6px 9px; font-size: 12px; }
.template-list { display: grid; gap: 14px; margin-top: 14px; }
.template-card {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px;
    display: grid;
    gap: 10px;
    background: #fbfdff;
}
.template-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 700; }
.template-card input,
.template-card textarea,
.form-grid input,
.form-grid textarea,
.form-grid select {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 11px;
    width: 100%;
    background: #fff;
}
.table-responsive { overflow-x: auto; }
.table-responsive table { width: 100%; border-collapse: collapse; }
.table-responsive th,
.table-responsive td {
    border-bottom: 1px solid var(--line);
    padding: 11px 10px;
    text-align: left;
    vertical-align: top;
}
.table-responsive th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.mt-8 { margin-top: 8px; }
@media (max-width: 700px) {
    .inline-form { align-items: stretch; flex-direction: column; }
    .wa-message-preview { max-width: 240px; }
}

/* Patch 009 additions */
.permission-matrix {
    display: grid;
    gap: 12px;
    margin: 12px 0 16px;
}
.permission-group {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 10px 12px;
    background: #fbfdff;
}
.permission-group summary {
    cursor: pointer;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 8px;
}
.button-row, .pagination-row, .section-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}
.button-row { justify-content: flex-start; }
.form-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.wide-inline-edit {
    display: grid;
    grid-template-columns: minmax(140px, 1fr) minmax(120px, 180px) minmax(180px, 1fr) auto auto;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
}
.audit-table td { vertical-align: top; }
.audit-metadata {
    max-width: 520px;
    max-height: 240px;
    overflow: auto;
    white-space: pre-wrap;
}
code {
    background: #eef2ff;
    color: #3730a3;
    border-radius: 6px;
    padding: 2px 5px;
    font-size: 12px;
}
@media (max-width: 1000px) {
    .form-grid.four { grid-template-columns: 1fr 1fr; }
    .wide-inline-edit { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
    .form-grid.four { grid-template-columns: 1fr; }
    .button-row, .pagination-row, .section-title-row { align-items: stretch; flex-direction: column; }
}


/* Patch 010 additions */
.compact-check-list {
    margin: 8px 0 0;
    padding-left: 20px;
}
.compact-check-list li {
    margin-bottom: 4px;
}
.uat-checklist {
    display: grid;
    gap: 10px;
    margin-top: 12px;
}
.system-settings-table {
    max-height: 520px;
    overflow: auto;
}
.stat-card.warning strong { color: #d97706; }

/* Patch 011 - layout usability hardening */
html {
    scroll-behavior: smooth;
}
body {
    overflow-x: hidden;
}
button,
input,
select,
textarea {
    font: inherit;
}
.sidebar {
    transition: transform .2s ease, box-shadow .2s ease;
    z-index: 80;
}
.main {
    transition: margin-left .2s ease, width .2s ease;
}
body.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
}
body.sidebar-collapsed .main {
    margin-left: 0;
    width: 100%;
}
.topbar {
    position: sticky;
    top: 0;
    z-index: 70;
    box-shadow: 0 8px 20px rgba(15, 23, 42, .04);
}
.topbar-title {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}
.sidebar-toggle {
    width: 42px;
    height: 42px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    display: inline-grid;
    place-items: center;
    font-size: 20px;
    font-weight: 800;
    line-height: 1;
    flex: 0 0 auto;
}
.sidebar-toggle:hover {
    border-color: #bfdbfe;
    background: #eff6ff;
    color: var(--primary);
}
body.sidebar-collapsed .sidebar-toggle {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: var(--primary);
}
.card-header,
.page-actions,
.section-title-row {
    row-gap: 12px;
}
.card-header form,
.page-actions form,
.section-title-row form {
    display: flex;
    align-items: end;
    gap: 10px;
    flex-wrap: wrap;
}
.card-header label,
.page-actions label,
.section-title-row label,
.compact-form label,
.filter-action label {
    display: grid;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
    font-weight: 700;
}
.card-header input,
.card-header select,
.page-actions input,
.page-actions select,
.section-title-row input,
.section-title-row select,
.compact-form input,
.compact-form select,
.filter-action input,
.filter-action select,
.inline-form input,
.inline-form select,
.filter-grid input,
.filter-grid select {
    min-height: 42px;
    min-width: 170px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    background: #fff;
}
.filter-action {
    align-items: end;
    flex-wrap: wrap;
}
.table-wrap,
.table-responsive,
.table-scroll,
.system-settings-table {
    width: 100%;
    max-height: 68vh;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
}
.table-wrap .table,
.table-responsive table,
.table-scroll table,
.system-settings-table table {
    min-width: 920px;
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}
.table-wrap .table th,
.table-responsive table th,
.table-scroll table th,
.system-settings-table table th,
.table-wrap .table thead th,
.table-responsive table thead th,
.table-scroll table thead th,
.system-settings-table table thead th {
    position: sticky;
    top: 0;
    z-index: 5;
    background: #f8fafc;
    box-shadow: inset 0 -1px 0 var(--line);
}
.table-wrap .table th:first-child,
.table-responsive table th:first-child,
.table-scroll table th:first-child,
.system-settings-table table th:first-child {
    border-top-left-radius: 14px;
}
.table-wrap .table th:last-child,
.table-responsive table th:last-child,
.table-scroll table th:last-child,
.system-settings-table table th:last-child {
    border-top-right-radius: 14px;
}
.table-wrap .table tr:last-child td,
.table-responsive table tr:last-child td,
.table-scroll table tr:last-child td,
.system-settings-table table tr:last-child td {
    border-bottom: 0;
}
.table-wrap::-webkit-scrollbar,
.table-responsive::-webkit-scrollbar,
.table-scroll::-webkit-scrollbar,
.system-settings-table::-webkit-scrollbar,
.sidebar::-webkit-scrollbar,
.report-list::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
.table-wrap::-webkit-scrollbar-thumb,
.table-responsive::-webkit-scrollbar-thumb,
.table-scroll::-webkit-scrollbar-thumb,
.system-settings-table::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb,
.report-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 999px;
}
.table-wrap::-webkit-scrollbar-track,
.table-responsive::-webkit-scrollbar-track,
.table-scroll::-webkit-scrollbar-track,
.system-settings-table::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track,
.report-list::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 999px;
}
@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        width: min(290px, 86vw);
        inset: 0 auto 0 0;
        transform: translateX(-100%);
    }
    body.sidebar-mobile-open .sidebar {
        transform: translateX(0);
        box-shadow: 20px 0 50px rgba(15, 23, 42, .25);
    }
    .app-shell {
        display: block;
    }
    .main,
    body.sidebar-collapsed .main {
        width: 100%;
        margin-left: 0;
    }
    .topbar {
        align-items: center;
        flex-direction: row;
    }
}
@media (max-width: 700px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }
    .topbar-title {
        width: 100%;
    }
    .card-header form,
    .page-actions form,
    .section-title-row form,
    .filter-action {
        width: 100%;
        align-items: stretch;
        flex-direction: column;
    }
    .card-header input,
    .card-header select,
    .page-actions input,
    .page-actions select,
    .section-title-row input,
    .section-title-row select,
    .compact-form input,
    .compact-form select,
    .filter-action input,
    .filter-action select,
    .inline-form input,
    .inline-form select,
    .filter-grid input,
    .filter-grid select {
        width: 100%;
        min-width: 0;
    }
    .table-wrap,
    .table-responsive,
    .table-scroll,
    .system-settings-table {
        max-height: 62vh;
    }
}

/* Patch 012 - filter form and select control size fix */
.filter-card {
    overflow: visible;
}
.filter-form {
    display: flex;
    align-items: end;
    gap: 14px;
    flex-wrap: wrap;
    width: 100%;
}
.filter-form > div {
    display: grid;
    gap: 7px;
    min-width: 240px;
}
.filter-form label {
    display: block;
    font-size: 13px;
    color: var(--muted);
    font-weight: 800;
    line-height: 1.3;
}
.filter-form input,
.filter-form select,
.filter-card input,
.filter-card select,
.card-header select,
.page-actions select,
.section-title-row select,
.compact-form select,
.inline-form select,
.filter-grid select,
.form-grid select {
    min-height: 44px;
    height: 44px;
    min-width: 220px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    line-height: 1.35;
    background-color: #fff;
    color: var(--text);
}
.filter-form select,
.filter-card select,
.card-header select,
.page-actions select,
.section-title-row select,
.compact-form select,
.inline-form select,
.filter-grid select,
.form-grid select {
    padding-right: 34px;
    cursor: pointer;
}
.filter-form input:focus,
.filter-form select:focus,
.filter-card input:focus,
.filter-card select:focus,
.card-header select:focus,
.page-actions select:focus,
.section-title-row select:focus,
.compact-form select:focus,
.inline-form select:focus,
.filter-grid select:focus,
.form-grid select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
    outline: none;
}
.filter-form .btn,
.filter-card .btn {
    min-height: 44px;
    padding: 10px 16px;
}
@media (max-width: 700px) {
    .filter-form {
        align-items: stretch;
        flex-direction: column;
    }
    .filter-form > div,
    .filter-form input,
    .filter-form select,
    .filter-card input,
    .filter-card select,
    .card-header select,
    .page-actions select,
    .section-title-row select,
    .compact-form select,
    .inline-form select,
    .filter-grid select,
    .form-grid select {
        width: 100%;
        min-width: 0;
    }
}

/* Patch 013 - profile and password security */
.user-profile-link {
    color: var(--text);
    font-weight: 800;
    padding: 8px 10px;
    border-radius: 10px;
    background: #f8fafc;
    border: 1px solid var(--line);
}
.user-profile-link:hover {
    background: #eef2ff;
    color: #3730a3;
}
.password-policy-box {
    border: 1px solid #bfdbfe;
    background: #eff6ff;
    color: #1e3a8a;
    border-radius: 14px;
    padding: 14px 16px;
    margin: 16px 0;
    font-size: 14px;
}
.password-policy-box strong {
    display: block;
    margin-bottom: 8px;
}
.password-policy-box ul {
    margin: 0;
    padding-left: 18px;
    line-height: 1.65;
}
@media (max-width: 700px) {
    .userbox {
        flex-wrap: wrap;
    }
    .user-profile-link {
        width: 100%;
        text-align: center;
    }
}

/* Patch 014 - Meeting follow-up and carry-forward */
.info-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    padding: 12px 14px;
    border: 1px solid #bfdbfe;
    background: #eff6ff;
    color: #1e3a8a;
    border-radius: 12px;
    margin-bottom: 16px;
    font-size: 14px;
}
.info-strip span {
    font-weight: 700;
}
.table-wrap-compact {
    max-height: 360px;
}
.compact-timeline .timeline-item {
    padding: 12px 0;
}
.card .form-grid.four input[type="date"],
.card .form-grid.four input[type="time"] {
    min-width: 0;
}
@media (max-width: 900px) {
    .info-strip {
        display: block;
    }
    .info-strip a {
        display: block;
        margin-top: 6px;
    }
}


/* Patch 018 - compact management layout */
.content {
    padding: 22px;
}
.card {
    padding: 18px;
}
.page-actions {
    margin-bottom: 14px;
}
.compact-card-header {
    margin-bottom: 12px;
}
.management-list-card {
    padding-top: 18px;
}
.action-drawer {
    margin: 0 0 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 8px 20px rgba(15, 23, 42, .035);
}
.action-drawer > summary {
    list-style: none;
    width: fit-content;
    margin: 12px;
}
.action-drawer > summary::-webkit-details-marker {
    display: none;
}
.action-drawer > summary::after {
    content: '+';
    margin-left: 10px;
    font-weight: 900;
}
.action-drawer[open] > summary::after {
    content: '−';
}
.action-drawer-body {
    border-top: 1px solid var(--line);
    padding: 14px;
    background: #fbfdff;
    border-radius: 0 0 14px 14px;
}
.inline-action-drawer {
    box-shadow: none;
    margin-top: 14px;
    margin-bottom: 0;
}
.inline-action-drawer > summary {
    margin: 10px;
}
.row-drawer > summary {
    cursor: pointer;
    width: fit-content;
}
.row-drawer[open] {
    min-width: 360px;
}
.compact-management-grid {
    align-items: start;
}
.compact-filter-grid {
    margin-top: 8px;
}
.compact-role-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    max-height: 260px;
    overflow: auto;
}
.compact-permission-matrix {
    max-height: 50vh;
    overflow: auto;
    padding-right: 4px;
}
.action-drawer .form,
.action-drawer .form-grid {
    gap: 10px;
}
.action-drawer h3 {
    margin-bottom: 6px;
}
.action-drawer .button-row {
    margin-bottom: 0;
}
.table-wrap,
.table-responsive,
.table-scroll,
.system-settings-table {
    max-height: 64vh;
}
@media (max-width: 1200px) {
    .compact-role-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
@media (max-width: 700px) {
    .content {
        padding: 16px;
    }
    .card {
        padding: 16px;
    }
    .action-drawer > summary {
        width: calc(100% - 20px);
        justify-content: center;
    }
    .compact-role-grid {
        grid-template-columns: 1fr;
        max-height: 320px;
    }
    .row-drawer[open] {
        min-width: 0;
    }
}

/* Patch 019 - user edit management */
.table-action-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.table-action-row form {
    margin: 0;
}
.status-stack {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}
.form-checkbox-line {
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
}
.edit-role-grid {
    margin-top: 8px;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px;
    background: #fbfdff;
}
.security-panel {
    margin-top: 18px;
    border: 1px solid #dbeafe;
    border-radius: 16px;
    background: #eff6ff;
    padding: 16px;
}
.security-panel h3 {
    margin: 0 0 4px;
}
.input-help {
    margin: 7px 0 0;
    color: var(--muted);
    font-size: 12px;
}
@media (max-width: 700px) {
    .status-stack {
        justify-content: flex-start;
    }
    .table-action-row {
        align-items: stretch;
        flex-direction: column;
    }
    .table-action-row .btn,
    .table-action-row form,
    .table-action-row button {
        width: 100%;
    }
}


/* Patch 020 - PICA documentation menu */
.documentation-hero {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(260px, .65fr);
    gap: 16px;
    align-items: stretch;
}
.documentation-hero .hero-card {
    background: linear-gradient(135deg, #eff6ff 0%, #ffffff 58%, #f8fafc 100%);
    border: 1px solid #bfdbfe;
}
.documentation-title {
    margin: 0 0 8px;
    font-size: 28px;
    line-height: 1.2;
}
.documentation-subtitle {
    color: var(--muted);
    max-width: 860px;
    line-height: 1.7;
    margin: 0;
}
.documentation-meta {
    display: grid;
    gap: 10px;
}
.documentation-meta div {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 14px;
    padding: 12px 14px;
}
.documentation-meta span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 2px;
}
.documentation-meta strong {
    display: block;
    color: var(--text);
}
.documentation-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}
.documentation-nav a {
    display: inline-flex;
    min-height: 38px;
    align-items: center;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: var(--text);
    text-decoration: none;
    font-weight: 700;
    font-size: 13px;
}
.documentation-nav a:hover {
    border-color: #93c5fd;
    color: #1d4ed8;
    background: #eff6ff;
}
.documentation-section {
    scroll-margin-top: 94px;
}
.documentation-section h2 {
    margin-bottom: 6px;
}
.documentation-section .lead {
    color: var(--muted);
    line-height: 1.7;
    margin-top: 0;
}
.doc-list {
    margin: 0;
    padding-left: 20px;
    line-height: 1.75;
}
.doc-list li + li {
    margin-top: 4px;
}
.doc-flow {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}
.doc-flow-step {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 12px;
    align-items: start;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 14px;
    background: #fff;
}
.doc-flow-number {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #1d4ed8;
    color: #fff;
    font-weight: 900;
}
.doc-flow-step h3 {
    margin: 0 0 4px;
    font-size: 16px;
}
.doc-flow-step p {
    margin: 0;
    color: var(--muted);
    line-height: 1.6;
}
.doc-callout {
    border: 1px solid #facc15;
    background: #fefce8;
    border-radius: 16px;
    padding: 14px 16px;
    line-height: 1.65;
}
.doc-callout strong {
    color: #854d0e;
}
.doc-two-col {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}
.doc-checklist {
    display: grid;
    gap: 8px;
}
.doc-checklist div {
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fbfdff;
    padding: 12px 14px;
}
.doc-checklist strong {
    display: block;
    margin-bottom: 4px;
}
.doc-checklist span {
    color: var(--muted);
    line-height: 1.55;
}
@media (max-width: 980px) {
    .documentation-hero,
    .doc-two-col {
        grid-template-columns: 1fr;
    }
}
@media (max-width: 700px) {
    .documentation-title {
        font-size: 23px;
    }
    .documentation-nav a {
        width: 100%;
        justify-content: center;
    }
    .doc-flow-step {
        grid-template-columns: 1fr;
    }
}
