/* css/customer.css - MODERN CUSTOMER MASTER & LEDGER WORKSPACE (Catalog Design System) */

:root {
    --bg-main: #F9FAFB;
    --bg-surface: #FFFFFF;
    --bg-hover: #F3F4F6;
    --bg-subtle: #F8FAFC;

    --text-main: #111827;
    --text-secondary: #374151;
    --text-muted: #6B7280;

    --brand-primary: #2563EB;
    --brand-primary-hover: #1D4ED8;
    --brand-soft: #EFF6FF;

    --status-success-bg: #D1FAE5;
    --status-success-text: #059669;
    --status-warning-bg: #FEF3C7;
    --status-warning-text: #D97706;
    --status-danger-bg: #FEE2E2;
    --status-danger-text: #DC2626;
    --status-purple-bg: #F3E8FF;
    --status-purple-text: #7E22CE;

    --wa-green: #16A34A;
    --wa-green-hover: #15803D;

    --border-light: #E5E7EB;
    --border-grid: #E2E8F0;
    --border-strong: #CBD5E1;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 12px 24px -4px rgba(15, 23, 42, 0.12), 0 4px 8px -2px rgba(15, 23, 42, 0.06);

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'Roboto Mono', monospace;
    --transition-fast: 0.15s ease-in-out;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    font-size: 13px;
    background-color: var(--bg-main);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    text-transform: uppercase;
    -webkit-font-smoothing: antialiased;
}

input[type="text"],
input[type="tel"],
select,
textarea {
    text-transform: uppercase;
}

input[type="email"] {
    text-transform: none;
}

input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type=number] {
    -moz-appearance: textfield;
}

.mono-input, .mono-text {
    font-family: var(--font-mono) !important;
    font-variant-numeric: tabular-nums;
}

/* --- 1. MODERN HEADER --- */
.app-header {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-light);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-shrink: 0;
    z-index: 40;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-badge {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, #2563EB 0%, #3B82F6 100%);
    color: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25);
}

.app-header h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-main);
    line-height: 1.2;
}

.header-submeta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 3px;
    font-size: 11px;
    color: var(--text-muted);
}

.meta-dot { color: var(--border-strong); }

.stats-pill, .sync-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 11px;
}
.stats-pill { background: var(--bg-hover); color: var(--text-secondary); }
.sync-pill { background: var(--status-success-bg); color: var(--status-success-text); }

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.header-divider {
    width: 1px;
    height: 22px;
    background: var(--border-light);
    margin: 0 2px;
}

.header-btn {
    height: 34px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.header-btn.ghost { background: transparent; color: var(--text-secondary); border-color: var(--border-light); }
.header-btn.ghost:hover { background: var(--bg-hover); color: var(--text-main); }

.header-btn.secondary { background: var(--bg-surface); color: var(--text-main); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.header-btn.secondary:hover { background: var(--bg-hover); }

.header-btn.primary { background: var(--brand-primary); color: #FFFFFF; box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25); }
.header-btn.primary:hover { background: var(--brand-primary-hover); }

.header-btn.danger-ghost { background: transparent; color: var(--text-muted); border-color: var(--border-light); }
.header-btn.danger-ghost:hover { background: var(--status-danger-bg); color: var(--status-danger-text); border-color: #FCA5A5; }

/* --- 2. WORKSPACE & KPI STRIP --- */
.catalog-workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px 24px 18px 24px;
    max-width: 1700px;
    width: 100%;
    margin: 0 auto;
    min-height: 0;
}

.kpi-strip {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 10px;
    flex-shrink: 0;
}

.kpi-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 10px;
}

.kpi-icon {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}
.kpi-icon.blue { background: var(--brand-soft); color: var(--brand-primary); }
.kpi-icon.slate { background: var(--bg-hover); color: var(--text-secondary); }
.kpi-icon.green { background: var(--status-success-bg); color: var(--status-success-text); }
.kpi-icon.purple { background: var(--status-purple-bg); color: var(--status-purple-text); }
.kpi-icon.red { background: var(--status-danger-bg); color: var(--status-danger-text); }
.kpi-icon.amber { background: var(--status-warning-bg); color: var(--status-warning-text); }

.kpi-label {
    display: block;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.kpi-value {
    font-family: var(--font-mono);
    font-size: 15px;
    font-weight: 700;
    color: var(--text-main);
    font-variant-numeric: tabular-nums;
}

/* --- 3. TOOLBAR & PILLS --- */
.toolbar-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex-shrink: 0;
}

.toolbar-row-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.search-wrap {
    position: relative;
    flex: 1;
    min-width: 260px;
    max-width: 480px;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 13px;
    pointer-events: none;
}

.toolbar-input {
    width: 100%;
    height: 36px;
    padding: 0 32px 0 36px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--text-main);
    background: var(--bg-subtle);
    outline: none;
    transition: all var(--transition-fast);
}
.toolbar-input:focus {
    background: var(--bg-surface);
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.input-clear-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 16px;
    color: var(--text-muted);
    cursor: pointer;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toolbar-select {
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-main);
}

.toolbar-btn {
    height: 34px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.toolbar-btn:hover { background: var(--bg-hover); color: var(--text-main); }
.toolbar-btn.primary-soft { background: var(--brand-soft); color: var(--brand-primary); border-color: #BFDBFE; }
.toolbar-btn.clear-btn { border-color: #FCA5A5; color: var(--status-danger-text); background: #FEF2F2; }

.toolbar-row-pills {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding-top: 8px;
    border-top: 1px solid var(--border-light);
}

.pills-label { font-size: 11px; font-weight: 600; color: var(--text-muted); }

.quick-pill {
    height: 26px;
    padding: 0 10px;
    border-radius: 999px;
    border: 1px solid var(--border-light);
    background: var(--bg-subtle);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all var(--transition-fast);
}
.quick-pill:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.quick-pill.active { background: var(--brand-primary); color: #FFFFFF; border-color: var(--brand-primary); }

.keyboard-hint { margin-left: auto; font-size: 11px; color: var(--text-muted); }

/* --- 4. DIRECTORY SHEET GRID --- */
.sheet-card {
    flex: 1;
    min-height: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.item-table-wrapper {
    flex: 1;
    overflow: auto;
    min-height: 0;
}

.ledger-grid {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.ledger-grid thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #F8FAFC;
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    height: 32px;
    padding: 0 8px;
    border-bottom: 1px solid var(--border-strong);
    border-right: 1px solid var(--border-grid);
    text-align: left;
    white-space: nowrap;
}

.ledger-grid tbody td {
    height: 30px;
    padding: 0 8px;
    border-bottom: 1px solid var(--border-grid);
    border-right: 1px solid var(--border-grid);
    background: var(--bg-surface);
    vertical-align: middle;
    font-size: 11.5px;
    color: var(--text-main);
    white-space: nowrap;
}

.ledger-grid tbody tr:hover td {
    background-color: #F8FAFC;
    cursor: pointer;
}

.sheet-footer {
    height: 40px;
    padding: 0 16px;
    border-top: 1px solid var(--border-light);
    background: var(--bg-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11.5px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.icon-btn {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    border: 1px solid var(--border-light);
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    margin: 0 1px;
    transition: all var(--transition-fast);
}
.icon-btn:hover { background: var(--brand-soft); color: var(--brand-primary); border-color: #93C5FD; }
.icon-btn.delete:hover { background: var(--status-danger-bg); color: var(--status-danger-text); border-color: #FCA5A5; }
.icon-btn.ledger:hover { background: var(--status-success-bg); color: var(--status-success-text); border-color: #6EE7B7; }

.dual-pill, .type-pill, .bal-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
}
.dual-pill { background: var(--status-purple-bg); color: var(--status-purple-text); }
.type-pill.b2b { background: var(--brand-soft); color: var(--brand-primary); }
.type-pill.b2c { background: var(--bg-hover); color: var(--text-secondary); }
.bal-pill.dr { color: var(--status-danger-text); font-family: var(--font-mono); }
.bal-pill.cr { color: var(--status-success-text); font-family: var(--font-mono); }
.bal-pill.zero { color: var(--text-muted); font-family: var(--font-mono); }

/* --- 5. MODALS & SLIDE-OVER PARTY LEDGER DRAWER --- */
.modal-backdrop, .drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
    display: none;
    z-index: 9999;
}

.modal-backdrop { justify-content: center; align-items: center; padding: 16px; }
.drawer-backdrop { justify-content: flex-end; }

.modal-content, .modal-card {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    width: 100%;
    overflow: hidden;
}
.modal-sm { max-width: 440px; }
.modal-lg { max-width: 860px; }

.drawer-panel {
    width: 520px;
    max-width: 96vw;
    height: 100vh;
    background: var(--bg-surface);
    box-shadow: -8px 0 30px rgba(15, 23, 42, 0.15);
    display: flex;
    flex-direction: column;
    animation: slideInRight 0.2s ease-out;
}
.drawer-panel.drawer-xl { width: 920px; }

@keyframes slideInRight {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.modal-header h2 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 6px;
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-main); }

.modal-body { padding: 18px 20px; overflow-y: auto; flex: 1; }

.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border-light);
    background: var(--bg-subtle);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.po-details-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.details-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
}

.ledger-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 12.5px;
    color: var(--text-main);
    background: var(--bg-surface);
    outline: none;
}
.ledger-input:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.ledger-input:disabled, .ledger-input[readonly] {
    background: var(--bg-hover);
    color: var(--text-muted);
}

.form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
}

.opening-bal-box {
    margin-top: 4px;
    padding: 10px 12px;
    background: var(--bg-subtle);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
}

.opening-bal-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--brand-primary);
    margin-bottom: 8px;
}

.dual-match-notice {
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: var(--status-purple-bg);
    color: var(--status-purple-text);
    font-size: 11.5px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* --- 6. DRAWER LEDGER STYLES --- */
.drawer-title-row { display: flex; align-items: center; gap: 10px; }

.drawer-ledger-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.dual-party-banner {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, #FAF5FF 0%, #EFF6FF 100%);
    border: 1px solid #DDD6FE;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.dual-banner-left { display: flex; align-items: center; gap: 10px; font-size: 12px; color: #4C1D95; }
.dual-stats { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--text-secondary); margin-top: 2px; }

.ledger-filter-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 12px;
    background: var(--bg-subtle);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
}

.inline-filter {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    padding: 0 8px;
    height: 32px;
}
.inline-filter label { font-size: 10px; font-weight: 700; color: var(--text-muted); }
.inline-filter input { border: none; outline: none; font-size: 11.5px; font-weight: 600; }

.drawer-kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.dkpi-box {
    background: var(--bg-subtle);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
}
.dkpi-box.highlight { background: var(--brand-soft); border-color: #BFDBFE; }
.dkpi-box span { display: block; font-size: 10px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; }
.dkpi-box strong { font-family: var(--font-mono); font-size: 14px; color: var(--text-main); }

.modal-table-wrap, .drawer-table-wrap {
    flex: 1;
    min-height: 220px;
    overflow: auto;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
}

.drawer-ledger-footer {
    justify-content: space-between;
    flex-wrap: wrap;
}
.drawer-footer-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.action-btn {
    height: 36px;
    padding: 0 15px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-family: var(--font-sans);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
}
.action-btn.primary { background: var(--brand-primary); color: #FFFFFF; }
.action-btn.primary:hover { background: var(--brand-primary-hover); }
.action-btn.secondary { background: var(--bg-surface); color: var(--text-main); border-color: var(--border-strong); }
.action-btn.secondary:hover { background: var(--bg-hover); }
.action-btn.whatsapp { background: var(--wa-green); color: #FFFFFF; }
.action-btn.whatsapp:hover { background: var(--wa-green-hover); }

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
}

.empty-grid-cell { text-align: center !important; padding: 28px !important; color: var(--text-muted) !important; }

/* --- 7. LOADING & TOASTS --- */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    backdrop-filter: blur(2px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10002;
}
.loading-card {
    background: var(--bg-surface);
    padding: 22px 28px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    font-weight: 600;
}
.spinner {
    width: 30px;
    height: 30px;
    border: 3px solid var(--border-light);
    border-top-color: var(--brand-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast-container {
    position: fixed;
    top: 18px;
    right: 20px;
    z-index: 10005;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast-msg {
    min-width: 260px;
    max-width: 380px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    background: #111827;
    color: #FFFFFF;
    font-size: 12.5px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
}
.toast-success { border-left: 4px solid #10B981; }
.toast-error { border-left: 4px solid #EF4444; }
.toast-warning { border-left: 4px solid #F59E0B; }
.toast-info { border-left: 4px solid #3B82F6; }

@media (max-width: 1200px) {
    .kpi-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
    .kpi-strip, .drawer-kpi-grid, .po-details-grid, .form-row-3 { grid-template-columns: 1fr; }
}
