/* ===================================
   TripDesk Resources Portal - PWA Styles
   Mobile-first responsive design
   =================================== */

/* ----- Root Variables ----- */
:root {
    --td-primary: #4361ee;
    --td-primary-rgb: 67, 97, 238;
    --td-primary-light: #e8ecfd;
    --td-secondary: #6c757d;
    --td-success: #28a745;
    --td-danger: #dc3545;
    --td-warning: #ffc107;
    --td-info: #17a2b8;
    --td-dark: #1e1e2d;
    --td-body-bg: #f5f6fa;
    --td-bottom-nav-height: 60px;
    --td-top-bar-height: 56px;
}

/* ----- Body ----- */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--td-body-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Prevent overscroll bounce on iOS */
html, body {
    overscroll-behavior: none;
}

/* ----- PWA Install & Standalone ----- */
@media all and (display-mode: standalone) {
    body {
        /* Safe area insets for notched devices */
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ----- Top Bar ----- */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--td-top-bar-height);
    background: white;
    border-bottom: 1px solid #e9ecef;
    z-index: 1030;
    display: flex;
    align-items: center;
    padding: 0 1rem;
}

.top-bar .logo-text {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--td-primary);
}

/* ----- Main Content Area ----- */
.main-content {
    padding-top: calc(var(--td-top-bar-height) + 1rem);
    padding-bottom: calc(var(--td-bottom-nav-height) + 1.5rem);
    padding-left: 1rem;
    padding-right: 1rem;
    min-height: 100vh;
}

/* ----- Bottom Navigation ----- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--td-bottom-nav-height);
    background: white;
    border-top: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 1030;
    padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav .nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--td-secondary);
    font-size: 0.7rem;
    padding: 0.25rem 0;
    transition: color 0.2s ease;
}

.bottom-nav .nav-item i {
    font-size: 1.4rem;
    margin-bottom: 0.15rem;
}

.bottom-nav .nav-item.active {
    color: var(--td-primary);
}

.bottom-nav .nav-item:hover {
    color: var(--td-primary);
}

/* ----- Avatar (shared component: .avatar + .avatar-fallback) ----- */
.avatar {
    --size: 48px;
    width: var(--size);
    height: var(--size);
    border-radius: 50%;
    overflow: hidden;
    display: inline-block;
    flex-shrink: 0;
}

.avatar > img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.avatar-fallback {
    --scale: .42; /* for 2 letters */
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--td-primary) 0%, var(--td-info) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    letter-spacing: 0.5px;
    line-height: 1;
    text-transform: uppercase;
    font-size: calc(var(--size) * var(--scale));
}

.avatar-fallback[data-chars="1"] {
    --scale: .58;
}

.avatar-fallback[data-chars="3"] {
    --scale: .34;
}

/* ----- Bottom Nav Active State (Blazor NavLink applies 'active' class) ----- */
.app-bottom-nav .nav-tab {
    color: var(--td-secondary);
    transition: color 0.2s ease;
    flex: 1;
}

.app-bottom-nav .nav-tab.active {
    color: var(--td-primary);
}

.app-bottom-nav .nav-tab:hover {
    color: var(--td-primary);
}

/* ----- Shift Cards ----- */
.shift-card {
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.shift-card:active {
    transform: scale(0.98);
}

.driver-shift-reminder {
    display: flex;
    align-items: flex-start;
    gap: 0.85rem;
    padding: 0.95rem;
    border: 1px solid rgba(255, 193, 7, 0.55);
    border-radius: 1rem;
    background:
        linear-gradient(135deg, rgba(255, 193, 7, 0.18), rgba(67, 97, 238, 0.08)),
        var(--bs-body-bg);
    box-shadow: 0 10px 28px rgba(255, 193, 7, 0.14);
}

.driver-shift-reminder__icon {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 999px;
    color: #1f2430;
    background: #ffc107;
    box-shadow: 0 8px 18px rgba(255, 193, 7, 0.28);
}

.driver-shift-reminder__icon i {
    font-size: 1.35rem;
}

.driver-shift-reminder__content {
    min-width: 0;
}

.driver-shift-reminder__eyebrow {
    margin-bottom: 0.12rem;
    color: #b7791f;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.driver-shift-reminder__title {
    margin-bottom: 0.45rem;
    font-size: 0.95rem;
    font-weight: 700;
}

.driver-shift-reminder__items {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    font-size: 0.82rem;
    line-height: 1.35;
}

.driver-shift-reminder__items > div {
    display: flex;
    align-items: flex-start;
    gap: 0.45rem;
}

.driver-shift-reminder__items i {
    flex: 0 0 auto;
    margin-top: 0.1rem;
    color: #b7791f;
}

/* ----- Auth Layout ----- */
.auth-layout {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--td-primary) 0%, #1e1e2d 100%);
    padding: 1rem;
}

.auth-layout .card {
    max-width: 400px;
    width: 100%;
    border-radius: 1rem;
}

/* ----- Loading States ----- */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 0.25rem;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ----- Status Badge Colors (matching Operations UI) ----- */
.badge.status-draft { background-color: #6c757d; }
.badge.status-dispatched { background-color: #ffc107; color: #000; }
.badge.status-accepted { background-color: #17a2b8; }
.badge.status-declined { background-color: #343a40; }
.badge.status-in-progress { background-color: #4361ee; }
.badge.status-completed { background-color: #28a745; }
.badge.status-cancelled { background-color: #dc3545; }

/* ----- Scrollable Tabs ----- */
.overflow-auto {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.overflow-auto::-webkit-scrollbar {
    display: none;
}

/* ----- Pull to Refresh Indicator ----- */
.pull-to-refresh {
    text-align: center;
    padding: 1rem;
    color: var(--td-secondary);
    font-size: 0.85rem;
}

/* ----- Modal Backdrop ----- */
.modal.show.d-block {
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ----- Toast Positioning (above bottom nav) ----- */
.toast {
    border-radius: 0.75rem;
}

/* ----- Topbar Link (icon buttons in header, no underline/border) ----- */
.topbar-link {
    background: none;
    border: none;
    color: #fff;
    padding: 0;
    cursor: pointer;
    line-height: 1;
    text-decoration: none;
}

.topbar-link:hover {
    color: rgba(255, 255, 255, 0.75);
    text-decoration: none;
}

/* ----- Bottom Nav — default light background ----- */
.app-bottom-nav {
    background: #fff;
}

/* ----- Dark Mode Support ----- */
/* Bootstrap 5.3 handles most dark mode via [data-bs-theme="dark"] on <html>.
   We only override what Bootstrap doesn't cover. */

[data-bs-theme="dark"] {
    --td-body-bg: #1a1a2e;
    --td-surface: #16213e;
    --td-surface-border: #2a2a4a;
}

/* Bottom navigation */
[data-bs-theme="dark"] .app-bottom-nav {
    background: var(--td-surface) !important;
    border-color: var(--td-surface-border) !important;
}

/* Nav tab text in dark mode */
[data-bs-theme="dark"] .app-bottom-nav .nav-tab {
    color: #8e94a0;
}

[data-bs-theme="dark"] .app-bottom-nav .nav-tab.active {
    color: var(--td-primary);
}

/* Card headers with bg-white override */
[data-bs-theme="dark"] .card-header.bg-white {
    background: var(--td-surface) !important;
}

/* bg-light override for dark body bg */
[data-bs-theme="dark"] .bg-light {
    background-color: var(--td-body-bg) !important;
}

/* List group borders */
[data-bs-theme="dark"] .list-group-item {
    border-color: var(--td-surface-border);
}

/* Modal */
[data-bs-theme="dark"] .modal-content {
    background: var(--td-surface);
    border-color: var(--td-surface-border);
}

/* Form controls */
[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select {
    background-color: #1a1a3e;
    border-color: var(--td-surface-border);
    color: #e0e0e0;
}

/* Status filter badges inside buttons */
[data-bs-theme="dark"] .btn .badge.bg-white {
    background-color: rgba(255, 255, 255, 0.15) !important;
    color: inherit !important;
}

/* Outline buttons in dark mode — better contrast */
[data-bs-theme="dark"] .btn-outline-secondary {
    color: #adb5bd;
    border-color: #3a3f5c;
}

[data-bs-theme="dark"] .btn-outline-secondary:hover {
    background-color: #2a2f4a;
    color: #fff;
}

/* Shift card press state */
[data-bs-theme="dark"] .shift-card:active {
    background-color: #1a1a3e;
}

[data-bs-theme="dark"] .driver-shift-reminder {
    border-color: rgba(255, 193, 7, 0.45);
    background:
        linear-gradient(135deg, rgba(255, 193, 7, 0.16), rgba(67, 97, 238, 0.12)),
        var(--td-surface);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
}

[data-bs-theme="dark"] .driver-shift-reminder__eyebrow,
[data-bs-theme="dark"] .driver-shift-reminder__items i {
    color: #ffd166;
}

/* ----- Responsive Adjustments ----- */
@media (min-width: 768px) {
    .main-content {
        max-width: 600px;
        margin: 0 auto;
    }

    .bottom-nav {
        max-width: 600px;
        left: 50%;
        transform: translateX(-50%);
        border-radius: 1rem 1rem 0 0;
    }
}

/* ----- Utility: Touch-friendly tap targets ----- */
.btn, .list-group-item-action {
    min-height: 44px;
}

/* ----- Stat Chips (compact Home stats) ----- */
.stat-chip {
    font-size: 0.8rem;
    white-space: nowrap;
}

/* ----- Task Accordion ----- */
.task-item {
    cursor: pointer;
    border-bottom: 1px solid var(--bs-border-color, #dee2e6);
    transition: background-color 0.15s ease;
}

.task-item:last-child {
    border-bottom: none;
}

.task-item:active {
    background-color: rgba(var(--td-primary-rgb), 0.05);
}

/* "Next" task — left accent border + subtle highlight */
.task-next {
    border-left: 3px solid var(--td-primary);
    background-color: rgba(var(--td-primary-rgb), 0.04);
}

/* Completed task — faded */
.task-completed {
    opacity: 0.55;
}

/* Expanded detail area */
.task-details {
    animation: taskSlideDown 0.2s ease;
}

@keyframes taskSlideDown {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ----- Dark Mode: Task Accordion ----- */
[data-bs-theme="dark"] .task-item {
    border-bottom-color: var(--td-surface-border);
}

[data-bs-theme="dark"] .task-next {
    background-color: rgba(var(--td-primary-rgb), 0.10);
}

[data-bs-theme="dark"] .stat-chip {
    border: 1px solid var(--td-surface-border);
}

/* ----- Print: hide nav elements ----- */
@media print {
    .top-bar, .bottom-nav {
        display: none !important;
    }

    .main-content {
        padding: 0;
    }
}
