/* TMC SOP Manager — shared admin + front-end styles */

.sop-wrap { --sop-accent: #1d3f72; --sop-line: #dfe3e8; --sop-bg: #f6f7f9; color: #22262b; }
.sop-wrap * { box-sizing: border-box; }
.sop-frontend { max-width: 1180px; margin: 0 auto; padding: 16px; font-size: 15px; }

.sop-page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 12px 0 8px; }
.sop-page-head h1 { margin: 0; font-size: 22px; line-height: 1.3; }
.sop-page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.sop-nav { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--sop-line); margin-bottom: 18px; }
.sop-nav-item { padding: 9px 14px; text-decoration: none; color: #555; border-bottom: 2px solid transparent; font-weight: 500; }
.sop-nav-item:hover { color: var(--sop-accent); }
.sop-nav-item.is-active { color: var(--sop-accent); border-bottom-color: var(--sop-accent); }
.sop-badge { background: #c0392b; color: #fff; border-radius: 10px; padding: 1px 7px; font-size: 11px; margin-left: 4px; }

.sop-card { background: #fff; border: 1px solid var(--sop-line); border-radius: 6px; padding: 18px; margin-bottom: 18px; }
.sop-card h3 { margin-top: 0; font-size: 16px; }
.sop-narrow { max-width: 640px; }

.sop-btn { display: inline-block; padding: 7px 14px; border: 1px solid var(--sop-line); background: #fff; border-radius: 4px; cursor: pointer; text-decoration: none; color: #22262b; font-size: 13px; line-height: 1.6; }
.sop-btn:hover { border-color: var(--sop-accent); color: var(--sop-accent); }
.sop-btn-primary { background: var(--sop-accent); border-color: var(--sop-accent); color: #fff; }
.sop-btn-primary:hover { opacity: .9; color: #fff; }
.sop-btn-danger { border-color: #c0392b; color: #c0392b; }
.sop-btn-small { padding: 4px 9px; font-size: 12px; }
.sop-btn[disabled] { opacity: .5; cursor: not-allowed; }

.sop-field { margin-bottom: 14px; }
.sop-field > label { display: block; font-weight: 600; margin-bottom: 4px; font-size: 13px; }
.sop-field input[type=text], .sop-field input[type=url], .sop-field input[type=email], .sop-field input[type=number],
.sop-field input[type=date], .sop-field input[type=search], .sop-field select, .sop-field textarea { width: 100%; padding: 7px 9px; border: 1px solid var(--sop-line); border-radius: 4px; font-size: 14px; background: #fff; }
.sop-field textarea { font-family: inherit; }
.sop-help { color: #6b7280; font-size: 12px; margin: 4px 0 0; }
.sop-inline { display: inline-flex; align-items: center; gap: 6px; font-weight: 400 !important; }
.sop-inline-pair { display: flex; gap: 6px; }
.sop-checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.sop-checks label { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; }
.sop-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.sop-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 18px; }
.sop-center { text-align: center; }
.sop-muted { color: #6b7280; }
.sop-nowrap { white-space: nowrap; }
.sop-overdue { color: #c0392b; font-weight: 600; }
.sop-empty { color: #6b7280; padding: 20px 0; }
.sop-scroll { overflow-x: auto; }

.sop-filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.sop-filters input, .sop-filters select { padding: 6px 9px; border: 1px solid var(--sop-line); border-radius: 4px; }

.sop-table { width: 100%; border-collapse: collapse; background: #fff; font-size: 13.5px; }
.sop-table th, .sop-table td { border: 1px solid var(--sop-line); padding: 8px 10px; text-align: left; vertical-align: top; }
.sop-table thead th { background: var(--sop-bg); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.sop-row-actions a { margin-right: 8px; font-size: 12.5px; }

.sop-chip { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11.5px; background: #eef1f5; color: #384150; white-space: nowrap; }
.sop-status-draft { background: #eef1f5; }
.sop-status-in_review { background: #fdf0d5; color: #8a6100; }
.sop-status-approved { background: #e3f1e6; color: #226b32; }
.sop-status-published { background: #dbeafe; color: #1d4ed8; }
.sop-status-rejected { background: #fde2e1; color: #9b2c2c; }
.sop-status-archived { background: #eceff1; color: #6b7280; }

.sop-notice { padding: 10px 14px; border-radius: 4px; margin: 10px 0 16px; border-left: 4px solid #999; background: #f4f6f8; }
.sop-notice-success { border-color: #2e7d32; background: #edf7ee; }
.sop-notice-warning { border-color: #e0a800; background: #fdf7e6; }
.sop-notice-error { border-color: #c0392b; background: #fdecea; }

/* Editor */
.sop-editor-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.sop-section { border: 1px solid var(--sop-line); border-radius: 5px; margin-bottom: 12px; background: #fff; }
.sop-section-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; background: var(--sop-bg); border-bottom: 1px solid var(--sop-line); }
.sop-section-type { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: #6b7280; font-weight: 600; }
.sop-section-tools a { text-decoration: none; padding: 0 5px; color: #6b7280; font-size: 15px; }
.sop-section-tools a:hover { color: var(--sop-accent); }
.sop-section-body { padding: 12px; }
.sop-section-body input[type=text], .sop-section-body textarea, .sop-section-body select { width: 100%; padding: 6px 8px; border: 1px solid var(--sop-line); border-radius: 4px; margin-bottom: 8px; font-size: 14px; font-family: inherit; }
.sop-item { display: flex; gap: 6px; align-items: center; }
.sop-item input { flex: 1; }
.sop-item-remove, .sop-row-remove, .sop-col-remove { text-decoration: none; color: #b0343c; padding: 0 4px; }
.sop-table-editor { width: 100%; border-collapse: collapse; }
.sop-table-editor th, .sop-table-editor td { border: 1px solid var(--sop-line); padding: 4px; }
.sop-table-editor th { background: var(--sop-bg); }
.sop-table-editor textarea { min-height: 42px; }
.sop-add-bar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; border-top: 1px dashed var(--sop-line); padding-top: 12px; }
.sop-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.sop-save-state { color: #2e7d32; font-size: 12px; }
.sop-list-plain { list-style: none; margin: 0; padding: 0; }
.sop-list-plain li { padding: 4px 0; border-bottom: 1px solid var(--sop-line); font-size: 13px; }

/* Reader */
.sop-readbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.sop-reader { background: #fff; border: 1px solid var(--sop-line); border-radius: 6px; padding: 32px 38px; }
.sop-reader .sop-document { max-width: 900px; margin: 0 auto; }
.sop-ackbox { background: #fdf7e6; border: 1px solid #f0d99a; border-radius: 6px; padding: 16px; margin-top: 16px; }

/* Diff */
.sop-diff-table td { font-size: 12.5px; }
.sop-diff-old { background: #fdecea; }
.sop-diff-new { background: #edf7ee; }
.sop-diff-head { font-size: 13px; color: #6b7280; }

/* Approvals */
.sop-approval-actions { display: flex; gap: 8px; margin: 10px 0; }
.sop-decision-comment { width: 100%; padding: 8px; border: 1px solid var(--sop-line); border-radius: 4px; }

/* Permissions */
.sop-matrix th { font-size: 12px; font-weight: 600; }
.sop-matrix tbody th { text-align: left; font-weight: 500; }
.sop-matrix code { font-size: 10.5px; color: #8892a0; }
.sop-grant { display: flex; justify-content: space-between; align-items: center; border: 1px solid var(--sop-line); border-radius: 4px; padding: 5px 9px; margin-bottom: 5px; font-size: 13px; }
.sop-grant-remove { text-decoration: none; color: #b0343c; }

/* Template editor */
.sop-template-code textarea { font-family: Menlo, Consolas, monospace; font-size: 12.5px; line-height: 1.5; width: 100%; }
.sop-tokens code { background: var(--sop-bg); padding: 1px 5px; border-radius: 3px; }

.sop-simple-list { list-style: none; padding: 0; }
.sop-simple-list li { padding: 6px 0; border-bottom: 1px solid var(--sop-line); }

@media (max-width: 960px) {
	.sop-editor-wrap { grid-template-columns: 1fr; }
	.sop-grid-2, .sop-grid-4 { grid-template-columns: 1fr; }
}

/* ---------------------------------------- Template background + palette */

.sop-subcard { border: 1px solid #e2e6ec; border-radius: 6px; padding: 14px 16px; margin: 16px 0; background: #fbfcfd; }
.sop-subcard h4 { margin: 0 0 4px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: #4a5568; }

.sop-bg-layout { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; }
.sop-bg-preview { width: 150px; min-height: 200px; flex: 0 0 150px; border: 1px solid #d8dde4; background: #fff repeating-conic-gradient(#f2f4f7 0% 25%, #fff 0% 50%) 50% / 14px 14px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.sop-bg-preview img { width: 100%; height: auto; display: block; }
.sop-bg-empty { font-size: 11px; color: #8b93a1; }
.sop-bg-controls { flex: 1 1 320px; min-width: 300px; }
.sop-bg-controls input[type="file"] { max-width: 100%; margin-bottom: 6px; }
.sop-bg-filename { font-size: 12px; color: #4a5568; margin-left: 8px; }
.sop-bg-state { font-size: 12px; color: #6b7280; margin-left: 8px; }

.sop-colour-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 16px; margin: 10px 0 18px; }
.sop-colour-field label { display: block; font-size: 11px; color: #4a5568; margin-bottom: 3px; }
.sop-colour-row { display: flex; align-items: center; gap: 6px; }
.sop-colour-row input[type="color"] { width: 34px; height: 30px; padding: 2px; border: 1px solid #d8dde4; border-radius: 4px; background: #fff; cursor: pointer; }
.sop-colour-row input[type="text"] { width: 92px; font-family: monospace; font-size: 12px; }

.sop-btn-link { background: none; border: none; color: #1d3f72; text-decoration: underline; padding: 0 6px; cursor: pointer; }

/* ------------------------------------------------------- Rich text fields */

.sop-rich { border: 1px solid #ccd2da; border-radius: 5px; background: #fff; overflow: hidden; }
.sop-rich-bar { display: flex; flex-wrap: wrap; gap: 2px; padding: 4px 6px; background: #f5f7fa; border-bottom: 1px solid #e2e6ec; }
.sop-rich-btn { min-width: 28px; height: 26px; padding: 0 6px; border: 1px solid transparent; border-radius: 3px; background: transparent; color: #33415c; font-size: 13px; line-height: 1; cursor: pointer; }
.sop-rich-btn:hover { background: #e6ebf2; }
.sop-rich-btn.is-active { background: #dbe4f0; border-color: #b9c7db; }
.sop-rich-btn.is-bold { font-weight: 700; }
.sop-rich-btn.is-italic { font-style: italic; }
.sop-rich-btn.is-underline { text-decoration: underline; }

.sop-rich-area { min-height: 110px; padding: 10px 12px; font-size: 14px; line-height: 1.5; outline: none; }
.sop-rich-area:focus { box-shadow: inset 0 0 0 2px #dbe4f0; }
.sop-rich-area p { margin: 0 0 8px; }
.sop-rich-area p:last-child { margin-bottom: 0; }
.sop-rich-area ul, .sop-rich-area ol { margin: 0 0 8px 20px; padding: 0; }
.sop-rich-area:empty::before { content: attr(data-placeholder); color: #9aa3b2; }

.sop-rich-source { display: none; width: 100%; border: 0; border-top: 1px solid #e2e6ec; padding: 10px 12px; font-family: Menlo, Consolas, monospace; font-size: 12px; }
.sop-rich.is-source .sop-rich-area { display: none; }
.sop-rich.is-source .sop-rich-source { display: block; }
.sop-rich.is-locked .sop-rich-bar { display: none; }
.sop-rich.is-locked .sop-rich-area { background: #f7f8fa; color: #5a6475; }

/* --------------------------------------------------- Per-person permissions */

.sop-people td { vertical-align: top; }
.sop-pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; line-height: 18px; }
.sop-pill-allow { background: #e3f1e6; color: #24603a; }
.sop-pill-deny { background: #fbe6e6; color: #8a2222; }

.sop-grant-add { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.sop-grant-add select { max-width: 220px; }

.sop-grant { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border: 1px solid #e2e6ec; border-radius: 4px; margin-bottom: 5px; background: #fff; font-size: 13px; }
.sop-grant.is-deny { border-left: 3px solid #c0392b; }
.sop-grant.is-allow { border-left: 3px solid #2e7d4f; }
.sop-grant-effect { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: #6b7280; min-width: 40px; }
.sop-grant-remove { margin-left: auto; text-decoration: none; color: #8a2222; }

.sop-effective-wrap { margin-top: 14px; }
.sop-effective-wrap summary { cursor: pointer; font-weight: 600; }
.sop-effective .sop-eff-mark { font-size: 15px; width: 40px; }
.sop-effective tr.is-yes .sop-eff-mark { color: #2e7d4f; }
.sop-effective tr.is-no .sop-eff-mark { color: #9aa3b2; }
.sop-effective tr.is-partial .sop-eff-mark { color: #b7791f; }
.sop-admin-warning { background: #fff8e5; border-left: 3px solid #e0b040; padding: 8px 12px; }

.sop-test-state { display: block; margin-top: 6px; font-size: 12px; color: #2e7d4f; }
.sop-test-state.is-error { color: #8a2222; }

.sop-snippet { margin-top: 4px; font-size: 12px; color: #5a6475; line-height: 1.45; }
.sop-snippet mark { background: #fdf0a8; padding: 0 2px; }
.sop-reindex-state { font-size: 12px; color: #4a5568; margin-left: 8px; }
.sop-token-help summary { cursor: pointer; font-weight: 600; margin: 6px 0 10px; }
.sop-dept-code-edit { text-transform: uppercase; font-family: monospace; }
