/**
 * ValueTrack admin UI — shared visual system (Inter, compact operational density).
 * Loaded globally from shared/admin/base.html after theme.css + base.css.
 * Scoped to .vt-admin (admin layout shell). CRM retains #crm-hub-root refinements in crm_typography.css.
 */

/* ------------------------------------------------------------------ tokens */
.vt-admin {
    --admin-font: var(--font-base);
    --admin-text-body: var(--font-size-base);
    --admin-text-meta: var(--admin-font-size-meta);
    --admin-text-label: var(--admin-font-size-label);
    --admin-text-nav: 13px;
    --admin-lh-body: 1.45;
    --admin-lh-snug: 1.35;
    --admin-lh-tight: 1.25;

    --admin-space-1: 4px;
    --admin-space-2: 8px;
    --admin-space-3: 12px;
    --admin-space-4: 16px;
    --admin-space-5: 24px;

    --admin-radius-sm: 4px;
    --admin-radius-md: 6px;
    --admin-radius-lg: 8px;

    --admin-input-h: 24px;
    --admin-btn-py: 6px;
    --admin-btn-px: 12px;

    --admin-table-cell-py: 6px;
    --admin-table-cell-px: 10px;

    --admin-card-pad: var(--admin-space-4);
    --admin-modal-pad: var(--admin-space-4);

    font-family: var(--admin-font);
    font-size: var(--admin-text-body);
    font-weight: 400;
    line-height: var(--admin-lh-body);
    font-feature-settings: "liga" 1, "calt" 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ------------------------------------------------------------------ hierarchy */
.vt-admin h1 {
    font-size: var(--admin-font-size-page-title);
    font-weight: 600;
    line-height: var(--admin-lh-tight);
    letter-spacing: -0.01em;
}

.vt-admin h2 {
    font-size: var(--admin-font-size-section);
    font-weight: 600;
    line-height: 1.3;
}

.vt-admin h3 {
    font-size: var(--admin-font-size-label);
    font-weight: 500;
    line-height: var(--admin-lh-snug);
}

.vt-admin .font-bold {
    font-weight: 600;
}

.vt-admin .font-semibold {
    font-weight: 600;
}

/* ------------------------------------------------------------------ top navigation */
.vt-admin .admin-top-nav {
    font-size: var(--admin-text-nav);
}

.vt-admin .admin-top-nav a,
.vt-admin .admin-top-nav button {
    font-size: inherit;
}

.vt-admin .admin-nav-flyout a {
    font-size: 13px;
    padding: 6px 12px;
}

.vt-admin .admin-nav-section-label {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #9ca3af;
}

/* ------------------------------------------------------------------ module header bar (green rail) */
.vt-admin .admin-module-header,
.vt-admin .admin-module-header h1 {
    font-size: var(--admin-font-size-section);
    font-weight: 600;
    line-height: var(--admin-lh-snug);
}

/* ------------------------------------------------------------------ hub tab bar (.tab-btn — Data Room, ValuTrek Pro) */
.vt-admin .tab-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--admin-space-1);
    padding: 8px 12px;
    font-family: var(--admin-font);
    font-size: 13px;
    font-weight: 500;
    line-height: var(--admin-lh-snug);
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.vt-admin .tab-btn:hover {
    color: var(--color-main);
}

.vt-admin .tab-btn.active,
.vt-admin .tab-btn.border-\[var\(--color-main\)\] {
    color: var(--color-main);
    border-bottom-color: var(--color-main);
    font-weight: 500;
}

/* ------------------------------------------------------------------ action-center / workspace tabs */
.vt-admin .mpsp-action-tab {
    font-family: var(--admin-font);
    font-size: 13px;
    font-weight: 500;
    line-height: var(--admin-lh-snug);
    padding: 6px 12px;
    border-radius: var(--admin-radius-md);
}

/* ------------------------------------------------------------------ dashboard hub cards */
.vt-admin .admin-hub-card {
    padding: var(--admin-space-4);
    border-radius: var(--admin-radius-lg);
    height: 240px;
    border: 1px solid #f3f4f6;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.vt-admin .admin-hub-card h2 {
    font-size: 14px;
    font-weight: 500;
}

.vt-admin .admin-hub-card p {
    font-size: var(--admin-text-meta);
    line-height: var(--admin-lh-snug);
}

.vt-admin .admin-hub-card .admin-hub-card-btn {
    font-size: 13px;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: var(--admin-radius-md);
}

/* ------------------------------------------------------------------ forms */
.vt-admin label {
    font-size: var(--admin-text-label);
    font-weight: 500;
    line-height: var(--admin-lh-snug);
}

.vt-admin input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]):not([type="file"]),
.vt-admin select,
.vt-admin textarea {
    font-family: var(--admin-font);
    font-size: var(--admin-text-body);
    font-weight: 400;
    line-height: var(--admin-lh-snug);
    border-radius: var(--admin-radius-md);
}

.vt-admin input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]),
.vt-admin select {
    /* min-height: var(--admin-input-h); */
    padding: 4px 8px;
}

.vt-admin textarea {
    padding: 4px 8px;
}

.vt-admin .admin-field-error,
.vt-admin .text-red-600.text-xs,
.vt-admin .text-red-500.text-xs {
    font-size: var(--admin-text-meta);
}

/* ------------------------------------------------------------------ buttons (utility classes; existing Tailwind btn classes still work) */
.vt-admin .admin-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--admin-space-1);
    font-family: var(--admin-font);
    font-size: 13px;
    font-weight: 500;
    line-height: var(--admin-lh-snug);
    padding: var(--admin-btn-py) var(--admin-btn-px);
    border-radius: var(--admin-radius-md);
    white-space: nowrap;
    cursor: pointer;
    transition: opacity 0.15s ease, background-color 0.15s ease;
}

.vt-admin .admin-btn-primary {
    background-color: var(--color-main);
    color: #fff;
    border: 1px solid transparent;
}

.vt-admin .admin-btn-primary:hover {
    opacity: 0.92;
}

.vt-admin .admin-btn-secondary {
    background-color: #fff;
    color: #374151;
    border: 1px solid #d1d5db;
}

.vt-admin .admin-btn-secondary:hover {
    background-color: #f9fafb;
}

.vt-admin .admin-btn-danger {
    background-color: var(--color-pop);
    color: #fff;
    border: 1px solid transparent;
}

.vt-admin .admin-btn-danger:hover {
    opacity: 0.92;
}

.vt-admin .admin-btn-ghost {
    background: transparent;
    color: #374151;
    border: 1px solid transparent;
}

.vt-admin .admin-btn-ghost:hover {
    background-color: #f3f4f6;
}

/* Normalize inline primary buttons that use legacy 12px Tailwind */
.vt-admin button.rounded.bg-\[var\(--color-main\)\],
.vt-admin a.rounded.bg-\[var\(--color-main\)\],
.vt-admin button.rounded.bg-\[var\(--color-main-soft\)\],
.vt-admin button.rounded.bg-\[var\(--color-main-blue\)\],
.vt-admin button.rounded.bg-\[var\(--color-pop\)\],
.vt-admin button.rounded.border.border-gray-300,
.vt-admin a.rounded.border.border-gray-300 {
    font-size: 13px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: var(--admin-radius-md);
}

/* ------------------------------------------------------------------ tables (native HTML tables in admin) */
.vt-admin table {
    font-size: var(--admin-text-body);
    border-collapse: collapse;
}

.vt-admin table thead th {
    font-size: var(--admin-text-label);
    font-weight: 500;
    padding: var(--admin-table-cell-py) var(--admin-table-cell-px);
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
    background-color: #f9fafb;
    color: #374151;
}

.vt-admin table tbody td {
    font-size: var(--admin-text-body);
    padding: var(--admin-table-cell-py) var(--admin-table-cell-px);
    border-bottom: 1px solid #f3f4f6;
    vertical-align: middle;
}

.vt-admin table tbody tr:hover td {
    background-color: #f9fafb;
}

.vt-admin table .admin-table-meta {
    font-size: var(--admin-text-meta);
    color: #6b7280;
}

/* ------------------------------------------------------------------ AG Grid (admin default; CRM overrides in theme.css) */
.vt-admin .ag-theme-alpine {
    --ag-font-family: var(--admin-font);
    --ag-font-size: 13px;
    --ag-header-font-size: 12px;
    --ag-header-font-weight: 500;
}

.vt-admin .ag-theme-alpine .ag-header-cell-text {
    font-weight: 500;
}

/* ------------------------------------------------------------------ badges / status chips */
.vt-admin .admin-badge {
    display: inline-flex;
    align-items: center;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.2;
    padding: 2px 8px;
    border-radius: var(--admin-radius-sm);
    white-space: nowrap;
}

/* ------------------------------------------------------------------ cards / panels */
.vt-admin .admin-panel,
.vt-admin .admin-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: var(--admin-radius-lg);
    padding: var(--admin-card-pad);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.vt-admin .admin-panel-title {
    font-size: var(--admin-font-size-label);
    font-weight: 500;
    line-height: var(--admin-lh-snug);
    color: #111827;
    margin: 0 0 var(--admin-space-2);
}

.vt-admin .admin-panel-subtitle {
    font-size: var(--admin-text-meta);
    color: #6b7280;
    line-height: var(--admin-lh-snug);
}

/* ------------------------------------------------------------------ modals (shared patterns; CRM .crm-sd-modal-* in theme.css) */
.vt-admin .admin-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--admin-space-3);
    background: rgba(0, 0, 0, 0.45);
}

.vt-admin .admin-modal-panel {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: var(--admin-radius-lg);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.14);
    width: 100%;
    max-width: 28rem;
    max-height: min(90vh, 520px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.vt-admin .admin-modal-head {
    padding: 12px 16px 8px;
    border-bottom: 1px solid #f3f4f6;
}

.vt-admin .admin-modal-title {
    font-size: 14px;
    font-weight: 600;
    color: #111827;
    line-height: var(--admin-lh-snug);
}

.vt-admin .admin-modal-body {
    padding: var(--admin-modal-pad);
    flex: 1;
    min-height: 0;
    overflow: auto;
    font-size: var(--admin-text-body);
}

.vt-admin .admin-modal-footer {
    padding: 10px 16px;
    border-top: 1px solid #f3f4f6;
    display: flex;
    justify-content: flex-end;
    gap: var(--admin-space-2);
    background: #f9fafb;
}

/* ------------------------------------------------------------------ MPSP sidebar (shared with Data Room hubs) */
.vt-admin .mpsp-sidebar-label {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.04em;
}

.vt-admin .mpsp-sidebar-section-heading {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.03em;
}

.vt-admin .mpsp-sidebar nav,
.vt-admin .mpsp-sidebar .mpsp-nav-item-label {
    font-size: 13px;
    font-weight: 400;
}

/* ------------------------------------------------------------------ typography utilities (usable outside CRM) */
.vt-admin .admin-type-page-title {
    font-size: var(--admin-font-size-page-title);
    font-weight: 600;
    line-height: var(--admin-lh-tight);
}

.vt-admin .admin-type-section {
    font-size: var(--admin-font-size-section);
    font-weight: 600;
    line-height: 1.3;
}

.vt-admin .admin-type-body {
    font-size: var(--admin-text-body);
    font-weight: 400;
    line-height: var(--admin-lh-body);
}

.vt-admin .admin-type-meta {
    font-size: var(--admin-text-meta);
    font-weight: 400;
    line-height: var(--admin-lh-snug);
    color: #6b7280;
}

.vt-admin .admin-type-label {
    font-size: var(--admin-text-label);
    font-weight: 500;
    line-height: var(--admin-lh-snug);
}

/* Pro / hub module headers on green title bar */
.vt-admin h1.text-lg.font-semibold.text-white,
.vt-admin .admin-module-header h1 {
    font-size: var(--admin-font-size-section);
    font-weight: 600;
}

/* Legacy shadow cards — normalize border/shadow when not using .admin-hub-card */
.vt-admin .rounded-xl.shadow-md {
    border: 1px solid #f3f4f6;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

/* CRM dashboard stat cards — align with admin meta/body scale */
#crm-hub-root .crm-hub-stat-label {
    font-size: var(--admin-font-size-meta);
    font-weight: 500;
    line-height: 1.35;
    color: #4b5563;
}

#crm-hub-root .crm-hub-stat-value {
    font-size: 20px;
    font-weight: 600;
    line-height: 1.25;
}

/* Buyer email template tab name (replaces browser prompt) */
.dr-buyer-et-tab-modal {
    z-index: 100055;
    padding: 2.5vh 2.5vw;
}

.dr-buyer-et-tab-modal-panel {
    width: min(420px, 100%);
    max-width: none;
}

/* Email template editor (Send Email → New Template nested modal) */
.email-template-editor-modal {
    padding: 2.5vh 2.5vw;
}

.email-template-editor-panel {
    display: flex;
    flex-direction: column;
    height: 95%;
    width: 70%;
    max-width: none;
    overflow: hidden;
}

.email-template-editor-name-subject-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

@media (max-width: 639px) {
    .email-template-editor-name-subject-row {
        grid-template-columns: 1fr;
    }
}

/* Email template editor — compact placeholder tag buttons */
.dr-email-ph-tag {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 9px;
    line-height: 1.2;
    padding: 0 4px;
}

/* TinyMCE email editors — soft gray toolbar (data-rich-email) */
[data-rich-fill="1"] .tox:not(.tox-tinymce-inline) .tox-editor-header,
[data-rich-body-block="1"] .tox:not(.tox-tinymce-inline) .tox-editor-header {
    background-color: #f3f4f6 !important;
    border-bottom: 1px solid #e5e7eb;
}

[data-rich-fill="1"] .tox .tox-toolbar-overlord,
[data-rich-fill="1"] .tox .tox-toolbar__primary,
[data-rich-fill="1"] .tox .tox-toolbar,
[data-rich-body-block="1"] .tox .tox-toolbar-overlord,
[data-rich-body-block="1"] .tox .tox-toolbar__primary,
[data-rich-body-block="1"] .tox .tox-toolbar {
    background-color: #f3f4f6 !important;
}

[data-rich-fill="1"] .tox .tox-toolbar__group,
[data-rich-body-block="1"] .tox .tox-toolbar__group {
    border-color: #e5e7eb;
}

/* ------------------------------------------------------------------ TinyMCE email body (fill remaining flex height) */
[data-rich-body-block="1"] {
    flex: 1 1 0%;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

[data-rich-fill="1"] {
    flex: 1 1 0%;
    min-height: 10rem;
    display: flex;
    flex-direction: column;
    width: 100%;
}

[data-rich-fill="1"] > textarea[data-rich-email] {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
}

[data-rich-fill="1"] .tox.tox-tinymce {
    flex: 1 1 auto !important;
    min-height: 10rem !important;
    width: 100% !important;
    display: flex !important;
    flex-direction: column !important;
}

[data-rich-fill="1"] .tox .tox-editor-container {
    flex: 1 1 auto !important;
    min-height: 0 !important;
}

[data-rich-fill="1"] .tox .tox-edit-area {
    flex: 1 1 auto !important;
}

[data-rich-fill="1"] .tox .tox-edit-area__iframe {
    flex: 1 1 auto !important;
}
