/* KAD Cash - Custom Styles + Responsive System */
*, *::before, *::after { box-sizing: border-box; }

html {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', sans-serif;
    overflow-x: hidden;
    max-width: 100vw;
}

.glass {
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.bg-gradient-modern {
    background: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #ec4899 100%);
}

/* Gradient logo text (works without relying on Tailwind bg-clip utilities) */
.logo-text {
    background: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #ec4899 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
}

.scrollbar-hide::-webkit-scrollbar { display: none; }
.scrollbar-hide { -ms-overflow-style: none; scrollbar-width: none; }

/* ─── Nice right-side scrollbar (main page content) ──────────── */
.kad-scrollbar,
.page-content {
    scrollbar-width: thin;
    scrollbar-color: rgba(99, 102, 241, 0.55) rgba(241, 245, 249, 0.9);
}
.kad-scrollbar::-webkit-scrollbar,
.page-content::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
.kad-scrollbar::-webkit-scrollbar-track,
.page-content::-webkit-scrollbar-track {
    background: rgba(241, 245, 249, 0.95);
    border-radius: 999px;
    margin: 6px 0;
}
.kad-scrollbar::-webkit-scrollbar-thumb,
.page-content::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #818cf8 0%, #a855f7 100%);
    border-radius: 999px;
    border: 2px solid rgba(241, 245, 249, 0.95);
    min-height: 40px;
}
.kad-scrollbar::-webkit-scrollbar-thumb:hover,
.page-content::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #6366f1 0%, #9333ea 100%);
}
/* Keep page scroll visible even if markup still has scrollbar-hide */
.page-content.scrollbar-hide {
    -ms-overflow-style: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(99, 102, 241, 0.55) rgba(241, 245, 249, 0.9);
}
.page-content.scrollbar-hide::-webkit-scrollbar {
    display: block;
    width: 10px;
}

.active-tab { position: relative; color: #6366f1; }
.active-tab::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 3px;
    background: #6366f1;
    border-radius: 99px;
}

@keyframes pulse-ring {
    0% { transform: scale(.33); }
    80%, 100% { opacity: 0; }
}

.animate-pulse-ring::before {
    content: '';
    position: absolute;
    left: -8px; top: -8px; right: -8px; bottom: -8px;
    border-radius: 9999px;
    background-color: #ef4444;
    animation: pulse-ring 1.25s cubic-bezier(0.455, 0.03, 0.515, 0.955) infinite;
}

/* ─── Page content area ─────────────────────────────────────── */
.page-content {
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
}

@media (min-width: 768px) {
    .page-content { padding-bottom: 1rem; }
}

/* ─── App shell ───────────────────────────────────────────────── */
.app-shell { min-height: 100dvh; max-width: 100vw; overflow: hidden; }

/* ─── Flash messages ──────────────────────────────────────────── */
#flash-message {
    left: 1rem;
    right: 1rem;
    max-width: calc(100vw - 2rem);
}

@media (min-width: 640px) {
    #flash-message { left: auto; right: 1rem; max-width: 24rem; }
}

/* ─── Mobile sidebar ──────────────────────────────────────────── */
#mobile-sidebar {
    display: none;
    align-items: stretch;
    justify-content: flex-start;
}
#mobile-sidebar:not(.hidden) {
    display: flex;
}
#mobile-sidebar .mobile-sidebar-panel {
    width: min(300px, 88vw);
    height: calc(100dvh - 2rem);
    max-height: calc(100dvh - 2rem);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: translateX(-110%);
    transition: transform 0.25s ease;
    -webkit-overflow-scrolling: touch;
}

#mobile-sidebar:not(.hidden) .mobile-sidebar-panel {
    transform: translateX(0);
}

#mobile-sidebar .mobile-sidebar-panel .mobile-sidebar-nav {
    flex: 1 1 auto;
    min-height: 0; /* allow scroll inside flex column */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding-bottom: 0.5rem;
}

#mobile-sidebar .mobile-sidebar-panel .mobile-sidebar-header,
#mobile-sidebar .mobile-sidebar-panel .mobile-sidebar-footer {
    flex-shrink: 0;
}

body.sidebar-open { overflow: hidden; }

/* ─── Desktop sidebar (scroll all menu items) ─────────────────── */
.desktop-sidebar {
    max-height: calc(100dvh - 2rem);
    min-height: 0;
}
.desktop-sidebar-nav {
    min-height: 0;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
.desktop-sidebar-brand,
.desktop-sidebar-footer {
    flex-shrink: 0;
}

/* ─── Bottom navigation ───────────────────────────────────────── */
.bottom-nav {
    height: calc(4.5rem + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bottom-nav a,
.bottom-nav button {
    min-width: 44px;
    min-height: 44px;
}

/* ─── Modal overlay ───────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: none;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    overflow-y: auto;
}

.modal-overlay:not(.hidden) {
    display: flex;
}

@media (min-width: 640px) {
    .modal-overlay:not(.hidden) {
        align-items: center;
        padding: 1rem;
    }
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 28rem;
    background: white;
    border-radius: 1.5rem 1.5rem 0 0;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    padding: 1.25rem;
    max-height: 90vh;
    max-height: 90dvh;
    overflow-y: auto;
    margin-top: auto;
}

@media (min-width: 640px) {
    .modal-content {
        border-radius: 2rem;
        padding: 2rem;
        max-height: 85vh;
        margin-top: 0;
    }
}

.modal-content-wide { max-width: 32rem; }

/* ─── Form inputs ─────────────────────────────────────────────── */
.kad-input {
    width: 100%;
    background: #f9fafb;
    border: 1px solid #f3f4f6;
    padding: 0.75rem;
    border-radius: 0.75rem;
    font-weight: 500;
    font-size: 16px; /* prevents iOS zoom on focus */
    outline: none;
    transition: all 0.2s;
}
.kad-input:focus {
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.kad-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: #9ca3af;
    text-transform: uppercase;
    margin-left: 0.25rem;
}

.kad-btn-primary {
    width: 100%;
    background: #4f46e5;
    color: white;
    padding: 0.875rem 1rem;
    min-height: 44px;
    border-radius: 1rem;
    font-weight: 700;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
    border: none;
    cursor: pointer;
}
.kad-btn-primary:hover { background: #4338ca; }
.kad-btn-primary:active { transform: scale(0.98); }

/* ─── OTP digit boxes ─────────────────────────────────────────── */
.otp-digits {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
}
@media (min-width: 640px) {
    .otp-digits { gap: 0.65rem; }
}
.otp-digit {
    width: 2.75rem;
    height: 3.25rem;
    text-align: center;
    font-size: 1.35rem;
    font-weight: 800;
    color: #1f2937;
    background: #fff;
    border: 2px solid #e5e7eb;
    border-radius: 0.9rem;
    outline: none;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
    caret-color: #4f46e5;
}
@media (min-width: 640px) {
    .otp-digit {
        width: 3.15rem;
        height: 3.6rem;
        font-size: 1.5rem;
        border-radius: 1rem;
    }
}
.otp-digit:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.18);
    transform: translateY(-1px);
}
.otp-digit.is-filled {
    border-color: #a5b4fc;
    background: #eef2ff;
}
.otp-digit.is-error {
    border-color: #f87171;
    background: #fef2f2;
}

/* Touch-friendly action buttons */
.btn-touch {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ─── Stat cards ──────────────────────────────────────────────── */
.stat-card {
    padding: 1rem 1.25rem;
    border-radius: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 7rem;
    height: auto;
}
.stat-card h4 {
    font-size: clamp(1.125rem, 4vw, 1.5rem);
    word-break: break-word;
}
.stat-card:hover { box-shadow: 0 4px 6px rgba(0,0,0,0.1); }

@media (min-width: 640px) {
    .stat-card {
        padding: 1.5rem;
        border-radius: 2rem;
        min-height: 9rem;
    }
}

/* ─── Responsive tables ───────────────────────────────────────── */
.kad-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

.kad-table-wrap table {
    min-width: 520px;
}

.kad-table-wrap table th,
.kad-table-wrap table td {
    white-space: nowrap;
}

@media (max-width: 767px) {
    .kad-table-wrap table th,
    .kad-table-wrap table td {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
        font-size: 0.8125rem;
    }
}

/* Mobile card list (alternative to tables) */
.mobile-card-list { display: flex; flex-direction: column; gap: 0.75rem; }
.mobile-data-card {
    background: rgba(255,255,255,0.6);
    border: 1px solid #f3f4f6;
    border-radius: 1rem;
    padding: 1rem;
}

/* ─── Chart containers ────────────────────────────────────────── */
.chart-container {
    position: relative;
    width: 100%;
    height: 220px;
}
@media (min-width: 640px) { .chart-container { height: 280px; } }
@media (min-width: 1024px) { .chart-container { height: 300px; } }

/* ─── PIN keypad ──────────────────────────────────────────────── */
.pin-key {
    height: 3rem;
    min-height: 44px;
    border-radius: 0.75rem;
    font-weight: 900;
    font-size: 1.125rem;
    transition: all 0.2s;
    background: white;
    border: 1px solid #f3f4f6;
    color: #374151;
    cursor: pointer;
}
@media (min-width: 640px) { .pin-key { height: 3.5rem; } }
.pin-key:hover { background: #f9fafb; }
.pin-key:active { transform: scale(0.95); }
.pin-key-ok { background: #4f46e5; color: white; border: none; }

/* ─── Page headers ────────────────────────────────────────────── */
.page-header {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
@media (min-width: 640px) {
    .page-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}

.page-header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
}
@media (min-width: 640px) {
    .page-header-actions { width: auto; }
}

/* ─── Filter bars ─────────────────────────────────────────────── */
.filter-bar {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
@media (min-width: 640px) {
    .filter-bar {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 1rem;
    }
}

.filter-bar select {
    width: 100%;
    min-height: 44px;
    padding: 0.5rem 0.75rem;
    border-radius: 0.75rem;
    border: 1px solid #e5e7eb;
    background: #f9fafb;
    font-weight: 600;
    font-size: 16px;
}
@media (min-width: 640px) {
    .filter-bar select { width: auto; min-width: 140px; }
}

/* ─── Transaction / list rows ─────────────────────────────────── */
.list-row {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.875rem;
    border-radius: 0.75rem;
    border: 1px solid #f3f4f6;
    background: #f9fafb;
}
@media (min-width: 480px) {
    .list-row {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}

/* ─── Category pills scroll ───────────────────────────────────── */
.pill-scroll {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.25rem;
    scrollbar-width: none;
}
.pill-scroll::-webkit-scrollbar { display: none; }
.pill-scroll a {
    flex-shrink: 0;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
}

/* ─── Pagination ──────────────────────────────────────────────── */
.kad-pagination {
    padding: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.kad-pagination a {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.75rem;
    background: white;
    border: 1px solid #f3f4f6;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* ─── Drop zone ───────────────────────────────────────────────── */
.drop-zone {
    border: 3px dashed #e5e7eb;
    border-radius: 1.5rem;
    padding: 2rem 1rem;
    text-align: center;
}
@media (min-width: 640px) {
    .drop-zone {
        border-width: 4px;
        border-radius: 2.5rem;
        padding: 3rem 2rem;
    }
}

/* ─── Grid forms stack on mobile ──────────────────────────────── */
@media (max-width: 479px) {
    .grid-cols-2 { grid-template-columns: 1fr !important; }
}

/* ─── Profile / detail info rows ──────────────────────────────── */
.info-row {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.5rem 0;
}
@media (min-width: 400px) {
    .info-row {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 1rem;
    }
    .info-row span:last-child { text-align: right; max-width: 60%; word-break: break-word; }
}

/* ─── Hide desktop-only / show mobile-only ────────────────────── */
@media (max-width: 767px) {
    .hide-mobile { display: none !important; }
}
@media (min-width: 768px) {
    .show-mobile-only { display: none !important; }
}

/* Touch devices: show action buttons without hover */
@media (max-width: 767px) {
    .group .opacity-0,
    .group-hover\:opacity-100 {
        opacity: 1 !important;
    }
}

/* ─── Top app header ──────────────────────────────────────────── */
.app-top-header {
    min-height: 4rem;
    height: auto;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}
.app-top-header h2 {
    font-size: clamp(1rem, 4.5vw, 1.5rem);
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: min(55vw, 280px);
}
@media (min-width: 768px) {
    .app-top-header h2 { max-width: none; white-space: normal; }
}
