:root {
    --bg: #0f1115;
    --surface: #1a1d24;
    --surface-2: #232730;
    --text: #e6e8ec;
    --muted: #9aa0ac;
    --accent: #4f8cff;
    --accent-hover: #3a78f0;
    --error: #ff6b6b;
    --border: #2c313b;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}


.muted { color: var(--muted); }
.error { color: var(--error); margin: 0.5rem 0 0; }
a { color: var(--accent); }

/* --- Logowanie --- */
.login-body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
}

.login-card h1 { margin: 0 0 0.25rem; }
.login-card p { margin-top: 0; }

form { text-align: left; margin-top: 1.5rem; }

label {
    display: block;
    font-size: 0.875rem;
    color: var(--muted);
    margin-bottom: 0.35rem;
}

input[type="password"],
input[type="text"] {
    width: 100%;
    padding: 0.7rem 0.85rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1rem;
}

input:focus {
    outline: none;
    border-color: var(--accent);
}

button {
    margin-top: 1rem;
    width: 100%;
    padding: 0.7rem 1rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

button:hover { background: var(--accent-hover); }
button:disabled { opacity: 0.6; cursor: not-allowed; }

/* --- Topbar / aplikacja --- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

/* Żadne linki w nagłówku nie są podkreślone (marka + nawigacja). */
.topbar a, .topbar a:hover { text-decoration: none; }

.brand { font-weight: 700; color: inherit; }

.btn-ghost {
    width: auto;
    margin: 0;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.45rem 0.9rem;
    font-size: 0.9rem;
}

.btn-ghost:hover { background: var(--surface-2); }

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1.25rem;
}

/* --- Nagłówek sekcji --- */
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.section-head h1 { margin: 0; }

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
    color: var(--muted);
    margin: 0;
}
.toggle input { width: auto; }

/* --- Formularz dodawania (inline) --- */
.inline-form {
    display: flex;
    gap: 0.6rem;
    margin: 1.25rem 0 1.5rem;
    align-items: center;
}
.inline-form input[type="text"] { flex: 1; }
.inline-form input[type="color"] {
    width: 44px;
    height: 44px;
    padding: 2px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
}
.inline-form button { width: auto; margin: 0; white-space: nowrap; }
.inline-form[hidden] { display: none; } /* display:flex nadpisałby atrybut hidden */

/* Przycisk rozwijający formularz dodawania (zwinięty stan domyślny). */
.btn-add {
    width: 100%;
    margin-top: 1.25rem;
    background: transparent;
    color: var(--muted);
    border: 1px dashed var(--border);
    font-weight: 600;
}
.btn-add:hover { background: var(--surface-2); color: var(--text); border-color: var(--accent); }

/* --- Pole koloru: próbka + HEX --- */
.color-field { display: flex; align-items: center; gap: 0.4rem; }
/* Próbka koloru spójna niezależnie od kontenera (formularz dodawania i modal edycji). */
.color-field input[type="color"] {
    width: 44px;
    height: 44px;
    padding: 2px;
    flex: 0 0 auto;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
}
.hex-input {
    width: 6.5rem;
    flex: 0 0 auto;
    font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
    text-transform: lowercase;
}
.hex-input.invalid {
    border-color: var(--error);
    color: var(--error);
}

/* --- Lista kart --- */
.card-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.card {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
}
.card.archived { opacity: 0.55; }

.dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex: 0 0 auto;
}

.card-main { flex: 1; min-width: 0; }
.card-title { font-weight: 600; }
.card-sub { font-size: 0.85rem; }

.card-actions {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}
.card-actions .btn-ghost {
    padding: 0.35rem 0.7rem;
    font-size: 0.8rem;
}
.btn-ghost.danger { color: var(--error); border-color: var(--error); }
.btn-ghost.danger:hover { background: rgba(255, 107, 107, 0.12); }

/* --- Klikalny obszar karty --- */
.card-main.clickable { cursor: pointer; }
.card-main.clickable:hover .card-title { color: var(--accent); }

/* --- Taski --- */
.card.done .card-title {
    text-decoration: line-through;
    color: var(--muted);
}
.task-check {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    cursor: pointer;
    accent-color: var(--accent);
}

#back-btn { margin-bottom: 1rem; }
#tasks-view .dot { display: inline-block; vertical-align: middle; }

/* --- Pasek licznika --- */
.timer-bar {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 50;
    max-width: min(92vw, 440px);
    padding: 0.6rem 0.8rem;
    background: linear-gradient(120deg, rgba(79,140,255,0.18), var(--surface));
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    box-shadow: 0 8px 28px rgba(0,0,0,0.35);
}
/* Stany widżetu: tylko jeden widoczny naraz (display nadpisuje atrybut hidden). */
.timer-running,
.timer-idle { display: none; align-items: center; gap: 0.7rem; }
.timer-running:not([hidden]),
.timer-idle:not([hidden]) { display: flex; }
.timer-select { flex: 1; min-width: 0; max-width: 240px; }
.timer-info { flex: 1; min-width: 0; }
.timer-task { font-weight: 600; }
.timer-project { font-size: 0.8rem; }
.timer-clock {
    font-variant-numeric: tabular-nums;
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}
.timer-bar .dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex: 0 0 auto;
    animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

/* --- Przyciski Start / Stop --- */
.btn-start, .btn-stop {
    width: auto;
    margin: 0;
    padding: 0.35rem 0.8rem;
    font-size: 0.8rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    white-space: nowrap;
}
.btn-start { background: #2e7d32; color: #fff; }
.btn-start:hover { background: #276b2a; }
.btn-stop { background: var(--error); color: #fff; }
.btn-stop:hover { background: #e85555; }

.card.running {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent) inset;
}

/* --- Nawigacja --- */
.topbar { gap: 1rem; }
.nav { display: flex; gap: 0.3rem; flex: 1; }
.nav-link {
    width: auto;
    margin: 0;
    background: transparent;
    color: var(--muted);
    border: none;
    padding: 0.45rem 0.8rem;
    font-size: 0.95rem;
    border-radius: var(--radius);
    cursor: pointer;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { color: var(--text); background: var(--surface-2); font-weight: 600; }

/* --- Filtry historii --- */
.filters { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.filters input[type="date"] {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 0.35rem 0.5rem;
    width: auto;
}
.filters .btn-ghost { padding: 0.4rem 0.8rem; font-size: 0.85rem; }

/* --- Czas trwania wpisu --- */
.entry-dur {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    font-size: 1.05rem;
    white-space: nowrap;
}

/* --- Edycja wpisu --- */
.card.editing { display: block; }
.entry-edit { display: flex; flex-direction: column; gap: 0.6rem; }
.entry-edit-row { display: flex; gap: 0.8rem; flex-wrap: wrap; }
.entry-edit label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    color: var(--muted);
    font-size: 0.8rem;
    flex: 1;
    min-width: 160px;
}
.entry-edit input {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 0.5rem 0.6rem;
    font-size: 0.95rem;
}
.entry-edit-actions { display: flex; gap: 0.5rem; }
.entry-edit-actions button { width: auto; margin: 0; }

/* --- Oś czasu (historia dnia) --- */
/* Popup edycji wybranego wpisu. */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none; /* atrybut hidden nadpisałby display:flex, więc sterujemy jawnie */
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.55);
}
.modal-overlay:not([hidden]) { display: flex; }
.modal {
    width: min(100%, 460px);
    max-height: 90vh;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.2rem;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}
.entry-detail-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.9rem; }

/* WAŻNE: wysokość .timeline-hour musi odpowiadać HOUR_PX w app.js (56). */
.timeline {
    position: relative;
    max-height: 72vh;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    margin-top: 0.5rem;
}
.timeline-hour {
    position: relative;
    height: 56px;
    border-top: 1px solid var(--border);
    box-sizing: border-box;
}
.timeline-hour:first-child { border-top: none; }
.timeline-hour-label {
    position: absolute;
    left: 0;
    top: -0.62em;
    width: 44px;
    text-align: right;
    font-size: 0.72rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    background: var(--surface);
    padding-right: 4px;
}
.timeline-entry {
    /* left/right/width ustawia JS (układ kolumnowy); poniżej wartości domyślne. */
    position: absolute;
    left: 56px;
    right: 8px;
    min-height: 42px; /* == MIN_ENTRY_PX w app.js — mieści 2 wiersze danych */
    box-sizing: border-box;
    padding: 3px 8px;
    border-radius: 6px;
    background: var(--surface-2);
    border-left: 3px solid var(--accent);
    overflow: hidden;
    cursor: pointer;
    line-height: 1.25;
}
.timeline-entry:hover { filter: brightness(1.15); }
.timeline-entry.running { border-left-style: dashed; }
.te-title { font-weight: 600; font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.te-sub { font-size: 0.72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.timeline-now {
    position: absolute;
    left: 56px;
    right: 8px;
    border-top: 2px solid #ff5d5d;
    z-index: 3;
    pointer-events: none;
}
.timeline-now::before {
    content: "";
    position: absolute;
    left: -4px;
    top: -4px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #ff5d5d;
}

/* --- Raport --- */
.report-total {
    font-size: 1.2rem;
    margin: 0.5rem 0 1.5rem;
}
.report-project {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.8rem;
    overflow: hidden;
}
.report-project-head {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.8rem 1rem;
    background: var(--surface-2);
    font-weight: 600;
}
.report-project-name { flex: 1; }
.report-project-dur { font-variant-numeric: tabular-nums; }
.report-tasks { list-style: none; margin: 0; padding: 0; }
.report-task {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.55rem 1rem 0.55rem 2.2rem;
    border-top: 1px solid var(--border);
    font-size: 0.92rem;
}
.report-task-name { flex: 1; }
.report-task-dur { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* --- Powiadomienia (toast) --- */
.toast-container {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: min(360px, calc(100vw - 2rem));
}
.toast {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius);
    padding: 0.7rem 0.9rem;
    font-size: 0.9rem;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { border-left-color: var(--error); }
.toast-success { border-left-color: #2e7d32; }

/* --- Responsywność (telefon / wąski ekran) --- */
@media (max-width: 640px) {
    .container { padding: 1.25rem 0.9rem; }

    .topbar {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.7rem 0.9rem;
    }
    .nav { order: 3; width: 100%; flex: 0 0 100%; justify-content: space-around; }
    .nav-link { flex: 1; text-align: center; }

    .inline-form { flex-wrap: wrap; }
    .inline-form input[type="text"] { flex: 1 1 100%; order: 2; }
    .inline-form button { flex: 1; }

    .card { flex-wrap: wrap; }
    .card-main { flex: 1 1 60%; }
    .card-actions { flex: 1 1 100%; }
    .card-actions button { flex: 1; }
    .entry-dur { order: 2; }

    .report-task { padding-left: 1.2rem; flex-wrap: wrap; }

    .timer-clock { font-size: 1.2rem; }
    /* Na wąskich ekranach widżet rozciąga się wzdłuż dolnej krawędzi z marginesami. */
    .timer-bar { left: 0.75rem; right: 0.75rem; bottom: 0.75rem; max-width: none; }
    .timer-running, .timer-idle { flex-wrap: wrap; }
    .timer-info { flex: 1 1 60%; }
    .timer-select { max-width: none; }
}
