/* ComCal - Modern Styling */
:root {
    --bg-primary: #0f172a;
    --bg-surface: #1e293b;
    --bg-surface-elevated: #283548;
    --bg-surface-subtle: #192233;
    --border-color: #334155;
    --border-subtle: #233044;

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --primary: #38bdf8;
    --primary-hover: #0ea5e9;
    --primary-glow: rgba(56, 189, 248, 0.25);

    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #0284c7;

    /* Status Colors */
    --status-w-bg: #064e3b;
    --status-w-border: #059669;
    --status-w-text: #6ee7b7;

    --status-v-bg: #0c4a6e;
    --status-v-border: #0284c7;
    --status-v-text: #7dd3fc;

    --status-u-bg: #78350f;
    --status-u-border: #d97706;
    --status-u-text: #fde68a;

    --status-s-bg: #7f1d1d;
    --status-s-border: #dc2626;
    --status-s-text: #fca5a5;

    --status-o-bg: #4c1d95;
    --status-o-border: #7c3aed;
    --status-o-text: #c4b5fd;

    --status-m-bg: #7c2d12;
    --status-m-border: #ea580c;
    --status-m-text: #fdba74;

    --weekend-bg: #141c2c;
    --today-border: #38bdf8;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow-md: 0 4px 16px -2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 30px -4px rgba(0, 0, 0, 0.5);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Header & Navigation */
.app-header {
    background: rgba(30, 41, 59, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-container {
    max-width: 100%;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #0284c7, #38bdf8);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    box-shadow: 0 0 15px var(--primary-glow);
}

.brand-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #ffffff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-tagline {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Tabs */
.nav-tabs {
    display: flex;
    background: var(--bg-surface-subtle);
    padding: 4px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    gap: 4px;
}

.nav-tab {
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    border: none;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.nav-tab.active {
    color: #ffffff;
    background: var(--primary-hover);
    box-shadow: 0 2px 8px var(--primary-glow);
}

/* Header Actions */
.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.team-switcher-wrap {
    position: relative;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    white-space: nowrap;
    text-decoration: none;
}

.btn-primary {
    background: #0284c7;
    color: #ffffff;
    border-color: #38bdf8;
    box-shadow: 0 2px 8px rgba(2, 132, 199, 0.3);
}

.btn-primary:hover {
    background: #0369a1;
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.btn-secondary:hover {
    background: #334155;
    border-color: #475569;
}

.btn-success {
    background: #059669;
    color: #ffffff;
}

.btn-success:hover {
    background: #047857;
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background: #dc2626;
    color: #ffffff;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-icon {
    padding: 8px;
    width: 34px;
    height: 34px;
}

/* Team Info Bar */
.team-bar {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}

.team-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.team-name-editable {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
}

.team-name-editable:hover {
    background: var(--bg-surface-elevated);
}

.badge-token {
    font-size: 11px;
    background: rgba(56, 189, 248, 0.12);
    color: #38bdf8;
    border: 1px solid rgba(56, 189, 248, 0.3);
    padding: 3px 8px;
    border-radius: 999px;
    font-family: monospace;
}

/* Period Navigator */
.period-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-surface-subtle);
    padding: 4px 8px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
}

.period-title {
    font-size: 15px;
    font-weight: 700;
    min-width: 140px;
    text-align: center;
    color: var(--text-primary);
}

/* Main Content Views */
.main-content {
    flex: 1;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.view-panel {
    display: none;
    flex-direction: column;
    gap: 16px;
}

.view-panel.active {
    display: flex;
}

/* Palette / Legend Bar */
.toolbar-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    flex-wrap: wrap;
}

.palette-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.palette-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-right: 4px;
}

.status-badge-radio {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    user-select: none;
    transition: all 0.15s ease;
}

.status-badge-radio:hover {
    transform: translateY(-1px);
}

.status-badge-radio.selected {
    box-shadow: 0 0 0 2px #ffffff, 0 0 10px rgba(255, 255, 255, 0.4);
}

.status-W { background: var(--status-w-bg); color: var(--status-w-text); border-color: var(--status-w-border); }
.status-V { background: var(--status-v-bg); color: var(--status-v-text); border-color: var(--status-v-border); }
.status-U { background: var(--status-u-bg); color: var(--status-u-text); border-color: var(--status-u-border); }
.status-S { background: var(--status-s-bg); color: var(--status-s-text); border-color: var(--status-s-border); }
.status-O { background: var(--status-o-bg); color: var(--status-o-text); border-color: var(--status-o-border); }
.status-M { background: var(--status-m-bg); color: var(--status-m-text); border-color: var(--status-m-border); }
.status-CLEAR { background: #334155; color: #cbd5e1; border-color: #475569; }

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

/* Timesheet Grid Container */
.grid-container {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
}

.table-responsive {
    overflow-x: auto;
    position: relative;
    max-height: calc(100vh - 280px);
}

.timesheet-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 12px;
    user-select: none;
}

.timesheet-table th,
.timesheet-table td {
    padding: 0;
    border-right: 1px solid var(--border-subtle);
    border-bottom: 1px solid var(--border-subtle);
    text-align: center;
    vertical-align: middle;
}

/* Sticky Headers and Frozen Columns */
.timesheet-table thead tr:first-child th {
    position: sticky;
    top: 0;
    background: #172233;
    z-index: 20;
    padding: 8px 4px;
    border-bottom: 1px solid var(--border-color);
}

.timesheet-table thead tr:nth-child(2) th {
    position: sticky;
    top: 35px;
    background: #172233;
    z-index: 20;
    padding: 4px;
    font-size: 10px;
    text-transform: uppercase;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
}

.sticky-col-1 {
    position: sticky;
    left: 0;
    z-index: 25;
    background: var(--bg-surface) !important;
    min-width: 200px;
    max-width: 220px;
    text-align: left !important;
    padding: 10px 14px !important;
    border-right: 2px solid var(--border-color) !important;
}

.sticky-col-2 {
    position: sticky;
    left: 220px;
    z-index: 25;
    background: var(--bg-surface) !important;
    min-width: 130px;
    max-width: 150px;
    text-align: center !important;
    padding: 8px 10px !important;
    border-right: 2px solid var(--border-color) !important;
}

thead .sticky-col-1,
thead .sticky-col-2 {
    z-index: 30 !important;
    background: #131d2e !important;
}

/* Day Column Header Styles */
.day-header {
    width: 32px;
    min-width: 32px;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-primary);
}

.day-header.is-weekend {
    background: rgba(0, 0, 0, 0.25) !important;
    color: #f87171 !important;
}

.day-header.is-today {
    background: rgba(56, 189, 248, 0.15) !important;
    color: #38bdf8 !important;
    border-top: 2px solid #38bdf8;
}

/* Member Cells */
.member-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.member-position {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.member-actions {
    opacity: 0;
    transition: opacity 0.15s;
    display: flex;
    gap: 4px;
}

tr:hover .member-actions {
    opacity: 1;
}

/* Vacation Balance Pill */
.balance-pill {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
    cursor: help;
    transition: transform 0.15s;
}

.balance-pill:hover {
    transform: scale(1.04);
}

.balance-pill.pos {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.balance-pill.neg {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.balance-pill.low {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.balance-sub {
    font-size: 9px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Calendar Date Day Cell */
.day-cell {
    width: 32px;
    min-width: 32px;
    height: 38px;
    cursor: pointer;
    position: relative;
    font-weight: 700;
    font-size: 11px;
    transition: filter 0.1s;
}

.day-cell.is-weekend {
    background: var(--weekend-bg);
}

.day-cell.is-today {
    box-shadow: inset 0 0 0 1px var(--today-border);
}

.day-cell:hover {
    filter: brightness(1.2);
    box-shadow: inset 0 0 0 2px #38bdf8;
}

/* Drag to Fill Selection Styles */
.day-cell.drag-selecting {
    box-shadow: inset 0 0 0 2px #38bdf8 !important;
    opacity: 0.85;
}

.day-cell.drag-origin {
    box-shadow: inset 0 0 0 2px #f59e0b !important;
}

/* Drag Handle */
.drag-handle {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 7px;
    height: 7px;
    background: #ffffff;
    border: 1px solid #000000;
    cursor: crosshair;
    display: none;
    z-index: 10;
}

.day-cell:hover .drag-handle,
.day-cell.selected .drag-handle {
    display: block;
}

/* Cell content text */
.cell-value {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.empty-state-icon {
    font-size: 48px;
    color: var(--text-muted);
}

/* Consolidated Report Styles */
.report-header {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.token-input-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.token-textarea {
    flex: 1;
    min-width: 300px;
    height: 70px;
    background: var(--bg-surface-subtle);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px;
    color: var(--text-primary);
    font-family: monospace;
    font-size: 13px;
    resize: vertical;
}

.token-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

.saved-teams-checklist {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
}

.team-chip-wrapper {
    display: inline-flex;
    align-items: center;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 2px 4px 2px 10px;
    transition: all 0.2s ease;
    position: relative;
}

.team-chip-wrapper:hover {
    border-color: var(--primary);
    background: #243247;
}

.team-chip-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
    padding: 3px 4px 3px 0;
}

.team-chip-label input[type="checkbox"] {
    accent-color: var(--primary);
    cursor: pointer;
}

.team-chip-forget-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transform: scale(0.85);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    margin-left: 2px;
}

.team-chip-wrapper:hover .team-chip-forget-btn {
    opacity: 1;
    transform: scale(1);
}

.team-chip-forget-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

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

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-val {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.stat-card.w { border-left: 4px solid var(--success); }
.stat-card.v { border-left: 4px solid var(--info); }
.stat-card.s { border-left: 4px solid var(--danger); }
.stat-card.u { border-left: 4px solid var(--warning); }
.stat-card.o { border-left: 4px solid #a855f7; }
.stat-card.m { border-left: 4px solid #f97316; }

/* Modals */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-backdrop.open {
    display: flex;
}

.modal-box {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: modalPop 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPop {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 16px;
    font-weight: 700;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    background: var(--bg-surface-subtle);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.form-control {
    background: var(--bg-surface-subtle);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    color: var(--text-primary);
    font-size: 13px;
    width: 100%;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

.form-hint {
    font-size: 11px;
    color: var(--text-muted);
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: #1e293b;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 12px 18px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: toastSlide 0.25s ease-out;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--primary); }

@keyframes toastSlide {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Tooltip / Balance Info Popover */
.popover-calc {
    font-family: monospace;
    font-size: 11px;
    line-height: 1.5;
}

/* Report Period Selector & Presets */
.report-period-selector {
    background: var(--bg-surface-subtle);
    padding: 14px 18px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.preset-btn {
    font-size: 11px;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    background: var(--bg-surface-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
    cursor: pointer;
    transition: all 0.15s ease;
}

.preset-btn:hover {
    color: var(--text-primary);
    background: #334155;
    border-color: var(--primary);
}

/* 3-Row Header for Consolidated Table */
#consolidatedReportTable thead tr:nth-child(1) th {
    position: sticky;
    top: 0;
    background: #111a28;
    z-index: 23;
}

#consolidatedReportTable thead tr:nth-child(2) th {
    position: sticky;
    top: 29px;
    background: #172233;
    z-index: 22;
}

#consolidatedReportTable thead tr:nth-child(3) th {
    position: sticky;
    top: 55px;
    background: #172233;
    z-index: 21;
    font-size: 10px;
    text-transform: uppercase;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
}

.team-group-row td {
    background: rgba(56, 189, 248, 0.09) !important;
    position: sticky;
    left: 0;
}

/* Print Styles */
@media print {
    body {
        background: #ffffff !important;
        color: #000000 !important;
    }
    .app-header, .toolbar-bar, .modal-backdrop, .btn, .nav-tabs, .toast-container, .saved-teams-checklist, .token-input-group, .report-period-selector {
        display: none !important;
    }
    .timesheet-table {
        font-size: 9px !important;
    }
    .timesheet-table th, .timesheet-table td {
        border-color: #cccccc !important;
    }
    .sticky-col-1, .sticky-col-2 {
        background: #ffffff !important;
        color: #000000 !important;
    }
    .status-W { background: #dcfce7 !important; color: #166534 !important; }
    .status-V { background: #e0f2fe !important; color: #075985 !important; }
    .status-U { background: #fef3c7 !important; color: #92400e !important; }
    .status-S { background: #fee2e2 !important; color: #991b1b !important; }
    .status-O { background: #ede9fe !important; color: #5b21b6 !important; }
    .status-M { background: #ffedd5 !important; color: #9a3412 !important; }
}
