:root {
    --bg: #ffffff;
    --surface: #ffffff;
    --text: #161616;
    --muted: #626262;
    --brand: #ec6445;
    --brand-dark: #b63d25;
    --brand-soft: #ffe2da;
    --ink: #111111;
    --line: #e6e7eb;
    --ok: #147c3e;
    --warn: #b15d00;
    --err: #a61313;
    --radius: 12px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, sans-serif;
    color: var(--text);
    background: var(--bg);
}

body.modal-open {
    overflow: hidden;
}

a {
    color: var(--brand-dark);
    text-decoration: none;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 10px 18px;
    background: linear-gradient(120deg, #111 0%, #2a2a2a 100%);
    color: #fff;
    min-height: 60px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex-shrink: 1;
}

.brand img {
    width: 44px;
    height: 44px;
    object-fit: contain;
    border-radius: 8px;
    background: #fff;
    padding: 4px;
    flex-shrink: 0;
}

.brand h1 {
    margin: 0;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand p {
    margin: 2px 0 0;
    color: #d9d9d9;
    font-size: 0.78rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

.user-pill {
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 5px 11px;
    border-radius: 999px;
    line-height: 1.3;
    max-width: 140px;
    overflow: hidden;
}

.user-pill strong {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.9rem;
    color: #fff;
}

.user-pill span {
    color: #ccc;
    font-size: 0.75rem;
}

.main-nav {
    display: flex;
    gap: 4px 2px;
    flex-wrap: wrap;
    padding: 6px 12px;
    border-bottom: 1px solid var(--line);
    background: #fff;
}

.main-nav a {
    padding: 7px 11px;
    border-radius: 8px;
    color: #333;
    font-weight: 600;
    white-space: nowrap;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    font-size: 0.88rem;
}

/* Hamburger */
.nav-hamburger {
    display: none;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
}

.nav-hamburger span {
    width: 18px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.nav-hamburger.is-open span:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
}

.nav-hamburger.is-open span:nth-child(2) {
    opacity: 0;
}

.nav-hamburger.is-open span:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
}

.main-nav a.active,
.main-nav a:hover {
    background: var(--brand);
    color: #fff;
}

.container {
    padding: 18px;
    max-width: 1400px;
    margin: 0 auto;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.toolbar-meta {
    color: var(--muted);
}

.inline-form {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 14px;
    box-shadow: none;
}

.card h2, .card h3 {
    margin-top: 0;
}

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px;
}

.stat p {
    font-size: 1.8rem;
    margin: 0;
    color: var(--brand-dark);
    font-weight: 700;
}

.stat .stat-label {
    font-size: 1rem;
    line-height: 1.3;
}

.grid-two {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 14px;
}

.inventory-stack {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.form-stack {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.compact-form {
    min-width: 210px;
}

.compact-form label {
    font-size: 0.82rem;
    color: var(--muted);
}

input, select, textarea, button {
    font: inherit;
}

input, select, textarea {
    border: 1px solid #cfd3da;
    border-radius: 8px;
    padding: 9px 10px;
    background: #fff;
    min-height: 40px;
}

.table-input {
    width: 100%;
    min-width: 140px;
}

.serial-input {
    min-width: 150px;
}

.actions-cell {
    white-space: nowrap;
}

.equipment-thumb {
    width: 72px;
    height: 54px;
    object-fit: cover;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f7f7f8;
}

.image-modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 28px;
    background: rgba(0, 0, 0, 0.82);
    z-index: 1000;
}

.image-modal[aria-hidden="false"] {
    display: flex;
}

.image-modal img {
    max-width: min(96vw, 1200px);
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
    background: #fff;
}

.image-modal-close {
    position: fixed;
    top: 14px;
    right: 16px;
    width: 42px;
    height: 42px;
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.35);
    color: #fff;
    font-size: 1.35rem;
    cursor: pointer;
}

textarea {
    resize: vertical;
}

.checks {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 14px;
}

.checks label {
    font-size: 0.92rem;
}

.btn {
    border: 1px solid var(--ink);
    border-radius: 8px;
    background: #fff;
    padding: 8px 14px;
    cursor: pointer;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
}

.btn.primary {
    background: var(--brand);
    border-color: var(--brand-dark);
    color: #fff;
    font-weight: 600;
}

.btn.ghost {
    background: transparent;
    color: #fff;
    border-color: rgba(255, 255, 255, 0.45);
}

.btn:hover {
    filter: brightness(0.96);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    border-bottom: 1px solid var(--line);
    text-align: left;
    padding: 8px 7px;
    vertical-align: top;
    font-size: 0.92rem;
}

th {
    background: #fafafb;
}

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
    background: #fff;
    position: relative;
}

/* scroll hint — widoczny tylko na dotykowych wąskich ekranach */
@media (max-width: 768px) and (pointer: coarse) {
    .table-scroll::after {
        content: "← przesuwaj →";
        display: block;
        text-align: center;
        font-size: 0.72rem;
        color: var(--muted);
        padding: 4px 0 2px;
        letter-spacing: 0.04em;
        opacity: 0.7;
    }
}

/* catch-all: każda tabela wewnątrz .card na mobile dostaje scroll bez wrappera */
@media (max-width: 768px) {
    .card > table,
    .card > div > table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }
}

.inventory-table {
    min-width: 1180px;
}

.inventory-table th:nth-child(5),
.inventory-table td:nth-child(5) {
    min-width: 260px;
}

.inventory-table th:nth-child(6),
.inventory-table td:nth-child(6) {
    min-width: 300px;
}

.inventory-table .compact-form,
.inventory-table .movement-form {
    min-width: 240px;
}

.inventory-name-form {
    margin-top: 8px;
}

.inventory-machine-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.inventory-machine-tools .btn {
    min-height: 34px;
    padding: 6px 10px;
    font-size: 0.8rem;
}

.inventory-name-form label {
    font-size: 0.82rem;
    color: var(--muted);
}

.inventory-table input[type="file"],
.inventory-table select,
.inventory-table input[type="text"] {
    width: 100%;
}

.movement-form {
    align-items: flex-start;
}

.flash {
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 10px;
}

.flash.success {
    background: rgba(20, 124, 62, 0.12);
    border: 1px solid rgba(20, 124, 62, 0.3);
}

.flash.error {
    background: rgba(166, 19, 19, 0.12);
    border: 1px solid rgba(166, 19, 19, 0.3);
}

.flash.info {
    background: rgba(17, 17, 17, 0.07);
    border: 1px solid rgba(17, 17, 17, 0.2);
}

.module-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 10px;
}

.module-item {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px;
}

.badge {
    display: inline-block;
    margin: 6px 0 10px;
    padding: 4px 8px;
    border-radius: 999px;
    background: #f2f3f6;
    border: 1px solid #d5d8de;
}

.badge.warn {
    background: #fff2dc;
    border-color: #f2c27c;
    color: #7b4700;
}

.module-settings-form {
    margin-top: 10px;
}

.module-settings-form input,
.module-settings-form select {
    width: 100%;
}

.status-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 700;
}

.status-badge.open {
    background: var(--brand-soft);
    color: var(--brand-dark);
}

.status-badge.resolved {
    background: rgba(20, 124, 62, 0.12);
    color: var(--ok);
}

.contact-type-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.contact-type-list span {
    display: inline-block;
    padding: 7px 10px;
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--brand-dark);
    font-weight: 700;
    font-size: 0.9rem;
}

.muted {
    color: var(--muted);
}

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 12px;
}

.login-wrap {
    width: 100%;
    max-width: 440px;
}

.login-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 20px;
    box-shadow: 0 16px 32px rgba(12, 12, 12, 0.08);
}

.login-card img {
    width: 100%;
    max-width: 120px;
    display: block;
    margin: 0 auto 12px;
}

/* ── TABLET (≤1024px) ───────────────────────────────── */
@media (max-width: 1024px) {
    .container {
        padding: 14px 16px;
    }

    .header-actions {
        flex-shrink: 1;
    }

    .grid-two {
        grid-template-columns: 1fr;
    }

    .inventory-table {
        min-width: 900px;
    }
}

/* ── PHABLET (≤768px) ───────────────────────────────── */
@media (max-width: 768px) {
    html { font-size: 15px; }

    /* header */
    .app-header {
        flex-direction: row;
        flex-wrap: wrap;
        padding: 10px 14px;
        gap: 8px;
    }

    .brand {
        gap: 10px;
        flex: 1;
        min-width: 0;
    }

    .brand img {
        width: 44px;
        height: 44px;
        flex-shrink: 0;
    }

    .brand h1 {
        font-size: 0.95rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .brand p {
        display: none;
    }

    .header-actions {
        gap: 6px;
        flex-wrap: wrap;
    }

    .nav-hamburger {
        display: inline-flex;
    }

    .user-pill {
        padding: 5px 10px;
        font-size: 0.82rem;
    }

    .main-nav {
        display: block;
        flex-wrap: nowrap;
        max-height: 0;
        overflow: hidden;
        padding-top: 0;
        padding-bottom: 0;
        border-bottom-width: 0;
        transition: max-height 0.22s ease, padding 0.22s ease, border-bottom-width 0.22s ease;
    }

    .main-nav.nav-open {
        max-height: 75vh;
        overflow-y: auto;
        padding-top: 8px;
        padding-bottom: 8px;
        border-bottom-width: 1px;
    }

    .main-nav a {
        display: flex;
        width: 100%;
        min-height: 44px;
        border-radius: 0;
        padding: 10px 12px;
    }

    /* toolbar */
    .toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .toolbar .inline-form {
        flex-direction: row;
        flex-wrap: nowrap;
    }

    .toolbar select {
        flex: 1;
        min-width: 0;
    }

    .toolbar-meta {
        font-size: 0.82rem;
    }

    /* karty */
    .card {
        padding: 12px;
        border-radius: 10px;
    }

    /* statystyki */
    .cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .stat p {
        font-size: 1.5rem;
    }

    /* tabele */
    th, td {
        font-size: 0.85rem;
        padding: 7px 6px;
    }

    /* machine detail */
    .machine-detail-header {
        flex-direction: column;
    }

    .machine-detail-img,
    .machine-detail-placeholder {
        width: 100%;
        height: 200px;
    }
}

/* ── MOBILE (≤480px) ────────────────────────────────── */
@media (max-width: 480px) {
    html { font-size: 14px; }

    .container {
        padding: 8px 10px;
    }

    /* header jeszcze kompaktowszy */
    .app-header {
        padding: 8px 12px;
    }

    .brand img {
        width: 36px;
        height: 36px;
    }

    .brand h1 {
        font-size: 0.88rem;
    }

    /* przyciski wyloguj – mniejsze */
    .btn.ghost {
        padding: 6px 10px;
        font-size: 0.82rem;
    }

    /* karty */
    .card {
        padding: 10px;
        margin-bottom: 10px;
    }

    .card h2 {
        font-size: 1rem;
    }

    .card h3 {
        font-size: 0.95rem;
    }

    /* grid → zawsze 1 kolumna */
    .grid-two,
    .cards,
    .module-list {
        grid-template-columns: 1fr;
    }

    /* stat cards – 2 kolumny */
    .cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .stat p {
        font-size: 1.3rem;
    }

    .stat .stat-label {
        font-size: 0.85rem;
    }

    /* toolbar – selektor pełna szerokość */
    .toolbar .inline-form {
        flex-direction: column;
        width: 100%;
    }

    .toolbar select {
        width: 100%;
    }

    /* formularze – wszystko pełna szerokość */
    .form-stack input,
    .form-stack select,
    .form-stack textarea,
    .form-stack button {
        width: 100%;
    }

    /* input + capture – większy obszar dotykowy */
    input[type="file"] {
        padding: 10px 8px;
        font-size: 0.85rem;
    }

    /* inline-form w tabeli – pionowo */
    .movement-form {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
        min-width: 160px;
    }

    .movement-form select,
    .movement-form input,
    .movement-form button {
        width: 100%;
    }

    /* tabele */
    th, td {
        font-size: 0.78rem;
        padding: 6px 5px;
    }

    /* miniatury */
    .equipment-thumb {
        width: 50px;
        height: 38px;
    }

    /* flash messages */
    .flash {
        font-size: 0.88rem;
    }

    /* modale QR / zdjecia – full screen na mobile */
    .qr-modal-box {
        padding: 18px 16px 16px;
        max-width: 100%;
    }

    /* machine detail */
    .machine-detail-img,
    .machine-detail-placeholder {
        width: 100%;
        height: 160px;
    }

    .detail-table th,
    .detail-table td {
        font-size: 0.82rem;
    }
}
.qr-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 1002;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.qr-modal[aria-hidden="true"] {
    display: none;
}

.qr-modal-box {
    background: #fff;
    border-radius: 16px;
    padding: 24px 28px 20px;
    text-align: center;
    max-width: 320px;
    width: 100%;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.qr-modal-box h3 {
    margin: 0 0 16px;
    font-size: 1rem;
}

.qr-canvas {
    display: flex;
    justify-content: center;
    margin-bottom: 10px;
}

.qr-modal-url {
    font-size: 0.72rem;
    color: var(--muted);
    word-break: break-all;
    margin: 4px 0 0;
}

.qr-modal-close {
    position: absolute;
    top: 10px;
    right: 12px;
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--muted);
    line-height: 1;
    padding: 4px 6px;
}

/* ── Machine Detail ─────────────────────────────────── */
.machine-detail-header {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.machine-detail-img {
    width: 200px;
    height: 150px;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid var(--line);
    display: block;
}

.machine-detail-placeholder {
    width: 200px;
    height: 150px;
    border: 2px dashed var(--line);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 0.85rem;
}

.machine-detail-info {
    flex: 1;
    min-width: 0;
}

.machine-detail-info h2 {
    margin-top: 0;
}

.detail-table {
    border-collapse: collapse;
    width: auto;
}

.detail-table th {
    text-align: left;
    color: var(--muted);
    font-weight: 500;
    padding: 3px 14px 3px 0;
    white-space: nowrap;
    background: transparent;
    border: none;
    font-size: 0.85rem;
}

.detail-table td {
    padding: 3px 0;
    border: none;
    font-size: 0.9rem;
}

.machine-qr-inline {
    display: inline-block;
}
