/* 
 * WOH Caloocan App Styles 
 * Mobile-first design system
 */

 :root {
    --woh-primary: #10B981;
    --woh-primary-hover: #059669;
    --woh-bg: #f3f4f6;
    --woh-surface: #ffffff;
    --woh-text: #1f2937;
    --woh-text-muted: #6b7280;
    --woh-border: #e5e7eb;
    --sidebar-width: 260px;
    --topbar-height: 64px;
}

body.woh-app-body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--woh-bg);
    color: var(--woh-text);
    overflow-x: hidden;
}

/* Base Layout */
.woh-app-container {
    display: flex;
    min-height: calc(100vh - var(--topbar-height));
    padding-top: var(--topbar-height);
}

.woh-main {
    flex: 1;
    min-width: 0; /* prevent flex blowout */
    transition: margin-left 0.3s ease;
}

.woh-content {
    padding: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
    animation: fadeIn 0.3s ease-in-out;
}

/* Topbar */
.woh-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: var(--woh-surface);
    border-bottom: 1px solid var(--woh-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 50;
    box-shadow: 0 1px 2px 0 rgba(0,0,0,0.05);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 600;
    font-size: 1.125rem;
}

.topbar-logo {
    height: 32px;
    width: auto;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--woh-text-muted);
    padding: 0.5rem;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: var(--woh-bg);
    color: var(--woh-text);
}

/* User Dropdown */
.user-dropdown {
    position: relative;
}

.user-dropdown-btn {
    background: none;
    border: none;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: background 0.2s;
}

.user-dropdown-btn:hover {
    background: var(--woh-bg);
}

.user-dropdown-btn .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.user-dropdown-btn .user-name {
    font-weight: 500;
    font-size: 0.875rem;
    display: none;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--woh-surface);
    border: 1px solid var(--woh-border);
    border-radius: 6px;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
    min-width: 160px;
    padding: 0.5rem 0;
    display: none;
    margin-top: 0.5rem;
}

.dropdown-menu.show {
    display: block;
    animation: fadeInDown 0.2s ease-out;
}

.dropdown-item {
    display: block;
    padding: 0.5rem 1rem;
    color: var(--woh-text);
    text-decoration: none;
    font-size: 0.875rem;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
}

.dropdown-item:hover {
    background: var(--woh-bg);
}

.dropdown-divider {
    height: 1px;
    background: var(--woh-border);
    margin: 0.5rem 0;
}

.text-danger { color: #dc2626; }

/* Dashboard Grids */
.woh-dashboard-grid {
    display: grid;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}
.woh-grid-3 { grid-template-columns: repeat(3, 1fr); }
.woh-grid-2 { grid-template-columns: repeat(2, 1fr); }

@media (max-width: 1023px) {
    .woh-grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
    .woh-grid-3, .woh-grid-2 { grid-template-columns: 1fr; }
}

/* Sidebar */
.woh-sidebar {
    position: fixed;
    top: var(--topbar-height);
    bottom: 0;
    left: calc(-1 * var(--sidebar-width));
    width: var(--sidebar-width);
    background: var(--woh-surface);
    border-right: 1px solid var(--woh-border);
    overflow-y: auto;
    transition: left 0.3s ease;
    z-index: 40;
}

.woh-sidebar.open {
    left: 0;
}

.sidebar-nav {
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--woh-text-muted);
    text-decoration: none;
    border-radius: 6px;
    font-weight: 500;
    transition: all 0.2s;
}

.sidebar-link svg {
    width: 20px;
    height: 20px;
}

.sidebar-link:hover {
    background: var(--woh-bg);
    color: var(--woh-text);
}

.sidebar-link.active {
    background: var(--woh-primary);
    color: white;
}

.sidebar-group {
    list-style: none;
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 600;
    color: #9ca3af;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    padding-left: 1rem;
    letter-spacing: 0.05em;
}

/* Progress Bar */
#woh-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: var(--woh-primary);
    z-index: 9999;
    transition: width 0.3s ease;
    width: 0;
    border-top-right-radius: 3px;
    border-bottom-right-radius: 3px;
}

/* Animations */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeInDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* Breakpoints */
@media (min-width: 768px) {
    .user-dropdown-btn .user-name { display: block; }
}

@media (min-width: 1024px) {
    .woh-sidebar {
        left: 0; /* Always show on desktop */
    }
    .woh-main {
        margin-left: var(--sidebar-width);
    }
    #woh-sidebar-toggle {
        display: none; /* Hide toggle on desktop */
    }
}

/* Premium Additions */
.card {
    transition: transform 0.2s, box-shadow 0.2s;
}
.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

.btn-primary {
    background: linear-gradient(135deg, var(--woh-primary) 0%, #047857 100%);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.4);
    transition: all 0.3s ease;
}
.btn-primary:hover {
    box-shadow: 0 10px 15px -3px rgba(16, 185, 129, 0.5);
    transform: translateY(-1px);
}

/* Glassmorphism for topbar */
.woh-topbar {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

table tr {
    transition: background-color 0.2s;
}
table tbody tr:hover {
    background-color: #f9fafb;
}

/* Modern Input Focus */
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--woh-primary) !important;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

/* Mobile Backdrop */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    z-index: 35;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.sidebar-backdrop.show {
    display: block;
    opacity: 1;
}

@media (max-width: 1023px) {
    .woh-content {
        padding: 1rem;
    }
    .card {
        padding: 1rem !important;
    }
    .header-section {
        flex-direction: column;
        align-items: flex-start !important;
    }
    .header-section > div:last-child {
        width: 100%;
        justify-content: space-between;
    }
}

/* ─── Global Overflow Protection ─────────────────────────── */

/* Tables always scroll rather than overflow */
.woh-content table,
.rep-card table,
[style*="overflow-x:auto"] table {
    min-width: 500px;
}
.woh-content .table-wrap,
.rep-card > div[style*="overflow-x"] {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Force all inline-styled horizontal scroll wrappers */
div[style*="overflow-x: auto"],
div[style*="overflow-x:auto"] {
    max-width: 100%;
}

/* ─── Mobile (<640px) ─────────────────────────────────────── */
@media (max-width: 640px) {

    /* Content padding */
    .woh-content {
        padding: 0.75rem;
    }

    /* Page titles */
    h1[style*="font-size: 1.5rem"],
    h1[style*="font-size:1.5rem"] {
        font-size: 1.2rem !important;
    }

    /* Make 2-col grids 1-col on mobile */
    div[style*="grid-template-columns: 1fr 1fr"],
    div[style*="grid-template-columns:1fr 1fr"],
    div[style*="grid-template-columns: repeat(2"],
    div[style*="grid-template-columns:repeat(2"] {
        grid-template-columns: 1fr !important;
    }

    /* Balance/stat cards – robust grid */
    #wohBalanceCards {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }
    @media (min-width: 480px) {
        #wohBalanceCards { grid-template-columns: repeat(2, 1fr) !important; }
    }
    @media (min-width: 1024px) {
        #wohBalanceCards { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)) !important; }
    }


    /* Filter rows – stack vertically */
    .rep-filter-row,
    div[style*="display:flex"][style*="flex-wrap:wrap"],
    div[style*="display: flex"][style*="flex-wrap: wrap"] {
        flex-direction: column;
        align-items: stretch !important;
    }
    .rep-filter-group { width: 100%; }
    .rep-filter-group select,
    .rep-filter-group input[type="date"] { width: 100%; }

    /* Header action rows */
    div[style*="display:flex"][style*="justify-content:space-between"],
    div[style*="display: flex"][style*="justify-content: space-between"] {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Tabs – horizontal scroll */
    div[style*="border-bottom:2px solid"][style*="display:flex"],
    div[style*="border-bottom: 2px solid"][style*="display: flex"] {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap !important;
        padding-bottom: 0;
    }

    /* Tab buttons – no shrink */
    .rep-tab-btn { flex-shrink: 0; }
    .woh-tab-btn { flex-shrink: 0; }

    /* Finance balance cards – specific overrides */
    #wohBalanceCards .woh-acc-card { 
        min-width: unset !important; 
        width: 100% !important; 
        flex: none !important;
    }
    .woh-acc-card .acc-balance {
        word-break: break-all;
        line-height: 1.2;
    }
    .woh-acc-card .acc-sub {
        flex-wrap: wrap;
        row-gap: 0.25rem;
    }


    /* Finance chart containers */
    #wohChartsRow { flex-direction: column !important; }
    #wohMonthlyChartWrap,
    #wohAccountChartWrap {
        height: 280px !important;
        min-height: 280px !important;
    }

    /* Record Transaction Button – Bigger on mobile */
    .woh-finance-page .btn-primary[onclick*="wohOpenFinanceModal"] {
        width: 100%;
        padding: 0.85rem !important;
        font-size: 1rem !important;
        justify-content: center;
        margin-top: 0.5rem;
    }


    /* Modal – full width on mobile */
    div[style*="max-width:580px"],
    div[style*="max-width: 580px"],
    div[style*="max-width:500px"],
    div[style*="max-width: 500px"],
    div[style*="max-width:340px"],
    div[style*="max-width: 340px"] {
        max-width: 100% !important;
        margin: 0.5rem !important;
        width: calc(100% - 1rem) !important;
    }

    /* Table action columns – wrap buttons */
    .rep-tbl td:last-child,
    .woh-tbl td:last-child {
        white-space: normal;
    }

    /* Report stats grid – 2 per row */
    #repStatsRow {
        grid-template-columns: 1fr 1fr !important;
    }

    /* Report category cards – 1 col */
    #repContent > div[style*="grid-template-columns:1fr 1fr"],
    #repContent > div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Profile page – avatar row */
    .woh-profile-page div[style*="display: flex"][style*="align-items: center"][style*="gap: 1.5rem"] {
        flex-wrap: wrap;
        gap: 1rem !important;
    }

    /* Topbar brand text – hide on very small screens */
    .topbar-brand span { display: none; }

    /* Button groups – full width */
    div[style*="justify-content:flex-end"],
    div[style*="justify-content: flex-end"] {
        justify-content: stretch !important;
    }
    div[style*="justify-content:flex-end"] button,
    div[style*="justify-content: flex-end"] button {
        flex: 1;
    }
}

/* ─── Small Tablet (641–1023px) ───────────────────────────── */
@media (min-width: 641px) and (max-width: 1023px) {
    /* Finance balance cards – grid layout for tablets */
    #wohBalanceCards { 
        grid-template-columns: repeat(2, 1fr) !important;
    }
    #wohBalanceCards .woh-acc-card { width: auto !important; }


    /* Report stat cards */
    #repStatsRow { grid-template-columns: repeat(3, 1fr) !important; }

    /* Modal max-width relaxed */
    div[style*="max-width:580px"],
    div[style*="max-width: 580px"] {
        max-width: 90vw !important;
    }
}

/* ─── Help System ────────────────────────────────────────── */
.help-icon-btn {
    color: var(--woh-text-muted);
}
.help-icon-btn:hover {
    color: var(--woh-primary);
    background: rgba(16, 185, 129, 0.1);
}

.woh-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.woh-modal-backdrop.show {
    display: flex;
    opacity: 1;
}

.woh-modal-card {
    background: var(--woh-surface);
    width: 100%;
    max-width: 600px;
    max-height: calc(100vh - 40px);
    border-radius: 12px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px);
    transition: transform 0.3s ease;
}
.woh-modal-backdrop.show .woh-modal-card {
    transform: translateY(0);
}

.woh-modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--woh-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.woh-modal-header h2 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--woh-text);
}

.woh-modal-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.5rem;
    color: var(--woh-text-muted);
    line-height: 1;
}

.woh-modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}
.help-section {
    margin-bottom: 1.5rem;
}
.help-section:last-child {
    margin-bottom: 0;
}
.help-section h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0 0 0.75rem 0;
    color: var(--woh-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.help-section ul {
    margin: 0;
    padding-left: 1.25rem;
    list-style-type: none;
}
.help-section li {
    font-size: 0.875rem;
    color: var(--woh-text);
    margin-bottom: 0.6rem;
    position: relative;
}
.help-section li::before {
    content: "•";
    color: var(--woh-primary);
    position: absolute;
    left: -1rem;
    font-weight: bold;
}
.help-section li strong {
    color: #111827;
}

.woh-modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--woh-border);
    display: flex;
    justify-content: flex-end;
}
