/* refined style.css */
:root {
    --primary-color: #007bff;
    --primary-dark: #0056b3;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --bg-color: #f4f7f6;
    --card-bg: #ffffff;
    --text-color: #333333;
    --text-muted: #6c757d;
    --border-radius: 8px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --header-height: 70px;
    --sidebar-width: 280px;
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --content-padding: 20px;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Auth Pages */
body:has(.login-container) {
    justify-content: center;
    align-items: center;
}

/* Fallback for browsers not supporting :has or generic styling */
.login-container {
    background: var(--card-bg);
    padding: 3rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 420px;
    margin: 20px auto;
    /* Auto margin for centering if flex fails or on small screens */
}

.main-content {
    padding: var(--content-padding);
}

@media (max-width: 480px) {
    body {
        font-size: 18px;
        /* Explicit base size as requested ~115% */
    }

    .login-container {
        padding: 1.5rem;
        width: 90%;
        /* Updated to 90% */
        max-width: 350px;
    }
}

.login-container h2 {
    color: var(--primary-color);
    margin-bottom: 2rem;
    font-weight: 600;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: #555;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 1px solid #ced4da;
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

button[type="submit"] {
    margin-top: 1rem;
    font-weight: 600;
    padding: 0.9rem;
}

/* Dashboard Layout */
.wrapper {
    display: flex;
    width: 100%;
}

/* Content area - add margin on desktop to account for sidebar */
#content {
    flex: 1;
    transition: margin-left 0.3s;
}

@media (min-width: 992px) {
    #content {
        margin-left: 250px;
    }
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: #2c3e50;
    color: white;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 99999;
    /* Standardized extremely high z-index to stay ahead of EVERYTHING */
    overflow-y: hidden;
    /* Changed from auto to prevent double scrollbars; inner components will scroll */
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    /* Use percentage for better responsiveness */
    visibility: hidden;
}

.sidebar.active {
    transform: translateX(0);
    box-shadow: 5px 0 15px rgba(0, 0, 0, 0.1);
    visibility: visible;
}

/* Prevent flicker when state is restored */
html.sidebar-active-stored .sidebar {
    transition: none !important;
}

html.sidebar-active-stored #content,
html.sidebar-active-stored .top-header {
    transition: none !important;
}

/* Lower z-index when SweetAlert is shown to prevent overlapping modals */
body.swal2-shown .sidebar,
body.swal2-shown .top-header,
body.swal2-shown .sidebar-backdrop,
body.swal2-shown .menu-toggle {
    z-index: 1 !important;
}

/* Active class brings it in */
.sidebar.active {
    transform: translateX(0);
    box-shadow: 5px 0 15px rgba(0, 0, 0, 0.1);
}

@media (min-width: 992px) {
    .sidebar {
        transform: translateX(0);
    }
}

/* Sidebar backdrop for mobile */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99990;
    opacity: 0;
    transition: opacity 0.3s, visibility 0.3s;
    backdrop-filter: blur(2px);
    visibility: hidden;
}

.sidebar-backdrop.active {
    display: block;
    visibility: visible;
    opacity: 1;
}

/* Menu toggle button handled below */

.sidebar-footer {
    margin-top: auto;
    padding: 20px;
    font-size: 1.4em;
    font-weight: bold;
    color: white;
    background-color: transparent;
    text-align: center;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header {
    padding: 20px;
    background: #1a252f;
    text-align: center;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

/* Internal sidebar styles (lists, links, spacing) are standardized in sidebar.php */


/* Dropdown/Collapse manual support */
.collapse:not(.show) {
    display: none;
}

.collapsing {
    height: 0;
    overflow: hidden;
    transition: height 0.35s ease;
}

.dropdown-toggle::after {
    display: inline-block;
    margin-left: auto;
    vertical-align: 0.255em;
    content: "";
    border-top: 0.3em solid;
    border-right: 0.3em solid transparent;
    border-bottom: 0;
    border-left: 0.3em solid transparent;
    transition: transform 0.3s;
}

.dropdown-toggle[aria-expanded="true"]::after {
    transform: rotate(180deg);
}


/* Content */
#content {
    width: 100%;
    transition: all 0.3s;
    min-height: 100vh;
    padding-top: var(--header-height);
}

/* Header - Fixed on Desktop */
.top-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: white;
    z-index: 1000;
    padding: 0 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.top-header h2 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--primary-color);
    font-weight: 900;
    -webkit-font-smoothing: antialiased;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Menu toggle button */
.menu-toggle {
    cursor: pointer;
    font-size: 1.5rem;
    background: transparent;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    color: var(--text-color, #333);
    margin-right: 15px;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1001;
    /* Must be above header */
}

.menu-toggle i {
    color: #444 !important;
    /* Force icon color */
    display: inline-block;
}

/* Filters Toolbar */
.filters-toolbar {
    background: #fff;
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    align-items: center;
    align-items: center;
    position: sticky;
    /* Sticky filters below header */
    top: var(--header-height);
    z-index: 900;
    box-shadow: 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}

.filters-toolbar h4 {
    margin: 0;
    margin-right: 10px;
    color: var(--text-muted);
}

.filter-group {
    display: flex;
    gap: 10px;
    flex: 1;
    min-width: 200px;
}

.filter-select {
    flex: 1;
    padding: 0.6rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    background-color: #fff;
    outline: none;
    cursor: pointer;
}

/* Cards (Payment Items) */
.payment-grid {
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.payment-card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 20px;
    box-shadow: var(--shadow);
    transition: transform 0.2s;
    border-left: 5px solid var(--primary-color);
}

.payment-card:hover {
    transform: translateY(-5px);
}

.payment-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    font-weight: bold;
    font-size: 1.1em;
}

.payment-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.payment-row {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
}

.payment-label {
    font-weight: 600;
    color: var(--text-muted);
}

.payment-value {
    text-align: right;
    word-break: break-word;
}

.payment-actions {
    margin-top: 20px;
    display: flex;
    gap: 10px;
}

.btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: opacity 0.2s;
}

.btn:hover {
    opacity: 0.8;
}

.btn-approve {
    background-color: var(--success-color);
    color: white;
}

.btn-deny {
    background-color: var(--danger-color);
    color: white;
}

.status-badge {
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 0.8em;
    font-weight: bold;
}

.status-pending {
    background: #ffeeba;
    color: #856404;
}

.status-ok {
    background: #d4edda;
    color: #155724;
}

.status-denied {
    background: #f8d7da;
    color: #721c24;
}

/* Ensure modals are ALWAYS in front of everything */
.swal2-container {
    z-index: 200000 !important;
    /* Extremely high z-index to stay on top */
}

/* RESPONSIVE LAYOUT FIXES */

/* Mobile First: Sidebar is hidden off-canvas via transform in base rule */
/* Content takes full width */
#content {
    width: 100%;
    margin-left: 0;
}

/* DESKTOP (Large Screens) */
@media (min-width: 992px) {

    /* Sidebar visible default */
    .sidebar {
        transform: translateX(0);
        visibility: visible;
    }

    /* Content pushed to right */
    #content {
        margin-left: 280px;
        width: calc(100% - 280px);
    }

    /* Ensure header matches content width/pos */
    .top-header {
        left: 280px;
        width: calc(100% - 280px);
    }

    /* IF 'active' class is present on desktop, it means the user wants it HIDDEN/RETRACTED */
    .sidebar.active {
        transform: translateX(-100%);
        visibility: hidden;
    }

    /* Target content expansion */
    .sidebar.active~#content {
        margin-left: 0 !important;
        width: 100% !important;
    }

    .sidebar.active~#content .top-header {
        left: 0 !important;
        width: 100% !important;
    }
}

/* Network Status Signal Bars */
.signal-container {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-right: 0;
    background: rgba(255, 255, 255, 0.9);
    padding: 2px 10px;
    border-radius: 30px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    white-space: nowrap;
    z-index: 1010;
}

.signal-group {
    display: flex;
    align-items: center;
    gap: 5px;
}

.signal-bars {
    display: inline-flex;
    align-items: flex-end;
    gap: 1.5px;
    height: 10px;
}

.signal-bar {
    width: 2px;
    background-color: #ddd;
    border-radius: 1px;
}

.signal-bar:nth-child(1) {
    height: 20%;
}

.signal-bar:nth-child(2) {
    height: 40%;
}

.signal-bar:nth-child(3) {
    height: 60%;
}

.signal-bar:nth-child(4) {
    height: 80%;
}

.signal-bar:nth-child(5) {
    height: 100%;
}

/* All Green level 5 */
.signal-bars.level-5 .signal-bar {
    background-color: #4CAF50 !important;
}

/* Light Green level 4 */
.signal-bars.level-4 .signal-bar:nth-child(-n+4) {
    background-color: #8bc34a !important;
}

/* Yellow level 3 */
.signal-bars.level-3 .signal-bar:nth-child(-n+3) {
    background-color: #ffc107 !important;
}

/* Orange level 2 */
.signal-bars.level-2 .signal-bar:nth-child(-n+2) {
    background-color: #ff9800 !important;
}

/* Red level 1 */
.signal-bars.level-1 .signal-bar:nth-child(1) {
    background-color: #f44336 !important;
}

/* Grey level 0 */
.signal-bars.level-0 .signal-bar {
    background-color: #ddd;
}

/* None (>300ms) */
/* Mobile Layout Optimizations */
@media (max-width: 991px) {

    /* Header: Fixed positioning on mobile - centered layout */
    .top-header {
        position: fixed !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        height: var(--header-height) !important;
        padding: 0 15px !important;
        display: flex;
        justify-content: space-between;
        align-items: center;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
        z-index: 1000;
    }

    .top-header h2 {
        font-size: 1.1rem !important;
        flex: 1;
        text-align: left;
    }

    /* Content: Top padding since header is fixed */
    #content {
        padding-top: var(--header-height) !important;
    }

    /* Content: No top padding since header is relative */
    #content {
        padding-top: 0 !important;
        margin-top: 0 !important;
    }

    /* User info: Compact layout */
    .user-info {
        flex-direction: column;
        align-items: flex-end;
        text-align: right;
        gap: 2px !important;
        margin: 0;
        font-size: 0.75em;
    }

    .user-info>div,
    .user-info-text-wrapper>div {
        font-size: 0.8em !important;
        line-height: 1.2;
        white-space: nowrap;
    }

    #sessionTimer {
        order: 2;
        font-size: 0.75em !important;
        margin-top: 2px;
    }

    /* Signal Monitor on Mobile */
    .signal-container {
        padding: 2px 8px;
        margin-right: 5px;
        gap: 8px;
    }

    .signal-group span {
        font-size: 0.65em !important;
    }

    /* Prevent horizontal overflow */
    .wrapper,
    #content {
        overflow-x: hidden;
    }

    .config-card,
    .form-card,
    .table-responsive {
        width: 100%;
        overflow-x: auto;
        padding: 10px;
    }

    .header-content {
        width: 100%;
    }

    /* Sticky Filters */
    .filters-toolbar,
    .filters-bar {
        position: sticky;
        top: 60px;
        /* Below sticky header */
        z-index: 950;
        background: white;
        padding: 10px 15px;
        gap: 10px;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
        margin-bottom: 10px;
    }

    .filter-group {
        min-width: 100%;
    }

    /* Touch-optimized buttons */
    .btn,
    button[type="submit"],
    button[type="button"],
    .btn-approve,
    .btn-deny,
    .btn-secondary {
        min-height: 44px;
        padding: 10px 16px;
        font-size: 1em;
    }

    /* Touch-optimized inputs */
    input[type="text"],
    input[type="password"],
    input[type="email"],
    input[type="number"],
    input[type="date"],
    input[type="time"],
    select,
    textarea {
        min-height: 44px;
        font-size: 16px;
        /* Prevents zoom on iOS */
        padding: 10px 12px;
    }

    /* Menu toggle button */
    .menu-toggle {
        min-width: 44px;
        min-height: 44px;
        padding: 10px;
    }
}

/* Standardized Icon Buttons */
.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    transition: opacity 0.2s, background-color 0.2s;
    background: transparent;
    color: var(--text-muted);
}

.btn-icon:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--text-color);
}

.btn-icon.edit {
    color: var(--primary-color);
}

.btn-icon.edit:hover {
    background-color: rgba(0, 123, 255, 0.1);
}

.btn-icon.delete {
    color: var(--danger-color);
}

.btn-icon.delete:hover {
    background-color: rgba(220, 53, 69, 0.1);
}

.btn-icon.block {
    color: var(--danger-color);
}

.btn-icon.unblock {
    color: var(--success-color);
}


/* Flex container for action buttons in tables */
.action-buttons {
    display: flex;
    gap: 5px;
    align-items: center;
    justify-content: center;
}

.action-buttons form {
    margin: 0;
    display: flex;
    /* Ensure form doesn't break flow */
}

/* Priority & Critical Alerts */
@keyframes blink-alert {
    0% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.6;
        transform: scale(1.1);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.blink-alert {
    animation: blink-alert 1s infinite;
    display: inline-block;
}