:root {
    --app-red: #b42318;
    --app-red-dark: #8f1d14;
    --app-bg: #f3f5f8;
    --app-card: #ffffff;
    --app-text: #17212b;
    --app-muted: #637083;
    --app-border: #dce2e9;
    --app-shadow: 0 8px 26px rgba(16, 24, 40, .055);
    --touch-height: 56px;
}

* { -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; }
body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--app-bg);
    color: var(--app-text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 16px;
}
.app-container { width: min(100%, 1540px); margin-inline: auto; padding-inline: clamp(14px, 2.2vw, 32px); }
.app-navbar { background: var(--app-red); color: #fff; box-shadow: 0 3px 14px rgba(20, 25, 35, .14); }
.app-navbar .navbar-brand, .app-navbar .nav-link, .app-navbar .navbar-text { color: #fff; }
.app-navbar .nav-link { padding: .75rem .85rem; border-radius: .6rem; }
.app-navbar .nav-link:hover, .app-navbar .nav-link:focus { background: rgba(255,255,255,.13); color: #fff; }
.app-navbar .navbar-toggler { border-color: rgba(255,255,255,.55); min-width: 48px; min-height: 48px; }
.app-navbar .navbar-toggler-icon { filter: brightness(0) invert(1); }
.brand-mark, .login-emblem { display: grid; place-items: center; font-weight: 900; letter-spacing: -.04em; background: #fff; color: var(--app-red); border-radius: 12px; }
.brand-mark { width: 44px; height: 44px; font-size: 14px; }
.brand-subtitle { font-size: .72rem; line-height: 1.1; opacity: .82; font-weight: 500; }
.theme-toggle { min-height: 42px; border-color: rgba(255,255,255,.65); color: #fff; }
.theme-toggle:hover { background: #fff; color: var(--app-red); }
.user-label { font-size: .9rem; }
.logout-btn { min-height: 40px; font-weight: 650; }

main { flex: 1 0 auto; }
.app-card, .login-card { background: var(--app-card); color: var(--app-text); border: 1px solid var(--app-border) !important; border-radius: 17px; box-shadow: var(--app-shadow); overflow: hidden; }
.app-card-header, .card-header { background: transparent; border-bottom: 1px solid var(--app-border); }
.app-card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px; }
.app-card-header h2, .app-card-header h3 { font-weight: 800; }
.dashboard-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.eyebrow { color: var(--app-red); font-size: .74rem; font-weight: 850; letter-spacing: .13em; }
.display-title { font-size: clamp(1.65rem, 3.5vw, 2.25rem); font-weight: 850; letter-spacing: -.04em; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 14px; }
.section-heading h2 { font-weight: 800; letter-spacing: -.025em; }
.section-heading p { font-size: .94rem; }
.count-pill { flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--app-border); border-radius: 999px; padding: 6px 11px; font-size: .82rem; font-weight: 800; background: var(--app-bg); }
.live-clock-card { min-width: 152px; padding: 12px 16px; border-radius: 14px; background: var(--app-card); border: 1px solid var(--app-border); display: flex; flex-direction: column; box-shadow: var(--app-shadow); }
.live-clock-card strong { font-size: 1.55rem; line-height: 1.4; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.live-clock-card span { color: var(--app-muted); }
.form-label { font-weight: 700; margin-bottom: .45rem; }
.form-control, .form-select { min-height: 48px; border-color: var(--app-border); color: var(--app-text); background-color: var(--app-card); }
.form-control:focus, .form-select:focus { border-color: var(--app-red); box-shadow: 0 0 0 .2rem rgba(180, 35, 24, .15); }
.form-control::placeholder { color: #8691a0; }
.touch-button { min-height: var(--touch-height); font-weight: 800; }
.btn-danger { --bs-btn-bg: var(--app-red); --bs-btn-border-color: var(--app-red); --bs-btn-hover-bg: var(--app-red-dark); --bs-btn-hover-border-color: var(--app-red-dark); --bs-btn-active-bg: var(--app-red-dark); }
.start-action-button { min-height: 64px; font-size: 1.05rem; letter-spacing: .025em; box-shadow: 0 5px 13px rgba(180,35,24,.14); }
.start-action-button span { font-size: 1.35rem; margin-right: .35rem; }

.action-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.action-tile { display: flex; flex-direction: column; min-width: 0; padding: 19px; color: inherit; text-decoration: none; background: var(--app-card); border: 1px solid var(--app-border); border-radius: 16px; box-shadow: var(--app-shadow); transition: transform .12s ease, border-color .12s ease; }
.action-tile:hover, .action-tile:focus-visible { transform: translateY(-2px); border-color: rgba(180,35,24,.6); color: inherit; }
.event-chip { display: inline-flex; align-items: center; gap: 5px; border-radius: 7px; padding: 6px 9px; font-size: .76rem; font-weight: 800; background: #fbe9e7; color: #912018; }
.event-wypadek { background: #fff0d2; color: #7d4e00; }
.event-miejscowe_zagrozenie { background: #e5efff; color: #174ea6; }
.event-inne { background: #e9eaf0; color: #343b49; }
.status-dot { width: 12px; height: 12px; flex: 0 0 12px; border-radius: 50%; background: #c77d00; box-shadow: 0 0 0 4px rgba(199,125,0,.13); }
.status-na_miejscu { background: #1971c2; box-shadow: 0 0 0 4px rgba(25,113,194,.13); }
.status-opanowane { background: #2f9e44; box-shadow: 0 0 0 4px rgba(47,158,68,.13); }
.tile-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.elapsed-counter { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 850; font-size: .9rem; }
.tile-status { display: flex; justify-content: space-between; align-items: center; padding-top: 10px; border-top: 1px solid var(--app-border); font-weight: 750; color: var(--app-red); }
.empty-state { display: grid; place-items: center; text-align: center; padding: 40px 20px; border: 1px dashed var(--app-border); border-radius: 16px; background: var(--app-card); }
.empty-icon { display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: 12px; border-radius: 50%; background: #e6f6eb; color: #177245; font-size: 1.5rem; font-weight: 900; }
.recent-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; background: var(--app-card); color: var(--app-text); border-color: var(--app-border); }
.recent-row:hover { background: var(--app-bg); color: var(--app-text); }

.action-topline { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.back-link { color: var(--app-red); font-weight: 750; text-decoration: none; padding: 8px 0; }
.back-link:hover { text-decoration: underline; }
.action-state { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 999px; background: #fff0d2; color: #714300; font-size: .82rem; font-weight: 850; }
.state-indicator { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.state-closed { background: #e5f5ea; color: #166534; }
.action-location { font-size: clamp(1.55rem, 3vw, 2.3rem); font-weight: 850; letter-spacing: -.04em; overflow-wrap: anywhere; }
.action-stopwatch { display: flex; flex-direction: column; min-width: 240px; padding: 14px 18px; border: 1px solid var(--app-border); border-radius: 14px; background: var(--app-bg); }
.action-stopwatch .small { color: var(--app-muted); }
.action-stopwatch strong { font-size: clamp(1.8rem, 4vw, 2.5rem); line-height: 1.35; letter-spacing: .025em; font-variant-numeric: tabular-nums; }
.status-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.status-step { min-width: 0; display: flex; flex-direction: column; gap: 12px; padding: 17px; background: var(--app-card); border: 1px solid var(--app-border); border-radius: 15px; box-shadow: var(--app-shadow); }
.status-completed { border-top: 4px solid #2f9e44; }
.status-next { border: 2px solid var(--app-red); box-shadow: 0 5px 19px rgba(180,35,24,.11); }
.status-waiting { opacity: .74; }
.status-step-number { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--app-bg); border: 1px solid var(--app-border); font-size: 1.1rem; font-weight: 900; }
.status-completed .status-step-number { background: #e5f5ea; color: #176738; border-color: #c6ead1; }
.status-next .status-step-number { background: #fbe9e7; color: var(--app-red); border-color: #f1c6c2; }
.status-step-content { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.status-step-content strong { line-height: 1.25; font-weight: 850; }
.status-time { font-size: .82rem; color: var(--app-muted); min-height: 1.25em; }
.status-action-button { min-height: 52px; font-size: .86rem; font-weight: 900; }
.step-mark { font-size: 1.65rem; line-height: 1; color: #24833e; font-weight: 900; }
.step-pending { color: var(--app-muted); font-size: .85rem; }
.crew-add-form { padding-bottom: 17px; border-bottom: 1px solid var(--app-border); }
.crew-list { display: flex; flex-direction: column; }
.crew-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--app-border); }
.crew-row:last-child { border-bottom: 0; }
.crew-avatar { display: grid; place-items: center; width: 42px; height: 42px; flex: 0 0 42px; border-radius: 12px; background: var(--app-bg); color: var(--app-red); font-weight: 900; font-size: 1.1rem; }
.crew-person { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.crew-person strong { overflow-wrap: anywhere; }
.crew-person span { color: var(--app-muted); font-size: .86rem; }
.remove-crew { min-height: 40px; }
.empty-inline { padding: 16px; color: var(--app-muted); background: var(--app-bg); border-radius: 10px; }
.notes-field { min-height: 245px; resize: vertical; line-height: 1.55; }
.save-state { text-align: right; color: var(--app-muted); font-size: .78rem; }
.save-state.is-saving { color: #9a6700; }
.save-state.is-saved { color: #188047; }
.save-state.is-error { color: #b42318; }
.checklist-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.checklist-item { min-width: 0; display: flex; align-items: flex-start; gap: 13px; padding: 17px; background: var(--app-bg); border: 1px solid var(--app-border); border-radius: 13px; cursor: pointer; font-weight: 650; line-height: 1.4; }
.checklist-item .form-check-input { margin: 1px 0 0; width: 25px; height: 25px; flex: 0 0 25px; cursor: pointer; }
.checklist-item.is-done { color: var(--app-muted); background: rgba(47,158,68,.08); }
.checklist-item.is-done span { text-decoration: line-through; }
.checklist-item .form-check-input:checked { background-color: #24833e; border-color: #24833e; }

.login-wrap { display: grid; align-items: start; }
.login-card { width: min(100%, 510px); }
.login-emblem { width: 64px; height: 64px; font-size: 1.1rem; }
.login-card .text-secondary { color: var(--app-muted) !important; }

.admin-count { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 88px; min-height: 80px; padding: 10px 16px; border: 1px solid var(--app-border); background: var(--app-card); border-radius: 14px; }
.admin-count strong { font-size: 1.7rem; line-height: 1.2; }
.admin-count span { color: var(--app-muted); font-size: .8rem; }
.admin-user-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.admin-user-card { min-width: 0; }
.admin-user-card .card-header { align-items: flex-start; }
.user-active-switch { padding: 10px 0; }
.user-active-switch .form-check-input { width: 2.6em; height: 1.4em; margin-top: .1em; }

.app-footer { color: var(--app-muted); font-size: .82rem; padding: 20px 0 max(20px, env(safe-area-inset-bottom)); margin-top: 30px; border-top: 1px solid var(--app-border); }
.app-toast { position: fixed; z-index: 1100; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); max-width: min(92vw, 430px); padding: 13px 17px; background: #17212b; color: #fff; border-radius: 12px; box-shadow: 0 7px 24px rgba(0,0,0,.2); opacity: 0; pointer-events: none; transform: translateY(10px); transition: opacity .18s ease, transform .18s ease; }
.app-toast.is-visible { opacity: 1; transform: translateY(0); }

[data-bs-theme="dark"] {
    --app-bg: #11161d;
    --app-card: #1b232d;
    --app-text: #edf2f7;
    --app-muted: #a7b2c0;
    --app-border: #35404d;
    --app-shadow: 0 8px 28px rgba(0, 0, 0, .18);
    color-scheme: dark;
}
[data-bs-theme="dark"] .app-navbar { background: #761d17; }
[data-bs-theme="dark"] .btn-light { --bs-btn-bg: #f3f4f6; }
[data-bs-theme="dark"] .event-chip { background: #492421; color: #ffc8c1; }
[data-bs-theme="dark"] .event-wypadek { background: #49371b; color: #ffda8f; }
[data-bs-theme="dark"] .event-miejscowe_zagrozenie { background: #1c3558; color: #bdd5ff; }
[data-bs-theme="dark"] .event-inne { background: #303640; color: #e0e5ec; }
[data-bs-theme="dark"] .status-completed .status-step-number { background: #193d2a; color: #9de0b1; border-color: #28553a; }
[data-bs-theme="dark"] .status-next .status-step-number { background: #492421; color: #ffc8c1; border-color: #6b3430; }
[data-bs-theme="dark"] .step-mark { color: #6fd28c; }
[data-bs-theme="dark"] .empty-icon { background: #193d2a; color: #9de0b1; }
[data-bs-theme="dark"] .action-state { background: #49371b; color: #ffda8f; }
[data-bs-theme="dark"] .state-closed { background: #193d2a; color: #9de0b1; }
[data-bs-theme="dark"] .checklist-item.is-done { background: rgba(47,158,68,.10); }
[data-bs-theme="dark"] .text-secondary { color: var(--app-muted) !important; }
[data-bs-theme="dark"] .list-group-item { background-color: var(--app-card); color: var(--app-text); border-color: var(--app-border); }
[data-bs-theme="dark"] .list-group-item-action:hover { background: #232d39; color: var(--app-text); }
[data-bs-theme="dark"] .alert-success { --bs-alert-bg: #173626; --bs-alert-color: #bce9c9; --bs-alert-border-color: #28553a; }
[data-bs-theme="dark"] .alert-warning { --bs-alert-bg: #453619; --bs-alert-color: #ffdda0; --bs-alert-border-color: #6c5428; }

@media (max-width: 1199.98px) {
    .status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .action-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 767.98px) {
    :root { --touch-height: 58px; }
    .app-container { padding-inline: 13px; }
    .dashboard-heading { align-items: flex-start; }
    .dashboard-heading .live-clock-card { min-width: 115px; padding: 9px 10px; }
    .live-clock-card strong { font-size: 1.25rem; }
    .live-clock-card span { font-size: .7rem !important; }
    .dashboard-heading > div:first-child { min-width: 0; }
    .dashboard-heading .display-title { font-size: 1.7rem; }
    .section-heading { align-items: flex-start; }
    .section-heading p { font-size: .86rem; }
    .action-grid, .admin-user-grid { grid-template-columns: 1fr; }
    .action-tile { padding: 16px; }
    .action-location { font-size: 1.55rem; }
    .action-stopwatch { width: 100%; min-width: 0; }
    .status-grid { grid-template-columns: 1fr; gap: 10px; }
    .status-step { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; gap: 11px; padding: 13px; }
    .status-step-content { gap: 3px; }
    .status-action-button { grid-column: 1 / -1; width: 100%; min-height: 58px; font-size: .95rem; }
    .step-mark, .step-pending { justify-self: end; }
    .checklist-grid { grid-template-columns: 1fr; }
    .checklist-item { min-height: 62px; padding: 16px 14px; }
    .app-card-header { padding: 15px; }
    .app-card-header h2 { font-size: 1.05rem; }
    .save-state { max-width: 44%; }
    .recent-row { padding: 14px; }
    .app-footer { font-size: .75rem; }
    .app-footer .app-container { align-items: flex-start !important; flex-direction: column; }
    .nav-account { padding: 10px 0 14px; align-items: flex-start !important; }
}
@media (max-width: 380px) {
    .dashboard-heading .live-clock-card { min-width: 102px; }
    .dashboard-heading .display-title { font-size: 1.45rem; }
    .live-clock-card strong { font-size: 1.1rem; }
    .status-step { grid-template-columns: 38px minmax(0, 1fr) auto; padding: 11px; }
    .status-step-number { width: 36px; height: 36px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
