/* ===================================
   PM - Main Styles
   Project Management
   =================================== */

/* CSS Variables */
:root {
    /* Neutral base — slightly cool, warmer whites */
    --bg-primary: #ffffff;
    --bg-secondary: #f6f8fb;
    --bg-tertiary: #eef2f7;
    --bg-app: linear-gradient(180deg, #f7f9fc 0%, #eef2f7 100%);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border: #e4e8ef;
    --border-dark: #cbd2dc;

    /* Component status colors */
    --component-in-progress: #4f46e5;
    --component-awaited: #d97706;
    --component-in-approval: #8b5cf6;
    --component-complete: #16a34a;

    /* Progress level colors */
    --progress-none: #ef4444;
    --progress-partial: #d97706;
    --progress-most: #4f46e5;
    --progress-complete: #16a34a;

    /* Priority colors */
    --priority-high: #ef4444;
    --priority-medium: #d97706;
    --priority-low: #16a34a;

    /* UI colors */
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --accent-soft: rgba(79, 70, 229, 0.08);
    --accent-ring: rgba(79, 70, 229, 0.18);
    --success: #16a34a;
    --warning: #d97706;
    --danger: #ef4444;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --font-mono: 'SF Mono', 'JetBrains Mono', Monaco, 'Courier New', monospace;
    --font-size-xs: 11px;
    --font-size-sm: 13px;
    --font-size-base: 14px;
    --font-size-lg: 16px;
    --font-size-xl: 20px;
    --font-size-2xl: 26px;

    /* Layout */
    --sidebar-width: 244px;
    --header-height: 60px;
    --footer-height: 32px;
    --border-radius: 8px;
    --border-radius-lg: 12px;

    /* Shadows — layered for depth */
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 1px rgba(15, 23, 42, 0.03);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06), 0 2px 4px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.10), 0 4px 12px rgba(15, 23, 42, 0.06);
    --shadow-focus: 0 0 0 3px var(--accent-ring);
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-app);
    background-attachment: fixed;
    min-height: 100vh;
    font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
}

/* Tabular numerals for tables, stats, dates */
.table, .stat-card__value, .gantt, .report-table,
.detail-grid__value, td, th, .progress-group__label {
    font-variant-numeric: tabular-nums;
}

/* Custom scrollbars (WebKit) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(15, 23, 42, 0.12);
    border-radius: 100px;
    border: 2px solid transparent;
    background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(15, 23, 42, 0.22); background-clip: padding-box; border: 2px solid transparent; }

::selection { background: var(--accent-ring); color: var(--text-primary); }

/* Layout Structure */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-lg);
    z-index: 100;
}

.app-header__title {
    font-size: var(--font-size-lg);
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.app-header__subtitle {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin-left: var(--space-sm);
}

.app-header__actions {
    display: flex;
    gap: var(--space-sm);
}

.app-body {
    display: flex;
    margin-top: var(--header-height);
    min-height: calc(100vh - var(--header-height) - var(--footer-height));
}

.app-sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: var(--footer-height);
    width: var(--sidebar-width);
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: saturate(180%) blur(10px);
    -webkit-backdrop-filter: saturate(180%) blur(10px);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: var(--space-lg) var(--space-md);
}

.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: var(--space-lg);
    background: transparent;
    min-height: calc(100vh - var(--header-height) - var(--footer-height));
    overflow: hidden;
}

.app-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--footer-height);
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: saturate(180%) blur(10px);
    -webkit-backdrop-filter: saturate(180%) blur(10px);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-lg);
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    z-index: 100;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.25;
    color: var(--text-primary);
    letter-spacing: -0.015em;
}

h1 { font-size: var(--font-size-2xl); font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: var(--font-size-xl); font-weight: 600; }
h3 { font-size: var(--font-size-lg); font-weight: 600; }
h4 { font-size: var(--font-size-base); font-weight: 600; }

p {
    margin-bottom: var(--space-md);
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    padding: 7px 14px;
    font-size: var(--font-size-sm);
    font-weight: 500;
    font-family: inherit;
    border: 1px solid transparent;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
    white-space: nowrap;
    letter-spacing: -0.005em;
}

.btn:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

.btn:active:not(:disabled) {
    transform: translateY(0.5px);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn--primary {
    background: linear-gradient(180deg, #5a51eb 0%, #4f46e5 100%);
    color: white;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 1px 2px rgba(15, 23, 42, 0.18);
}

.btn--primary:hover:not(:disabled) {
    background: linear-gradient(180deg, #4f46e5 0%, #4338ca 100%);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 4px 10px rgba(79, 70, 229, 0.32);
}

.btn--secondary {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-color: var(--border);
    box-shadow: var(--shadow-sm);
}

.btn--secondary:hover:not(:disabled) {
    background: var(--bg-secondary);
    border-color: var(--border-dark);
}

.btn--danger {
    background: linear-gradient(180deg, #f56565 0%, #ef4444 100%);
    color: white;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 1px 2px rgba(15, 23, 42, 0.18);
}

.btn--danger:hover:not(:disabled) {
    background: linear-gradient(180deg, #ef4444 0%, #dc2626 100%);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 4px 10px rgba(239, 68, 68, 0.30);
}

.btn--ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn--ghost:hover:not(:disabled) {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.btn--sm {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-xs);
}

.btn--lg {
    padding: var(--space-md) var(--space-lg);
    font-size: var(--font-size-base);
}

/* Forms */
.form-group {
    margin-bottom: var(--space-md);
}

.form-label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: var(--space-xs);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 9px 12px;
    font-size: var(--font-size-sm);
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--text-muted);
}

.form-input:hover,
.form-select:hover,
.form-textarea:hover {
    border-color: var(--border-dark);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--shadow-focus);
}

.form-textarea {
    min-height: 100px;
    resize: vertical;
}

.form-select {
    cursor: pointer;
}

/* Cards */
.card {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card__header {
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card__title {
    font-size: var(--font-size-base);
    font-weight: 600;
    letter-spacing: -0.005em;
}

.card__body {
    padding: var(--space-lg);
}

.card__footer {
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
    border-radius: 0 0 var(--border-radius-lg) var(--border-radius-lg);
}

/* Tables */
.table-container {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
}

.table th,
.table td {
    padding: 11px var(--space-md);
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    font-weight: 600;
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--bg-secondary);
    white-space: nowrap;
}

.table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: color 0.15s ease, background 0.15s ease;
}

.table th.sortable:hover {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.table th.sorted-asc,
.table th.sorted-desc {
    color: var(--accent);
}

.table th.sorted-asc::after {
    content: ' ↑';
}

.table th.sorted-desc::after {
    content: ' ↓';
}

.table tbody tr {
    transition: background 0.12s ease;
}

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

.table tbody tr.clickable {
    cursor: pointer;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: var(--space-2xl);
    color: var(--text-secondary);
}

.empty-state__icon {
    font-size: 48px;
    margin-bottom: var(--space-md);
    opacity: 0.5;
}

.empty-state__title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    margin-bottom: var(--space-sm);
    color: var(--text-primary);
}

.empty-state__description {
    margin-bottom: var(--space-lg);
}

/* Utilities */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-muted {
    color: var(--text-secondary);
}

.text-sm {
    font-size: var(--font-size-sm);
}

.text-xs {
    font-size: var(--font-size-xs);
}

.font-mono {
    font-family: var(--font-mono);
}

.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }

/* Hamburger menu button — visible only on mobile */
.app-header__menu {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 36px;
    height: 36px;
    padding: 0 6px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    cursor: pointer;
}

.app-header__menu span {
    display: block;
    height: 2px;
    background: var(--text-primary);
    border-radius: 1px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.app-container.sidebar-open .app-header__menu span:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
}
.app-container.sidebar-open .app-header__menu span:nth-child(2) {
    opacity: 0;
}
.app-container.sidebar-open .app-header__menu span:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
}

.app-sidebar__overlay {
    display: none;
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
    z-index: 105;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

/* -----------------------------------------
   Mobile / tablet breakpoint
   ----------------------------------------- */
@media (max-width: 768px) {
    :root {
        --header-height: 52px;
        --space-lg: 16px;
        --space-xl: 20px;
    }

    .app-header {
        padding: 0 var(--space-sm);
        gap: var(--space-xs);
    }

    .app-header__menu {
        display: flex;
    }

    .app-header__title {
        font-size: var(--font-size-base);
    }

    .app-header__subtitle {
        display: none;
    }

    .app-header__actions {
        gap: 4px;
    }

    /* Hide secondary toolbar buttons (Import/Export) — accessible from
       their respective tabs (Tasks tab has its own Import/Export). */
    .app-header__action--wide {
        display: none;
    }

    .user-badge__name {
        display: none;
    }

    /* Sidebar becomes an off-canvas drawer */
    .app-sidebar {
        z-index: 110;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: none;
        bottom: 0;
        width: min(280px, 80vw);
    }

    .app-container.sidebar-open .app-sidebar {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .app-sidebar__overlay {
        display: block;
    }

    .app-container.sidebar-open .app-sidebar__overlay {
        opacity: 1;
        visibility: visible;
    }

    /* Main content fills width */
    .app-main {
        margin-left: 0;
        padding: var(--space-md);
    }

    /* Footer: smaller, compact */
    .app-footer {
        height: 28px;
        font-size: 10px;
        padding: 0 var(--space-sm);
    }

    /* Typography scaling */
    h1 { font-size: var(--font-size-xl); }
    h2 { font-size: var(--font-size-lg); }

    /* Page header rows — let action buttons wrap below the title.
       Also allow inline button groups (`.flex.gap-sm`) to wrap so toolbars
       don't overflow on narrow screens. */
    .flex-between {
        flex-wrap: wrap;
        gap: var(--space-sm);
    }
    .flex {
        flex-wrap: wrap;
    }

    /* Form inline date inputs adapt to phone width */
    .form-input,
    .form-select,
    .form-textarea {
        font-size: 16px;  /* prevents iOS zoom on focus */
    }

    /* Inline grids inside forms (Zone/Type/Priority, Planned start/end)
       collapse to a single column. */
    form > div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }

    /* Detail view 2-column layout stacks */
    .detail-view > div[style*="grid-template-columns: 2fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
    .detail-grid {
        grid-template-columns: 1fr;
    }

    /* Stat cards stay readable */
    .stat-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-sm);
    }
    .stat-card {
        padding: var(--space-sm) var(--space-md);
    }
    .stat-card__value {
        font-size: 22px;
    }

    /* Modal: full-screen-ish on phone */
    .modal {
        width: calc(100vw - 16px);
        max-height: calc(100vh - 16px);
        max-width: none;
    }
    .modal__header,
    .modal__body,
    .modal__footer {
        padding: var(--space-md);
    }

    /* Toast container — keep clear of the footer */
    .toast-container {
        right: var(--space-md);
        left: var(--space-md);
        bottom: calc(var(--footer-height) + var(--space-sm));
    }
    .toast {
        font-size: var(--font-size-sm);
    }
}

/* Very small phones — fine-tune */
@media (max-width: 420px) {
    .stat-cards {
        grid-template-columns: 1fr 1fr;
    }
    .stat-card__value {
        font-size: 20px;
    }
    .app-header__title {
        font-size: var(--font-size-sm);
    }
    .user-badge__role {
        font-size: 9px;
        padding: 2px 6px;
    }
}

.flex {
    display: flex;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.gap-sm {
    gap: var(--space-sm);
}

.gap-md {
    gap: var(--space-md);
}
