/* ── Theme variables ── */
:root, [data-theme="light"] {
    --bg-body: #f5f6fa;
    --bg-card: #fff;
    --bg-card-header: #fff;
    --bg-input: #fff;
    --bg-hover: #e9ecef;
    --bg-table-stripe: #f8f9fa;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-muted: #adb5bd;
    --border-color: #dee2e6;
    --border-light: #efefef;
    --border-card: transparent;
    --nav-bg: #212529;
    --nav-text: rgba(255,255,255,.85);
    --cal-event-bg: #d4e5fc;
    --cal-event-border: #4285f4;
    --cal-event-text: #1a1a1a;
    --cal-hosted-bg: #e8daf8;
    --cal-hosted-border: #8e44ad;
    --cal-hosted-text: #1a1a1a;
    --cal-other-bg: #d5f5e3;
    --cal-other-border: #27ae60;
    --cal-other-text: #1a1a1a;
    --code-bg: #f8f9fa;
}

[data-theme="dark"] {
    --bg-body: #1a1d23;
    --bg-card: #23272e;
    --bg-card-header: #2b303a;
    --bg-input: #2b303a;
    --bg-hover: #343a46;
    --bg-table-stripe: #2b303a;
    --text-primary: #e4e6ea;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --border-color: #374151;
    --border-light: #2d333b;
    --border-card: #374151;
    --nav-bg: #111318;
    --nav-text: rgba(255,255,255,.85);
    --cal-event-bg: #1e3a5f;
    --cal-event-border: #4285f4;
    --cal-event-text: #d1e0f0;
    --cal-hosted-bg: #3a2050;
    --cal-hosted-border: #a855f7;
    --cal-hosted-text: #ddc5f0;
    --cal-other-bg: #1a4a3a;
    --cal-other-border: #27ae60;
    --cal-other-text: #c5e8d5;
    --code-bg: #2b303a;
}

[data-theme="navy"] {
    --bg-body: #0f1729;
    --bg-card: #1a2640;
    --bg-card-header: #1f2f50;
    --bg-input: #1f2f50;
    --bg-hover: #263b5e;
    --bg-table-stripe: #1f2f50;
    --text-primary: #d6e4f0;
    --text-secondary: #8da4bf;
    --text-muted: #5a7a99;
    --border-color: #2a4060;
    --border-light: #1f3050;
    --border-card: #2a4060;
    --nav-bg: #0a1020;
    --nav-text: rgba(255,255,255,.85);
    --cal-event-bg: #1a3a6a;
    --cal-event-border: #5b9cf6;
    --cal-event-text: #c5d8f0;
    --cal-hosted-bg: #2a1850;
    --cal-hosted-border: #9b59f6;
    --cal-hosted-text: #d5c5f0;
    --cal-other-bg: #1a4a3a;
    --cal-other-border: #4caf70;
    --cal-other-text: #c5e8d5;
    --code-bg: #1f2f50;
}

[data-theme="green"] {
    --bg-body: #f0f7f0;
    --bg-card: #fff;
    --bg-card-header: #f0f7f0;
    --bg-input: #fff;
    --bg-hover: #e0efe0;
    --bg-table-stripe: #f5faf5;
    --text-primary: #1a2e1a;
    --text-secondary: #4a6e4a;
    --text-muted: #8aab8a;
    --border-color: #c0d8c0;
    --border-light: #d8ecd8;
    --border-card: #c0d8c0;
    --nav-bg: #1a3a2a;
    --nav-text: rgba(255,255,255,.85);
    --cal-event-bg: #d0f0d0;
    --cal-event-border: #2e7d32;
    --cal-event-text: #1a3a1a;
    --cal-hosted-bg: #e8daf8;
    --cal-hosted-border: #8e44ad;
    --cal-hosted-text: #1a3a1a;
    --cal-other-bg: #d4e5fc;
    --cal-other-border: #4285f4;
    --cal-other-text: #1a1a1a;
    --code-bg: #e8f5e8;
}

/* ── Global ── */
body {
    background: var(--bg-body);
    color: var(--text-primary);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.app-version {
    position: fixed;
    bottom: 8px;
    right: 12px;
    font-size: .7rem;
    color: #adb5bd;
    z-index: 999;
}

.card {
    border: 1px solid var(--border-card);
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
    border-radius: .5rem;
    background: var(--bg-card);
    color: var(--text-primary);
}

.card-header {
    background: var(--bg-card-header);
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    color: var(--text-primary);
}

/* ── Connection dots ── */
.status-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #dc3545;
}
.status-dot.ok {
    background: #198754;
}

/* ── Calendar grid ── */
.cal-grid {
    display: grid;
    grid-template-columns: 56px repeat(7, 1fr);
    grid-template-rows: auto 1fr;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    font-size: .85rem;
}

/* Header row */
.cal-corner {
    grid-row: 1;
    grid-column: 1;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
}
.cal-head {
    grid-row: 1;
    text-align: center;
    padding: 8px 4px;
    font-weight: 500;
    font-size: .75rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    border-left: 1px solid var(--border-light);
    letter-spacing: .02em;
}
.cal-head .day-num {
    display: block;
    font-size: 1.3rem;
    font-weight: 500;
    color: var(--text-primary);
    letter-spacing: 0;
    text-transform: none;
}

/* Time labels column */
.cal-times {
    grid-row: 2;
    grid-column: 1;
    border-right: 1px solid var(--border-color);
}
.cal-time-label {
    height: 96px;
    padding: 0 8px 0 0;
    text-align: right;
    font-size: .7rem;
    color: var(--text-secondary);
    line-height: 1;
    box-sizing: border-box;
}

/* Day columns */
.cal-day-col {
    grid-row: 2;
    position: relative;
    border-left: 1px solid var(--border-light);
}
.cal-hour-line {
    height: 96px;
    border-bottom: 1px solid var(--border-light);
    box-sizing: border-box;
}

/* Events */
.cal-event {
    position: absolute;
    background: var(--cal-event-bg);
    border-left: 4px solid var(--cal-event-border);
    border-radius: 4px;
    padding: 3px 6px;
    font-size: .8rem;
    overflow: hidden;
    cursor: default;
    line-height: 1.35;
    color: var(--cal-event-text);
    box-sizing: border-box;
    margin-bottom: 2px;
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--cal-event-border);
}
.cal-event.compact {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 1px 6px;
    font-size: .75rem;
    line-height: 1.2;
}
.cal-event.compact .ev-time {
    flex-shrink: 0;
}
.cal-event.compact .ev-title {
    min-width: 0;
}
.cal-event .ev-title {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cal-event .ev-time {
    color: var(--text-secondary);
    font-size: .72rem;
    font-weight: 400;
}
.cal-event.hosted {
    background: var(--cal-hosted-bg);
    border-left-color: var(--cal-hosted-border);
    color: var(--cal-hosted-text);
}
.cal-event.other {
    background: var(--cal-other-bg);
    border-left-color: var(--cal-other-border);
    color: var(--cal-other-text);
}
.cal-event.tentative {
    background: #f0f0f0;
    border-left-color: #999;
    opacity: 0.6;
    border-left-style: dashed;
}
.cal-event .ev-status {
    color: #d97706;
    font-weight: 700;
}
.cal-event.has-note .ev-time::before {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #f59e0b;
    margin-right: 3px;
    vertical-align: middle;
}

.cal-scroll {
    max-height: calc(100vh - 160px);
    overflow-y: auto;
}

/* ── Timesheet ── */
.ts-table th, .ts-table td {
    vertical-align: middle;
    font-size: .85rem;
}
.ts-table .hours-cell {
    text-align: center;
    min-width: 70px;
    cursor: pointer;
    transition: background .15s;
}
.ts-table .hours-cell:hover {
    background: var(--bg-hover);
}
.ts-table .totals-row td {
    font-weight: 700;
    background: var(--bg-table-stripe);
}
.project-link {
    color: #0d6efd;
    cursor: pointer;
    text-decoration: none;
}
.project-link:hover {
    text-decoration: underline;
}
.date-sep {
    border: 0;
    border-top: 1px solid #dee2e6;
    margin: 2px 0;
}

/* ── Allocation ── */
.alloc-table th {
    background: #343a40;
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 2;
    text-align: center;
    font-size: .8rem;
}
.alloc-table td {
    font-size: .85rem;
    padding: 4px 8px;
}
.alloc-table tr:nth-child(even) {
    background: #f8f9fa;
}
.alloc-table .user-header td {
    background: #e9ecef;
    font-weight: 700;
}
.alloc-scroll {
    max-height: calc(100vh - 220px);
    overflow: auto;
}

/* ── Modal overlay ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 1050;
    justify-content: center;
    align-items: center;
}
.modal-overlay.show {
    display: flex;
}
.modal-box {
    background: var(--bg-card);
    color: var(--text-primary);
    border-radius: .5rem;
    width: 480px;
    max-width: 95vw;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,.3);
}

/* ── Calendar events list (timesheet page) ── */
.cal-events-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: .5rem;
    padding: 1rem;
    color: var(--text-primary);
}
/* ── Timesheet loading overlay ── */
.ts-loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,.4);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    backdrop-filter: blur(2px);
}
.ts-loading-overlay.d-none { display: none !important; }
.ts-loading-box {
    background: var(--bg-card);
    color: var(--text-primary);
    border-radius: .75rem;
    padding: 2rem 3rem;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,.3);
}

.sync-entry-done {
    opacity: 0.5;
    background: var(--bg-table-stripe);
    border-radius: 4px;
}

.cal-events-table {
    table-layout: auto;
    word-break: break-word;
}
.cal-day-divider td {
    background: var(--bg-table-stripe);
    font-size: .85rem;
    padding: 6px 8px !important;
    border-bottom: 2px solid var(--border-color);
}

/* ── Dark theme overrides for Bootstrap components ── */
[data-theme="dark"] .navbar,
[data-theme="navy"] .navbar {
    background: var(--nav-bg) !important;
}
[data-theme="dark"] .table,
[data-theme="navy"] .table {
    --bs-table-bg: var(--bg-card);
    --bs-table-color: var(--text-primary);
    --bs-table-border-color: var(--border-color);
    --bs-table-striped-bg: var(--bg-table-stripe);
    --bs-table-hover-bg: var(--bg-hover);
}
[data-theme="dark"] .table-dark,
[data-theme="navy"] .table-dark {
    --bs-table-bg: #111318;
    --bs-table-border-color: var(--border-color);
}
[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select,
[data-theme="navy"] .form-control,
[data-theme="navy"] .form-select {
    background-color: var(--bg-input);
    color: var(--text-primary);
    border-color: var(--border-color);
}
[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus,
[data-theme="navy"] .form-control:focus,
[data-theme="navy"] .form-select:focus {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}
[data-theme="dark"] .alert-info,
[data-theme="navy"] .alert-info {
    background: #1a2d40;
    color: #8ec5fc;
    border-color: #2a4060;
}
[data-theme="dark"] .alert-success,
[data-theme="navy"] .alert-success {
    background: #1a3a2a;
    color: #8ad8a0;
    border-color: #2a5040;
}
[data-theme="dark"] .text-muted,
[data-theme="navy"] .text-muted {
    color: var(--text-muted) !important;
}
[data-theme="dark"] code,
[data-theme="navy"] code {
    background: var(--code-bg);
    color: #e685b5;
}
[data-theme="dark"] .sync-preview-list,
[data-theme="navy"] .sync-preview-list {
    background: var(--bg-input);
    border-color: var(--border-color);
}
[data-theme="dark"] .sync-preview-item,
[data-theme="navy"] .sync-preview-item {
    border-color: var(--border-color);
}

/* ── Theme picker ── */
.theme-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 3px solid transparent;
    cursor: pointer;
    transition: transform .15s, border-color .15s;
    position: relative;
}
.theme-btn:hover {
    transform: scale(1.15);
}
.theme-btn.active {
    border-color: #0d6efd;
    box-shadow: 0 0 0 2px rgba(13,110,253,.4);
}
.theme-btn .bi-check-lg {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.1rem;
    text-shadow: 0 1px 2px rgba(0,0,0,.5);
}

/* ── Sync progress modal ── */
.sync-modal-header {
    background: linear-gradient(135deg, #198754 0%, #0d6efd 100%);
    color: #fff;
    border-radius: .5rem .5rem 0 0;
}
.sync-modal-header .btn-close {
    filter: brightness(0) invert(1);
}
.sync-preview-list {
    max-height: 180px;
    overflow-y: auto;
    font-size: .85rem;
    border: 1px solid #e9ecef;
    border-radius: .375rem;
    background: #f8f9fa;
}
.sync-preview-item {
    padding: 6px 12px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.sync-preview-item:last-child {
    border-bottom: none;
}
.sync-log {
    max-height: 250px;
    overflow-y: auto;
    font-size: .82rem;
}
.sync-log-entry {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 5px 0;
    border-bottom: 1px solid #f0f0f0;
}
.sync-log-entry:last-child {
    border-bottom: none;
}
.sync-log-icon {
    flex-shrink: 0;
    width: 20px;
    text-align: center;
    font-size: .9rem;
    line-height: 1.4;
}
.sync-log-text {
    flex: 1;
    min-width: 0;
}
.sync-result-card {
    padding: 12px 16px;
    border-radius: .375rem;
    text-align: center;
}
.sync-result-card.success {
    background: #d1e7dd;
    color: #0f5132;
}
.sync-result-card.partial {
    background: #fff3cd;
    color: #664d03;
}
.sync-result-card.fail {
    background: #f8d7da;
    color: #842029;
}
@keyframes syncPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .6; }
}
.syncing-active {
    animation: syncPulse 1.2s ease-in-out infinite;
}
