/* ========================================================================
   base.css - Design System, Layout, Badges, Overlays, Print
   CSS variables, base reset, header/nav, buttons, status/priority/type/section
   badges, action icons, loading overlay, session expired, toasts, dev banner,
   empty state, print styles, scrollbar.
   ======================================================================== */

/* ========================================================================
   CSS VARIABLES / DESIGN SYSTEM
   ======================================================================== */
:root {
    /* Primary palette (muted blue) */
    --primary: #4a6da7;
    --primary-dark: #3b5998;
    --primary-light: #dce4f0;
    --primary-bg: #f2f5fa;

    /* Semantic colors (desaturated) */
    --success: #3d8b6e;
    --success-dark: #2d6b54;
    --success-light: #dceee6;

    --warning: #c4933f;
    --warning-dark: #a57a2e;
    --warning-light: #f5ead4;

    --danger: #b85450;
    --danger-dark: #9a3f3c;
    --danger-light: #f0d8d7;

    --info: #6b8db5;
    --info-light: #dfe8f2;

    /* Grays */
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    /* Dynamic status palette - assigned by index from API */
    --status-pal-0-bg: #e8e8e8;    --status-pal-0-text: #555;        --status-pal-0-border: #a0a0a0;
    --status-pal-1-bg: #dce4f0;    --status-pal-1-text: #3b5998;     --status-pal-1-border: #4a6da7;
    --status-pal-2-bg: #f5ead4;    --status-pal-2-text: #a57a2e;     --status-pal-2-border: #c4933f;
    --status-pal-3-bg: #dceee6;    --status-pal-3-text: #2d6b54;     --status-pal-3-border: #3d8b6e;
    --status-pal-4-bg: #f0d8d7;    --status-pal-4-text: #9a3f3c;     --status-pal-4-border: #b85450;
    --status-pal-5-bg: #e8dff0;    --status-pal-5-text: #6b4f8a;     --status-pal-5-border: #7b5fa0;
    --status-pal-6-bg: #d8eef0;    --status-pal-6-text: #3a7a82;     --status-pal-6-border: #4a8a92;
    --status-pal-7-bg: #f0e8d8;    --status-pal-7-text: #7a6a3a;     --status-pal-7-border: #8a7a4a;

    /* Priority colors (muted) */
    --priority-high: #b85450;
    --priority-normal: #4a6da7;
    --priority-low: #a0a0a0;

    /* Layout */
    --container-max: 1720px;

    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-size-xs: 10px;
    --font-size-sm: 11px;
    --font-size-base: 13px;
    --font-size-md: 14px;
    --font-size-lg: 16px;
    --font-size-xl: 20px;

    /* Transitions */
    --ease: cubic-bezier(0.2, 0, 0, 1);
    --transition: all 0.15s var(--ease);

    /* Interaction-state vocabulary (shared across every control) */
    --focus-ring: 0 0 0 2px var(--primary-light);        /* keyboard focus outline */
    --shadow-overlay: 0 4px 16px rgba(17, 24, 39, 0.12), 0 1px 3px rgba(17, 24, 39, 0.08); /* floating panels only */
    --row-hover-bg: rgba(74, 109, 167, 0.12);            /* primary @ 12% - data-row band */
    --row-hover-accent: rgba(74, 109, 167, 0.55);        /* row-end accent bar */
}

/* ========================================================================
   BASE STYLES
   ======================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background: var(--gray-100);
    color: var(--gray-900);
    line-height: 1.4;
    font-size: var(--font-size-base);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 10px 24px;
}

/* ========================================================================
   HEADER
   ======================================================================== */
.dashboard-header {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    padding: 8px 12px;
    margin-bottom: 8px;
    border: 1px solid var(--gray-200);
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.header-title-group {
    display: flex;
    flex-direction: column;
}

.header-title-group h1 {
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -0.3px;
}

.report-meta {
    font-size: var(--font-size-xs);
    color: var(--gray-500);
    margin-top: 2px;
}

.report-meta .client-code {
    font-weight: 600;
    color: var(--primary);
}

.project-filter-badge {
    display: inline-block;
    background: var(--primary-light);
    color: var(--primary-dark);
    border: 1px solid var(--primary);
    font-size: var(--font-size-xs);
    font-weight: 600;
    padding: 1px 6px;
    margin-left: 6px;
    vertical-align: middle;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

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

/* View toggle buttons */
.view-toggle {
    display: flex;
    background: var(--gray-100);
    overflow: hidden;
    border: 1px solid var(--gray-200);
}

.view-toggle .btn-toggle {
    padding: 5px 12px;
    border: none;
    background: transparent;
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--gray-600);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 4px;
}

.view-toggle .btn-toggle:hover {
    background: var(--gray-200);
}

.view-toggle .btn-toggle.active {
    background: var(--primary);
    color: white;
}

/* ========================================================================
   BUTTONS
   ======================================================================== */
.btn {
    padding: 5px 10px;
    background: var(--primary);
    color: white;
    border: none;
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: var(--transition);
    white-space: nowrap;
    font-family: var(--font-family);
}

.btn:hover {
    background: var(--primary-dark);
}

.btn:active {
    transform: translateY(1px);
}

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

.btn-secondary {
    background: white;
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}

.btn-secondary:hover {
    background: var(--gray-50);
    border-color: var(--gray-400);
}

.btn-icon {
    width: 28px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.btn-sm {
    padding: 3px 8px;
    font-size: var(--font-size-xs);
}

.btn-create {
    background: var(--success);
    color: white;
}

.btn-create:hover {
    background: var(--success-dark);
}

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

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: var(--danger-dark);
}

/* ========================================================================
   STATUS & PRIORITY BADGES
   ======================================================================== */
.status-badge {
    display: inline-block;
    padding: 2px 7px;
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    line-height: 1.4;
    min-width: 74px;
}

.status-0 { background: var(--status-pal-0-bg); color: var(--status-pal-0-text); }
.status-1 { background: var(--status-pal-1-bg); color: var(--status-pal-1-text); }
.status-2 { background: var(--status-pal-2-bg); color: var(--status-pal-2-text); }
.status-3 { background: var(--status-pal-3-bg); color: var(--status-pal-3-text); }
.status-4 { background: var(--status-pal-4-bg); color: var(--status-pal-4-text); }
.status-5 { background: var(--status-pal-5-bg); color: var(--status-pal-5-text); }
.status-6 { background: var(--status-pal-6-bg); color: var(--status-pal-6-text); }
.status-7 { background: var(--status-pal-7-bg); color: var(--status-pal-7-text); }
.status-default { background: var(--gray-100); color: var(--gray-600); }

.priority-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 7px;
    font-size: var(--font-size-xs);
    font-weight: 600;
    white-space: nowrap;
}

.priority-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.priority-high { background: var(--danger-light); color: var(--danger-dark); }
.priority-high .priority-dot { background: var(--danger); }
.priority-normal { background: var(--info-light); color: #3b5998; }
.priority-normal .priority-dot { background: var(--info); }
.priority-low { background: var(--gray-100); color: var(--gray-600); }
.priority-low .priority-dot { background: var(--gray-400); }

/* Type badge */
/* Dynamic type palette - assigned by index from API */
.type-0 { background: #dce4f0; color: #3b5998; }
.type-1 { background: #e8dff0; color: #6b4f8a; }
.type-2 { background: #d8eef0; color: #3a7a82; }
.type-3 { background: #f0e8d8; color: #7a6a3a; }
.type-4 { background: #f0d8d7; color: #9a3f3c; }
.type-5 { background: #dceee6; color: #2d6b54; }
.type-6 { background: #f5ead4; color: #a57a2e; }
.type-7 { background: #e8e8e8; color: #555; }
.type-default { background: var(--gray-100); color: var(--gray-700); }

.type-badge {
    display: inline-block;
    padding: 2px 7px;
    font-size: var(--font-size-xs);
    font-weight: 600;
    white-space: nowrap;
}

/* Date styles */
.date-cell {
    display: inline-block;
    font-size: var(--font-size-sm);
    color: var(--gray-600);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.date-overdue {
    color: var(--danger);
    font-weight: 600;
}

/* CSS-only "OVERDUE" tag above an overdue date (survives inline-edit refresh) */
.date-overdue::before {
    content: 'Overdue';
    display: block;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: var(--danger);
    line-height: 1.25;
}

/* PM cell */
.pm-cell {
    font-size: var(--font-size-sm);
    color: var(--gray-600);
}

/* Meta cells (Created By, Modified By) */
.meta-cell {
    font-size: var(--font-size-xs);
    color: var(--gray-500);
}

/* Section color palette */
.section-0 { background: var(--status-pal-0-bg); color: var(--status-pal-0-text); }
.section-1 { background: var(--status-pal-1-bg); color: var(--status-pal-1-text); }
.section-2 { background: var(--status-pal-2-bg); color: var(--status-pal-2-text); }
.section-3 { background: var(--status-pal-3-bg); color: var(--status-pal-3-text); }
.section-4 { background: var(--status-pal-4-bg); color: var(--status-pal-4-text); }
.section-5 { background: var(--status-pal-5-bg); color: var(--status-pal-5-text); }
.section-6 { background: var(--status-pal-6-bg); color: var(--status-pal-6-text); }
.section-7 { background: var(--status-pal-7-bg); color: var(--status-pal-7-text); }
.section-default { background: var(--gray-100); color: var(--gray-600); }

.section-badge {
    display: inline-block;
    padding: 1px 6px;
    font-size: var(--font-size-xs);
    font-weight: 600;
    white-space: nowrap;
}

/* Cell assignees display */
.cell-assignees {
    font-size: var(--font-size-xs);
    color: var(--gray-600);
    line-height: 1.3;
}

.cell-assignees-overflow {
    color: var(--gray-400);
    font-weight: 500;
}

/* ========================================================================
   PERSON MONOGRAMS
   Square initial chips anchoring "who" at a glance (owner/assignee/kanban).
   Color is deterministic per EmpID (see utils.js monoColorIndex).
   ======================================================================== */
.mono {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 19px;
    height: 19px;
    font-size: 9px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.2px;
    flex-shrink: 0;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.mono-0 { background: #6b7280; }
.mono-1 { background: #4a6da7; }
.mono-2 { background: #a57a2e; }
.mono-3 { background: #3d8b6e; }
.mono-4 { background: #9a3f3c; }
.mono-5 { background: #7b5fa0; }
.mono-6 { background: #3a7a82; }
.mono-7 { background: #8a7a4a; }
.person-name { font-size: var(--font-size-sm); color: var(--gray-700); }

/* ========================================================================
   ROW & KANBAN ACTION ICONS (Edit / Copy / Comments / Assignees)
   ======================================================================== */
.row-actions {
    display: flex;
    gap: 4px;
    align-items: center;
    justify-content: center;
}

.row-actions .btn-action,
.kanban-card-actions .btn-action {
    width: 20px;
    height: 20px;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.row-actions .btn-action:hover,
.kanban-card-actions .btn-action:hover {
    color: var(--primary);
}

.btn-action svg {
    width: 14px;
    height: 14px;
}

/* Comment icon filled green when activity has comments */
.btn-action.has-comments svg {
    fill: var(--success);
    stroke: var(--success);
}

.btn-action.has-comments:hover svg {
    fill: var(--success-dark);
    stroke: var(--success-dark);
}

/* Delete button — red on hover */
.row-actions .btn-action-delete:hover,
.kanban-card-actions .btn-action-delete:hover {
    color: var(--danger);
}

/* ========================================================================
   LOADING OVERLAY
   ======================================================================== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    margin-top: 16px;
    font-size: var(--font-size-md);
    color: var(--gray-600);
    font-weight: 500;
}

.loading-subtext {
    margin-top: 4px;
    font-size: var(--font-size-sm);
    color: var(--gray-400);
}

/* ========================================================================
   SESSION EXPIRED MODAL
   ======================================================================== */
.session-expired-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

.session-expired-modal.active {
    display: flex;
}

.session-expired-content {
    background: white;
    padding: 32px 40px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    border: 1px solid var(--gray-200);
}

.session-expired-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 12px;
    background: var(--warning-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.session-expired-content h2 {
    font-size: 18px;
    color: var(--gray-900);
    margin-bottom: 8px;
}

.session-expired-content p {
    font-size: var(--font-size-base);
    color: var(--gray-500);
    line-height: 1.5;
}

/* ========================================================================
   CONFIRM DIALOG (on-brand replacement for window.confirm)
   ======================================================================== */
.confirm-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(17, 24, 39, 0.5);
    z-index: 10001;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.confirm-modal.active {
    display: flex;
}

.confirm-content {
    background: white;
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-overlay);
    max-width: 380px;
    width: 100%;
    padding: 24px;
    text-align: center;
    animation: confirm-in 0.14s var(--ease);
}

@keyframes confirm-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .confirm-content { animation: none; }
}

.confirm-icon {
    width: 44px;
    height: 44px;
    margin: 0 auto 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-bg);
    color: var(--primary);
}

.confirm-content.confirm-danger .confirm-icon {
    background: var(--danger-light);
    color: var(--danger);
}

.confirm-icon svg { width: 22px; height: 22px; }

.confirm-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 6px;
}

.confirm-message {
    font-size: var(--font-size-base);
    color: var(--gray-600);
    line-height: 1.5;
    margin-bottom: 18px;
}

.confirm-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.confirm-actions .btn {
    min-width: 92px;
    justify-content: center;
}

/* ========================================================================
   TOAST NOTIFICATIONS
   ======================================================================== */
.toast-container {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 9000;
    display: flex;
    flex-direction: column;
    gap: 6px;
    pointer-events: none;
}

.toast {
    padding: 8px 14px;
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: white;
    pointer-events: auto;
    transform: translateX(120%);
    transition: transform 0.3s ease, opacity 0.3s ease;
    max-width: 340px;
}

.toast-show {
    transform: translateX(0);
}

.toast-hide {
    opacity: 0;
    transform: translateX(120%);
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning-dark); }
.toast-info { background: var(--primary); }

/* ========================================================================
   DEV MODE BANNER
   ======================================================================== */
.dev-banner {
    background: var(--warning-light);
    border: 1px solid var(--warning);
    color: var(--warning-dark);
    padding: 4px 12px;
    font-size: var(--font-size-sm);
    text-align: center;
    margin-bottom: 8px;
}

/* ========================================================================
   EMPTY STATE
   ======================================================================== */
.empty-state {
    padding: 40px 24px;
    text-align: center;
    color: var(--gray-500);
}

.empty-state-icon {
    font-size: 36px;
    margin-bottom: 8px;
    opacity: 0.4;
}

.empty-state h3 {
    font-size: var(--font-size-md);
    color: var(--gray-700);
    margin-bottom: 4px;
}

.empty-state p {
    font-size: var(--font-size-sm);
}

/* ========================================================================
   PRINT STYLES
   ======================================================================== */
@media print {
    body {
        background: white;
        font-size: 9px;
    }

    .no-print {
        display: none !important;
    }

    .container {
        padding: 0;
        max-width: none;
    }

    /* Print whichever view is active */
    .list-view:not(.active),
    .kanban-view:not(.active),
    .calendar-view:not(.active) {
        display: none !important;
    }
    .list-view.active {
        display: block !important;
    }
    .kanban-view.active {
        display: block !important;
    }
    .calendar-view.active {
        display: block !important;
    }

    /* Calendar print styles */
    .calendar-month-label-print {
        display: block !important;
    }
    .calendar-day-cell {
        min-height: 60px !important;
    }
    .calendar-event {
        font-size: 8px !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .calendar-event-status {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .calendar-day-popover {
        display: none !important;
    }
    .calendar-no-date-sidebar {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .dashboard-header {
        border-bottom: 1px solid #ccc;
        padding: 4px 0;
        margin-bottom: 4px;
    }

    .header-title-group h1 {
        font-size: 14px;
    }

    .report-meta {
        font-size: 8px;
    }

    /* KPIs */
    .kpi-grid {
        gap: 4px !important;
        margin-bottom: 4px !important;
        grid-template-columns: repeat(6, 1fr) !important;
    }
    .kpi-card {
        padding: 3px 6px !important;
        border: 1px solid #ddd !important;
        break-inside: avoid;
    }
    .kpi-card .kpi-label { font-size: 7px !important; }
    .kpi-card .kpi-value { font-size: 12px !important; }

    /* Table */
    .table-card {
        border: 1px solid #ddd !important;
    }
    .table-scroll {
        overflow: visible !important;
    }
    table {
        min-width: unset !important;
        width: 100% !important;
        font-size: 8px !important;
        table-layout: fixed !important;
    }
    th {
        padding: 2px 4px !important;
        font-size: 7px !important;
    }
    td {
        padding: 2px 4px !important;
        font-size: 8px !important;
        line-height: 1.2 !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        white-space: normal !important;
    }

    .group-header-row td {
        padding: 3px 5px !important;
        font-size: 9px !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Hide edit UI */
    .cell-editable:hover {
        background: none;
    }
    .cell-edit-input {
        display: none !important;
    }

    /* Preserve color */
    .status-badge, .priority-badge, .type-badge {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .row-actions,
    .kanban-card-actions {
        display: none !important;
    }

    .loading-overlay,
    .toast-container,
    .comments-modal,
    .assignees-modal,
    .calendar-day-popover {
        display: none !important;
    }

    .btn-action.has-comments {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .section-badge, .status-badge {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

@media print and (orientation: landscape) {
    .kpi-grid { grid-template-columns: repeat(6, 1fr) !important; }
    table { font-size: 9px !important; }
    th, td { padding: 3px 6px !important; }
}

@media print and (orientation: portrait) {
    .kpi-grid { grid-template-columns: repeat(3, 1fr) !important; }
    table { font-size: 8px !important; }
    th, td { padding: 2px 4px !important; }
}

/* ========================================================================
   SCROLLBAR (subtle styling for Chrome app mode)
   ======================================================================== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--gray-300);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gray-400);
}
