/* =====================================================
 * RESPONSIVE CSS - SisFix
 * Mobile-first responsive breakpoints
 *
 * Breakpoints:
 *   - Small phones:       max-width  480px
 *   - Tablets portrait:   max-width  768px
 *   - Tablets landscape:  max-width 1024px
 *   - Desktop:            min-width  769px
 *   - Large desktop:      min-width 1200px
 *   - Print
 *
 * Layout reference:
 *   Navbar        - fixed top, 60px height
 *   Sidebar       - fixed left, 260px wide (collapses to 70px)
 *   Main content  - fills remaining space
 *   Mobile nav    - fixed bottom, 60px, mobile only
 * ===================================================== */


/* =====================================================
 * SMALL PHONES (max-width: 480px)
 * Compact layout for narrow screens
 * ===================================================== */
@media (max-width: 480px) {

    /* --- Typography --- */
    h1 {
        font-size: 22px;
    }

    h2 {
        font-size: 18px;
    }

    h3 {
        font-size: 16px;
    }

    /* --- Auth card (login / register) --- */
    .auth-card {
        padding: 24px;
        margin: 12px;
        border-radius: 12px;
    }

    .auth-card .auth-header {
        margin-bottom: 16px;
    }

    /* --- Statistics grid --- */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    /* --- Navbar --- */
    .navbar-search {
        display: none;
    }

    .navbar-brand-text {
        font-size: 14px;
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* --- Cards --- */
    .card-body {
        padding: 14px;
    }

    .card-header {
        padding: 12px 14px;
    }

    .card-footer {
        padding: 10px 14px;
    }

    /* --- Tables --- */
    .table,
    .table th,
    .table td {
        font-size: 13px;
    }

    .table th,
    .table td {
        padding: 8px 10px;
    }

    /* --- Forms --- */
    .form-group {
        margin-bottom: 14px;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .form-row .form-group {
        width: 100%;
    }

    /* --- Buttons --- */
    .btn {
        padding: 8px 14px;
        font-size: 13px;
    }

    .btn-group {
        flex-direction: column;
        width: 100%;
    }

    .btn-group .btn {
        width: 100%;
    }

    /* --- Mobile bottom nav adjustments --- */
    .mobile-bottom-nav .mobile-nav-item span {
        font-size: 10px;
    }

    /* --- Modal --- */
    .modal-content {
        margin: 8px;
        max-height: calc(100vh - 16px);
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 14px;
    }

    /* --- Page header --- */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .page-header .btn,
    .page-header .btn-group {
        width: 100%;
    }

    /* --- Dashboard stat cards --- */
    .stat-card {
        padding: 14px;
    }

    .stat-card .stat-value {
        font-size: 22px;
    }

    .stat-card .stat-label {
        font-size: 12px;
    }

    /* --- Flash messages --- */
    .flash-container {
        left: 12px;
        right: 12px;
        max-width: none;
    }

    .flash-message {
        font-size: 13px;
        padding: 10px 14px;
    }
}


/* =====================================================
 * TABLETS PORTRAIT (max-width: 768px)
 * Sidebar becomes off-canvas, bottom nav appears
 * ===================================================== */
@media (max-width: 768px) {

    /* --- Sidebar: hidden off-canvas by default --- */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 260px;
        z-index: 1001;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    /* Sidebar visible when toggled open */
    .sidebar-open .sidebar {
        transform: translateX(0);
    }

    /* Sidebar overlay (backdrop) */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 1000;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .sidebar-open .sidebar-overlay {
        display: block;
        opacity: 1;
    }

    /* --- Main content: full width, no sidebar offset --- */
    .main-content {
        margin-left: 0 !important;
        padding-bottom: 70px;
    }

    /* Override collapsed sidebar margin on mobile */
    .app-wrapper.sidebar-collapsed .main-content {
        margin-left: 0 !important;
    }

    /* --- Mobile bottom navigation: visible --- */
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 60px;
        z-index: 999;
        align-items: center;
        justify-content: space-around;
        background-color: var(--color-surface, #ffffff);
        border-top: 1px solid var(--color-border, #e5e7eb);
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
        padding: 0 4px;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    .mobile-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        flex: 1;
        padding: 6px 0;
        font-size: 11px;
        color: var(--color-text-secondary, #6b7280);
        text-decoration: none;
        border: none;
        background: none;
        cursor: pointer;
        transition: color 0.2s ease;
    }

    .mobile-nav-item.active {
        color: var(--color-primary, #10B981);
    }

    .mobile-nav-item svg,
    .mobile-nav-item i {
        width: 22px;
        height: 22px;
    }

    .mobile-nav-center .mobile-nav-plus {
        width: 44px;
        height: 44px;
        border-radius: 50%;
        background-color: var(--color-primary, #10B981);
        color: #ffffff;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-top: -14px;
        box-shadow: 0 2px 8px rgba(16, 185, 129, 0.35);
    }

    .mobile-nav-center .mobile-nav-plus svg,
    .mobile-nav-center .mobile-nav-plus i {
        width: 24px;
        height: 24px;
    }

    /* --- Statistics grid: 2 columns --- */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    /* --- Navbar adjustments --- */
    .navbar-brand-text {
        display: none;
    }

    .navbar-search {
        max-width: 180px;
    }

    .navbar-search .search-input {
        font-size: 13px;
        padding: 6px 10px 6px 32px;
    }

    /* --- Dropdown menus: full width on mobile --- */
    .dropdown-menu {
        position: fixed;
        top: 60px;
        left: 8px;
        right: 8px;
        width: auto;
        max-width: none;
        max-height: calc(100vh - 130px);
        overflow-y: auto;
        border-radius: 12px;
    }

    .dropdown-notifications {
        width: auto;
        min-width: auto;
    }

    .dropdown-user {
        width: auto;
        min-width: auto;
    }

    /* --- Hide sidebar footer plan info when sidebar is closed --- */
    .sidebar-footer .plan-info {
        opacity: 0;
        transition: opacity 0.2s ease;
    }

    .sidebar-open .sidebar-footer .plan-info {
        opacity: 1;
    }

    /* --- Tables: horizontal scroll --- */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* --- Auth card --- */
    .auth-card {
        max-width: none;
        margin: 16px;
    }

    /* --- Cards grid --- */
    .cards-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    /* --- Action bar / Toolbar --- */
    .action-bar {
        flex-direction: column;
        gap: 10px;
    }

    .action-bar .btn {
        width: 100%;
    }

    /* --- Tabs: scrollable --- */
    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
    }

    .tabs .tab-item {
        white-space: nowrap;
        flex-shrink: 0;
    }
}


/* =====================================================
 * TABLETS LANDSCAPE (max-width: 1024px)
 * Sidebar starts collapsed, content adjusts
 * ===================================================== */
@media (max-width: 1024px) and (min-width: 769px) {

    /* --- Sidebar: collapsed (icon-only) by default --- */
    .sidebar {
        width: 70px;
    }

    .sidebar .nav-text {
        display: none;
    }

    .sidebar .nav-label {
        display: none;
    }

    .sidebar .nav-separator {
        margin: 8px 12px;
    }

    .sidebar .nav-link {
        justify-content: center;
        padding: 12px;
    }

    .sidebar .nav-link i,
    .sidebar .nav-link svg {
        margin-right: 0;
    }

    /* Show full sidebar on hover */
    .sidebar:hover {
        width: 260px;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.1);
    }

    .sidebar:hover .nav-text {
        display: inline;
    }

    .sidebar:hover .nav-label {
        display: block;
    }

    .sidebar:hover .nav-link {
        justify-content: flex-start;
    }

    .sidebar:hover .nav-link i,
    .sidebar:hover .nav-link svg {
        margin-right: 12px;
    }

    /* Sidebar footer: collapsed state */
    .sidebar-footer .plan-info {
        flex-direction: column;
        align-items: center;
        gap: 4px;
    }

    .sidebar-footer .plan-info a {
        display: none;
    }

    .sidebar:hover .sidebar-footer .plan-info {
        flex-direction: row;
    }

    .sidebar:hover .sidebar-footer .plan-info a {
        display: inline;
    }

    /* --- Main content: offset by collapsed sidebar width --- */
    .main-content {
        margin-left: 70px;
    }

    /* --- Statistics grid: 2 columns --- */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* --- Auth card --- */
    .auth-card {
        max-width: 400px;
    }

    /* --- Navbar search: compact --- */
    .navbar-search {
        max-width: 240px;
    }
}


/* =====================================================
 * DESKTOP (min-width: 769px)
 * Sidebar always visible, no mobile nav
 * ===================================================== */
@media (min-width: 769px) {

    /* --- Mobile bottom nav: always hidden on desktop --- */
    .mobile-bottom-nav {
        display: none !important;
    }

    /* --- Sidebar overlay: always hidden on desktop --- */
    .sidebar-overlay {
        display: none !important;
    }

    /* --- Sidebar: always visible --- */
    .sidebar {
        transform: translateX(0);
    }

    /* --- Main content: offset by sidebar width --- */
    .main-content {
        margin-left: 260px;
        padding-bottom: 0;
        transition: margin-left 0.3s ease;
    }

    /* Collapsed sidebar state */
    .app-wrapper.sidebar-collapsed .sidebar {
        width: 70px;
    }

    .app-wrapper.sidebar-collapsed .sidebar .nav-text {
        display: none;
    }

    .app-wrapper.sidebar-collapsed .sidebar .nav-label {
        display: none;
    }

    .app-wrapper.sidebar-collapsed .sidebar .nav-link {
        justify-content: center;
    }

    .app-wrapper.sidebar-collapsed .sidebar .nav-link i,
    .app-wrapper.sidebar-collapsed .sidebar .nav-link svg {
        margin-right: 0;
    }

    .app-wrapper.sidebar-collapsed .main-content {
        margin-left: 70px;
    }

    .app-wrapper.sidebar-collapsed .sidebar-footer .plan-info a {
        display: none;
    }

    /* --- Dropdown menus: positioned normally --- */
    .dropdown-menu {
        position: absolute;
        top: 100%;
        right: 0;
        left: auto;
        width: auto;
        max-height: 420px;
    }

    .dropdown-notifications {
        width: 360px;
    }

    .dropdown-user {
        width: 240px;
    }
}


/* =====================================================
 * LARGE DESKTOP (min-width: 1200px)
 * Expanded grid, wider content
 * ===================================================== */
@media (min-width: 1200px) {

    /* --- Statistics grid: 4 columns --- */
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 20px;
    }

    /* --- Main content: cap width for readability --- */
    .main-content {
        padding-left: 32px;
        padding-right: 32px;
    }

    /* --- Cards grid: multi-column --- */
    .cards-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 24px;
    }

    /* --- Auth card --- */
    .auth-card {
        max-width: 440px;
    }

    /* --- Tables: comfortable spacing --- */
    .table th,
    .table td {
        padding: 12px 16px;
    }

    /* --- Dashboard layout --- */
    .dashboard-grid {
        grid-template-columns: 2fr 1fr;
        gap: 24px;
    }
}


/* =====================================================
 * EXTRA LARGE DESKTOP (min-width: 1440px)
 * Ultra-wide adjustments
 * ===================================================== */
@media (min-width: 1440px) {

    .main-content {
        max-width: 1320px;
    }

    .stats-grid {
        gap: 24px;
    }

    .cards-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}


/* =====================================================
 * PRINT STYLES
 * Clean output for printing
 * ===================================================== */
@media print {

    /* --- Hide non-printable elements --- */
    .navbar,
    .sidebar,
    .sidebar-overlay,
    .mobile-bottom-nav,
    .flash-container,
    .flash-message,
    .btn,
    .btn-icon,
    .sidebar-toggle,
    .theme-toggle,
    .notification-btn,
    .dropdown-menu,
    .navbar-search,
    .mobile-menu-trigger,
    .action-bar,
    .pagination,
    .tabs {
        display: none !important;
    }

    /* --- Main content: full page, no offset --- */
    .main-content {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    .app-wrapper {
        display: block;
    }

    /* --- Remove decorative styles --- */
    *,
    *::before,
    *::after {
        box-shadow: none !important;
        text-shadow: none !important;
    }

    body {
        background: #ffffff !important;
        color: #000000 !important;
        font-size: 12pt;
        line-height: 1.5;
    }

    /* --- Cards: no background/border decoration --- */
    .card,
    .stat-card,
    .auth-card {
        border: 1px solid #cccccc !important;
        background: #ffffff !important;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    /* --- Links: show URL --- */
    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 10pt;
        color: #666666;
    }

    a[href^="#"]::after,
    a[href^="javascript"]::after {
        content: "";
    }

    /* --- Tables: clean borders --- */
    .table {
        border-collapse: collapse;
        width: 100%;
    }

    .table th,
    .table td {
        border: 1px solid #cccccc !important;
        padding: 8px !important;
        background: #ffffff !important;
    }

    .table th {
        font-weight: bold;
        background: #f3f4f6 !important;
    }

    /* --- Images: prevent overflow --- */
    img {
        max-width: 100% !important;
        page-break-inside: avoid;
    }

    /* --- Page breaks --- */
    h1, h2, h3 {
        page-break-after: avoid;
    }

    .page-header {
        border-bottom: 2px solid #000000;
        padding-bottom: 8px;
        margin-bottom: 16px;
    }
}


/* =====================================================
 * ACCESSIBILITY / REDUCED MOTION
 * Respect user preference for reduced motion
 * ===================================================== */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .sidebar {
        transition: none;
    }

    .sidebar-overlay {
        transition: none;
    }

    .main-content {
        transition: none;
    }
}


/* =====================================================
 * HIGH CONTRAST MODE
 * Improve visibility for high contrast preference
 * ===================================================== */
@media (forced-colors: active) {

    .btn,
    .btn-icon {
        border: 1px solid ButtonText;
    }

    .card,
    .stat-card,
    .auth-card {
        border: 1px solid CanvasText;
    }

    .nav-link.active {
        border-left: 3px solid Highlight;
    }

    .mobile-nav-item.active {
        border-bottom: 2px solid Highlight;
    }

    .badge,
    .notification-badge {
        border: 1px solid CanvasText;
    }
}


/* =====================================================
 * LANDSCAPE ORIENTATION (mobile)
 * Adjustments when phone is held sideways
 * ===================================================== */
@media (max-height: 500px) and (orientation: landscape) {

    .navbar {
        height: 48px;
    }

    .main-content {
        padding-top: 48px;
    }

    .mobile-bottom-nav {
        height: 48px;
    }

    .mobile-nav-item span {
        display: none;
    }

    .mobile-nav-center .mobile-nav-plus {
        width: 36px;
        height: 36px;
        margin-top: -8px;
    }

    .auth-card {
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-content {
        max-height: 90vh;
        overflow-y: auto;
    }
}


/* =====================================================
 * SAFE AREA INSETS (notched devices)
 * Support for devices with notches / rounded corners
 * ===================================================== */
@supports (padding: env(safe-area-inset-bottom)) {

    .mobile-bottom-nav {
        padding-bottom: env(safe-area-inset-bottom);
        height: calc(60px + env(safe-area-inset-bottom));
    }

    @media (max-width: 768px) {
        .main-content {
            padding-bottom: calc(70px + env(safe-area-inset-bottom));
        }
    }

    .sidebar {
        padding-left: env(safe-area-inset-left);
    }
}
