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

:root {
    --color-bg:           #f0f2f5;
    --color-surface:      #ffffff;
    --color-border:       #d9dde8;
    --color-text:         #1a1a2e;
    --color-muted:        #6b7280;
    --color-primary:      #4f46e5;
    --color-primary-dark: #4338ca;
    --color-subtask:      #3b82f6;
    --color-subtask-dark: #1d4ed8;
    --color-defect:       #f97316;
    --color-defect-dark:  #c2410c;
    --color-today:        #fef9c3;
    --color-today-border: #fbbf24;
    --color-error:        #ef4444;
    --radius:             6px;
    --shadow:             0 1px 3px rgba(0,0,0,.12);
    --cell-height:        300px; /* 6h × 50px */
    --assignee-col:       160px;
    --day-col-min:        120px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 13px;
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 12px;
    flex-wrap: wrap;
}

.header-left { display: flex; align-items: baseline; gap: 10px; }
.app-title   { font-size: 20px; font-weight: 700; color: var(--color-primary); }
.app-subtitle { font-size: 12px; color: var(--color-muted); }
.header-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.last-updated { font-size: 11px; color: var(--color-muted); white-space: nowrap; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
    padding: 7px 14px;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background .15s, opacity .15s;
    white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary  { background: var(--color-primary);   color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--color-primary-dark); }

.btn-secondary { background: #e5e7eb; color: var(--color-text); }
.btn-secondary:hover:not(:disabled) { background: #d1d5db; }

/* ── App body ──────────────────────────────────────────────────────────────── */
.app-body { padding: 16px 20px; }

/* ── Toolbar ───────────────────────────────────────────────────────────────── */
.toolbar {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.filter-group { display: flex; align-items: center; gap: 6px; }
.filter-group label { font-weight: 500; color: var(--color-muted); white-space: nowrap; }

.filter-select {
    padding: 5px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    font-size: 13px;
    cursor: pointer;
    min-width: 120px;
}
.filter-select:focus { outline: 2px solid var(--color-primary); }

.status-bar { font-size: 12px; color: var(--color-muted); margin-left: auto; }

/* ── Loading ───────────────────────────────────────────────────────────────── */
.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 48px;
    font-size: 14px;
    color: var(--color-muted);
}

.loading-spinner {
    width: 24px; height: 24px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Error banner ──────────────────────────────────────────────────────────── */
.error-banner {
    padding: 12px 16px;
    background: #fef2f2;
    border: 1px solid #fca5a5;
    border-radius: var(--radius);
    color: var(--color-error);
    margin-bottom: 16px;
    font-size: 13px;
}

/* ── Calendar ──────────────────────────────────────────────────────────────── */
.calendar-container {
    overflow-x: auto;
    background: var(--color-surface);
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow);
}

.calendar-empty {
    padding: 60px;
    text-align: center;
    color: var(--color-muted);
    font-size: 14px;
}

.calendar-grid { display: table; width: 100%; border-collapse: collapse; }

/* Header row */
.calendar-header-row {
    display: table-row;
    background: #f8f9fa;
}

.calendar-corner,
.day-header {
    display: table-cell;
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    vertical-align: middle;
    white-space: nowrap;
    font-weight: 600;
    font-size: 12px;
}

.calendar-corner { width: var(--assignee-col); min-width: var(--assignee-col); }

.day-header {
    text-align: center;
    min-width: var(--day-col-min);
}
.day-header.today { background: var(--color-today); border-color: var(--color-today-border); }
.day-header .day-name { display: block; font-size: 11px; color: var(--color-muted); font-weight: 400; }

/* Assignee rows */
.calendar-row { display: table-row; }
.calendar-row:hover > * { background: #fafafa; }

.assignee-label {
    display: table-cell;
    width: var(--assignee-col);
    min-width: var(--assignee-col);
    padding: 6px 10px;
    border: 1px solid var(--color-border);
    font-weight: 600;
    font-size: 12px;
    vertical-align: top;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: var(--assignee-col);
    background: #f8f9fa;
}

.day-cell {
    display: table-cell;
    min-width: var(--day-col-min);
    height: var(--cell-height);
    border: 1px solid var(--color-border);
    position: relative;
    vertical-align: top;
    background: var(--color-surface);
}
.day-cell.today { background: #fffdf0; border-color: var(--color-today-border); }

/* ── Task blocks ───────────────────────────────────────────────────────────── */
.task-block {
    position: absolute;
    left: 3px;
    right: 3px;
    border-radius: 4px;
    padding: 3px 5px;
    cursor: default;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,.15);
    transition: filter .1s;
    min-height: 18px;
}
.task-block:hover { filter: brightness(1.08); z-index: 10; }

.task-subtask {
    background: var(--color-subtask);
    border-left: 3px solid var(--color-subtask-dark);
    color: #fff;
}
.task-defect {
    background: var(--color-defect);
    border-left: 3px solid var(--color-defect-dark);
    color: #fff;
}
.task-phantom { opacity: .75; background-image: repeating-linear-gradient(
    45deg, transparent, transparent 4px, rgba(0,0,0,.08) 4px, rgba(0,0,0,.08) 8px
); }

.task-block-inner { height: 100%; overflow: hidden; }

.task-key   { font-weight: 700; font-size: 11px; line-height: 1.3; }
.task-hours { font-size: 12px; opacity: .9; }
.task-summary { font-size: 10px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

.badge {
    display: inline-block;
    font-size: 9px;
    font-weight: 700;
    padding: 1px 4px;
    border-radius: 3px;
    margin-top: 2px;
    letter-spacing: .3px;
}
.badge-phantom { background: rgba(0,0,0,.35); color: #fff; }
.badge-default { background: rgba(0,0,0,.2);  color: #fff; }

/* ── Tooltip ───────────────────────────────────────────────────────────────── */
.tooltip {
    position: fixed;
    z-index: 1000;
    background: #1e293b;
    color: #f1f5f9;
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 12px;
    line-height: 1.6;
    pointer-events: none;
    box-shadow: 0 4px 16px rgba(0,0,0,.3);
    max-width: 280px;
}
.tooltip a { color: #93c5fd; text-decoration: none; }
.tooltip a:hover { text-decoration: underline; }
.tooltip-key  { font-weight: 700; font-size: 13px; margin-bottom: 4px; }
.tooltip-row  { display: flex; gap: 6px; }
.tooltip-label { color: #94a3b8; min-width: 90px; }
.tooltip-badge-phantom { color: #fbbf24; font-weight: 600; }
.tooltip-badge-default { color: #34d399; font-weight: 600; }

/* ── Anomalies ─────────────────────────────────────────────────────────────── */
.anomalies-section {
    margin-top: 24px;
    background: var(--color-surface);
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow);
    padding: 20px;
}

.section-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--color-text);
}

.anomaly-block { margin-bottom: 20px; }

.anomaly-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.anomaly-phantom-title { color: #b45309; }
.anomaly-overrun-title  { color: #b91c1c; }
.anomaly-default-title  { color: #0369a1; }

.anomaly-hint {
    font-size: 11px;
    font-weight: 400;
    color: var(--color-muted);
    background: #f3f4f6;
    padding: 2px 7px;
    border-radius: 999px;
}

.anomaly-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.anomaly-table th,
.anomaly-table td {
    padding: 6px 10px;
    border: 1px solid var(--color-border);
    text-align: left;
    white-space: nowrap;
}
.anomaly-table th { background: #f8f9fa; font-weight: 600; color: var(--color-muted); }
.anomaly-table tr:hover td { background: #f9fafb; }
.anomaly-table a { color: var(--color-primary); text-decoration: none; }
.anomaly-table a:hover { text-decoration: underline; }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .app-header { padding: 10px 12px; }
    .app-body   { padding: 12px; }
    :root { --assignee-col: 100px; --day-col-min: 90px; --cell-height: 240px; }
}
