/* ================================================================
   Outprime — Doc Panel Extras
   Extends hud_theme.css with: shell grid, tab nav, form controls,
   lookups, toolbars, switches, radios, status chip, modals.
   Load AFTER hud_theme.css.
   Uses existing tokens: --text, --muted, --line, --accent, --accent2,
                         --mono, --ui, --bg, --bg2, --shadow, --shadow2
   ================================================================ */


/* ─── Outer panel hook ───
   If your wrapper uses id="docPanel" class="open" you already get width
   rules from hud_theme.css. This just makes sure a bare .doc-panel class
   also works (for preview / standalone pages).                        */
.doc-panel:not(#docPanel) {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, .6);
    border-right: 1px solid var(--line);
    overflow: hidden;
    flex: 1;
    min-width: 0;
    position: relative;
}


/* ─── Shell: left tab-nav + content ─── */
/* minmax(0, 1fr) is CRITICAL — prevents grid cells from being forced
   wider than the container by wide children (tables, long text, etc).
   Without it, the 1fr column refuses to shrink below its min-content
   width and the Items tab blows out horizontally.                   */
.doc-shell {
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: 170px minmax(0, 1fr);
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}


/* ─── Doc nav (tabs on the left inside the doc) ─── */
.doc-nav {
    border-right: 1px solid var(--line);
    background: rgba(255, 255, 255, .45);
    backdrop-filter: blur(8px);
    padding: 10px 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.doc-nav button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    padding: 7px 14px;
    border: 0;
    background: transparent;
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--muted);
    border-left: 2px solid transparent;
    cursor: pointer;
    transition: background .12s, color .12s, border-color .12s;
    position: relative;
}

.doc-nav button:hover {
    background: rgba(37, 99, 235, .04);
    color: var(--text);
}

.doc-nav button.active {
    background: rgba(37, 99, 235, .06);
    color: var(--accent);
    border-left-color: var(--accent);
    font-weight: 600;
}

.doc-nav .nav-num {
    font-size: 9px;
    opacity: .5;
    letter-spacing: .5px;
    min-width: 14px;
}

.doc-nav button.active .nav-num {
    opacity: 1;
}


/* ─── Doc body padding + shrink rules ───
   min-width: 0 is the flex/grid "escape hatch" that lets this cell
   shrink below its intrinsic content width. Combined with overflow-x:auto,
   any too-wide child (typically a data table) scrolls inside the pane
   instead of breaking the whole layout.                              */
.doc-body {
    padding: 18px 22px 16px;
    min-width: 0;
    min-height: 0;
    overflow-x: auto;
}

/* Sections need the same escape hatch so they don't propagate width up */
.doc-body .doc-section {
    min-width: 0;
}

/* Wide tables (Items, Warranty, etc.) scroll horizontally inside their
   section rather than blowing out the whole doc-panel.                */
.doc-body .doc-table {
    max-width: 100%;
}


/* ─── Section title with bottom rule ─── */
.doc-section-title {
    padding-bottom: 6px;
    border-bottom: 1px solid var(--line);
}

.doc-divider {
    height: 1px;
    background: var(--line);
    margin: 20px 0;
}


/* ─── Fields: slightly wider label column ─── */
.doc-field {
    grid-template-columns: 150px 1fr;
    padding: 5px 0;
    margin-bottom: 0;
    min-height: 28px;
}

.doc-label {
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--muted);
    padding-top: 2px;
}


/* ─── Inputs / selects / textarea ─── */
.doc-input,
.doc-select,
.doc-textarea {
    width: 100%;
    border: 0;
    border-bottom: 1px dashed rgba(223, 228, 241, .7);
    background: transparent;
    padding: 3px 3px;
    font-family: var(--ui);
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
    outline: 0;
    border-radius: 3px 3px 0 0;
    transition: background .15s, border-color .15s;
}

.doc-input:hover,
.doc-select:hover,
.doc-textarea:hover {
    background: rgba(37, 99, 235, .04);
    border-bottom-color: rgba(37, 99, 235, .35);
}

.doc-input:focus,
.doc-select:focus,
.doc-textarea:focus {
    border-bottom: 1px solid var(--accent);
    background: rgba(37, 99, 235, .05);
}

.doc-input[readonly],
.doc-input:disabled,
.doc-textarea[readonly],
.doc-textarea:disabled {
    color: var(--muted);
    cursor: default;
    border-bottom-style: dotted;
    border-bottom-color: var(--line);
}

.doc-input[readonly]:hover,
.doc-input:disabled:hover,
.doc-textarea[readonly]:hover {
    background: transparent;
    border-bottom-color: var(--line);
}

.doc-textarea {
    resize: vertical;
    min-height: 42px;
    padding: 6px 8px;
    border: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    border-radius: 5px;
    line-height: 1.5;
    font-family: var(--ui);
}

.doc-textarea:hover {
    border-color: rgba(37, 99, 235, .25);
}

.doc-textarea:focus {
    border: 1px solid var(--accent);
}

.doc-select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%23596276' d='M0 0h10L5 6z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 4px center;
    padding-right: 18px;
}


/* ─── Lookup (input + buttons) ─── */
.doc-lookup {
    display: flex;
    align-items: center;
    gap: 6px;
}

.doc-lookup .doc-input,
.doc-lookup .doc-select {
    flex: 1;
    min-width: 0;
}

.doc-lookup-btn {
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 4px 10px;
    background: rgba(255, 255, 255, .9);
    border: 1px solid var(--line);
    color: var(--muted);
    cursor: pointer;
    clip-path: polygon(5px 0%, 100% 0%, 100% calc(100% - 5px), calc(100% - 5px) 100%, 0% 100%, 0% 5px);
    transition: all .15s;
    white-space: nowrap;
    line-height: 1.4;
}

.doc-lookup-btn:hover:not(:disabled) {
    border-color: rgba(37, 99, 235, .4);
    color: var(--accent);
    background: rgba(37, 99, 235, .06);
}

.doc-lookup-btn.primary {
    border-color: rgba(37, 99, 235, .45);
    color: var(--accent);
    background: rgba(37, 99, 235, .04);
}

.doc-lookup-btn.primary:hover {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: #fff;
    border-color: transparent;
}

.doc-lookup-btn:disabled {
    opacity: .4;
    cursor: not-allowed;
}


/* ─── Switch ─── */
.doc-switch {
    position: relative;
    display: inline-block;
    width: 30px;
    height: 17px;
}

.doc-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.doc-switch-track {
    position: absolute;
    inset: 0;
    background: var(--line);
    border-radius: 9px;
    cursor: pointer;
    transition: background .15s;
}

.doc-switch-track::before {
    content: "";
    position: absolute;
    left: 2px;
    top: 2px;
    width: 13px;
    height: 13px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(11, 18, 32, .2);
    transition: transform .18s;
}

.doc-switch input:checked+.doc-switch-track {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
}

.doc-switch input:checked+.doc-switch-track::before {
    transform: translateX(13px);
}


/* ─── Radio ─── */
.doc-radio {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.doc-radio input[type="radio"],
.doc-radio input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    margin: 0;
    border: 1px solid var(--muted);
    border-radius: 50%;
    display: grid;
    place-items: center;
    cursor: pointer;
    background: #fff;
    transition: border-color .15s;
}

.doc-radio input[type="checkbox"] {
    border-radius: 3px;
}

.doc-radio input:checked {
    border-color: var(--accent);
}

.doc-radio input[type="radio"]:checked::after {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
}

.doc-radio input[type="checkbox"]:checked::after {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 1px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
}

.doc-radio-label {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: .8px;
    text-transform: uppercase;
    color: var(--muted);
}


/* ─── Toolbar (above tables) ─── */
.doc-toolbar {
    display: flex;
    align-items: stretch;
    margin-bottom: 12px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, .85);
    backdrop-filter: blur(6px);
    width: fit-content;
    clip-path: polygon(6px 0%, 100% 0%, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0% 100%, 0% 6px);
}

.doc-toolbar button {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: .8px;
    text-transform: uppercase;
    padding: 7px 11px;
    border: 0;
    border-right: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: background .12s, color .12s;
}

.doc-toolbar button:hover:not(:disabled) {
    background: rgba(37, 99, 235, .05);
    color: var(--accent);
}

.doc-toolbar button:disabled {
    opacity: .4;
    cursor: not-allowed;
}

.doc-toolbar button .material-symbols-rounded,
.doc-toolbar button .material-icons-outlined {
    font-size: 14px;
    line-height: 1;
}

.doc-toolbar .sep {
    width: 1px;
    background: var(--line);
    margin: 4px 4px;
    align-self: stretch;
}

.doc-toolbar>button:last-child,
.doc-toolbar>.sep+button {
    border-right: 0;
}

.doc-toolbar .danger {
    color: #b91c1c;
}

.doc-toolbar .danger:hover {
    background: rgba(220, 38, 38, .06);
    color: #991b1b;
}


/* ─── Table extras ─── */
.doc-table td.mono {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--muted);
}

.doc-table td.num {
    font-variant-numeric: tabular-nums;
    font-size: 11px;
}

.doc-table tbody tr.selected td {
    background: rgba(37, 99, 235, .08);
    color: var(--text);
}

.doc-table .checkbox-cell {
    width: 28px;
}

.doc-table input[type="checkbox"],
.doc-table input[type="radio"] {
    accent-color: var(--accent);
    cursor: pointer;
}


/* ─── Status chip (amber, sits next to the doc badge) ─── */
.status-chip {
    font-family: var(--mono);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: .8px;
    text-transform: uppercase;
    padding: 2px 7px;
    border: 1px solid rgba(217, 119, 6, .4);
    color: #d97706;
    background: rgba(217, 119, 6, .08);
    border-radius: 3px;
}

.status-chip.ok {
    border-color: rgba(22, 163, 74, .4);
    color: #16a34a;
    background: rgba(22, 163, 74, .08);
}

.status-chip.danger {
    border-color: rgba(185, 28, 28, .4);
    color: #b91c1c;
    background: rgba(185, 28, 28, .08);
}


/* ─── Tab pane switching ─── */
.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
    animation: paneIn .18s ease;
}

@keyframes paneIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}


/* ─── Grow helper (used in topbar) ─── */
.grow {
    flex: 1;
}


/* ─── Warn / danger colors for inline use ─── */
:root {
    --warn: #d97706;
    --danger: #b91c1c;
}


/* ─── Modals (HUD-styled, clip-path corners) ─── */
.doc-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(11, 18, 32, .45);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 24px;
    animation: modalBackIn .18s ease;
}

.doc-modal-backdrop.open {
    display: flex;
}

@keyframes modalBackIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.doc-modal {
    background: rgba(255, 255, 255, .98);
    border: 1px solid var(--line);
    box-shadow: 0 24px 60px rgba(11, 18, 32, .2), 0 4px 12px rgba(11, 18, 32, .08);
    width: 100%;
    max-width: 720px;
    max-height: 85vh;
    display: grid;
    grid-template-rows: auto 1fr auto;
    overflow: hidden;
    clip-path: polygon(12px 0%, 100% 0%, 100% calc(100% - 12px), calc(100% - 12px) 100%, 0% 100%, 0% 12px);
    animation: modalIn .22s ease;
    position: relative;
}

.doc-modal.lg {
    max-width: 960px;
}

.doc-modal.xl {
    max-width: 1200px;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

/* HUD corner accents on modal */
.doc-modal::before,
.doc-modal::after {
    content: "";
    position: absolute;
    width: 14px;
    height: 14px;
    pointer-events: none;
    z-index: 5;
}

.doc-modal::before {
    top: 0;
    left: 0;
    border-top: 2px solid var(--accent);
    border-left: 2px solid var(--accent);
}

.doc-modal::after {
    bottom: 0;
    right: 0;
    border-bottom: 2px solid var(--accent2);
    border-right: 2px solid var(--accent2);
}

.doc-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, .7);
    backdrop-filter: blur(6px);
}

.doc-modal-title {
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--text);
}

.doc-modal-body {
    padding: 18px 22px;
    overflow-y: auto;
}

.doc-modal-footer {
    padding: 10px 16px;
    border-top: 1px solid var(--line);
    background: rgba(244, 246, 251, .6);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.doc-modal-footer .link-btn {
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 5px 10px;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    border-bottom: 1px solid transparent;
    transition: color .12s, border-color .12s;
}

.doc-modal-footer .link-btn:hover {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.doc-modal-footer .link-btn.primary {
    color: var(--accent);
    border-bottom-color: rgba(37, 99, 235, .4);
}

.doc-modal-footer .link-btn.primary:hover {
    border-bottom-color: var(--accent);
}

.doc-modal-footer .link-btn:disabled {
    opacity: .4;
    cursor: not-allowed;
}


/* ─── Tariff modal inner grid ─── */
.tariff-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 14px 18px;
    align-items: center;
    max-width: 560px;
    margin: 0 auto;
}

.tariff-grid .doc-lookup,
.tariff-grid .doc-input {
    grid-column: 2 / 3;
}


/* ─── Doc topbar tweaks (status chip, search already in base) ─── */
.doc-topbar .status-chip {
    margin-left: 4px;
}

.doc-topbar .tbl-search-clear {
    cursor: pointer;
    display: block;
}

.doc-topbar .tbl-search-clear:hover {
    color: var(--text);
}