/* ===========================
   MAIN STYLES
   =========================== */

:root {
    --primary-color: #2563eb;
    --danger-color: #dc2626;
    --warning-color: #f59e0b;
    --success-color: #16a34a;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --card-bg-secondary: #f8fafc;
    --border-color: #e2e8f0;
    --text-color: #1e293b;
    --text-secondary: #64748b;
    
    /* Category colors */
    --default-category-color: #94a3b8;
    --default-group-color: #3b82f6;
    
    /* Focus colors */
    --focus-color: #2563eb;
    --focus-width: 3px;
}

/* Dark Mode Variables */
body.dark-mode {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --card-bg-secondary: #0f172a;
    --border-color: #334155;
    --text-color: #f1f5f9;
    --text-secondary: #94a3b8;
    --primary-color: #3b82f6;
    --danger-color: #ef4444;
    --warning-color: #fbbf24;
    --success-color: #22c55e;
    
    /* Category colors for dark mode */
    --default-category-color: #94a3b8;
    --default-group-color: #60a5fa;
}

/* High Contrast Mode */
body.high-contrast {
    --primary-color: #0000ff;
    --danger-color: #ff0000;
    --warning-color: #ff8c00;
    --success-color: #008000;
    --bg-color: #000000;
    --card-bg: #000000;
    --card-bg-secondary: #1a1a1a;
    --border-color: #ffffff;
    --text-color: #ffffff;
    --text-secondary: #ffff00;
    
    /* Category colors for high contrast */
    --default-category-color: #ffff00;
    --default-group-color: #00ffff;
}

body.high-contrast * {
    border-width: 2px !important;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    padding: 24px 32px;
    transition: background-color 0.3s, color 0.3s;
    font-size: var(--desktop-body, 0.9375rem);
}

/* Screen Reader Only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Keyboard Navigation Indicators */
body.keyboard-navigation *:focus {
    outline: var(--focus-width) solid var(--focus-color);
    outline-offset: 2px;
}

body:not(.keyboard-navigation) *:focus {
    outline: none;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-overlay.is-visible {
    display: flex;
}

.loading-spinner {
    text-align: center;
    color: white;
}

.spinner {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#loadingText {
    font-size: 1.2em;
    font-weight: 600;
    margin: 0;
}

.container {
    max-width: var(--content-max-width, 1600px);
    margin: 0 auto;
}

/* Header inner layout — replaces inline styles */
.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.header-title {
    flex: 1;
    min-width: 0; /* allow text to shrink/truncate rather than overflow */
}

.header-title h1 {
    font-size: var(--desktop-h1, 1.75rem);
    margin-bottom: 3px;
    font-weight: 700;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-title p {
    opacity: 0.85;
    font-size: 0.9375em;
    line-height: 1.4;
}

.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    flex-shrink: 0;
}

/* Header */
header {
    background: linear-gradient(135deg, var(--primary-color), #1d4ed8);
    color: white;
    padding: 20px 28px;
    border-radius: 12px;
    margin-bottom: 24px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* Header Buttons */
.header-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 10px 15px;
    font-size: 1.1em;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 45px;
    min-height: 45px;
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.35);
    border-color: rgba(255, 255, 255, 0.6);
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.header-btn:active {
    transform: translateY(0) scale(0.98);
    box-shadow: none;
}

.header-btn:focus {
    outline: 3px solid rgba(255, 255, 255, 0.6);
    outline-offset: 2px;
}

.header-btn:focus-visible {
    outline: 3px solid rgba(255, 255, 255, 0.8);
    outline-offset: 2px;
}

.header-btn i {
    font-size: 1.2em;
}

/* Active state for theme buttons */
body.dark-mode .header-btn#darkModeBtn {
    background: rgba(255, 255, 255, 0.4);
    border-color: rgba(255, 255, 255, 0.6);
}

body.dark-mode .header-btn#darkModeBtn i::before {
    content: "\f185"; /* fa-sun */
}

body.high-contrast .header-btn#highContrastBtn {
    background: rgba(255, 255, 255, 0.4);
    border-color: rgba(255, 255, 255, 0.6);
}

body.reduced-motion .header-btn#reducedMotionBtn {
    background: rgba(255, 255, 255, 0.4);
    border-color: rgba(255, 255, 255, 0.6);
}

body.reduced-motion .header-btn#reducedMotionBtn i::before {
    content: "\f28b"; /* fa-pause */
}

/* ===========================
   APP BODY LAYOUT
   Desktop: sidebar left + content right
   Tablet:  horizontal scrollable tab bar on top
   Mobile:  bottom navigation bar
   =========================== */

.app-body {
    display: flex;
    gap: 0;
    align-items: flex-start;
}

.tab-pane-container {
    flex: 1;
    min-width: 0; /* prevent flex overflow */
}

/* ===========================
   SIDEBAR (desktop ≥ 1025px)
   =========================== */
.tabs {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: var(--sidebar-width, 220px);
    flex-shrink: 0;
    padding: 8px;
    background: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 24px;
    max-height: calc(100vh - 48px);
    align-self: flex-start;
    margin-right: 20px;
}

/* Dark mode tabs enhancement */
body.dark-mode .tabs {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.tab {
    padding: 10px 14px;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: background-color var(--transition-base), color var(--transition-base), box-shadow var(--transition-base);
    position: relative;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: flex-start; /* left-aligned for sidebar */
    gap: 10px;
    width: 100%;
    text-align: left;
}

.tab .tab-label {
    flex: 1;
}

.tab:hover {
    background: rgba(79, 70, 229, 0.07);
    color: var(--text-color);
}

.tab:active {
    transform: scale(0.98);
}

.tab.active {
    /* inset box-shadow is not clipped by border-radius/overflow:hidden */
    box-shadow: inset 3px 0 0 var(--primary-color);
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.10) 0%, rgba(99, 102, 241, 0.06) 100%);
    color: var(--primary-color);
}

/* keep ::before empty on desktop — indicator is via box-shadow */
.tab.active::before {
    content: none;
}

body.dark-mode .tab.active {
    background: rgba(99, 102, 241, 0.15);
    color: #a5b4fc;
    box-shadow: inset 3px 0 0 #818cf8;
}

body.dark-mode .tab.active::before {
    content: none;
}

/* Ripple effect */
.tab-ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.6);
    transform: scale(0);
    animation: ripple 0.6s ease-out;
    pointer-events: none;
}

@keyframes ripple {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Sidebar section divider */
.tabs-divider {
    height: 1px;
    background: var(--border-color);
    margin: 4px 6px;
}

/* Language Selector */
.language-selector {
    position: relative;
}

.language-dropdown {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 10px 15px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    min-width: 150px;
}

.language-dropdown:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
}

.language-dropdown:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.35);
    border-color: rgba(255, 255, 255, 0.6);
}

.language-dropdown option {
    background: var(--card-bg);
    color: var(--text-color);
    padding: 10px;
}

/* ===========================
   RESPONSIVE DESIGN
   =========================== */

/* ===========================
   TABLET (769px – 1024px)
   Horizontal scrollable tab bar on top
   =========================== */
@media (max-width: 1024px) {
    body {
        padding: 15px;
    }

    .container {
        max-width: 100%;
    }

    header {
        padding: 20px;
    }

    header h1 {
        font-size: 1.75em;
    }

    header p {
        font-size: 1em;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
        gap: 12px;
    }

    /* Switch from sidebar to horizontal tab bar */
    .app-body {
        flex-direction: column;
    }

    .tabs {
        flex-direction: row;
        width: 100%;
        position: static;
        max-height: none;
        margin-right: 0;
        margin-bottom: 16px;
        overflow-x: auto;
        padding: 6px;
        gap: 4px;
        border-radius: 10px;
    }

    .tabs::-webkit-scrollbar {
        height: 4px;
    }

    .tabs::-webkit-scrollbar-track {
        background: transparent;
    }

    .tabs::-webkit-scrollbar-thumb {
        background: var(--border-color);
        border-radius: 4px;
    }

    .tabs-divider {
        display: none;
    }

    /* Tablet tabs: icon above label, centred */
    .tab {
        flex-direction: column;
        width: auto;
        flex-shrink: 0;
        padding: 8px 16px;
        font-size: 0.8rem;
        gap: 4px;
        text-align: center;
        justify-content: center;
        min-width: 76px;
    }

    .tab .tab-label {
        flex: none;
    }

    /* Tablet: revert to bottom-edge indicator line */
    .tab.active {
        box-shadow: inset 0 -3px 0 var(--primary-color);
        color: var(--primary-color);
        background: rgba(79, 70, 229, 0.06);
    }

    .tab.active::before {
        content: none;
    }

    .tab i {
        font-size: 1.1em;
    }
}

/* ===========================
   MOBILE (≤ 768px)
   Fixed bottom navigation bar
   =========================== */
@media (max-width: 768px) {
    body {
        padding: 10px 10px 80px; /* bottom padding clears the nav bar */
        font-size: 14px;
    }

    .container {
        max-width: 100%;
    }

    /* Header Mobile */
    header {
        padding: 16px 14px;
        margin-bottom: 14px;
        border-radius: 10px;
    }

    header h1 {
        font-size: 1.4em;
        margin-bottom: 4px;
    }

    header p {
        font-size: 0.875em;
        line-height: 1.4;
    }

    header > div {
        flex-direction: column;
        gap: 12px;
    }

    header > div > div:last-child {
        width: 100%;
        justify-content: space-between;
    }

    .header-btn {
        min-width: 44px;
        min-height: 44px;
        padding: 10px;
        font-size: 1.1em;
        flex: 1;
    }

    .language-selector {
        flex: 1;
        width: auto;
    }

    .language-dropdown {
        width: 100%;
        padding: 10px 12px;
        font-size: 0.95em;
    }

    /* Bottom navigation bar */
    .app-body {
        flex-direction: column;
    }

    .tabs {
        position: fixed;
        top: auto;           /* unset sticky top so it doesn't stretch top→bottom */
        bottom: 0;
        left: 0;
        right: 0;
        z-index: var(--z-fixed);
        flex-direction: row;
        width: 100%;
        max-height: none;
        margin: 0;
        padding: 6px 8px;
        padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
        border-radius: 0;
        border: none;
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
        background: var(--card-bg);
        justify-content: space-around;
        gap: 0;
    }

    .tabs-divider {
        display: none;
    }

    /* Mobile tabs: icon above label, centred, full-width spread */
    .tab {
        flex: 1;
        flex-direction: column;
        width: auto;
        padding: 6px 4px;
        font-size: 0.68rem;
        gap: 3px;
        text-align: center;
        justify-content: center;
        border-radius: 8px;
        min-height: 48px;
    }

    .tab .tab-label {
        flex: none;
        font-size: 0.68rem;
        line-height: 1.2;
    }

    .tab i {
        font-size: 1.25em;
        margin: 0;
    }

    /* Active indicator — dot above label */
    .tab.active::before {
        content: '';
        position: absolute;
        top: 4px;
        left: 50%;
        transform: translateX(-50%);
        width: 4px;
        height: 4px;
        border-radius: 50%;
        background: var(--primary-color);
        box-shadow: none;
    }

    /* Mobile active: highlight colour only, dot indicator via ::before */
    .tab.active {
        color: var(--primary-color);
        background: transparent;
        box-shadow: none;
    }

    body.dark-mode .tab.active {
        color: #818cf8;
        background: transparent;
        box-shadow: none;
    }

    /* Cards Mobile */
    .card {
        padding: 15px;
        margin-bottom: 15px;
        border-radius: 10px;
    }

    .card h2 {
        font-size: 1.3em;
        margin-bottom: 12px;
    }

    .card h3 {
        font-size: 1.1em;
        margin-bottom: 10px;
    }

    /* Stats Grid Mobile */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        margin-bottom: 15px;
    }

    .stat-card {
        padding: 15px;
    }

    .stat-label {
        font-size: 0.8em;
    }

    .stat-value {
        font-size: 1.5em;
    }

    /* Loading Overlay Mobile */
    .loading-spinner {
        padding: 20px;
    }

    .spinner {
        width: 50px;
        height: 50px;
        margin: 0 auto 15px;
    }

    #loadingText {
        font-size: 1em;
    }

    /* Toast Mobile */
    .toast-container {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }

    .toast {
        padding: 12px 15px;
        font-size: 0.9em;
    }

    .toast-icon {
        font-size: 1.3em;
    }

    .toast-title {
        font-size: 0.95em;
    }

    .toast-message {
        font-size: 0.85em;
    }
}

/* Small Mobile Breakpoint (max-width: 480px) */
@media (max-width: 480px) {
    body {
        padding: 8px 8px 72px;
        font-size: 13px;
    }

    header {
        padding: 13px 11px;
    }

    header h1 {
        font-size: 1.2em;
    }

    header p {
        font-size: 0.82em;
    }

    .header-btn {
        min-width: 40px;
        min-height: 40px;
        padding: 8px;
        font-size: 1em;
    }

    .language-dropdown {
        font-size: 0.9em;
        padding: 8px 10px;
    }

    /* Tighter bottom nav on very small screens */
    .tab {
        font-size: 0.62rem;
        padding: 5px 2px;
        min-height: 46px;
    }

    .tab i {
        font-size: 1.15em;
    }

    .card {
        padding: 12px;
    }

    .card h2 {
        font-size: 1.2em;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-card {
        padding: 12px;
    }

    .stat-value {
        font-size: 1.3em;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    /* Increase tap targets for touch devices */
    button,
    .tab,
    .header-btn,
    a,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 44px;
        min-width: 44px;
    }

    /* Improve form controls */
    input[type="text"],
    input[type="number"],
    input[type="date"],
    textarea,
    select {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px;
    }

    /* Disable hover effects on touch devices */
    .tab:hover::before {
        width: 0;
    }

    .header-btn:hover {
        transform: none;
    }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    header {
        padding: 15px;
    }

    header h1 {
        font-size: 1.3em;
    }

    header p {
        font-size: 0.85em;
    }

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

/* ===========================
   LARGE DESKTOP (1280px+)
   Sidebar is already visible; optimise content area
   =========================== */
@media (min-width: 1280px) {
    body {
        padding: 24px 40px;
    }

    .container {
        max-width: var(--content-max-width, 1600px);
    }

    header {
        padding: 18px 32px;
        margin-bottom: 20px;
        border-radius: 14px;
        display: flex;
        align-items: center;
    }

    header h1 {
        font-size: 1.6rem;
    }

    /* Wider sidebar */
    .tabs {
        width: 240px;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
        gap: 14px;
    }

    .card {
        padding: 22px 26px;
        margin-bottom: 16px;
    }

    /* Two-column layout utility */
    .two-col-desktop {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 16px;
    }

    /* Wider modal on large screens */
    .modal-content {
        max-width: 720px;
    }
}

/* Extra-wide screens (1600px+) */
@media (min-width: 1600px) {
    body {
        padding: 28px 56px;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    }
}

