/**
 * BrikPanel — Operational Expenses
 * Shopify-inspired, monochrome design system.
 */

/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
    --ex-bg:             #f1f1f1;
    --ex-card:           #ffffff;
    --ex-text:           #303030;
    --ex-text-secondary: #616161;
    --ex-text-muted:     #8a8a8a;
    --ex-border:         #e3e3e3;
    --ex-input-border:   #8a8a8a;
    --ex-input-focus:    #303030;
    --ex-primary:        #303030;
    --ex-primary-hover:  #1a1a1a;
    --ex-success:        #1a8917;
    --ex-error:          #d72c0d;
    --ex-radius:         0.5rem;
    --ex-radius-card:    0.75rem;
}

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.brikpanel-expenses-wrap {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 0 2rem;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--ex-text);
    box-sizing: border-box;
}

.brikpanel-expenses-wrap *,
.brikpanel-expenses-wrap *::before,
.brikpanel-expenses-wrap *::after {
    box-sizing: border-box;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
.brikpanel-ex-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 1.5rem 0 1rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.brikpanel-ex-header h1 {
    margin: 0 0 0.25rem;
    font-size: 1.125rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--ex-text);
}

.brikpanel-ex-subtitle {
    margin: 0;
    font-size: 0.8125rem;
    color: var(--ex-text-secondary);
    line-height: 1.5;
}

/* ── Summary bar ────────────────────────────────────────────────────────────── */
.brikpanel-ex-summary {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.brikpanel-ex-summary-card {
    background: var(--ex-card);
    border: 1px solid var(--ex-border);
    border-radius: var(--ex-radius-card);
    padding: 1rem 1.25rem;
    min-width: 140px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.brikpanel-ex-summary-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--ex-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.375rem;
}

.brikpanel-ex-summary-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--ex-text);
    line-height: 1.2;
}

/* ── Cards ───────────────────────────────────────────────────────────────────── */
.brikpanel-ex-card {
    background: var(--ex-card);
    border: 1px solid var(--ex-border);
    border-radius: var(--ex-radius-card);
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    margin-bottom: 1rem;
}

/* ── Filters ─────────────────────────────────────────────────────────────────── */
.brikpanel-ex-filters {
    padding: 1.125rem 1.25rem;
}

.brikpanel-ex-filter-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.brikpanel-ex-field {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    min-width: 0;
}

.brikpanel-ex-field label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--ex-text);
    line-height: 1;
}

.brikpanel-ex-field input[type="date"],
.brikpanel-ex-field input[type="text"],
.brikpanel-ex-field input[type="number"],
.brikpanel-ex-field select,
.brikpanel-ex-field textarea {
    border: 1px solid var(--ex-input-border);
    border-radius: var(--ex-radius);
    padding: 0.625rem 0.75rem;
    font-size: 0.875rem;
    color: var(--ex-text);
    background: #fff;
    line-height: 1.4;
    transition: border-color 0.15s, box-shadow 0.15s;
    width: 100%;
    font-family: inherit;
}

.brikpanel-ex-field input:focus,
.brikpanel-ex-field select:focus,
.brikpanel-ex-field textarea:focus {
    outline: none;
    border-color: var(--ex-input-focus);
    box-shadow: 0 0 0 1px var(--ex-input-focus);
}

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

.brikpanel-ex-field textarea {
    resize: vertical;
}

.brikpanel-ex-filter-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    padding-bottom: 0;
    flex-shrink: 0;
}

/* ── Input Group (prefix/suffix) ─────────────────────────────────────────────── */
.brikpanel-ex-input-group {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--ex-input-border);
    border-radius: var(--ex-radius);
    overflow: hidden;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.brikpanel-ex-input-group:focus-within {
    border-color: var(--ex-input-focus);
    box-shadow: 0 0 0 1px var(--ex-input-focus);
}

.brikpanel-ex-prefix,
.brikpanel-ex-suffix {
    display: flex;
    align-items: center;
    padding: 0 0.625rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--ex-text-secondary);
    background: #f7f7f7;
    border-right: 1px solid var(--ex-border);
    flex-shrink: 0;
    user-select: none;
}

.brikpanel-ex-suffix {
    border-right: none;
    border-left: 1px solid var(--ex-border);
}

.brikpanel-ex-input-group input {
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    flex: 1;
    min-width: 0;
}

.brikpanel-ex-input-group input:focus {
    outline: none;
    box-shadow: none !important;
}

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.brikpanel-ex-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
    font-weight: 550;
    border-radius: var(--ex-radius);
    border: none;
    cursor: pointer;
    line-height: 1.4;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
    font-family: inherit;
    white-space: nowrap;
}

.brikpanel-ex-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.brikpanel-ex-btn-primary {
    background: var(--ex-primary);
    color: #fff;
    box-shadow: inset 0 -1px 0 rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.1);
}

.brikpanel-ex-btn-primary:hover:not(:disabled) {
    background: var(--ex-primary-hover);
}

.brikpanel-ex-btn-secondary {
    background: #fff;
    color: var(--ex-text);
    box-shadow: inset 0 0 0 1px var(--ex-border), 0 1px 0 rgba(0,0,0,0.05);
}

.brikpanel-ex-btn-secondary:hover:not(:disabled) {
    background: #f7f7f7;
}

/* ── Icon buttons ──────────────────────────────────────────────────────────── */
.brikpanel-ex-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 0.375rem;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--ex-text-muted);
    transition: background 0.1s, color 0.1s;
    padding: 0;
}

.brikpanel-ex-icon-btn:hover {
    background: #f0f0f0;
    color: var(--ex-text);
}

.brikpanel-ex-delete-btn:hover {
    background: #fce4e4;
    color: var(--ex-error);
}

/* ── Table ───────────────────────────────────────────────────────────────────── */
.brikpanel-ex-table-card {
    padding: 0;
    overflow: hidden;
}

.brikpanel-ex-table-wrap {
    overflow-x: auto;
}

.brikpanel-ex-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.brikpanel-ex-table thead th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--ex-text-secondary);
    border-bottom: 1px solid var(--ex-border);
    white-space: nowrap;
    background: #fafafa;
}

.brikpanel-ex-table tbody tr {
    border-bottom: 1px solid var(--ex-border);
    transition: background 0.1s;
}

.brikpanel-ex-table tbody tr:last-child {
    border-bottom: none;
}

.brikpanel-ex-table tbody tr:hover {
    background: #fafafa;
}

.brikpanel-ex-table tbody td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
    color: var(--ex-text);
}

.brikpanel-ex-table th.brikpanel-ex-num,
.brikpanel-ex-table td.brikpanel-ex-num {
    text-align: right;
}

.brikpanel-ex-table th.brikpanel-ex-actions-th,
.brikpanel-ex-actions-cell {
    text-align: right;
    white-space: nowrap;
    width: 72px;
}

.brikpanel-ex-actions-cell {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.25rem;
    padding-right: 0.75rem;
}

.brikpanel-ex-date-cell {
    white-space: nowrap;
    color: var(--ex-text-secondary);
    font-size: 0.8125rem;
}

.brikpanel-ex-desc-cell {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--ex-text-secondary);
    font-size: 0.8125rem;
}

/* ── Badges ──────────────────────────────────────────────────────────────────── */
.brikpanel-ex-cat-badge {
    display: inline-block;
    padding: 0.1875rem 0.5rem;
    border-radius: 999px;
    background: #f0f0f0;
    color: var(--ex-text);
    font-size: 0.75rem;
    font-weight: 550;
    line-height: 1.4;
    white-space: nowrap;
}

.brikpanel-ex-rec-badge {
    display: inline-block;
    padding: 0.1875rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 550;
    line-height: 1.4;
    white-space: nowrap;
    background: #f0f0f0;
    color: var(--ex-text-secondary);
}

.brikpanel-ex-rec-none {
    background: #f0f0f0;
    color: var(--ex-text-muted);
}

.brikpanel-ex-rec-monthly {
    background: #e8f4e8;
    color: #1a6b15;
}

.brikpanel-ex-rec-weekly {
    background: #e8f0f8;
    color: #1a4a8a;
}

.brikpanel-ex-rec-yearly {
    background: #f5f0e8;
    color: #7a5a10;
}

/* ── Empty / loading states ──────────────────────────────────────────────────── */
.brikpanel-ex-empty {
    text-align: center;
    padding: 2.5rem 1rem !important;
    color: var(--ex-text-muted);
    font-size: 0.875rem;
}

.brikpanel-ex-loading {
    text-align: center;
    padding: 2rem 1rem !important;
}

.brikpanel-ex-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--ex-border);
    border-top-color: var(--ex-text-secondary);
    border-radius: 50%;
    animation: brikpanel-ex-spin 0.7s linear infinite;
}

@keyframes brikpanel-ex-spin {
    to { transform: rotate(360deg); }
}

/* ── Pagination ──────────────────────────────────────────────────────────────── */
.brikpanel-ex-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1rem;
    border-top: 1px solid var(--ex-border);
}

.brikpanel-ex-page-info {
    font-size: 0.8125rem;
    color: var(--ex-text-secondary);
    min-width: 56px;
    text-align: center;
}

/* ── Modal overlay ───────────────────────────────────────────────────────────── */
.brikpanel-ex-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: brikpanel-ex-fade-in 0.2s ease;
}

.brikpanel-ex-overlay[hidden] {
    display: none !important;
}

@keyframes brikpanel-ex-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.brikpanel-ex-modal {
    background: var(--ex-card);
    border-radius: var(--ex-radius-card);
    box-shadow: 0 8px 32px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 540px;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    animation: brikpanel-ex-slide-up 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

@keyframes brikpanel-ex-slide-up {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.brikpanel-ex-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.125rem 1.25rem;
    border-bottom: 1px solid var(--ex-border);
    flex-shrink: 0;
}

.brikpanel-ex-modal-header h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--ex-text);
}

.brikpanel-ex-modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 0.375rem;
    font-size: 1.25rem;
    line-height: 1;
    color: var(--ex-text-muted);
    transition: background 0.1s, color 0.1s;
    padding: 0;
}

.brikpanel-ex-modal-close:hover {
    background: #f0f0f0;
    color: var(--ex-text);
}

.brikpanel-ex-modal-body {
    padding: 1.25rem;
    flex: 1;
}

.brikpanel-ex-modal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.brikpanel-ex-field-full {
    grid-column: 1 / -1;
}

.brikpanel-ex-modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--ex-border);
    flex-shrink: 0;
}

/* ── Toast ────────────────────────────────────────────────────────────────────── */
.brikpanel-ex-toast {
    position: fixed;
    top: 44px;
    right: 20px;
    z-index: 100001;
    padding: 0.625rem 1rem;
    border-radius: var(--ex-radius);
    font-size: 0.875rem;
    font-weight: 500;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    transform: translateX(110%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s;
    opacity: 0;
    max-width: 320px;
    pointer-events: none;
}

.brikpanel-ex-toast--visible {
    transform: translateX(0);
    opacity: 1;
}

.brikpanel-ex-toast--success {
    background: #e4f5e1;
    color: #1a6b15;
    border: 1px solid #b7e1b0;
}

.brikpanel-ex-toast--error {
    background: #fce4e4;
    color: #c62828;
    border: 1px solid #f1b0b0;
}

/* ── [hidden] enforcement (CSS display: flex/block overrides native hidden) ── */
.brikpanel-ex-pagination[hidden],
.brikpanel-ex-overlay[hidden] {
    display: none !important;
}

/* ── Body class lock (prevent scroll when modal open) ──────────────────────── */
body.brikpanel-ex-modal-open {
    overflow: hidden;
}

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .brikpanel-ex-modal-grid {
        grid-template-columns: 1fr;
    }

    .brikpanel-ex-filter-row {
        flex-direction: column;
    }

    .brikpanel-ex-filter-row .brikpanel-ex-field,
    .brikpanel-ex-filter-row .brikpanel-ex-filter-actions {
        width: 100%;
    }

    .brikpanel-ex-header {
        flex-direction: column;
    }

    .brikpanel-ex-table thead th:nth-child(3),
    .brikpanel-ex-table tbody td:nth-child(3) {
        display: none;
    }
}
