/* Velocity Application - Main Stylesheet */

/* ============================================
   CSS Custom Properties (Theme Variables)
   ============================================ */
:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #a5b4fc;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --info-color: #06b6d4;
    --background-color: #f8fafc;
    --surface-color: #ffffff;
    --surface-hover: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --border-radius: 12px;
    --border-radius-lg: 16px;
    --radius-xs: 4px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 50%;
    --radius-pill: 50px;
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);

    /* Minimum hit area for any tappable element (WCAG 2.5.8 Target Size (Minimum)
       asks for 24px; 44px is the Apple HIG / project standard we hold to). */
    --touch-target-min: 44px;
    /* Inset of the skip link from the top-left corner once it is focused. */
    --space-skip-link-offset: 8px;
    /* Gap between a mobile toast and the FAB beneath it. */
    --space-toast-gap: 12px;

    /* Hover/pressed shade for the flat brand button (one step past --primary-dark). */
    --primary-hover: #4338ca;
    /* Secondary accent for checklist and long-break UI; lightened in the dark theme. */
    --accent-purple: #6f42c1;
    /* End stop of the FAB gradient (the one "hero" gradient kept in the shell). */
    --accent-violet: #8b5cf6;
    /* Text/icons on a solid brand-colored surface — must stay white in both themes. */
    --on-primary: #ffffff;
    /* Third-party brand color for WhatsApp share affordances. */
    --brand-whatsapp: #25d366;

    --navbar-bg: rgba(255, 255, 255, 0.95);
    --body-gradient-end: #f1f5f9;
    --card-bg: var(--surface-color);
    --dropdown-bg: var(--surface-color);

    /* Point Bootstrap's own primary at the brand indigo, so .text-primary, .bg-primary,
       links and focus rings stop rendering Bootstrap blue next to indigo UI. (Bootstrap
       5.3 still hardcodes blue inside some component variables — see the palette rule
       in base-inline.css for how to override one where it shows.) */
    --bs-primary: var(--primary-color);
    --bs-primary-rgb: 99, 102, 241;
    --bs-link-color: var(--primary-dark);
    --bs-link-color-rgb: 79, 70, 229;
    --bs-link-hover-color: var(--primary-hover);
    --bs-focus-ring-color: rgba(99, 102, 241, 0.25);
}

/* Dark theme overrides */
[data-theme="dark"] {
    --primary-color: #818cf8;
    --primary-dark: #6366f1;
    --primary-light: #4f46e5;
    --secondary-color: #94a3b8;
    --success-color: #34d399;
    --warning-color: #fbbf24;
    --danger-color: #f87171;
    --info-color: #22d3ee;
    --background-color: #0f172a;
    --surface-color: #1e293b;
    --surface-hover: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --border-color: #334155;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.3);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.4), 0 8px 10px -6px rgb(0 0 0 / 0.3);
    --accent-purple: #a78bfa;
    --primary-hover: #4f46e5;
    --navbar-bg: rgba(15, 23, 42, 0.95);
    --body-gradient-end: #1e293b;
    --card-bg: var(--surface-color);
    --dropdown-bg: #1e293b;

    /* Bootstrap CSS variable overrides — eliminates ~400 lines of
       [data-theme="dark"] .component {} overrides and expensive
       [style*="..."] attribute selectors.  Bootstrap components use
       these vars internally, so the cascade handles dark mode
       without per-class selectors. */
    color-scheme: dark;
    --bs-body-color: var(--text-primary);
    --bs-body-bg: var(--surface-color);
    --bs-secondary-color: var(--text-secondary);
    --bs-tertiary-color: var(--text-muted);
    --bs-border-color: var(--border-color);
    --bs-heading-color: var(--text-primary);
    --bs-link-color: var(--primary-color);
    --bs-link-color-rgb: 129, 140, 248;
    --bs-link-hover-color: var(--primary-dark);
    --bs-primary-rgb: 129, 140, 248;
    --bs-code-color: var(--primary-light);
}

/* ============================================
   Base Body Styles
   ============================================ */
body {
    background: linear-gradient(135deg, var(--background-color) 0%, var(--body-gradient-end) 100%);
    /* System stack only: 'Inter' was listed first but never loaded, so it only ever
       matched on machines that happened to have it installed. */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text-primary);
    min-height: 100vh;
}

/* Smooth theme transition */
body,
.navbar,
.card,
.dropdown-menu,
.btn,
.form-control,
.form-select,
.alert,
.badge,
.table,
.progress,
.list-group-item,
.modal-content {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* ============================================
   Navbar Styles
   ============================================ */
.navbar {
    background: var(--navbar-bg) !important;
    /* -webkit- prefix required for Safari/iOS, which is the primary PWA target here. */
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    z-index: 1000;
}

.navbar-brand {
    font-weight: 700;
    color: var(--primary-color) !important;
}

.nav-link {
    font-weight: 500;
    color: var(--text-secondary) !important;
    transition: var(--transition);
    border-radius: var(--radius-sm);
    margin: 0 2px;
}

.nav-link:hover {
    color: var(--primary-color) !important;
    background: rgba(99, 102, 241, 0.1);
}

/* Current page. Colour alone is not a sufficient cue (WCAG 1.4.1 Use of Colour), so
   the active item also carries a weight change and an underline bar. */
.nav-link.active {
    color: var(--primary-color) !important;
    font-weight: 700;
    position: relative;
}

.nav-link.active::after {
    content: "";
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 2px;
    height: 2px;
    border-radius: 2px;
    background: var(--primary-color);
}

/* Inside dropdowns the underline bar would collide with the item padding; a left
   accent rail reads better in a vertical menu. */
.dropdown-item.active,
.dropdown-item.active:focus,
.dropdown-item.active:hover {
    background: rgba(99, 102, 241, 0.12);
    color: var(--primary-color);
    font-weight: 600;
    box-shadow: inset 3px 0 0 0 var(--primary-color);
}

/* ============================================
   Theme Toggle Button
   ============================================ */
.theme-toggle {
    background: none;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-full);
    /* Was 38px — below the 44px minimum touch target. */
    width: var(--touch-target-min);
    height: var(--touch-target-min);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition);
    padding: 0;
}

.theme-toggle:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
    transform: rotate(15deg);
}

.theme-toggle .bi {
    font-size: 1.1rem;
}

/* ============================================
   Dropdown Menu Styles
   ============================================ */
.dropdown-menu {
    border: none;
    box-shadow: var(--shadow-lg);
    border-radius: var(--border-radius);
    margin-top: 8px;
    z-index: 1100;
}

.dropdown-item {
    padding: 12px 16px;
    border-radius: var(--radius-xs);
    margin: 2px 4px;
    transition: var(--transition);
}

.dropdown-item:hover {
    background: var(--surface-hover);
    color: var(--primary-color);
}

/* ============================================
   Container Styles
   ============================================ */
.container {
    max-width: 1400px;
}

/* ============================================
   Card Styles
   ============================================ */
.card {
    border: none;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    transition: var(--transition);
    background: var(--surface-color);
}

/* Lift only cards that are links. A lift on every .card told users that static
   panels were clickable. */
a:hover > .card,
.card-link:hover .card {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.card-header {
    /* Flat brand surface. --primary-dark rather than --primary-color: white on
       #6366f1 is ~4.46:1, just under WCAG AA for body text; #4f46e5 is ~6.3:1. */
    background: var(--primary-dark);
    color: var(--on-primary);
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0 !important;
    border-bottom: none;
    padding: 20px 24px;
}

.card-header .btn-link {
    color: var(--on-primary);
}

.card-header h6 {
    color: var(--on-primary) !important;
}

.card-body {
    padding: 24px;
}

/* ============================================
   Button Styles
   ============================================ */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
    padding: 12px 24px;
    transition: var(--transition);
    /* No `border: none` here: it stripped the outline from every .btn-outline-*
       button (~240 of them), leaving them indistinguishable from plain text.
       Solid buttons are unaffected — Bootstrap draws their border in the fill color. */
}

/* Flat brand button, set through Bootstrap's own button variables so hover, active,
   focus and disabled states all stay consistent. The gradient + glow + hover lift is
   gone; btn-success/-warning/-danger use Bootstrap's native flat styles, whose text
   colors are contrast-checked (the old gradients put white on #10b981, ~2.5:1). */
.btn-primary {
    --bs-btn-color: var(--on-primary);
    --bs-btn-bg: var(--primary-dark);
    --bs-btn-border-color: var(--primary-dark);
    --bs-btn-hover-color: var(--on-primary);
    --bs-btn-hover-bg: var(--primary-hover);
    --bs-btn-hover-border-color: var(--primary-hover);
    --bs-btn-active-color: var(--on-primary);
    --bs-btn-active-bg: var(--primary-hover);
    --bs-btn-active-border-color: var(--primary-hover);
    --bs-btn-disabled-color: var(--on-primary);
    --bs-btn-disabled-bg: var(--primary-dark);
    --bs-btn-disabled-border-color: var(--primary-dark);
}

/* Outline brand button: Bootstrap 5.3 hardcodes blue in these variables. */
.btn-outline-primary {
    --bs-btn-color: var(--primary-dark);
    --bs-btn-border-color: var(--primary-dark);
    --bs-btn-hover-color: var(--on-primary);
    --bs-btn-hover-bg: var(--primary-dark);
    --bs-btn-hover-border-color: var(--primary-dark);
    --bs-btn-active-color: var(--on-primary);
    --bs-btn-active-bg: var(--primary-dark);
    --bs-btn-active-border-color: var(--primary-dark);
    --bs-btn-disabled-color: var(--primary-dark);
    --bs-btn-disabled-border-color: var(--primary-dark);
}

[data-theme="dark"] .btn-outline-primary {
    --bs-btn-color: var(--primary-color);
    --bs-btn-border-color: var(--primary-color);
}

/* Card headers are a solid brand surface, so an indigo outline button there was
   invisible (e.g. "Add Manual Time"). Invert it to white-on-brand. */
.card-header .btn-outline-primary {
    --bs-btn-color: var(--on-primary);
    --bs-btn-border-color: var(--on-primary);
    --bs-btn-hover-color: var(--primary-dark);
    --bs-btn-hover-bg: var(--on-primary);
    --bs-btn-hover-border-color: var(--on-primary);
    --bs-btn-active-color: var(--primary-dark);
    --bs-btn-active-bg: var(--on-primary);
    --bs-btn-active-border-color: var(--on-primary);
}

/* Focus states.
   :focus-visible rather than :focus so the ring appears for keyboard/AT users but not
   on every mouse click. A global rule covers links, dropdown items, nav links and the
   close buttons too — previously only .btn and form controls had any visible ring, so
   tabbing through the navbar gave no indication of position. */
:focus-visible,
.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible,
.nav-link:focus-visible,
.dropdown-item:focus-visible,
.btn-close:focus-visible {
    outline: 3px solid rgba(99, 102, 241, 0.5);
    outline-offset: 2px;
}

/* Form controls keep a persistent border/shadow cue on plain :focus (below), so the
   heavy outline is reserved for keyboard focus. */

/* ============================================
   Form Control Styles
   ============================================ */
.form-control,
.form-select {
    border-radius: 10px;
    border: 2px solid var(--border-color);
    padding: 12px 16px;
    transition: var(--transition);
    background: var(--surface-color);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

[data-theme="dark"] .form-control::placeholder {
    color: var(--text-muted);
}

/* ============================================
   Badge Styles
   ============================================ */
.badge {
    border-radius: 20px;
    font-weight: 600;
    padding: 6px 12px;
    font-size: 0.8rem;
}

/* ============================================
   Alert Styles
   ============================================ */
.alert {
    border-radius: var(--border-radius);
    border: none;
    box-shadow: var(--shadow-sm);
}

/* ============================================
   Table Styles
   ============================================ */
.table {
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.table thead th {
    background: var(--surface-hover);
    border-bottom: 2px solid var(--border-color);
    font-weight: 600;
    color: var(--text-primary);
    padding: 16px;
}

.table tbody tr {
    transition: var(--transition);
}

.table tbody tr:hover {
    background: var(--surface-hover);
}

/* ============================================
   Progress Bar Styles
   ============================================ */
.progress {
    border-radius: 10px;
    background: var(--surface-hover);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.progress-bar {
    background: var(--primary-color);
    border-radius: 10px;
}

/* Dark Mode — minimal overrides not covered by Bootstrap CSS vars.
   Most Bootstrap components are themed via --bs-* vars on
   [data-theme="dark"] above. Only keep overrides that use
   app-specific rgba colors, !important utilities, or special filters. */
[data-theme="dark"] .text-dark { color: var(--text-primary) !important; }
[data-theme="dark"] .text-muted { color: var(--text-muted) !important; }
[data-theme="dark"] .text-secondary { color: var(--text-secondary) !important; }
[data-theme="dark"] .text-primary { color: var(--primary-color) !important; }
[data-theme="dark"] .text-success { color: var(--success-color) !important; }
[data-theme="dark"] .text-warning { color: var(--warning-color) !important; }
[data-theme="dark"] .text-danger { color: var(--danger-color) !important; }
[data-theme="dark"] .text-info { color: var(--info-color) !important; }
[data-theme="dark"] .bg-light { background-color: var(--surface-hover) !important; }
[data-theme="dark"] .small,
[data-theme="dark"] small { color: var(--text-muted) !important; }
[data-theme="dark"] .spinner-border,
[data-theme="dark"] .spinner-grow { color: var(--primary-color); }

/* Alert contextual colors — use app-specific rgba tones */
[data-theme="dark"] .alert-info {
    background-color: rgba(6, 182, 212, 0.15);
    border-color: rgba(6, 182, 212, 0.3);
    color: var(--info-color);
}
[data-theme="dark"] .alert-warning {
    background-color: rgba(245, 158, 11, 0.15);
    border-color: rgba(245, 158, 11, 0.3);
    color: var(--warning-color);
}
[data-theme="dark"] .alert-danger {
    background-color: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.3);
    color: var(--danger-color);
}
[data-theme="dark"] .alert-success {
    background-color: rgba(16, 185, 129, 0.15);
    border-color: rgba(16, 185, 129, 0.3);
    color: var(--success-color);
}

/* Table contextual colors — match alert style */
[data-theme="dark"] .table-success {
    background-color: rgba(16, 185, 129, 0.15) !important;
    color: var(--success-color) !important;
}
[data-theme="dark"] .table-warning {
    background-color: rgba(245, 158, 11, 0.15) !important;
    color: var(--warning-color) !important;
}
[data-theme="dark"] .table-danger {
    background-color: rgba(239, 68, 68, 0.15) !important;
    color: var(--danger-color) !important;
}
[data-theme="dark"] .table-info {
    background-color: rgba(6, 182, 212, 0.15) !important;
    color: var(--info-color) !important;
}

/* ============================================
   Navbar Dark Mode Fixes
   ============================================ */
[data-theme="dark"] .navbar {
    background: var(--navbar-bg) !important;
}

[data-theme="dark"] .navbar-brand {
    color: var(--primary-color) !important;
}

[data-theme="dark"] .nav-link {
    color: var(--text-secondary) !important;
}

[data-theme="dark"] .nav-link:hover {
    color: var(--primary-color) !important;
    background: rgba(99, 102, 241, 0.1);
}

[data-theme="dark"] .navbar-toggler {
    border-color: var(--border-color);
    background-color: var(--surface-hover);
}

/* No .navbar-toggler-icon filter here: Bootstrap's [data-bs-theme=dark] already
   swaps in a light icon, and an invert() on top of it turned it black again. */

/* Fix Bootstrap .bg-white utility class for dark mode */
[data-theme="dark"] .bg-white {
    background-color: var(--bs-body-bg) !important;
}

/* ============================================
   Specific Page Dark Mode Fixes
   ============================================ */

/* Pomodoro page fixes */
[data-theme="dark"] .timer-display { color: var(--text-primary); }

/* Project map page fixes */
[data-theme="dark"] .task-row:hover { background-color: var(--surface-hover); }
[data-theme="dark"] .task-title { color: var(--text-primary); }
[data-theme="dark"] .task-identifier { color: var(--text-muted); }
[data-theme="dark"] .toggle-children:hover { background-color: var(--surface-hover); }
[data-theme="dark"] .task-children { background-color: var(--surface-hover); }
[data-theme="dark"] .line-segment::before,
[data-theme="dark"] .line-segment::after { background-color: var(--border-color); }

/* ============================================
   Micro-interactions
   ============================================ */
.interactive-element {
    transition: var(--transition);
}

.interactive-element:hover {
    transform: translateY(-1px);
}

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

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   Responsive Improvements
   ============================================ */
@media (max-width: 768px) {
    .navbar-nav {
        margin-top: 10px;
    }

    .card-body {
        padding: 16px;
    }

    .btn {
        padding: 10px 20px;
        font-size: 14px;
    }

    .dropdown-menu {
        left: 0 !important;
        right: auto !important;
    }
}

/* ============================================
   Quadrant Styles (Task Management)
   ============================================ */
.quadrant {
    min-height: 200px;
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 10px;
    position: relative;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.quadrant:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}

/* Quadrant bodies follow the app-wide convention the headers and task badges use:
   Do=danger, Plan=warning, Delegate=info, Drop=secondary. (They used to be green,
   blue, yellow and red — a red "Do It Now" header over a green body.) Bootstrap's
   subtle vars flip with data-bs-theme, so no dark-mode overrides are needed. */
#do-it {
    background: var(--bs-danger-bg-subtle);
    border: 2px solid var(--bs-danger-border-subtle);
}

#plan-it {
    background: var(--bs-warning-bg-subtle);
    border: 2px solid var(--bs-warning-border-subtle);
}

#delegate-it {
    background: var(--bs-info-bg-subtle);
    border: 2px solid var(--bs-info-border-subtle);
}

#drop-it {
    background: var(--bs-secondary-bg-subtle);
    border: 2px solid var(--bs-secondary-border-subtle);
}

/* ============================================
   Task Card Styles
   ============================================ */
.task-card {
    margin-bottom: 5px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* ============================================
   Card Title and Text (Summary Cards)
   ============================================ */
.card-title {
    font-size: 1.5rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
}

.card-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0;
}

/* Expandable text pattern */
.expandable-text-content {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.expandable-text.expanded .expandable-text-content {
    -webkit-line-clamp: unset;
    overflow: visible;
}
.expandable-text-toggle {
    cursor: pointer;
    font-size: 0.8rem;
    text-decoration: none;
}

/* Minimum 44px touch targets for small interactive elements */
.priority-btn.btn-sm {
    min-width: 44px;
    min-height: 44px;
    padding: 0.25rem 0.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.bg-gradient-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
}

/* Profile avatar placeholder icon (was an inline #6c757d, which did not shift in dark mode). */
.profile-avatar-icon {
    font-size: 4rem;
    color: var(--text-secondary);
}

/* Organization logo thumbnail (was an inline #ddd border, invisible on dark surfaces). */
.org-logo-preview {
    max-width: 100px;
    max-height: 100px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xs);
}

/* ============================================
   Toast Notifications (responsive)
   ============================================ */
.toast-notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    min-width: 300px;
    max-width: 420px;
}

@media (max-width: 991.98px) {
    .toast-notification {
        /* Sit above the FAB (which sits above the bottom nav), with a small gap. */
        bottom: calc(var(--fab-offset-bottom) + var(--fab-size) + var(--space-toast-gap) + env(safe-area-inset-bottom, 0px));
        left: 12px;
        right: 12px;
        min-width: 0;
        max-width: 100%;
    }
}

/* Skeleton width for a dashboard stat before its number arrives — about three digits,
   so the tile doesn't jump in width when the real value replaces it. */
.stat-placeholder {
    width: 3ch;
}
