:root{
    --bg:#2f3947;
    --panel:#2f3947;
    --panel-dark:#202833;
    --panel-header:#394555;
    --line:#a7adb6;
    --text:#f0f3f7;
    --muted:#cdd4dd;
    --accent:#79a5ff;
    --button-bg:#f2f2f2;
    --button-text:#1f1f1f;
    --danger:#c95a5a;
}
html[data-theme="light"]{
    --bg:#ebe7df;
    --panel:#f5f2eb;
    --panel-dark:#ffffff;
    --panel-header:#d7d1c6;
    --line:#8d8a84;
    --text:#1d2126;
    --muted:#525963;
    --accent:#4c70d4;
    --button-bg:#ffffff;
    --button-text:#1f1f1f;
    --danger:#b54545;
}
*{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}
.page-shell{padding:12px}
.auth-shell{min-height:100vh;display:grid;place-items:center;padding:18px}
.app-top{
    display:flex;
    justify-content:space-between;
    align-items:center;
    padding:10px 14px;
    background:#7c4eb0;
    color:#fff;
}
.brand{font-weight:700;font-size:20px}
.top-actions{display:flex;align-items:center;gap:10px;flex-wrap:wrap}
.user-label{padding:8px 10px;background:rgba(255,255,255,.14);border:1px solid rgba(255,255,255,.25)}
.panel{
    border:1px solid var(--line);
    background:var(--panel);
    padding:10px;
}
.panel-title{
    color:var(--accent);
    font-weight:700;
    margin:-10px -10px 10px -10px;
    padding:6px 8px;
    background:var(--panel-header);
    border-bottom:1px solid var(--line);
}
.howto-content h1{
    margin:4px 0 10px;
    color:var(--accent);
    font-size:26px;
}
.howto-content ol{
    margin:0;
    padding-left:20px;
    line-height:1.55;
}
.workspace-grid{
    display:grid;
    grid-template-columns:355px 1fr;
    gap:10px;
    margin-top:10px;
}
.left-panel,.right-panel{min-width:0}
.details-head{
    display:flex;
    justify-content:space-between;
    gap:14px;
    align-items:flex-start;
    flex-wrap:wrap;
    margin-bottom:10px;
}
.details-head h2{
    margin:0;
    font-size:26px;
}
.content-grid{
    display:grid;
    grid-template-columns:460px 1fr;
    gap:14px;
    align-items:start;
}
.field-label{
    color:var(--accent);
    font-weight:700;
    margin-bottom:6px;
}
.section-block,.field-block{margin-bottom:14px}
.button-row{
    display:flex;
    gap:10px;
    flex-wrap:wrap;
}
.top-gap-sm{margin-top:8px}
.btn{
    display:inline-flex;
    align-items:center;
    justify-content:center;
    padding:10px 16px;
    background:var(--button-bg);
    color:var(--button-text);
    border:1px solid var(--line);
    cursor:pointer;
    text-align:center;
}
.btn.danger{
    background:var(--danger);
    color:#fff;
    border-color:var(--danger);
}
input,textarea{
    width:100%;
    padding:10px 12px;
    border:1px solid var(--line);
    background:var(--panel-dark);
    color:var(--text);
    font:inherit;
}
textarea{resize:vertical}
.auth-card{
    width:min(460px,100%);
    border:1px solid var(--line);
    background:var(--panel);
    padding:20px;
}
.stack{
    display:grid;
    gap:12px;
}
label{
    display:grid;
    gap:6px;
    font-weight:700;
}
.flash-wrap{
    display:grid;
    gap:8px;
    margin-bottom:10px;
}
.flash{
    padding:10px 12px;
    border:1px solid var(--line);
    background:var(--panel-dark);
}
.flash.danger{border-color:var(--danger)}
.flash.success{border-color:#6cb07c}
.territory-list{
    display:grid;
    gap:8px;
    max-height:460px;
    overflow:auto;
}
.territory-item{
    display:block;
    padding:12px 10px;
    border:1px solid var(--line);
    background:var(--button-bg);
    color:var(--button-text);
}
.territory-item.selected{
    outline:2px dotted var(--line);
    outline-offset:-4px;
}
.meta-row{
    display:grid;
    grid-template-columns:110px 1fr;
    gap:10px;
    align-items:end;
    margin-bottom:14px;
}
.meta-box{
    padding:10px 12px;
    border:1px solid var(--line);
    background:var(--panel-dark);
    min-height:46px;
}
.field-inline{
    display:grid;
    gap:6px;
}
.inline-field{
    display:grid;
    grid-template-columns:1fr auto;
    gap:10px;
}
.log-head,.log-row{
    display:grid;
    grid-template-columns:80px 150px 1fr;
}
.log-head{
    background:var(--button-bg);
    color:var(--accent);
    font-weight:700;
    border:1px solid var(--line);
    border-bottom:none;
}
.log-head > div,.log-row > div{
    padding:10px 8px;
    border-right:1px solid var(--line);
}
.log-head > div{
    padding:0;
}
.log-sort-link{
    display:flex;
    align-items:center;
    width:100%;
    min-height:100%;
    padding:10px 8px;
    color:inherit;
}
.log-head > div:last-child,.log-row > div:last-child{border-right:none}
.log-body{
    border:1px solid var(--line);
    background:var(--panel-dark);
    max-height:280px;
    overflow:auto;
}
.log-row{
    border-top:1px solid var(--line);
    color:var(--text);
}
.log-row:first-child{border-top:none}
.log-row.selected{
    background:#667792;
}
.snapshot-box{
    border:1px solid var(--line);
    background:var(--panel-dark);
    min-height:320px;
    padding:12px;
}
.archive-list{
    display:grid;
    gap:10px;
}
.archive-item{
    border:1px solid var(--line);
    background:var(--panel-dark);
    padding:10px;
}
.archive-actions{
    display:flex;
    gap:10px;
    margin-top:10px;
}
.empty-box{
    padding:12px;
    border:1px solid var(--line);
    background:var(--panel-dark);
    color:var(--muted);
}
.muted{color:var(--muted)}
.pre{white-space:pre-wrap}
@media (max-width: 1200px){
    .workspace-grid{grid-template-columns:1fr}
    .content-grid{grid-template-columns:1fr}
}


.compact-under-todo{
    margin-top:-2px;
}


.task-add-row{
    display:grid;
    grid-template-columns:1fr auto;
    gap:10px;
    margin-bottom:10px;
}
.todo-list-box{
    display:grid;
    gap:8px;
}
.todo-item{
    display:grid;
    grid-template-columns:1fr auto;
    gap:10px;
    align-items:start;
    padding:10px;
    border:1px solid var(--line);
    background:var(--panel-dark);
}
.todo-actions{
    display:flex;
    gap:6px;
    flex-wrap:wrap;
    justify-content:flex-end;
}
.todo-text{
    white-space:pre-wrap;
    line-height:1.35;
}
.todo-item.done .todo-text{
    color:#70c070;
    text-decoration:line-through;
}
.done-item .pre{
    color:#70c070;
    text-decoration:line-through;
}
.todo-edit-row{
    display:grid;
    grid-template-columns:1fr auto auto;
    gap:8px;
    width:100%;
}
.mini-btn{
    padding:6px 10px;
    border:1px solid var(--line);
    background:var(--button-bg);
    color:var(--button-text);
    cursor:pointer;
    text-decoration:none;
    display:inline-flex;
    align-items:center;
    justify-content:center;
    text-align:center;
}
.mini-link{
    line-height:1.2;
}


.top-actions{display:flex;align-items:center;gap:10px;flex-wrap:wrap}


.utility-bar{
    display:flex;
    gap:12px;
    flex-wrap:wrap;
    align-items:center;
    padding:10px 14px;
    border-bottom:1px solid var(--line);
    background:var(--panel-header);
}
.utility-btn{
    min-width:170px;
    text-align:center;
    font-weight:700;
}


.forced-topbar{
    display:flex;
    justify-content:space-between;
    align-items:center;
    gap:12px;
    flex-wrap:wrap;
    margin-bottom:12px;
    padding:12px 14px;
    border:1px solid var(--line);
    background:var(--panel-header);
}
.forced-topbar-left,
.forced-topbar-right{
    display:flex;
    gap:10px;
    flex-wrap:wrap;
    align-items:center;
}
.forced-user{
    padding:8px 12px;
    border:1px solid var(--line);
    background:var(--panel-dark);
    color:var(--text);
    font-weight:700;
}


.utility-bar,
.forced-topbar{
    display:none !important;
}


.top-actions,
.utility-bar,
.forced-topbar,
.workspace-toolbar{
    display:none !important;
}
.forced-purple-bar{
    display:flex;
    justify-content:space-between;
    align-items:center;
    gap:12px;
    flex-wrap:wrap;
    margin-bottom:12px;
    padding:12px 18px;
    background:#7c4eb0;
    color:#fff;
    border:1px solid rgba(255,255,255,.15);
}
.forced-purple-left{
    display:flex;
    align-items:center;
    gap:10px;
}
.forced-purple-title{
    font-size:20px;
    font-weight:700;
    color:#fff;
}
.forced-purple-right{
    display:flex;
    align-items:center;
    gap:12px;
    flex-wrap:wrap;
}
.forced-purple-user{
    padding:10px 14px;
    border:1px solid rgba(255,255,255,.25);
    background:rgba(255,255,255,.12);
    color:#fff;
    font-weight:700;
}
.inline-form{
    margin:0;
}
.hidden-bar{
    display:none !important;
}


.todo-main-row{
    display:grid;
    grid-template-columns:1fr auto;
    gap:10px;
    align-items:start;
}
.todo-actions{
    display:flex;
    gap:6px;
    flex-wrap:wrap;
    justify-content:flex-end;
}
.inline-form{
    margin:0;
}



.task-add-row{
    display:grid;
    grid-template-columns:minmax(0,1fr) 140px auto;
    gap:10px;
    margin-bottom:10px;
}
.todo-main-row{
    display:grid;
    grid-template-columns:minmax(0,1fr) auto;
    gap:10px;
    align-items:start;
}
.todo-actions{
    display:flex;
    gap:6px;
    flex-wrap:wrap;
    justify-content:flex-end;
    align-items:center;
}
.priority-pill{
    display:inline-block;
    padding:6px 10px;
    border:1px solid var(--line);
    background:var(--button-bg);
    color:var(--button-text);
    font-size:12px;
    font-weight:700;
}
.priority-1{border-color:#b54545}
.priority-2{border-color:#c08a2d}
.priority-3{border-color:#5a6f9e}
.mini-select{
    padding:6px 8px;
    border:1px solid var(--line);
    background:var(--button-bg);
    color:var(--button-text);
    font:inherit;
}
.print-panel{
    margin-bottom:10px;
}
.print-options-form{
    display:flex;
    gap:10px;
    flex-wrap:wrap;
    align-items:center;
}
.checkbox-inline{
    display:flex;
    gap:6px;
    align-items:center;
    font-weight:700;
}
.archive-subinfo{
    margin-top:8px;
    color:var(--muted);
}
.print-item{
    padding:10px 0;
    border-bottom:1px solid var(--line);
}
.print-task{
    font-weight:700;
    margin-bottom:4px;
}
.print-meta{
    color:var(--muted);
}
.howto-row{
    display:flex;
    gap:20px;
    align-items:flex-start;
}

.howto-content{
    flex:1;
}


select{
    width:100%;
    padding:10px 12px;
    border:1px solid var(--line);
    background:var(--panel-dark);
    color:var(--text);
    font:inherit;
}
button,input,select,textarea{
    font-size:16px;
}
img{max-width:100%;height:auto}
.auth-card h1,
.panel h1,
.panel h2,
.panel h3{
    overflow-wrap:anywhere;
}
.howto-row{
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:16px;
    align-items:start;
}
.editor-column,
.right-column,
.todo-main-row,
.print-panel,
.print-options-form{
    min-width:0;
}
.print-options-form{
    display:flex;
    flex-wrap:wrap;
    gap:10px;
    align-items:center;
}
.checkbox-inline{
    display:inline-flex;
    align-items:center;
    gap:6px;
    font-weight:700;
}
.checkbox-inline input{
    width:auto;
    margin:0;
}
.log-head,
.log-body{
    min-width:0;
}
.log-head > div,
.log-row > div,
.todo-text,
.archive-subinfo,
.snapshot-box,
.meta-box,
.territory-item,
.panel-title,
.empty-box{
    overflow-wrap:anywhere;
}
.mini-select{
    min-width:120px;
}
.mobile-toolbar-toggle{
    display:none;
    padding:10px 14px;
    min-width:0;
}
.mobile-toolbar-toggle .toggle-label-close{
    display:none;
}
.mobile-toolbar-toggle.is-open .toggle-label-open{
    display:none;
}
.mobile-toolbar-toggle.is-open .toggle-label-close{
    display:inline;
}
@media (max-width: 980px){
    .page-shell{padding:10px}
    .forced-purple-bar{
        padding:12px;
        align-items:stretch;
    }
    .forced-purple-left,
    .forced-purple-right{
        width:100%;
    }
    .forced-purple-right{
        gap:10px;
    }
    .details-head h2,
    .howto-content h1{
        font-size:22px;
    }
    .log-head,.log-row{
        grid-template-columns:72px 124px minmax(160px,1fr);
    }
}
@media (max-width: 760px){
    .auth-shell{padding:12px}
    .auth-card{padding:16px}
    .panel{padding:8px}
    .panel-title{margin:-8px -8px 10px -8px}
    .workspace-grid,
    .content-grid,
    .howto-row,
    .meta-row,
    .task-add-row,
    .todo-item,
    .todo-edit-row,
    .inline-field{
        grid-template-columns:1fr;
    }
    .forced-purple-bar{
        gap:10px;
    }
    .forced-purple-title{
        font-size:18px;
    }
    .mobile-toolbar-toggle{
        display:inline-flex;
        align-items:center;
        justify-content:center;
        width:100%;
    }
    .forced-purple-right{
        display:none;
        flex-direction:column;
        align-items:stretch;
    }
    .forced-purple-right.mobile-open{
        display:flex;
    }
    .forced-purple-right .btn,
    .forced-purple-right .inline-form,
    .forced-purple-right .forced-purple-user,
    .details-head .button-row > *,
    .archive-actions > *,
    .todo-actions > *,
    .print-options-form > *{
        width:100%;
    }
    .forced-purple-right .inline-form .btn,
    .details-head .button-row .btn,
    .archive-actions .btn,
    .archive-actions .mini-btn,
    .todo-actions .mini-btn,
    .print-options-form .btn{
        width:100%;
    }
    .forced-purple-user{
        text-align:center;
    }
    .button-row,
    .archive-actions,
    .todo-actions,
    .print-options-form{
        flex-direction:column;
        align-items:stretch;
    }
    .details-head{
        gap:10px;
    }
    .details-head .button-row,
    .archive-actions,
    .todo-actions{
        width:100%;
    }
    .log-head{
        display:none;
    }
    .log-body{
        display:grid;
        gap:8px;
        border:none;
        background:transparent;
        max-height:none;
        overflow:visible;
    }
    .log-row{
        display:grid;
        grid-template-columns:1fr;
        gap:4px;
        border:1px solid var(--line);
        background:var(--panel-dark);
        padding:8px;
    }
    .log-row > div{
        border:none;
        padding:0;
    }
    .log-row > div:nth-child(1)::before{content:"#: ";font-weight:700;color:var(--accent)}
    .log-row > div:nth-child(2)::before{content:"Date: ";font-weight:700;color:var(--accent)}
    .log-row > div:nth-child(3)::before{content:"Sub Territory: ";font-weight:700;color:var(--accent)}
    .snapshot-box{
        min-height:0;
    }
    .territory-list{
        max-height:none;
    }
    .mini-select{
        min-width:0;
        width:100%;
    }
}


.sticky-return-bar{
    position:sticky;
    top:12px;
    z-index:50;
    margin-bottom:10px;
    display:flex;
    justify-content:flex-start;
}
.archive-subinfo{
    margin-top:8px;
    color:var(--muted);
}

.sticky-return-actions{display:flex;gap:10px;flex-wrap:wrap;align-items:center}

.page-print-form{flex:1 1 auto}

.sr-only{
    position:absolute;
    width:1px;
    height:1px;
    padding:0;
    margin:-1px;
    overflow:hidden;
    clip:rect(0,0,0,0);
    white-space:nowrap;
    border:0;
}


.btn, .mini-btn, .territory-item, .log-row, .log-sort-link {
    cursor:pointer;
    touch-action:manipulation;
}

button.btn, a.btn, button.mini-btn, a.mini-btn {
    min-height:42px;
}

.todo-item, .archive-item {
    transition:background-color .12s ease, opacity .12s ease;
}


.all-todos-toolbar{
    display:flex;
    gap:16px;
    align-items:flex-end;
    justify-content:space-between;
    flex-wrap:wrap;
    margin-bottom:14px;
}
.all-todos-sort-form{
    display:inline-flex;
    align-items:center;
    gap:10px;
    flex:0 0 auto;
}
select.all-todos-sort-select{
    width:auto !important;
    min-width:160px;
    max-width:100%;
    font-size:18px;
    padding:12px 40px 12px 14px;
}
.all-todo-group{
    margin-top:16px;
}
.all-todo-group-title{
    font-weight:700;
    margin:0 0 8px;
    color:var(--text);
}
.all-todos-list{
    gap:10px;
}
.all-todo-row{
    user-select:text;
}
.all-todo-row-main{
    display:grid;
    grid-template-columns:auto 1fr auto;
    gap:12px;
    align-items:start;
}
.all-todo-number,
.all-todo-number-input{
    height:40px;
    border-radius:999px;
    display:flex;
    align-items:center;
    justify-content:center;
    font-weight:700;
    text-align:center;
    border:1px solid var(--line);
}
.all-todo-number{
    min-width:62px;
    width:62px;
    background:rgba(255,255,255,0.08);
}
.all-todo-number-input{
    appearance:textfield;
    -moz-appearance:textfield;
    width:4.25ch;
    min-width:4.25ch;
    padding:0 6px;
    background:#ffffff;
    color:#111111;
    border-color:#b8b8b8;
}
.all-todo-number-input::-webkit-outer-spin-button,
.all-todo-number-input::-webkit-inner-spin-button{
    -webkit-appearance:none;
    margin:0;
}
.all-todo-number-wrap,
.all-todo-number-form{
    display:flex;
    align-items:center;
    justify-content:center;
}
.all-todo-body{
    min-width:0;
}
.all-todo-controls{
    display:flex;
    align-items:center;
    justify-content:flex-end;
    gap:8px;
    flex-wrap:wrap;
}
.all-todo-edit-body{
    grid-column:2 / -1;
}
.all-todo-edit-row{
    margin-bottom:6px;
}
.all-todo-priority-form,
.all-todo-priority-form .all-todo-priority-select{
    width:auto;
}
@media (max-width: 760px){
    .all-todo-row-main{
        grid-template-columns:auto 1fr;
    }
    .all-todo-controls{
        grid-column:1 / -1;
        justify-content:flex-start;
        padding-left:74px;
    }
    select.all-todos-sort-select{
        min-width:150px;
    }
}


/* Baseline mobile cleanup + visible all-to-dos number field tweak */
.archive-list-box{
    display:grid;
    gap:10px;
}
.recent-active-list{
    display:grid;
    gap:10px;
}
.recent-active-row{
    display:grid;
    grid-template-columns:minmax(0, 1.35fr) minmax(180px, 1fr);
    gap:12px;
    align-items:center;
    padding:12px 14px;
    border:1px solid var(--line);
    background:var(--panel-dark);
}
.recent-active-user,
.recent-active-time{
    min-width:0;
    overflow-wrap:anywhere;
}
.recent-active-time{
    text-align:right;
    color:var(--muted);
}

.all-todo-number-input{
    width:3.25rem !important;
    min-width:3.25rem;
    max-width:3.25rem;
    height:2.3rem;
    padding:0 4px;
    border-radius:10px;
    background:#ffffff !important;
    color:#111111 !important;
    border:1px solid #b8b8b8;
    box-shadow:inset 0 0 0 1px rgba(255,255,255,0.7);
}

@media (max-width: 980px){
    .sticky-return-bar{
        position:static;
        top:auto;
    }
    .sticky-return-actions{
        width:100%;
        align-items:stretch;
    }
    .page-print-form{
        width:100%;
    }
    .recent-active-row{
        grid-template-columns:1fr;
        gap:6px;
    }
    .recent-active-time{
        text-align:left;
    }
}

@media (max-width: 760px){
    .all-todos-toolbar{
        align-items:stretch;
    }
    .all-todos-sort-form{
        width:100%;
        flex-wrap:wrap;
        align-items:center;
        gap:8px;
    }
    select.all-todos-sort-select{
        width:auto !important;
        min-width:0;
        max-width:11rem;
        font-size:17px;
        padding:10px 36px 10px 12px;
    }
    .sticky-return-actions,
    .print-options-form,
    .button-row{
        width:100%;
    }
    .sticky-return-actions > *,
    .print-options-form > *,
    .button-row > *,
    .button-row .inline-form{
        width:100%;
    }
    .log-row .button-row{
        align-items:stretch !important;
    }
    .log-row .button-row > div:first-child,
    .log-row .button-row > div:last-child{
        width:100%;
    }
    .meta-box,
    .panel,
    .archive-item,
    .empty-box,
    .recent-active-row{
        min-width:0;
    }
    .all-todo-row-main{
        gap:10px;
    }
    .all-todo-controls{
        padding-left:0;
    }
}



/* Global search, autosave, and journal additions */
.top-search-form{
    display:flex;
    align-items:center;
    gap:6px;
    min-width:min(360px, 100%);
}
.top-search-form input[type="search"]{
    min-width:150px;
    max-width:220px;
    padding:9px 10px;
    border-radius:999px;
    border:1px solid rgba(255,255,255,0.55);
    background:rgba(255,255,255,0.92);
    color:#111;
}
.global-search-page-form{
    display:flex;
    gap:10px;
    align-items:center;
    margin-bottom:16px;
}
.global-search-page-form input[type="search"]{
    flex:1;
    min-width:0;
    font-size:18px;
    padding:12px 14px;
    border-radius:12px;
}
.search-count{
    margin:8px 0 14px;
    color:var(--muted);
}
.search-results{
    display:grid;
    gap:10px;
}
.search-result-card{
    display:block;
    text-decoration:none;
    color:var(--text);
    border:1px solid var(--line);
    border-radius:14px;
    background:var(--panel-dark);
    padding:14px;
}
.search-result-card:hover{
    border-color:var(--accent);
}
.search-result-type{
    color:var(--muted);
    font-size:13px;
    text-transform:uppercase;
    letter-spacing:.05em;
}
.search-result-title{
    font-weight:800;
    font-size:18px;
    margin:4px 0;
}
.search-result-snippet{
    color:var(--text);
    overflow-wrap:anywhere;
}
.autosave-status{
    display:inline-flex;
    align-items:center;
    justify-content:center;
    min-height:34px;
    padding:7px 12px;
    border-radius:999px;
    border:1px solid var(--line);
    background:rgba(255,255,255,0.09);
    color:var(--muted);
    font-size:14px;
}
.global-autosave-status{
    position:fixed;
    right:18px;
    bottom:18px;
    z-index:9999;
    opacity:0;
    pointer-events:none;
    transform:translateY(6px);
    transition:opacity .18s ease, transform .18s ease;
}
.autosave-status.is-visible,
.global-autosave-status.is-visible{
    opacity:1;
    transform:translateY(0);
}
.autosave-status.is-saving{
    color:var(--text);
}
.autosave-status.is-error{
    color:#ffb4b4;
    border-color:#d34b4b;
}
.journal-choice-grid,
.journal-choice-stack{
    display:flex;
    flex-direction:column;
    gap:18px;
}
.journal-choice-card{
    border:1px solid var(--line);
    border-radius:16px;
    background:var(--panel-dark);
    padding:16px;
    width:100%;
}
.journal-choice-card h2{
    margin-top:0;
}
.journal-list{
    display:flex;
    flex-direction:column;
    gap:10px;
    width:100%;
}
.journal-list-item{
    display:flex;
    flex-direction:column;
    gap:4px;
    width:100%;
    padding:12px;
    border:1px solid var(--line);
    border-radius:12px;
    color:var(--text);
    text-decoration:none;
    background:rgba(255,255,255,0.05);
}
.journal-list-item span{
    color:var(--muted);
    font-size:14px;
}
.journal-title-row{
    display:flex;
    align-items:flex-end;
    gap:12px;
    margin-bottom:12px;
}
.journal-title-label{
    flex:1;
    display:grid;
    gap:6px;
    font-weight:700;
}
.rich-toolbar{
    display:flex;
    gap:8px;
    flex-wrap:wrap;
    padding:10px;
    border:1px solid var(--line);
    border-radius:14px 14px 0 0;
    background:rgba(0,0,0,0.16);
}
.rich-toolbar button{
    border:1px solid var(--line);
    background:rgba(255,255,255,0.10);
    color:var(--text);
    border-radius:10px;
    padding:8px 10px;
    cursor:pointer;
}
.rich-toolbar button:hover{
    background:rgba(255,255,255,0.18);
}
.journal-body-label{
    display:block;
    font-weight:800;
    margin:12px 0 6px;
    color:var(--text);
}
.journal-editor{
    display:block;
    width:100%;
    min-height:620px;
    height:62vh;
    max-height:78vh;
    border:2px solid var(--accent);
    border-radius:14px;
    background:#202833;
    color:#f0f3f7;
    padding:20px;
    box-shadow:inset 0 0 0 1px rgba(255,255,255,0.06);
    overflow:auto;
    line-height:1.55;
    cursor:text;
    white-space:normal;
    overflow-wrap:anywhere;
}
.journal-editor:empty::before{
    content:attr(data-placeholder);
    color:var(--muted);
    pointer-events:none;
}
.journal-editor:focus{
    outline:2px solid var(--accent);
    outline-offset:2px;
}
.journal-editor ul,
.journal-editor ol{
    padding-left:28px;
}
.journal-editor blockquote{
    margin-left:0;
    padding-left:14px;
    border-left:4px solid var(--line);
    color:var(--muted);
}

@media (max-width: 900px){
    .top-search-form{
        width:100%;
    }
    .top-search-form input[type="search"]{
        flex:1;
        max-width:none;
    }
    .journal-choice-grid{
        grid-template-columns:1fr;
    }
    .journal-title-row,
    .global-search-page-form{
        flex-direction:column;
        align-items:stretch;
    }
}

/* Always-visible workspace access for search and journal */
.workspace-tools-panel{
    margin-bottom:12px;
}
.workspace-tools-row{
    display:flex;
    align-items:center;
    gap:12px;
    flex-wrap:wrap;
}
.workspace-search-form{
    display:flex;
    align-items:center;
    gap:10px;
    flex:1 1 420px;
    min-width:260px;
}
.workspace-search-form input[type="search"]{
    flex:1;
    min-width:180px;
    background:var(--panel-dark);
    color:var(--text);
}
.journal-main-button{
    font-weight:800;
    min-width:170px;
}
.forced-purple-right .top-search-form{
    flex:0 1 360px;
}
.forced-purple-right .top-search-form input[type="search"]{
    width:auto;
}
@media (max-width: 760px){
    .workspace-tools-row{
        flex-direction:column;
        align-items:stretch;
        width:100%;
        min-width:0;
    }
    .workspace-search-form{
        flex-direction:row;
        align-items:center;
        width:100%;
        min-width:0;
    }
    .workspace-search-form input[type="search"]{
        flex:1 1 auto;
        min-width:0;
        width:auto;
    }
    .workspace-search-form .btn{
        flex:0 0 auto;
        width:auto;
        white-space:nowrap;
    }
    .journal-main-button{
        width:100%;
    }
}

/* pof1.13: keep search controls horizontal and journal editor visibly writable */
.top-search-form,
.workspace-search-form,
.global-search-page-form{
    flex-direction:row;
}
.top-search-form input[type="search"],
.workspace-search-form input[type="search"],
.global-search-page-form input[type="search"]{
    min-width:0;
}
.top-search-form .btn,
.workspace-search-form .btn,
.global-search-page-form .btn{
    flex:0 0 auto;
    white-space:nowrap;
}

/* pof1.14: search submits with Enter, no separate Search button needed */
.enter-search-form{
    display:flex;
    align-items:center;
    min-width:0;
}
.enter-search-form input[type="search"]{
    width:100%;
}
.forced-purple-right .top-search-form{
    flex:0 1 230px;
    min-width:160px;
}
.forced-purple-right .top-search-form input[type="search"]{
    max-width:none;
}
.workspace-search-form{
    max-width:620px;
}
.workspace-search-form input[type="search"]{
    min-height:42px;
}
.journal-editor-panel .journal-editor{
    min-height:620px;
    height:62vh;
    background:#202833;
    color:#f0f3f7;
    border-color:var(--accent);
}
@media (max-width: 760px){
    .forced-purple-right .top-search-form{
        flex:1 1 100%;
        width:100%;
    }
    .journal-editor-panel .journal-editor{
        min-height:520px;
        height:60vh;
    }
}


/* pof1.15: force Enter-only header search, visible journal editor, and ordered journal controls */
.forced-purple-right .top-search-form{
    display:inline-flex !important;
    flex-direction:row !important;
    align-items:center !important;
    flex-wrap:nowrap !important;
    margin:0 !important;
    width:clamp(180px, 18vw, 320px) !important;
    min-width:180px !important;
    max-width:320px !important;
}
.forced-purple-right .top-search-form input[type="search"]{
    display:block !important;
    width:100% !important;
    min-width:0 !important;
    max-width:none !important;
}
.forced-purple-right .top-search-form button,
.forced-purple-right .top-search-form .btn,
.workspace-tools-row .workspace-search-form button,
.workspace-tools-row .workspace-search-form .btn{
    display:none !important;
}
.journal-editor-panel .journal-editor{
    display:block !important;
    min-height:640px !important;
    height:64vh !important;
    background:var(--panel-dark) !important;
    color:var(--text) !important;
    border:2px solid var(--accent) !important;
}
.journal-list{
    display:flex !important;
    flex-direction:column !important;
    gap:10px !important;
}
.journal-list-item{
    display:flex !important;
    flex-direction:column !important;
    width:100% !important;
}
@media (max-width:760px){
    .forced-purple-right .top-search-form{
        width:100% !important;
        max-width:none !important;
    }
}


/* pof1.16: keep header controls on one desktop row, move Export CSV to the end, and shrink territory list buttons to their labels */
@media (min-width: 761px){
    .forced-purple-bar{
        flex-wrap:nowrap !important;
        align-items:center !important;
        gap:12px !important;
    }
    .forced-purple-left{
        flex:0 0 auto !important;
        min-width:max-content !important;
    }
    .forced-purple-right{
        flex:1 1 auto !important;
        min-width:0 !important;
        display:flex !important;
        flex-direction:row !important;
        align-items:center !important;
        justify-content:flex-end !important;
        flex-wrap:nowrap !important;
        gap:8px !important;
    }
    .forced-purple-right .btn,
    .forced-purple-right .forced-purple-user{
        flex:0 0 auto !important;
        width:auto !important;
        white-space:nowrap !important;
        padding:9px 12px !important;
        min-height:38px !important;
    }
    .forced-purple-right .top-search-form{
        flex:0 1 210px !important;
        width:clamp(140px, 16vw, 230px) !important;
        min-width:140px !important;
        max-width:230px !important;
    }
    .forced-purple-right .top-search-form input[type="search"]{
        min-height:38px !important;
        height:38px !important;
        padding:8px 10px !important;
    }
    .details-head .button-row{
        flex-wrap:nowrap !important;
        justify-content:flex-end !important;
        align-items:center !important;
        overflow-x:auto;
        max-width:100%;
    }
    .details-head .button-row > *,
    .details-head .button-row > form{
        flex:0 0 auto !important;
        width:auto !important;
    }
    .details-head .button-row .btn{
        width:auto !important;
        white-space:nowrap !important;
        padding-left:14px;
        padding-right:14px;
    }
}

/* Territory list buttons should fit the text instead of stretching across the panel. */
.territory-list{
    display:flex !important;
    flex-direction:column !important;
    align-items:flex-start !important;
    gap:8px !important;
}
.territory-item{
    display:inline-flex !important;
    align-items:center !important;
    width:auto !important;
    max-width:100% !important;
    white-space:normal !important;
    overflow-wrap:anywhere;
}

/* Keep header search Enter-only even if an older cached template still contains a Search button. */
.forced-purple-right .top-search-form button,
.forced-purple-right .top-search-form .btn{
    display:none !important;
}

@media (max-width: 760px){
    .forced-purple-bar{
        flex-wrap:wrap !important;
    }
    .forced-purple-left{
        width:100% !important;
        min-width:0 !important;
    }
    .forced-purple-right{
        display:none !important;
        flex-direction:column !important;
        align-items:stretch !important;
        width:100% !important;
        flex-wrap:nowrap !important;
    }
    .forced-purple-right.mobile-open{
        display:flex !important;
    }
    .forced-purple-right .top-search-form{
        width:100% !important;
        max-width:none !important;
        min-width:0 !important;
    }
}

/* pof1.17: remove top Search All from the purple bar, keep desktop top buttons on one row, restore full-width territory buttons, and show unsaved fields with red save buttons. */
.forced-purple-right .top-search-form{
    display:none !important;
}
@media (min-width: 761px){
    .forced-purple-bar{
        flex-wrap:nowrap !important;
        align-items:center !important;
    }
    .forced-purple-left{
        flex:1 1 auto !important;
        min-width:0 !important;
    }
    .forced-purple-right{
        flex:0 0 auto !important;
        width:auto !important;
        display:flex !important;
        flex-direction:row !important;
        align-items:center !important;
        justify-content:flex-end !important;
        flex-wrap:nowrap !important;
        gap:10px !important;
    }
    .forced-purple-right .btn,
    .forced-purple-right .forced-purple-user{
        flex:0 0 auto !important;
        width:auto !important;
        white-space:nowrap !important;
    }
}
.territory-list{
    display:grid !important;
    grid-template-columns:1fr !important;
    align-items:stretch !important;
    gap:8px !important;
    max-height:none !important;
    overflow:visible !important;
}
.territory-item{
    display:block !important;
    width:100% !important;
    max-width:none !important;
    white-space:normal !important;
}
.btn.save-dirty,
.mini-btn.save-dirty,
button.save-dirty,
input[type="submit"].save-dirty{
    background:var(--danger) !important;
    color:#fff !important;
    border-color:var(--danger) !important;
}
.journal-editor{
    background:var(--panel-dark) !important;
    color:var(--text) !important;
}

/* pof1.18: visible background autosave safety net. */
.autosave-inline-status{
    display:inline-flex;
    align-items:center;
    justify-content:center;
    min-height:30px;
    margin-left:8px;
    padding:5px 10px;
    border-radius:999px;
    border:1px solid transparent;
    font-size:13px;
    font-weight:700;
    opacity:0;
    transform:translateY(2px);
    transition:opacity .18s ease, transform .18s ease;
    vertical-align:middle;
    pointer-events:none;
}
.autosave-inline-status.is-visible{
    opacity:1;
    transform:translateY(0);
}
.autosave-inline-status.is-unsaved{
    color:#ffdede;
    border-color:rgba(220,53,69,.75);
    background:rgba(220,53,69,.18);
}
.autosave-inline-status.is-saving{
    color:var(--text);
    border-color:var(--line);
    background:rgba(255,255,255,.10);
}
.autosave-inline-status.is-saved{
    color:#d8ffd8;
    border-color:rgba(80,180,90,.75);
    background:rgba(80,180,90,.16);
}
.autosave-inline-status.is-error{
    color:#ffb4b4;
    border-color:#d34b4b;
    background:rgba(211,75,75,.22);
}
.rich-toolbar + input + .journal-body-label + .journal-editor{
    margin-top:8px;
}
