@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --app-sidebar-width: 260px;
    --app-bg: #f4f6fb;
    --app-surface: #ffffff;
    --app-border: #e8ecf4;
    --app-text: #0f172a;
    --app-muted: #64748b;
    --app-primary: #2563eb;
    --app-primary-soft: #eff6ff;
    --app-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.04);
    --app-radius: 14px;
}

html, body {
    min-height: 100%;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: var(--app-text);
    background: var(--app-bg);
}

body.minimal-layout {
    background: linear-gradient(135deg, #f5f7fa 0%, #e4ecf7 100%);
}

/* ---- App Shell ---- */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-sidebar {
    width: var(--app-sidebar-width);
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1040;
    transition: transform 0.25s ease;
}

.app-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.app-sidebar-logo {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.85rem;
    color: #fff;
    letter-spacing: 0.04em;
}

.app-sidebar-title {
    font-weight: 700;
    font-size: 1rem;
    color: #fff;
    line-height: 1.2;
}

.app-sidebar-subtitle {
    font-size: 0.7rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.app-sidebar-nav {
    flex: 1;
    padding: 1rem 0.75rem;
    overflow-y: auto;
}

.app-nav-section {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #64748b;
    padding: 0.75rem 0.75rem 0.35rem;
}

.app-nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    margin-bottom: 0.15rem;
    border-radius: 10px;
    color: #cbd5e1;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.app-nav-link i {
    font-size: 1.1rem;
    width: 1.25rem;
    text-align: center;
    opacity: 0.85;
}

.app-nav-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.app-nav-link.active {
    background: rgba(37, 99, 235, 0.25);
    color: #fff;
}

.app-nav-link.active i {
    color: #93c5fd;
}

.app-sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.app-user-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
}

.app-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
}

.app-user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: #fff;
    line-height: 1.2;
}

.app-user-role {
    font-size: 0.72rem;
    color: #94a3b8;
}

.app-main {
    flex: 1;
    margin-left: var(--app-sidebar-width);
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--app-surface);
    border-bottom: 1px solid var(--app-border);
    position: sticky;
    top: 0;
    z-index: 1030;
}

.app-content {
    flex: 1;
    padding: 1.5rem 1.75rem 2rem;
}

.app-footer {
    padding: 1rem 1.75rem;
    font-size: 0.78rem;
    color: var(--app-muted);
    border-top: 1px solid var(--app-border);
    background: var(--app-surface);
}

/* ---- Page Header ---- */
.page-header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.75rem;
}

.page-header-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: var(--app-primary-soft);
    color: var(--app-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    flex-shrink: 0;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.02em;
}

.page-subtitle {
    margin: 0.25rem 0 0;
    color: var(--app-muted);
    font-size: 0.9rem;
}

/* ---- Stat Cards ---- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    padding: 1.15rem 1.25rem;
    box-shadow: var(--app-shadow);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-card-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.stat-card-icon.warning { background: #fffbeb; color: #d97706; }
.stat-card-icon.success { background: #ecfdf5; color: #059669; }
.stat-card-icon.danger { background: #fef2f2; color: #dc2626; }
.stat-card-icon.primary { background: #eff6ff; color: #2563eb; }
.stat-card-icon.info { background: #ecfeff; color: #0891b2; }
.stat-card-icon.purple { background: #f5f3ff; color: #7c3aed; }

.stat-card-label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--app-muted);
}

.stat-card-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
    margin-top: 0.15rem;
}

.stat-card-sub {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--app-muted);
    margin-top: 0.2rem;
}

.stat-card-kpi {
    cursor: pointer;
    border: 1px solid var(--app-border);
    width: 100%;
    text-align: left;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.stat-card-kpi:hover {
    border-color: #93c5fd;
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.08);
}

.stat-grid-kpi {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

/* ---- Tenant management ---- */
.page-header.flex-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tenant-detail-header h2 {
    letter-spacing: -0.02em;
}

.tenant-detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1.25rem;
    font-size: 0.875rem;
    color: var(--app-muted);
}

.detail-tabs {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.25rem;
    -webkit-overflow-scrolling: touch;
}

.detail-tab {
    border: 1px solid var(--app-border);
    background: var(--app-surface);
    border-radius: 999px;
    padding: 0.55rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--app-muted);
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: all 0.15s ease;
}

.detail-tab:hover {
    border-color: #cbd5e1;
    color: var(--app-text);
}

.detail-tab.active {
    background: var(--app-primary-soft);
    border-color: #93c5fd;
    color: var(--app-primary);
}

.tenant-mobile-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.75rem;
}

.tenant-mobile-card,
.tenant-transaction-card {
    background: #fafbfd;
    border: 1px solid var(--app-border);
    border-radius: 12px;
    padding: 0.9rem 1rem;
}

.tenant-mobile-card {
    cursor: pointer;
    transition: border-color 0.15s ease;
}

.tenant-mobile-card:active {
    border-color: #93c5fd;
}

.tenant-mobile-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.tenant-mobile-card-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--app-border);
}

.tenant-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 1050;
}

.tenant-modal {
    position: fixed;
    inset: 0;
    z-index: 1060;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    pointer-events: none;
}

.tenant-modal-content {
    width: 100%;
    max-width: 480px;
    pointer-events: auto;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
}

.tenant-modal-wide {
    max-width: 820px;
}

.form-section-title {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--app-muted);
    margin-bottom: 0.75rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--app-border);
}

/* ---- Panels ---- */
.panel-card {
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow);
    overflow: hidden;
}

.panel-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--app-border);
    background: #fafbfd;
}

.panel-card-header h5,
.panel-card-header .panel-title {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.panel-card-body {
    padding: 1.25rem;
}

/* ---- Quick Actions ---- */
.action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
}

.action-card {
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    padding: 1.25rem;
    box-shadow: var(--app-shadow);
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
    height: 100%;
}

.action-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 28px rgba(15, 23, 42, 0.08);
    border-color: #c7d2fe;
    color: inherit;
}

.action-card-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.action-card-title {
    font-weight: 600;
    font-size: 1rem;
    margin: 0;
}

.action-card-desc {
    font-size: 0.85rem;
    color: var(--app-muted);
    margin: 0;
    flex: 1;
}

.action-card-link {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--app-primary);
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

/* ---- Tabs / Pills ---- */
.report-tabs {
    display: inline-flex;
    gap: 0.35rem;
    padding: 0.25rem;
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: 12px;
    margin-bottom: 1.5rem;
}

.report-tab {
    padding: 0.5rem 1rem;
    border-radius: 9px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--app-muted);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: background 0.15s, color 0.15s;
}

.report-tab:hover {
    color: var(--app-primary);
    background: var(--app-primary-soft);
}

.report-tab.active {
    background: var(--app-primary);
    color: #fff;
}

/* ---- Forms ---- */
.form-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: #334155;
}

.form-control, .form-select {
    border-radius: 10px;
    border-color: var(--app-border);
    padding: 0.6rem 0.85rem;
    font-size: 0.9rem;
}

.form-control:focus, .form-select:focus {
    border-color: #93c5fd;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.btn {
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.875rem;
    padding: 0.55rem 1rem;
}

.btn-primary {
    background: var(--app-primary);
    border-color: var(--app-primary);
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

/* ---- Tables ---- */
.data-table {
    margin: 0;
}

.data-table thead th {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--app-muted);
    background: #f8fafc;
    border-bottom: 1px solid var(--app-border);
    padding: 0.85rem 1.25rem;
    white-space: nowrap;
}

.data-table tbody td {
    padding: 0.85rem 1.25rem;
    vertical-align: middle;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.875rem;
}

.data-table tbody tr:hover {
    background: #f8fafc;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* ---- Reconciliation report ---- */
.recon-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.recon-table thead th {
    padding: 0.65rem 0.55rem;
    font-size: 0.68rem;
    cursor: help;
}

.recon-table tbody td {
    padding: 0.6rem 0.55rem;
    font-size: 0.8rem;
}

.recon-table .recon-col-date { min-width: 5.5rem; max-width: 6.5rem; }
.recon-table .recon-col-tenant { min-width: 4.5rem; max-width: 7rem; }
.recon-table .recon-col-order { min-width: 6.5rem; max-width: 9rem; }
.recon-table .recon-col-code { min-width: 4rem; max-width: 5.5rem; }
.recon-table .recon-col-bank { min-width: 4.5rem; max-width: 7rem; }
.recon-table .recon-col-num { width: 3rem; }
.recon-table .recon-col-money { min-width: 5rem; white-space: nowrap; }

.recon-date {
    display: block;
    font-variant-numeric: tabular-nums;
    color: #475569;
    white-space: nowrap;
}

.recon-pay-cell {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    align-items: flex-start;
}

.recon-paid-badge {
    font-size: 0.62rem !important;
    padding: 0.2em 0.45em !important;
}

.recon-tenant-name,
.recon-bank,
.recon-code-text {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 6.5rem;
}

.recon-code {
    display: block;
    font-size: 0.72rem;
    padding: 0.15rem 0.35rem;
    background: #f8fafc;
    border-radius: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 8.5rem;
}

.recon-money {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.recon-money-merchant { color: #059669; }
.recon-money-paratika { color: #64748b; }

.recon-table tbody tr.recon-row-paid {
    background: #f8fffb;
}

.recon-table tbody tr.recon-row-paid:hover {
    background: #f0fdf4;
}

@media (max-width: 1200px) {
    .stat-grid-kpi {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }

    .stat-grid-kpi .stat-card-value {
        font-size: 1.2rem;
    }
}

/* ---- Payment error detail modal ---- */
.payment-error-modal .panel-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.payment-error-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--app-muted);
    margin-bottom: 0.2rem;
}

.payment-error-section-title {
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--app-muted);
}

.payment-error-summary {
    background: #f8fafc;
    border: 1px solid var(--app-border);
    border-radius: 12px;
    padding: 1rem 1.1rem;
}

.payment-error-reason {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 12px;
    padding: 1rem 1.1rem;
}

.payment-error-reason-title {
    font-weight: 700;
    color: #991b1b;
    margin-bottom: 0.35rem;
}

/* ---- Badges ---- */
.badge-soft {
    font-weight: 600;
    font-size: 0.72rem;
    padding: 0.35em 0.65em;
    border-radius: 6px;
}

.badge-soft-success { background: #dcfce7; color: #166534; }
.badge-soft-warning { background: #fef3c7; color: #92400e; }
.badge-soft-danger { background: #fee2e2; color: #991b1b; }
.badge-soft-info { background: #e0f2fe; color: #075985; }
.badge-soft-secondary { background: #f1f5f9; color: #475569; }
.badge-soft-primary { background: #dbeafe; color: #1e40af; }

/* ---- Alerts ---- */
.alert-modern {
    border-radius: 12px;
    border: none;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ---- Provider list ---- */
.provider-list .list-group-item {
    border: 1px solid var(--app-border);
    border-radius: 12px !important;
    margin-bottom: 0.5rem;
    padding: 1rem;
}

.provider-list .list-group-item.active {
    background: var(--app-primary-soft);
    border-color: #93c5fd;
    color: var(--app-text);
}

.provider-list .list-group-item.active .fw-semibold {
    color: var(--app-primary);
}

/* ---- Success panel ---- */
.success-panel {
    border: 1px solid #a7f3d0;
    background: linear-gradient(180deg, #ecfdf5 0%, #fff 40%);
}

.success-panel .panel-card-header {
    background: #059669;
    color: #fff;
    border: none;
}

/* ---- Empty ---- */
.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--app-muted);
}

.empty-state i {
    font-size: 2rem;
    opacity: 0.4;
    margin-bottom: 0.75rem;
}

/* ---- Welcome banner ---- */
.welcome-banner {
    background: linear-gradient(135deg, #1e40af 0%, #2563eb 50%, #3b82f6 100%);
    border-radius: var(--app-radius);
    padding: 1.5rem 1.75rem;
    color: #fff;
    margin-bottom: 1.5rem;
    position: relative;
    overflow: hidden;
}

.welcome-banner::after {
    content: '';
    position: absolute;
    right: -20px;
    top: -20px;
    width: 140px;
    height: 140px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 50%;
}

.welcome-banner h2 {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0 0 0.35rem;
}

.welcome-banner p {
    margin: 0;
    opacity: 0.88;
    font-size: 0.9rem;
}

/* ---- Payment / legacy ---- */
.payment-page { min-height: 100vh; }
.payment-card { border: none; border-radius: 1rem; overflow: hidden; }
.payment-summary { background: #f8f9fa; border-radius: 0.75rem; padding: 1rem; }
.result-icon { font-size: 4rem; line-height: 1; }

/* ---- Responsive ---- */
@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
    }

    .app-sidebar.show {
        transform: translateX(0);
    }

    .app-main {
        margin-left: 0;
    }

    .app-topbar {
        display: flex;
    }

    .app-content {
        padding: 1rem;
    }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.5);
        z-index: 1035;
    }

    .sidebar-backdrop.show {
        display: block;
    }
}

@media (min-width: 992px) {
    .sidebar-backdrop {
        display: none !important;
    }
}
