/* ============================================================================
 * BASHIER ELHAFY — TARGET | INSTITUTIONAL TRADING INTELLIGENCE (v2.3)
 * Agents B13 & B14: Reusable Enterprise Component Library & Breakpoints
 * ============================================================================ */

/* --- Focus Accessibility (WCAG 2.2 AA) --- */
:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

/* --- Enterprise Buttons --- */
.btn,
.btn-primary,
.btn-secondary,
.btn-ghost,
.btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.01em;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    text-decoration: none;
    transition: background-color var(--duration-fast) var(--ease-standard),
                border-color var(--duration-fast) var(--ease-standard),
                color var(--duration-fast) var(--ease-standard);
}

.btn svg,
.btn-primary svg,
.btn-secondary svg,
.btn-ghost svg,
.btn-danger svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.btn-primary {
    background-color: var(--accent-primary);
    border-color: var(--accent-primary);
    color: var(--text-inverse);
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-secondary {
    background-color: var(--bg-elevated);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--bg-hover);
    border-color: var(--border-strong);
}

.btn-ghost {
    background-color: transparent;
    border-color: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
    background-color: var(--bg-elevated);
    color: var(--text-primary);
}

.btn-danger {
    background-color: var(--status-negative-bg);
    border-color: var(--status-negative-border);
    color: var(--status-negative);
}

.btn-danger:hover:not(:disabled) {
    background-color: var(--status-negative);
    border-color: var(--status-negative);
    color: var(--text-inverse);
}

.btn-xs {
    height: 24px;
    padding: 0 8px;
    font-size: var(--text-2xs);
}

.btn-sm {
    height: 28px;
    padding: 0 10px;
    font-size: var(--text-xs);
}

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
}

.btn:disabled,
.btn-primary:disabled,
.btn-secondary:disabled,
.btn-danger:disabled {
    opacity: 0.48;
    cursor: not-allowed;
}

/* --- Enterprise Form Controls --- */
.ent-input,
.ent-select,
.ent-textarea,
.intel-input,
.intel-select {
    height: 32px;
    padding: 0 10px;
    background-color: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    transition: border-color var(--duration-fast) var(--ease-standard);
}

.ent-textarea {
    height: auto;
    min-height: 84px;
    padding: 8px 10px;
    line-height: 1.45;
    resize: vertical;
}

.ent-input:focus,
.ent-select:focus,
.ent-textarea:focus,
.intel-input:focus,
.intel-select:focus {
    border-color: var(--border-focus);
}

.ent-input::placeholder,
.ent-textarea::placeholder {
    color: var(--text-muted);
}

.ent-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ent-label {
    font-size: var(--text-2xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

/* --- Segmented Controls & Layer Toggle Chips --- */
.segmented-group {
    display: inline-flex;
    align-items: center;
    background-color: var(--bg-canvas);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 2px;
    gap: 2px;
}

.seg-btn {
    height: 24px;
    padding: 0 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: var(--text-2xs);
    font-weight: 600;
    border-radius: var(--radius-xs);
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--duration-fast) var(--ease-standard);
}

.seg-btn:hover {
    color: var(--text-primary);
    background-color: var(--bg-elevated);
}

.seg-btn.active {
    background-color: var(--accent-primary);
    color: var(--text-inverse);
}

.chip-toggle {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 24px;
    padding: 0 8px;
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    font-size: var(--text-2xs);
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    transition: all var(--duration-fast) var(--ease-standard);
}

.chip-toggle:hover {
    border-color: var(--border-strong);
    color: var(--text-primary);
}

.chip-toggle.active {
    background-color: var(--accent-soft);
    border-color: var(--accent-border);
    color: var(--accent-text);
}

.chip-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: currentColor;
}

/* --- Tabs --- */
.tab-bar {
    display: flex;
    align-items: center;
    gap: 2px;
    border-bottom: 1px solid var(--border-subtle);
    background-color: var(--bg-surface);
    padding: 0 8px;
    overflow-x: auto;
}

.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 12px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: color var(--duration-fast), border-color var(--duration-fast);
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    color: var(--accent-text);
    border-bottom-color: var(--accent-primary);
}

/* --- Enterprise Panels & Cards --- */
.panel,
.settings-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 40px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border-subtle);
    background-color: var(--bg-elevated);
    flex-wrap: wrap;
}

.panel-title-group {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.panel-title {
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-primary);
    margin: 0;
}

.panel-subtitle {
    font-size: var(--text-2xs);
    color: var(--text-muted);
}

.panel-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.panel-body {
    padding: 14px;
    flex: 1;
    min-width: 0;
}

.panel-body-flush {
    padding: 0;
    flex: 1;
    min-width: 0;
}

.panel-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 14px;
    border-top: 1px solid var(--border-subtle);
    background-color: var(--bg-canvas);
    font-size: var(--text-2xs);
    color: var(--text-muted);
}

/* --- KPI Metric Strip --- */
.kpi-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
    gap: 10px;
}

.kpi-tile,
.stat-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.kpi-label,
.stat-card h3 {
    font-size: var(--text-2xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.kpi-value,
.stat-card .stat-value {
    font-family: var(--font-mono);
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.25;
    background: none;
    -webkit-text-fill-color: initial;
}

.kpi-meta,
.stat-card .stat-sub {
    font-size: var(--text-2xs);
    color: var(--text-muted);
    line-height: 1.35;
}

/* --- WCAG 2.2 AA Status Pills (Icon + Text Always Paired) --- */
.status-pill,
.intel-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 22px;
    padding: 0 7px;
    border-radius: var(--radius-xs);
    font-size: var(--text-2xs);
    font-weight: 600;
    letter-spacing: 0.02em;
    border: 1px solid var(--status-neutral-border);
    background-color: var(--status-neutral-bg);
    color: var(--text-secondary);
    white-space: nowrap;
    line-height: 1;
}

.status-pill svg {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

.status-pill.positive,
.intel-pill.ok {
    background-color: var(--status-positive-bg);
    border-color: var(--status-positive-border);
    color: var(--status-positive);
}

.status-pill.negative,
.intel-pill.err {
    background-color: var(--status-negative-bg);
    border-color: var(--status-negative-border);
    color: var(--status-negative);
}

.status-pill.warning,
.intel-pill.warn {
    background-color: var(--status-warning-bg);
    border-color: var(--status-warning-border);
    color: var(--status-warning);
}

.status-pill.info {
    background-color: var(--status-info-bg);
    border-color: var(--status-info-border);
    color: var(--status-info);
}

.status-pill.primary {
    background-color: var(--accent-soft);
    border-color: var(--accent-border);
    color: var(--accent-text);
}

.status-pill.locked {
    background-color: var(--status-negative-bg);
    border-color: var(--status-negative-border);
    color: var(--status-negative);
    font-weight: 700;
}

/* --- Sortable & Filterable Financial Data Tables --- */
.fin-table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-subtle);
    background-color: var(--bg-surface);
    flex-wrap: wrap;
}

.fin-table-wrap {
    width: 100%;
    overflow-x: auto;
}

.fin-table,
.assets-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-xs);
    text-align: left;
}

.fin-table thead th,
.assets-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background-color: var(--bg-elevated);
    color: var(--text-secondary);
    font-size: var(--text-2xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-subtle);
    white-space: nowrap;
    user-select: none;
}

.fin-table thead th.sortable,
.assets-table thead th[onclick] {
    cursor: pointer;
}

.fin-table thead th.sortable:hover,
.assets-table thead th[onclick]:hover {
    color: var(--text-primary);
    background-color: var(--bg-hover);
}

.fin-table tbody tr,
.assets-table tbody tr {
    border-bottom: 1px solid var(--border-muted);
    transition: background-color var(--duration-fast);
}

.fin-table tbody tr:hover,
.assets-table tbody tr:hover {
    background-color: var(--bg-elevated);
}

.fin-table tbody tr.clickable-row {
    cursor: pointer;
}

.fin-table tbody tr.selected-row {
    background-color: var(--accent-soft);
}

.fin-table td,
.assets-table td {
    padding: 8px 10px;
    color: var(--text-primary);
    vertical-align: middle;
}

.fin-table th[data-num="true"],
.fin-table td[data-num="true"] {
    text-align: right;
    font-family: var(--font-mono);
}

.na-cell {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: var(--text-2xs);
    background: repeating-linear-gradient(
        -45deg,
        transparent,
        transparent 4px,
        rgba(148, 163, 184, 0.08) 4px,
        rgba(148, 163, 184, 0.08) 8px
    );
}

/* --- Agent B17: 13 Structured Operational & Error States --- */
.op-state {
    border: 1px solid var(--border-subtle);
    border-left-width: 3px;
    border-radius: var(--radius-md);
    background-color: var(--bg-surface);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.op-state.tone-positive { border-left-color: var(--status-positive); }
.op-state.tone-negative { border-left-color: var(--status-negative); }
.op-state.tone-warning  { border-left-color: var(--status-warning); }
.op-state.tone-info     { border-left-color: var(--status-info); }
.op-state.tone-neutral  { border-left-color: var(--text-muted); }

.op-state-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.op-state-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: var(--text-xs);
    font-weight: 700;
    color: var(--text-primary);
}

.op-state-title svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.op-state-desc {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    line-height: 1.45;
}

.op-state-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-muted);
    font-size: var(--text-2xs);
}

.op-meta-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.op-meta-key {
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.04em;
}

.op-meta-val {
    color: var(--text-primary);
    font-weight: 500;
}

/* Skeleton Loader */
@keyframes entShimmer {
    0% { opacity: 0.45; }
    50% { opacity: 0.85; }
    100% { opacity: 0.45; }
}

.skeleton-line {
    height: 12px;
    border-radius: var(--radius-xs);
    background-color: var(--bg-elevated);
    animation: entShimmer 1.4s ease-in-out infinite;
}

/* --- Modals, Confirm Dialogs & Slide-Over Drawers --- */
.ent-modal-backdrop,
.ent-drawer-backdrop,
.cmd-palette-backdrop {
    position: fixed;
    inset: 0;
    background-color: var(--bg-overlay);
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.ent-modal-backdrop.hidden,
.ent-drawer-backdrop.hidden,
.cmd-palette-backdrop.hidden {
    display: none !important;
}

.ent-modal {
    width: 100%;
    max-width: 680px;
    max-height: 88vh;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ent-modal.modal-lg {
    max-width: 1040px;
}

.ent-modal.modal-sm {
    max-width: 460px;
}

.ent-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background-color: var(--bg-elevated);
    border-bottom: 1px solid var(--border-subtle);
}

.ent-modal-title {
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.ent-modal-body {
    padding: 16px;
    overflow-y: auto;
    font-size: var(--text-xs);
    color: var(--text-primary);
    line-height: 1.5;
}

.ent-modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px 16px;
    background-color: var(--bg-canvas);
    border-top: 1px solid var(--border-subtle);
}

/* Slide-Over Drawer */
.ent-drawer-backdrop {
    z-index: var(--z-drawer);
    justify-content: flex-end;
    padding: 0;
}

.ent-drawer {
    width: min(640px, 94vw);
    height: 100vh;
    background-color: var(--bg-surface);
    border-left: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- Toast Stack & Notification Center --- */
.toast-container {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 380px;
    pointer-events: none;
}

.toast-item {
    pointer-events: auto;
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-left: 3px solid var(--accent-primary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: 10px 12px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: var(--text-xs);
    color: var(--text-primary);
}

.toast-item.positive { border-left-color: var(--status-positive); }
.toast-item.negative { border-left-color: var(--status-negative); }
.toast-item.warning  { border-left-color: var(--status-warning); }

/* --- Ctrl+K Global Command & Symbol Palette --- */
.cmd-palette-backdrop {
    z-index: var(--z-palette);
    align-items: flex-start;
    padding-top: 10vh;
}

.cmd-palette {
    width: min(600px, 94vw);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.cmd-input-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-subtle);
    background-color: var(--bg-elevated);
}

.cmd-input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: var(--text-base);
}

.cmd-list {
    max-height: 360px;
    overflow-y: auto;
    padding: 6px;
}

.cmd-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-primary);
    font-size: var(--text-xs);
}

.cmd-item:hover,
.cmd-item.active {
    background-color: var(--accent-soft);
    color: var(--accent-text);
}

.cmd-item-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cmd-kbd {
    font-family: var(--font-mono);
    font-size: 10px;
    padding: 2px 5px;
    border-radius: var(--radius-xs);
    background-color: var(--bg-canvas);
    border: 1px solid var(--border-subtle);
    color: var(--text-muted);
}

/* --- SVG / Canvas Visualization Containers & Tooltips --- */
.viz-wrap {
    position: relative;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.viz-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

.viz-svg-host {
    width: 100%;
    overflow-x: auto;
}

.viz-svg-host svg {
    display: block;
    width: 100%;
    height: auto;
}

.viz-tooltip {
    position: fixed;
    z-index: var(--z-tooltip);
    pointer-events: none;
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    padding: 6px 10px;
    font-size: var(--text-2xs);
    color: var(--text-primary);
    max-width: 280px;
    line-height: 1.4;
}

.viz-tooltip.hidden {
    display: none !important;
}

/* ============================================================================
 * AGENT B14: RESPONSIVE BREAKPOINTS (2560px 4K .. 390px Mobile Operator)
 * ============================================================================ */

/* Ultra-Wide 4K Institutional Monitors (2560px+) */
@media (min-width: 2200px) {
    .kpi-strip {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* Compact Desktop / Laptop (<= 1366px) */
@media (max-width: 1366px) {
    .hide-compact {
        display: none !important;
    }
}

/* Tablet & Off-Canvas Sidebar Mode (<= 1024px) */
@media (max-width: 1024px) {
    .kpi-strip {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }
    .hide-tablet {
        display: none !important;
    }
}

/* Mobile & Narrow Viewport (<= 768px .. 390px) */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
    .panel-header {
        padding: 8px 10px;
    }
    .panel-body {
        padding: 10px;
    }
    .kpi-strip {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 440px) {
    .kpi-strip {
        grid-template-columns: 1fr;
    }
}
