/* =========================================================================
   Plan 30 dni — arkusz stylów
   Kolorystyka wyłącznie czarno-biała. Układ mobile-first.
   ========================================================================= */

:root {
    --bg:        #ffffff;
    --surface:   #ffffff;
    --surface-2: #f4f4f4;
    --fg:        #000000;
    --fg-soft:   #3d3d3d;
    --muted:     #737373;
    --line:      #d6d6d6;
    --line-hard: #000000;
    --inverse-bg: #000000;
    --inverse-fg: #ffffff;
    --focus:     #000000;
    --shadow:    0 8px 30px rgba(0, 0, 0, .14);

    --radius:    14px;
    --radius-sm: 10px;
    --gap:       10px;
    --tap:       44px;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color-scheme: light;
}

html[data-theme="dark"] {
    --bg:        #000000;
    --surface:   #0a0a0a;
    --surface-2: #161616;
    --fg:        #ffffff;
    --fg-soft:   #d4d4d4;
    --muted:     #9a9a9a;
    --line:      #333333;
    --line-hard: #ffffff;
    --inverse-bg: #ffffff;
    --inverse-fg: #000000;
    --focus:     #ffffff;
    --shadow:    0 8px 30px rgba(0, 0, 0, .6);
    color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) {
        --bg:        #000000;
        --surface:   #0a0a0a;
        --surface-2: #161616;
        --fg:        #ffffff;
        --fg-soft:   #d4d4d4;
        --muted:     #9a9a9a;
        --line:      #333333;
        --line-hard: #ffffff;
        --inverse-bg: #ffffff;
        --inverse-fg: #000000;
        --focus:     #ffffff;
        --shadow:    0 8px 30px rgba(0, 0, 0, .6);
        color-scheme: dark;
    }
}

*, *::before, *::after { box-sizing: border-box; }

/* Atrybut hidden musi wygrać z każdym display ustawionym niżej (np. .btn). */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-wrap: break-word;
}

:where(a) { color: inherit; }

:where(a, button, input, select, textarea, summary):focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
    border-radius: 4px;
}

/* --------------------------------------------------------------- przyciski */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: var(--tap);
    padding: 0 16px;
    border: 1px solid var(--line-hard);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--fg);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s ease, color .15s ease, transform .08s ease;
    -webkit-tap-highlight-color: transparent;
}

.btn:hover  { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }

.btn[disabled] { opacity: .45; cursor: not-allowed; }

.btn--primary {
    background: var(--inverse-bg);
    color: var(--inverse-fg);
    border-color: var(--line-hard);
}
.btn--primary:hover { background: var(--fg-soft); color: var(--inverse-fg); }

.btn--ghost { border-color: var(--line); }

.btn--danger { border-style: dashed; }

/* 44px to minimalny wygodny cel dotykowy - nie schodzimy niżej. */
.btn--compact { min-height: var(--tap); padding: 0 12px; font-size: .875rem; }

.btn--icon {
    min-width: var(--tap);
    width: var(--tap);
    padding: 0;
    font-size: 1.35rem;
    line-height: 1;
    border-color: var(--line);
}

.btn--block { width: 100%; }

/* ---------------------------------------------------------------- formularz */
.field { display: flex; flex-direction: column; gap: 6px; }

.field__label {
    font-size: .8125rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--muted);
}

.field__input {
    width: 100%;
    min-height: var(--tap);
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--fg);
    font: inherit;
    font-size: 16px; /* < 16px powoduje przybliżanie strony na iOS */
}

.field__input:focus { border-color: var(--line-hard); }

.field__input--area { min-height: 120px; resize: vertical; line-height: 1.55; }

select.field__input {
    appearance: none;
    -webkit-appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                      linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%;
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
    padding-right: 34px;
}

.field__group { display: flex; gap: 8px; align-items: stretch; }
.field__group .field__input { flex: 1 1 auto; }
.field__toggle {
    flex: 0 0 auto;
    min-height: var(--tap);
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--fg);
    font: inherit;
    font-size: .875rem;
    cursor: pointer;
}

.field__hint { margin: 2px 0 0; font-size: .75rem; color: var(--muted); }

.field__counter { float: right; font-weight: 500; text-transform: none; letter-spacing: 0; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }

/* Pole-pułapka dla botów — niewidoczne, ale nie display:none. */
.honeypot {
    position: absolute !important;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* ---------------------------------------------------------------- komunikaty */
.alert {
    margin: 0 0 12px;
    padding: 12px 14px;
    border: 1px solid var(--line-hard);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    font-size: .9375rem;
}
.alert--error { border-width: 2px; font-weight: 600; }
.alert--warn  { border-style: dashed; }
.alert code   { font-size: .875em; }

/* ------------------------------------------------------------------ logowanie */
.login {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100svh;
    padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}

.login__card {
    width: 100%;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 28px 24px;
    border: 2px solid var(--line-hard);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.login__brand { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.login__mark { width: 44px; height: 44px; }
.login__title { margin: 0; font-size: 1.5rem; letter-spacing: -.02em; }
.login__subtitle { margin: 0; font-size: .875rem; color: var(--muted); }
.login__foot { margin: 0; text-align: center; font-size: .75rem; color: var(--muted); }

/* --------------------------------------------------------------- górny pasek */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    padding-top: env(safe-area-inset-top);
}

.topbar__inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.topbar__brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar__mark { width: 22px; height: 22px; flex: 0 0 auto; }
.topbar__name {
    font-weight: 700;
    letter-spacing: -.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar__actions { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.topbar__logout { margin: 0; }

/* ------------------------------------------------------------------- układ */
.wrap {
    max-width: 1280px;
    margin: 0 auto;
    padding: 16px 14px calc(40px + env(safe-area-inset-bottom));
}

.meta { margin: 18px 0 0; font-size: .75rem; color: var(--muted); text-align: center; }

/* ----------------------------------------------------------- kopia zapasowa */
.tools {
    margin-top: 26px;
    padding: 16px;
    border: 1px dashed var(--line);
    border-radius: var(--radius);
}
.tools__title {
    margin: 0 0 12px;
    font-size: .8125rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
}
.tools__row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.tools__form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 0; }
.tools__file { display: flex; flex-direction: column; gap: 4px; font-size: .8125rem; }
.tools__file-label { font-weight: 600; }
/* Domyślny wygląd pola pliku bywa kolorowy — sprowadzamy go do czerni i bieli. */
.tools__file input[type="file"] {
    max-width: 100%;
    font: inherit;
    font-size: .8125rem;
    color: var(--fg);
}
.tools__file input[type="file"]::file-selector-button {
    min-height: 36px;
    margin-right: 10px;
    padding: 0 12px;
    border: 1px solid var(--line-hard);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--fg);
    font: inherit;
    font-size: .8125rem;
    font-weight: 600;
    cursor: pointer;
}
.tools__file input[type="file"]::-webkit-file-upload-button {
    min-height: 36px;
    margin-right: 10px;
    padding: 0 12px;
    border: 1px solid var(--line-hard);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--fg);
    font: inherit;
    font-size: .8125rem;
    font-weight: 600;
    cursor: pointer;
}
.tools__hint { margin: 12px 0 0; font-size: .75rem; color: var(--muted); }

/* ------------------------------------------------------------------- okres */
.period {
    display: grid;
    grid-template-columns: var(--tap) 1fr var(--tap);
    grid-template-areas: "prev label next" "today today today";
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.period > a[rel="prev"] { grid-area: prev; }
.period > a[rel="next"] { grid-area: next; }
.period__label { grid-area: label; text-align: center; min-width: 0; }
.period__today { grid-area: today; justify-self: center; }

.period__full  { display: none; font-weight: 700; }
.period__short { display: inline; font-weight: 700; font-size: 1.0625rem; }

/* ---------------------------------------------------------------- statystyki */
.stats { margin-bottom: 16px; }

.stats__bar {
    appearance: none;
    -webkit-appearance: none;
    display: block;
    width: 100%;
    height: 8px;
    border: 1px solid var(--line-hard);
    border-radius: 999px;
    overflow: hidden;
    background: var(--surface);
    color: var(--inverse-bg);  /* wypełnienie w przeglądarkach bez pseudoelementów */
}
.stats__bar::-webkit-progress-bar   { background: var(--surface); }
.stats__bar::-webkit-progress-value { background: var(--inverse-bg); }
.stats__bar::-moz-progress-bar      { background: var(--inverse-bg); }

.stats__list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
    margin: 8px 0 0;
    padding: 0;
    list-style: none;
    font-size: .8125rem;
    color: var(--muted);
}
.stats__list strong { color: var(--fg); }

/* -------------------------------------------------------------- siatka dni */
.grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--gap);
    margin: 0;
    padding: 0;
    list-style: none;
}

.grid__cell { display: flex; }

.day {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    min-height: 106px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--fg);
    text-decoration: none;
    transition: border-color .15s ease, background .15s ease, transform .08s ease;
    -webkit-tap-highlight-color: transparent;
}

.day:hover  { border-color: var(--line-hard); }
.day:active { transform: scale(.985); }

.day__head { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.day__num  { font-size: 1.5rem; font-weight: 700; line-height: 1; letter-spacing: -.03em; }
.day__meta {
    font-size: .6875rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    white-space: nowrap;
    text-align: right;
}

.day__body { flex: 1 1 auto; display: flex; align-items: flex-start; min-height: 0; }
.day__title {
    font-size: .875rem;
    font-weight: 600;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.day__title--muted { font-weight: 400; color: var(--fg-soft); }
.day__empty { font-size: .8125rem; color: var(--muted); }

.day__foot { display: flex; flex-wrap: wrap; gap: 4px; }

.tag {
    display: inline-block;
    padding: 2px 7px;
    border: 1px solid currentColor;
    border-radius: 999px;
    font-size: .6875rem;
    font-weight: 700;
    letter-spacing: .03em;
    text-transform: uppercase;
    white-space: nowrap;
}

/* --- stany kafla --- */
.day.is-filled { border-color: var(--line-hard); }

.day:not(.is-filled) { border-style: dashed; }

.day.is-done {
    background: var(--inverse-bg);
    color: var(--inverse-fg);
}
.day.is-done .day__meta { color: var(--inverse-fg); opacity: .7; }

/* Zamiast opacity (obniżało kontrast tekstu poniżej progu WCAG AA)
   wyciszamy sam kafel: przerywana ramka i przekreślony tytuł. */
.day.is-skipped { border-style: dashed; }
.day.is-skipped .day__title { text-decoration: line-through; color: var(--fg-soft); }

/* Miniony pusty dzień - wyciszamy sam numer. Nie przygaszamy całego kafla,
   bo spadłby kontrast tekstu poniżej progu WCAG AA. */
.day.is-past:not(.is-filled) .day__num { color: var(--muted); font-weight: 600; }

.day.is-today {
    box-shadow: 0 0 0 2px var(--line-hard);
    border-color: var(--line-hard);
}
.day.is-today::after {
    content: "dziś";
    position: absolute;
    top: -9px;
    right: 10px;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--inverse-bg);
    color: var(--inverse-fg);
    font-size: .625rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
}

/* ------------------------------------------------------------------ edytor */
.editor {
    padding: 0;
    border: none;
    background: transparent;
    color: var(--fg);
    max-width: none;
    max-height: none;
    width: 100%;
}

.editor::backdrop { background: rgba(0, 0, 0, .55); }
html[data-theme="dark"] .editor::backdrop { background: rgba(0, 0, 0, .72); }

.editor__form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    border: 2px solid var(--line-hard);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.editor__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.editor__title { margin: 0; font-size: 1.0625rem; line-height: 1.3; letter-spacing: -.01em; }
.editor__close { flex: 0 0 auto; }

.editor__body { display: flex; flex-direction: column; gap: 14px; }

/* Na telefonie klawiatura ekranowa potrafi zasłonić dół arkusza, dlatego
   pasek przycisków przykleja się do dołu przewijanego formularza. */
.editor__foot {
    position: sticky;
    bottom: 0;
    z-index: 2;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 -16px -18px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--line);
}
.editor__foot .btn { flex: 1 1 auto; }

/* Bez JS okno jest zwykłą sekcją na dole strony. */
html:not(.js) .editor[open] {
    position: static;
    display: block;
    margin: 20px auto 0;
    max-width: 560px;
    padding: 0 14px;
}

/* Z JS pokazujemy je wyłącznie przez showModal(). */
html.js .editor:not(.is-open) { display: none !important; }

html.js .editor.is-open {
    position: fixed;
    inset: auto 0 0 0;
    margin: 0;
    width: 100%;
    max-height: 92vh;
    max-height: 92svh;
    overflow: hidden;
    background: transparent;
    animation: sheet-in .18s ease-out;
}
html.js .editor.is-open .editor__form {
    max-height: 92vh;
    max-height: 92svh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

@keyframes sheet-in {
    from { transform: translateY(14px); opacity: .4; }
    to   { transform: translateY(0);    opacity: 1; }
}

html.js .editor.is-open .editor__form {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom: none;
}

/* ------------------------------------------------------------------ toasty */
.toast-stack {
    position: fixed;
    left: 50%;
    bottom: calc(18px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 90;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    width: max-content;
    max-width: calc(100vw - 32px);
    pointer-events: none;
}

.toast {
    padding: 10px 16px;
    border: 1px solid var(--line-hard);
    border-radius: 999px;
    background: var(--inverse-bg);
    color: var(--inverse-fg);
    font-size: .875rem;
    font-weight: 600;
    text-align: center;
    box-shadow: var(--shadow);
    animation: toast-in .18s ease-out;
}
.toast--error { background: var(--surface); color: var(--fg); border-width: 2px; }

@keyframes toast-in {
    from { transform: translateY(10px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

/* ============================ punkty przełamania ========================== */
/* Bardzo wąskie telefony - sama ikona zamiast obcinanej nazwy aplikacji. */
@media (max-width: 359px) {
    .topbar__name { display: none; }
}

@media (min-width: 420px) {
    .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-width: 640px) {
    .wrap { padding: 22px 20px 60px; }
    .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
    .day  { min-height: 130px; }

    .period {
        grid-template-columns: var(--tap) 1fr var(--tap) auto;
        grid-template-areas: "prev label next today";
    }
    .period__full  { display: inline; }
    .period__short { display: none; }

    html.js .editor.is-open {
        inset: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 24px;
        max-height: none;
    }
    html.js .editor.is-open .editor__form {
        width: 100%;
        max-width: 560px;
        max-height: 88vh;
        max-height: 88svh;
        overflow: auto;
        border-radius: var(--radius);
        border-bottom: 2px solid var(--line-hard);
        padding: 22px;
    }
    .editor__foot .btn { flex: 0 1 auto; min-width: 120px; }
}

@media (min-width: 960px)  { .grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (min-width: 1200px) { .grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}

@media print {
    .topbar__actions, .period, .editor, .toast-stack { display: none !important; }
    .day { break-inside: avoid; }
}
