/* Leonardo Codex -- the look shared by the tool pages: History, Setup, Actions, Review, Search,
   and by the margin notes (Story 3510). Everything is prefixed cxt- (tools) or cxc- (comments) so
   it can never collide with codex.css, which the reading pages own.

   Shell rule: the page is a flex column exactly one screen tall; the chrome rows never shrink and
   exactly one element (.cxt-body) scrolls, so the icon band and the black header stay put. */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: #F2F2F4; color: #1F2937; font-family: "Segoe UI", system-ui, sans-serif; font-size: 14px; }

.cxt-shell { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; width: 100%; }
#lwIconBand, .cxt-shell > .ct-header, .cxt-tabs, .cxt-bar { flex: 0 0 auto; }

/* The black header: the same look codex.css gives it, restated so a tool page stands up without that file. */
.cxt-shell > .ct-header { background: #1F2937; color: #fff; padding: 8px 12px; display: flex; align-items: center; gap: 8px; min-height: 40px; }
.cxt-shell > .ct-header h1 { margin: 0; font-size: 15pt; font-weight: 650; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cxt-shell > .ct-header h1 small { font-weight: 400; font-size: 10pt; color: #C9CBD1; margin-left: 8px; }
.cxt-shell > .ct-header button { color: #fff; background: transparent; border: 1px solid #4B5563; border-radius: 4px; padding: 0 12px; min-height: 40px; font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap; }
.cxt-shell > .ct-header button:hover { background: #374151; }

/* ---- tabs ---- */
.cxt-tabs { display: flex; gap: 2px; background: #E5E7EB; padding: 6px 12px 0; overflow-x: auto; white-space: nowrap; }
.cxt-tab {
    border: none; background: transparent; padding: 9px 14px; font: inherit; font-size: 14px; color: #4B5563;
    border-radius: 6px 6px 0 0; cursor: pointer; flex: 0 0 auto;
}
.cxt-tab.active { background: #F2F2F4; color: #111827; font-weight: 600; }
.cxt-tab .badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: #B45309; color: #fff; font-size: 11px; font-weight: 600; text-align: center; }
.cxt-tab .badge:empty { display: none; }

/* ---- the toolbar row (filters and actions live at the TOP, never docked at the bottom) ---- */
.cxt-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; padding: 10px 14px; background: #fff; border-bottom: 1px solid #DCDDE1; }
.cxt-bar .fld { display: flex; flex-direction: column; gap: 3px; min-width: 150px; }
.cxt-bar .fld.grow { flex: 1 1 240px; }
.cxt-bar label { font-size: 11px; color: #6B7280; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.cxt-bar .fld input[type=search], .cxt-bar .fld input[type=text] {
    display: block; width: 100%; padding: 8px 10px; font: inherit; border: 1px solid #C9CBD1; border-radius: 6px; background: #fff; color: #111827;
}
.cxt-bar .voice-mic-wrap, .cxt-field .voice-mic-wrap, .cxc-add .voice-mic-wrap { display: block; }
.cxt-bar .check, .cxt-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: #374151; text-transform: none; letter-spacing: 0; font-weight: 400; padding: 8px 0; cursor: pointer; }
.cxt-bar .check input, .cxt-check input { width: 18px; height: 18px; }
.cxt-bar .spacer { flex: 1 1 auto; }
.cxt-meta { font-size: 13px; color: #4B5563; padding: 8px 0; }
.cxt-meta b { color: #111827; }
.cxt-meta .late { color: #B91C1C; font-weight: 600; }

.cxt-btn {
    border: 1px solid #C9CBD1; background: #fff; color: #1F2937; border-radius: 6px; padding: 8px 14px;
    font: inherit; font-size: 13px; cursor: pointer; text-decoration: none; display: inline-block; line-height: 1.2;
}
.cxt-btn:hover { background: #F3F4F6; }
.cxt-btn.primary { background: #4F46E5; border-color: #4F46E5; color: #fff; }
.cxt-btn.primary:hover { background: #4338CA; }
.cxt-btn.danger { background: #fff; border-color: #DC2626; color: #B91C1C; }
.cxt-btn.danger:hover { background: #FEF2F2; }
.cxt-btn.good { border-color: #15803D; color: #15803D; }
.cxt-btn.small { padding: 5px 10px; font-size: 12px; }
.cxt-btn[disabled] { opacity: .5; cursor: default; }
.cxt-btn.on { background: #EEF2FF; border-color: #4F46E5; color: #3730A3; }

/* ---- the one scroller ---- */
.cxt-body { flex: 1 1 auto; min-height: 0; overflow: auto; -webkit-overflow-scrolling: touch; padding: 14px; }
.cxt-wrap { max-width: 1100px; margin: 0 auto; width: 100%; }
.cxt-wrap.wide { max-width: 1500px; }

.cxt-empty { padding: 22px 16px; text-align: center; color: #6B7280; background: #fff; border: 1px dashed #D1D5DB; border-radius: 8px; }
.cxt-error { color: #B91C1C; border-color: #FCA5A5; background: #FEF2F2; }
.cxt-note { font-size: 12.5px; color: #6B7280; margin: 0 0 10px; }

/* ---- groups and rows ---- */
.cxt-group { background: #fff; border: 1px solid #DCDDE1; border-radius: 8px; margin: 0 0 12px; overflow: hidden; }
.cxt-group-h {
    display: flex; align-items: center; gap: 8px; width: 100%; border: none; background: #F7F7F9; padding: 9px 12px;
    font: inherit; font-weight: 600; font-size: 13.5px; color: #111827; text-align: left; cursor: pointer; border-bottom: 1px solid #E5E7EB;
}
.cxt-group.collapsed .cxt-group-h { border-bottom: none; }
.cxt-group-h .tw { width: 12px; color: #6B7280; flex: 0 0 auto; }
.cxt-group-h .nm { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cxt-group-h .ct { font-weight: 400; color: #6B7280; font-size: 12.5px; flex: 0 0 auto; }
.cxt-group-h .ct .late { color: #B91C1C; font-weight: 600; }

.cxt-row { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border-bottom: 1px solid #EEF0F3; }
.cxt-row:last-child { border-bottom: none; }
.cxt-row .main { flex: 1 1 auto; min-width: 0; }
.cxt-row .ttl { font-size: 14.5px; color: #111827; overflow-wrap: anywhere; }
.cxt-row a.ttl, .cxt-row .ttl a { color: #1D4ED8; text-decoration: none; font-weight: 600; }
.cxt-row .sub { font-size: 12.5px; color: #6B7280; margin-top: 3px; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.cxt-row .sub a { color: #4B5563; }
.cxt-row .acts { flex: 0 0 auto; display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.cxt-row.done .ttl { color: #6B7280; }
.cxt-row .tick { color: #15803D; font-weight: 700; margin-right: 4px; }
.cxt-row .bigcheck { width: 22px; height: 22px; margin: 1px 0 0; flex: 0 0 auto; accent-color: #15803D; cursor: pointer; }
.cxt-row.tappable { cursor: pointer; }
.cxt-row.tappable:hover { background: #F9FAFB; }
.cxt-row .snip { font-size: 13px; color: #374151; margin-top: 4px; overflow-wrap: anywhere; }
mark { background: #FDE68A; color: inherit; padding: 0 1px; border-radius: 2px; }

.cxt-chip { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11.5px; line-height: 1.5; border: 1px solid #D1D5DB; color: #4B5563; background: #fff; white-space: nowrap; }
.cxt-chip.status { font-weight: 600; background: #fff; }
.cxt-chip.late { background: #FEE2E2; border-color: #FCA5A5; color: #B91C1C; font-weight: 600; }
.cxt-chip.soon { background: #FEF3C7; border-color: #FCD34D; color: #92400E; font-weight: 600; }
.cxt-chip.good { background: #DCFCE7; border-color: #86EFAC; color: #166534; }
.cxt-chip.src-task { background: #EEF2FF; border-color: #C7D2FE; color: #3730A3; }
.cxt-chip.src-checklist { background: #ECFEFF; border-color: #A5F3FC; color: #155E75; }
.cxt-chip.quiet { background: #F3F4F6; }
.cxt-swatch { display: inline-block; width: 14px; height: 14px; border-radius: 50%; vertical-align: -2px; margin-right: 6px; border: 1px solid rgba(0,0,0,.15); }

/* ---- the row menu ---- */
.cxt-menu-btn { border: 1px solid #D1D5DB; background: #fff; border-radius: 6px; width: 34px; height: 32px; font-size: 18px; line-height: 1; cursor: pointer; color: #374151; flex: 0 0 auto; }
.cxt-menu {
    position: fixed; z-index: 4000; min-width: 190px; background: #fff; border: 1px solid #C9CBD1; border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,.2); padding: 4px; max-width: calc(100vw - 16px);
}
.cxt-menu button { display: block; width: 100%; text-align: left; border: none; background: transparent; padding: 10px 12px; font: inherit; font-size: 14px; border-radius: 5px; cursor: pointer; color: #1F2937; }
.cxt-menu button:hover { background: #F3F4F6; }
.cxt-menu button.danger { color: #B91C1C; }

/* ---- modals ---- */
.cxt-modal-bd { position: fixed; inset: 0; z-index: 5000; background: rgba(17,24,39,.55); display: flex; align-items: center; justify-content: center; padding: 14px; }
.cxt-modal { background: #fff; border-radius: 10px; width: 100%; max-width: 460px; max-height: 90vh; max-height: 90dvh; overflow: auto; padding: 18px 20px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.cxt-modal.form { max-width: 560px; }
.cxt-modal h2 { margin: 0 0 10px; font-size: 17px; color: #111827; }
.cxt-modal-msg { margin: 0 0 14px; color: #374151; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.cxt-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.cxt-field { margin: 0 0 12px; }
.cxt-field > label { display: block; font-size: 12px; font-weight: 600; color: #4B5563; margin: 0 0 4px; }
.cxt-field > label .req { font-weight: 400; color: #B45309; font-size: 11px; }
.cxt-field input[type=text], .cxt-field input[type=date], .cxt-field input[type=number], .cxt-field textarea {
    display: block; width: 100%; padding: 8px 10px; font: inherit; border: 1px solid #C9CBD1; border-radius: 6px; background: #fff; color: #111827;
}
.cxt-field textarea { resize: vertical; min-height: 84px; }
.cxt-help { font-size: 12px; color: #6B7280; margin-top: 3px; }
.cxt-warn { background: #FEF2F2; border: 1px solid #FCA5A5; color: #B91C1C; border-radius: 6px; padding: 8px 10px; font-size: 13px; margin-top: 8px; }
.cxt-toast { position: fixed; left: 50%; top: 70px; transform: translateX(-50%); z-index: 6000; background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; max-width: 90vw; }

/* ---- two panes (Setup) ---- */
.cxt-split { display: flex; gap: 14px; align-items: flex-start; }
.cxt-split > .list { flex: 0 0 320px; min-width: 0; }
.cxt-split > .detail { flex: 1 1 auto; min-width: 0; }
.cxt-card { background: #fff; border: 1px solid #DCDDE1; border-radius: 8px; padding: 14px; margin: 0 0 12px; }
.cxt-card h2 { margin: 0 0 10px; font-size: 16px; }
.cxt-card h3 { margin: 16px 0 8px; font-size: 14px; color: #374151; }
.cxt-pick { display: flex; align-items: center; gap: 8px; width: 100%; border: none; border-bottom: 1px solid #EEF0F3; background: #fff; text-align: left; padding: 10px 12px; font: inherit; cursor: pointer; color: #111827; }
.cxt-pick:last-child { border-bottom: none; }
.cxt-pick.sel { background: #EEF2FF; }
.cxt-pick .nm { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.cxt-pick .ct { color: #6B7280; font-size: 12.5px; flex: 0 0 auto; }
.cxt-grid2 { display: flex; flex-wrap: wrap; gap: 0 14px; }
.cxt-grid2 > .cxt-field { flex: 1 1 220px; }
.cxt-preview { border: 1px solid #E5E7EB; border-radius: 6px; padding: 10px 12px; background: #FAFAFB; min-height: 84px; max-height: 360px; overflow: auto; }
.cxt-code { display: block; font-family: Consolas, monospace; font-size: 13px; background: #F3F4F6; border: 1px solid #E5E7EB; border-radius: 5px; padding: 6px 8px; margin-top: 5px; overflow-wrap: anywhere; user-select: all; }
.cxt-tablewrap { overflow-x: auto; }
table.cxt-table { border-collapse: collapse; width: 100%; font-size: 13px; }
table.cxt-table th, table.cxt-table td { border-bottom: 1px solid #EEF0F3; padding: 7px 8px; text-align: left; vertical-align: middle; }
table.cxt-table th { font-size: 11.5px; color: #6B7280; text-transform: uppercase; letter-spacing: .03em; }
table.cxt-table td.n, table.cxt-table th.n { text-align: right; white-space: nowrap; }
table.cxt-table td.acts { white-space: nowrap; text-align: right; }

.cxt-more { display: block; margin: 12px auto; }

@media (max-width: 760px) {
    .cxt-body { padding: 10px; }
    .cxt-bar { padding: 8px 10px; }
    .cxt-bar .fld { min-width: 0; flex: 1 1 45%; }
    .cxt-split { flex-direction: column; }
    .cxt-split > .list { flex: 0 0 auto; width: 100%; }
    .cxt-split > .detail { width: 100%; }
    .cxt-row { flex-wrap: wrap; }
    .cxt-row .acts { width: 100%; justify-content: flex-start; padding-left: 0; }
    .cxt-row.action .acts { width: auto; }
}

/* ---- margin notes (codex-comments.js) ---- */
.cxc { font-size: 14px; }
.cxc-head { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; }
.cxc-head h3 { margin: 0; font-size: 15px; flex: 1 1 auto; }
.cxc-note { background: #FFFBEB; border: 1px solid #FDE68A; border-left: 4px solid #F59E0B; border-radius: 6px; padding: 8px 10px; margin: 0 0 8px; }
.cxc-note.resolved { background: #F0FDF4; border-color: #BBF7D0; border-left-color: #15803D; }
.cxc-note.resolved .cxc-body { color: #4B5563; }
.cxc-meta { font-size: 12px; color: #6B7280; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; margin-bottom: 4px; }
.cxc-meta .tick { color: #15803D; font-weight: 700; }
.cxc-anchor { color: #1D4ED8; text-decoration: none; }
.cxc-body { color: #1F2937; line-height: 1.45; overflow-wrap: anywhere; }
.cxc-acts { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.cxc-add textarea { display: block; width: 100%; padding: 8px 10px; font: inherit; border: 1px solid #C9CBD1; border-radius: 6px; min-height: 70px; resize: vertical; background: #fff; color: #111827; }
.cxc-add .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-top: 8px; }
.cxc-add .row .fld { flex: 1 1 200px; min-width: 0; }
.cxc-add .row label { display: block; font-size: 12px; font-weight: 600; color: #4B5563; margin: 0 0 4px; }
.cxc-toggle { border: none; background: transparent; color: #15803D; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; padding: 6px 0; }
.cxc-empty { color: #6B7280; font-size: 13px; margin: 0 0 8px; }
