.is-hidden {
    display: none !important;
}

#cpmDocModal.cpm-modal.is-open{
    display: grid;
    grid-template-columns: 33% 33% 33%;
    align-items: stretch;
    justify-items: center;
    gap: 0;
}

#cpmDocModal .cpm-modal__dialog{
    grid-column: 2;
    width: 100%;
}

#cpmDocModal .cpm-modal__body{

}


.cpm-modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--space-lg);
    z-index: 1;
    background: rgba(0,0,0,.5);
}

.cpm-modal.is-open {
    display: flex;
}

.cpm-modal__dialog {
    background: var(--bg-primary, #fff);
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
    box-shadow: var(--shadow-lg, 0 8px 30px rgba(0,0,0,.12));
    width: min(90vw, 900px);
    overflow: hidden;
    display: grid;
    grid-template-rows: auto 1fr auto;
    padding-right: var(--space-sm);
}

.cpm-modal__header,
.cpm-modal__footer {
    padding: var(--space-md, 16px) var(--space-lg, 20px);
    background: var(--bg-secondary, #f7f7f8);
    display: flex;
}

.cpm-modal__body {
    overflow: hidden;
}

.cpm-modal__title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
}

.cpm-close-btn {
    background: transparent;
    border: 0;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    margin-left: auto;
}

.cpm-doc-preview {
    display: flex;
    align-items: center;
    justify-content: center;
}

.cpm-doc-preview canvas{
    width: 100% !important;
    height: auto !important;
    display: block;
    margin: 0 auto var(--space-md);
}

.cpm-doc-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.cpm-doc-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.cpm-doc-name, .cpm-doc-meta { pointer-events: none; }

.cpm-doc-actions-inline {
    display: inline-flex;
    align-items: center;
    gap: var(--space-lg);
}

.cpm-doc-analyze-btn {
    padding: 6px var(--space-lg);
    border-radius: 8px;
    border: 0;
    background: var(--accent-primary);
    color: var(--bg-primary);
    font-weight: 600;
    cursor: pointer;

}

.cpm-doc-delete-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    border: 0;
    background: transparent;
    cursor: pointer;
    border-radius: 6px;
    transition: transform .12s ease, background .12s ease, opacity .12s ease;
}
.cpm-doc-delete-btn svg { fill: var(--error-color, #ff6b6b); }
.cpm-doc-delete-btn:hover { background: rgba(255, 107, 107, .08); }

.cpm-doc-layout{
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    min-height: 60vh;
}

#cpmAnalysisDock{
    width: 100%;
    z-index: 1;
    pointer-events: none;
    display: none;
    grid-column: 3;
    overflow-y: auto;
    border-left: 1px solid var(--accent-primary);
    padding-left: var(--space-sm);
}


#cpmAnalysisDock .cpm-ana{
    height: 100%;
    max-height: none;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    overflow-y: auto !important;
}

@media (max-width: 900px){
    .cpm-doc-layout{ grid-template-columns: 1fr; }
}

.cpm-ana{
    background: var(--bg-secondary, #1f1f22);
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
    box-shadow: var(--shadow-sm, 0 2px 8px rgba(0,0,0,.15));
    padding: var(--space-md,12px);
    display:flex;
    flex-direction:column;
    max-height: 70vh;
    overflow: hidden;
}
.cpm-ana.is-hidden{ display:none; }

.cpm-ana__head{
    display:flex; align-items:center; gap:8px;
    padding: 4px 6px 10px;
    border-bottom:1px solid var(--text-muted);
    margin-bottom:8px;
    justify-content: space-between;
}
.cpm-ana__title{
    font-weight:700; font-size:14px; letter-spacing:.4px;
}
.cpm-ana__quota{
    margin-left:auto; opacity:.7; font-size:12px;
}

#cpmAnaSystem{
    border-bottom: 1px solid var(--text-muted);
}

.cpm-ana__section{
    margin-bottom: 10px;
    padding-bottom: var(--space-sm);
}

.cpm-ana__type{
    font-size: var(--font-size-md);
    text-transform: uppercase;
    opacity: .8;
    margin: 6px 0 8px;
    color: var(--text-primary);
}
.cpm-ana__sysbtn{
    width:100%; padding:8px 10px; border:0; border-radius:8px;
    background: var(--accent-primary); color: var(--bg-primary);
    font-weight:700; cursor:pointer; transition:opacity .15s ease;
}
.cpm-ana__sysbtn[disabled]{ opacity:.6; cursor:default; }

.cpm-ana__form{ display:flex; gap:8px; margin-top:6px; }
.cpm-ana__input{
    flex:1 1 auto; border-radius:8px; border:1px solid rgba(255,255,255,.1);
    background:var(--bg-primary); color:inherit; padding:8px 10px;
}
.cpm-ana__input[disabled]{ cursor:not-allowed; }

.cpm-ana__send{
    border:0; border-radius:8px; padding:8px 12px; font-weight:700;
    background: var(--accent-primary); color: var(--bg-primary); cursor:pointer;
}
.cpm-ana__send[disabled]{ opacity:.6; cursor: not-allowed; }

.cpm-ana__list{
    margin-top:10px; overflow:auto; padding-right:6px;
    border-top:3px dashed var(--text-muted);
}
.cpm-ana__item{ padding:10px 2px; border-bottom:3px dashed var(--text-muted); }
.cpm-ana__item small{ opacity:.6; font-size: var(--font-size-md); }
.cpm-ana__q{
    font-weight: 600;
    margin: 2px 0 4px;
    display: flex;
    justify-content: end;
}

.cpm-ana__q .user_message{
    background-color: var(--accent-primary);
    color: var(--text-primary);
    margin-right: 0.3rem;
    margin-left: auto;
    border-radius: 18px 18px 4px 18px;
    box-shadow: var(--shadow-sm);
    padding: var(--space-md);
    font-size: 18px;
    word-break: break-word;
    min-width: 40px;
    max-width: 100%;
}
.cpm-ana__a{
    white-space:pre-wrap;
    font-size: 18px;
    font-weight: 600;
}


.cpm-ana__section h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    padding-bottom: 0.4rem;
    line-height: 1.2;
}
.cpm-ana__section h1:first-of-type { margin-top: 0 !important; }

.cpm-ana__section h2 {
    font-size: 17px;
    font-weight: 650;
    color: var(--text-primary);
    padding-bottom: 0.2rem;
    line-height: 1.3;
}
.cpm-ana__section h2:first-of-type { margin-top: 1.2rem !important; }

.cpm-ana__section h3 {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.4;
}
.cpm-ana__section h3:first-of-type { margin-top: 0 !important; }

.cpm-ana__section h4 {
    font-size: 16px;
    font-weight: 550;
    color: var(--text-primary);
    line-height: 1.4;
    padding-top: 2rem;
}
.cpm-ana__section h4:first-of-type { margin-top: 0 !important; }

.cpm-ana__section h5 {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    letter-spacing: 0.04em;
    line-height: 1.4;
}
.cpm-ana__section h5:first-of-type { margin-top: 0 !important; }

.cpm-ana__section hr {
    border: none;
    border-top: 1px solid var(--text-muted);
}

.cpm-ana__section p { font-size: 16px; line-height: 1.7; }
.cpm-ana__section strong { color: var(--text-primary); font-weight: 600; border-radius: 3px; }

.cpm-ana__section a { color: #66D9EF; text-decoration: underline; }
.cpm-ana__section a:hover { color: #66D9EF; text-decoration: none; }

.cpm-ana__section ol,
.cpm-ana__section ul {
    padding-left: 1.5em;
    font-size: 16px;
    margin-left: 0;
}
.cpm-ana__section ol { list-style-type: decimal; }
.cpm-ana__section ul { list-style-type: disc; }

.cpm-ana__section ol li,
.cpm-ana__section ul li {
    font-size: 16px;
}

.cpm-ana__section ol ol,
.cpm-ana__section ul ul,
.cpm-ana__section ol ul,
.cpm-ana__section ul ol {
    margin-top: 0.5em;
    margin-bottom: 0.5em;
}

.cpm-ana__section ol ol { list-style-type: lower-alpha; }
.cpm-ana__section ul ul { list-style-type: circle; }
.cpm-ana__section ol ol ol { list-style-type: lower-roman; }
.cpm-ana__section ul ul ul { list-style-type: square; }

.cpm-ana__section table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
    font-size: 16px;
    background-color: var(--bg-secondary);
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.cpm-ana__section th,
.cpm-ana__section td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--bg-secondary, #e0e0e0);
    vertical-align: top;
}

.cpm-ana__section th {
    background-color: var(--accent-primary);
    color: var(--bg-primary);
    font-weight: 600;
    font-size: 16px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.cpm-ana__section td {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 16px;
}

.cpm-ana__section tbody tr:nth-child(even) td { background-color: var(--bg-tertiary); }
.cpm-ana__section tbody tr:hover td {
    background-color: rgba(102,217,239,0.1);
    transition: background-color 0.2s ease;
}

.cpm-ana__section td:first-child { font-weight: 500; }
.cpm-ana__section td:last-child {
    text-align: right;
    font-family: 'Courier New', monospace;
}

.cpm-ana__section tbody tr:last-child td { border-bottom: none; }

.cpm-ana__section table.tax-calc { border: 2px solid var(--accent-primary); }
.cpm-ana__section table.tax-calc th { background-color: var(--accent-primary); }
.cpm-ana__section table.tax-calc .total-row td {
    font-weight: bold;
    border-top: 2px solid var(--accent-primary);
    background-color: rgba(102, 217, 239, 0.1);
}

.cpm-docs-card { position: relative; }

.cpm-docs-drop-overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 20;

    background: rgba(0, 0, 0, 0.35);
    border: 2px dashed var(--accent-primary);
    border-radius: var(--radius-lg, 12px);
    backdrop-filter: blur(2px);
}
.cpm-docs-drop-overlay.active { display: flex; }

.cpm-docs-drop-overlay__inner {
    text-align: center;
    padding: 16px 24px;
}
.cpm-docs-drop-overlay__title {
    color: var(--text-primary);
    font-weight: 700;
    font-size: 16px;
    line-height: 1.2;
}
.cpm-docs-drop-overlay__hint {
    color: var(--text-secondary);
    margin-top: 4px;
    font-size: 12px;
    opacity: 0.9;
}

@media (max-width: 1280px) {

    #cpmDocModal.cpm-modal.is-open{
        position: fixed;
        inset: 0;
        display: grid;
        justify-items: center;
        align-items: start;
        padding: 16px;
        gap: 0;
        height: 100dvh;
        overflow-y: auto;
        grid-template-columns: repeat(1, minmax(0, 1fr));
        z-index: 1000;
    }

    #cpmDocModal .cpm-modal__dialog{
        display: grid;
        grid-template-rows: auto 1fr auto;
        min-height: 100vh;
        grid-column: 1 / -1;
        width: 100%;
        border-radius: 0;
        margin-bottom: var(--space-sm);
    }

    #cpmAnalysisDock{
        grid-column: 1 / -1;
        border-top: 1px solid var(--accent-primary);
        border-left: 0;
        padding: var(--space-sm) 0 var(--space-md) 0;
    }

    #cpmAnalysisDock .cpm-ana{
        overflow-y: hidden;
        border-radius: 0;
    }

    .cpm-modal__dialog{
        padding-right: 0;
    }
}

@media (max-width: 768px) {
    .cpm-ana__section table { font-size: 14px; }
    .cpm-ana__section th,
    .cpm-ana__section td { padding: 8px 12px; }
    .cpm-ana__section th { font-size: 14px; }
    .cpm-ana__section td { font-size: 14px; }
}