:root {
    --bg: #faf9f7;
    --bg-dark: #f0ede8;
    --card: rgba(255, 255, 255, 0.97);
    --line: #e5ddd4;
    --text: #1f2937;
    --muted: #6b7280;
    --brand: #d97706;
    --brand-dark: #b45309;
    --brand-blue: #78350f;
    --brand-blue-2: #f59e0b;
    --secondary: #334155;
    --danger-bg: #fee2e2;
    --danger-text: #991b1b;
    --waste: #cbd5e1;
    --kerf: #111827;
    --shadow: 0 8px 28px rgba(120, 53, 15, 0.08);
    --radius: 14px;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: Arial, sans-serif;
    color: var(--text);
    background: linear-gradient(180deg, rgba(217, 119, 6, 0.08) 0%, rgba(255, 255, 255, 0) 280px), radial-gradient(circle at top right, rgba(245, 158, 11, 0.10), transparent 30%), linear-gradient(135deg, var(--bg) 0%, #fffbf5 45%, var(--bg-dark) 100%);
    background-attachment: fixed;
}

.brand-shell {
    min-height: 100vh;
}

.top-brand-bar {
    background: linear-gradient(90deg, #ffffff 0%, #fffbf0 100%);
    border-bottom: 1px solid #fde68a;
    box-shadow: 0 2px 10px rgba(120, 53, 15, 0.06);
    position: sticky;
    top: 0;
    z-index: 30;
}

.top-brand-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 18px 16px 18px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-logo-link {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    margin-left: 6px;
}

.brand-logo {
    height: 44px;
    width: auto;
    display: block;
}

.btn-magazyn {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: #fff;
    border-radius: 10px;
    font-size: 0.875rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    text-decoration: none;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(180, 83, 9, 0.25);
    transition: box-shadow 0.15s, transform 0.1s;
}
.btn-magazyn::before {
    content: '📦';
    font-size: 1rem;
}
.btn-magazyn:hover {
    box-shadow: 0 4px 14px rgba(180, 83, 9, 0.35);
    transform: translateY(-1px);
}
.btn-magazyn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(180, 83, 9, 0.2);
}

.brand-copy {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.brand-name {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--brand-blue);
}

.brand-tagline {
    font-size: 13px;
    color: var(--muted);
    text-transform: lowercase;
}

.wrap {
    max-width: 1280px;
    margin: 32px auto 60px;
    padding: 0 16px;
}

.page-head {
    margin-bottom: 24px;
}

.page-head-branded {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 10px 0 4px;
}

.page-head h1 {
    margin: 0 0 8px;
    color: var(--brand-blue);
    font-size: 34px;
    line-height: 1.15;
}

.page-head p {
    margin: 0;
    color: var(--muted);
    font-size: 16px;
    line-height: 1.5;
    max-width: 860px;
}

.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(219, 230, 238, 0.9);
    margin-bottom: 24px;
    backdrop-filter: blur(2px);
}

    .card h2 {
        margin-top: 0;
        margin-bottom: 16px;
        color: var(--brand-blue);
    }

.alert {
    border-radius: 10px;
    padding: 14px 16px;
    margin-bottom: 20px;
}

.alert-error {
    background: var(--danger-bg);
    color: var(--danger-text);
    border: 1px solid #fecaca;
}

.form-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: 1fr 220px;
}

    .form-grid.form-grid-top {
        grid-template-columns: 1fr 200px 200px;
    }

    .form-grid.two-cols {
        grid-template-columns: 1fr 1fr;
        margin-top: 16px;
    }

.field {
    display: flex;
    flex-direction: column;
}

    .field label {
        font-weight: 700;
        margin-bottom: 8px;
        color: var(--brand-blue);
    }

    .field input,
    .field textarea {
        border: 1px solid #cbd5e1;
        border-radius: 10px;
        padding: 12px;
        font-size: 15px;
        width: 100%;
        background: #fff;
        color: var(--text);
        transition: border-color 0.2s ease, box-shadow 0.2s ease;
    }

        .field input:focus,
        .field textarea:focus {
            outline: none;
            border-color: var(--brand-blue-2);
            box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.20);
        }

    .field textarea {
        min-height: 280px;
        resize: vertical;
        font-family: Consolas, "Courier New", monospace;
        line-height: 1.45;
    }

    .field small {
        color: var(--muted);
        margin-top: 8px;
        line-height: 1.45;
    }

.grid-hint {
    font-weight: 400;
    font-size: 12px;
    color: var(--muted);
}

.grid-wrap {
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    overflow: hidden;
    flex: 1;
}

.input-grid {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    background: #fff;
}

.input-grid thead th {
    background: #fef3c7;
    color: var(--brand-blue);
    font-weight: 700;
    font-size: 13px;
    padding: 8px 10px;
    border-bottom: 1px solid #fde68a;
    text-align: left;
}

.input-grid tbody tr:not(:last-child) td {
    border-bottom: 1px solid #e8eef4;
}

.gc {
    padding: 7px 10px;
    font-size: 14px;
    outline: none;
    cursor: text;
    min-height: 34px;
    display: table-cell;
}

.gc:focus {
    background: #fffbeb;
    box-shadow: inset 0 0 0 2px var(--brand-blue-2);
    position: relative;
    z-index: 1;
}

.gc-selected {
    background: #fde68a !important;
    box-shadow: inset 0 0 0 1px #f59e0b;
}

.gc-num {
    text-align: right;
}

.gc-del {
    display: block;
    width: 100%;
    border: none;
    background: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 14px;
    padding: 6px;
    line-height: 1;
    transition: color 0.15s, background 0.15s;
}

.gc-del:hover {
    color: #dc2626;
    background: #fee2e2;
}

.btn-add-row {
    display: block;
    width: 100%;
    border: none;
    background: #fffbf0;
    color: var(--brand-blue);
    font-weight: 600;
    padding: 8px 12px;
    cursor: pointer;
    border-top: 1px solid #fde68a;
    font-size: 13px;
    text-align: left;
    transition: background 0.15s;
}

.btn-add-row:hover {
    background: #fef3c7;
}

.actions,
.download-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.btn {
    border: none;
    background: var(--brand-blue-2);
    color: #fff;
    padding: 12px 18px;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.12s ease, background 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 4px 14px rgba(245, 158, 11, 0.28);
}

    .btn:hover {
        background: var(--brand-dark);
        transform: translateY(-1px);
    }

.btn-secondary {
    background: var(--secondary);
    box-shadow: 0 4px 14px rgba(51, 65, 85, 0.16);
}

    .btn-secondary:hover {
        background: #1e293b;
    }

.btn-print {
    background: #7c3aed;
    box-shadow: 0 4px 14px rgba(124, 58, 237, 0.18);
}

    .btn-print:hover {
        background: #6d28d9;
    }

.btn-orient {
    background: #0f766e;
    box-shadow: 0 4px 14px rgba(15, 118, 110, 0.18);
}

    .btn-orient:hover {
        background: #115e59;
    }

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

    .summary-grid div {
        background: linear-gradient(180deg, #fffbf0 0%, #fef9ec 100%);
        border: 1px solid #fde68a;
        border-radius: 10px;
        padding: 12px;
    }

    .summary-grid span {
        display: block;
        color: var(--muted);
        font-size: 13px;
        margin-bottom: 6px;
    }

    .summary-grid strong {
        font-size: 18px;
        color: var(--brand-blue);
    }

table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    overflow: hidden;
}

.bar-group {
    border: 1px solid #fde68a;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 40px;
}

.bar-group-title {
    background: #fef3c7;
    padding: 8px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #fde68a;
    font-size: 14px;
}

.bars-table {
    table-layout: fixed;
    border-radius: 0;
    margin: 0;
}

.bars-table .viz-row td {
    overflow: hidden;
}

.detale-cell {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

th,
td {
    border: 1px solid #e5e7eb;
    padding: 10px;
    vertical-align: top;
    text-align: left;
}

th {
    background: #fef3c7;
    color: var(--brand-blue);
    font-weight: 700;
}

tr:nth-child(even) td {
    background: rgba(248, 250, 252, 0.65);
}

.status {
    display: inline-block;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.status-ok {
    background: #dcfce7;
    color: #166534;
}

.status-warn {
    background: #fef3c7;
    color: #92400e;
}

.status-bad {
    background: #fee2e2;
    color: #991b1b;
}

.error-card {
    border: 2px solid #fecaca;
}

.error-list {
    margin: 0;
    padding-left: 20px;
    color: #991b1b;
    line-height: 1.6;
}

.viz-row td {
    background: #fbfdff !important;
    overflow: hidden;
    max-width: 0;
}

.bar-card {
    padding: 10px 0 4px;
    overflow: hidden;
}

.bar-meta {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 10px;
    font-size: 13px;
    color: #475569;
}

    .bar-meta strong {
        color: var(--brand-blue);
    }

.cut-bar {
    width: 100%;
    min-height: 56px;
    border: 1px solid #94a3b8;
    display: flex;
    align-items: stretch;
    overflow: hidden;
    border-radius: 8px;
    background: repeating-linear-gradient( 90deg, rgba(255, 255, 255, 0.08) 0, rgba(255, 255, 255, 0.08) 1px, transparent 1px, transparent 40px ), #e2e8f0;
}

.piece,
.waste {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 56px;
    min-width: 0;
    flex-shrink: 1;
    padding: 4px 6px;
    text-align: center;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    overflow: hidden;
}

    .piece span,
    .waste span {
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
    }

.kerf {
    flex-shrink: 0;
    min-width: 2px;
    background: var(--kerf);
}

.waste {
    background: var(--waste);
    color: #111827;
}

.repeat-badge {
    display: inline-block;
    background: var(--brand-blue);
    color: #fff;
    font-weight: 700;
    border-radius: 999px;
    padding: 2px 9px;
    font-size: 12px;
    vertical-align: middle;
    margin-left: 4px;
}

.piece-list {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
    padding-bottom: 12px;
}

.piece-badge {
    color: #fff;
    font-weight: 700;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 12px;
}

.print-brand-block {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 18px;
    padding: 12px 0 4px;
}

.print-brand-left {
    flex: 0 0 auto;
}

.print-brand-right {
    flex: 1 1 auto;
    text-align: right;
    font-size: 13px;
    line-height: 1.5;
}

    .print-brand-right h2 {
        margin: 0 0 8px 0;
        color: var(--brand-blue);
    }

.print-logo {
    height: 56px;
    width: auto;
    display: block;
}

@media (max-width: 960px) {
    .form-grid,
    .form-grid.two-cols {
        grid-template-columns: 1fr;
    }

    .page-head h1 {
        font-size: 28px;
    }

    .top-brand-inner {
        padding: 12px 16px;
    }

    .brand-logo {
        height: 38px;
    }
}

@media (max-width: 640px) {
    .wrap {
        margin-top: 20px;
    }

    .page-head h1 {
        font-size: 24px;
    }

    .page-head p {
        font-size: 15px;
    }

    .card {
        padding: 16px;
    }

    th,
    td {
        padding: 8px;
        font-size: 14px;
    }

    .piece,
    .waste {
        font-size: 11px;
    }
}

@media print {
    @page {
        size: A4 landscape;
        margin: 8mm 10mm;
    }

    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    body {
        background: #fff !important;
        color: #000 !important;
        font-size: 9px !important;
        font-family: Arial, sans-serif !important;
    }

    .top-brand-bar,
    .form-card,
    .download-row,
    .actions,
    .btn,
    .alert,
    .page-head {
        display: none !important;
    }

    .wrap {
        max-width: none;
        margin: 0;
        padding: 0;
    }

    /* ── Brand nagłówek ── */
    .print-brand-block {
        display: flex;
        margin-bottom: 6px;
        padding-bottom: 5px;
        border-bottom: 2px solid #000;
    }

    .print-logo { height: 36px; }

    .print-brand-right {
        font-size: 9px;
        line-height: 1.4;
    }

    .print-brand-right h2 {
        font-size: 12px;
        margin: 0 0 2px;
        color: #000 !important;
    }

    /* ── Karty ── */
    .card {
        box-shadow: none !important;
        border: 1.5px solid #000;
        background: #fff !important;
        border-radius: 0 !important;
        padding: 5px 8px !important;
        margin-bottom: 6px !important;
        break-inside: avoid;
        page-break-inside: avoid;
        backdrop-filter: none;
    }

    .card h2 {
        font-size: 10px !important;
        font-weight: 700;
        margin: 0 0 4px !important;
        padding-bottom: 3px;
        border-bottom: 1px solid #000;
        text-transform: uppercase;
        letter-spacing: .04em;
    }

    /* ── Podsumowanie — wiersz zamiast siatki ── */
    .summary-grid {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 2px 18px !important;
        font-size: 9px !important;
    }

    .summary-grid > div {
        display: flex !important;
        gap: 4px;
        align-items: baseline;
    }

    .summary-grid span {
        color: #555;
        font-size: 8px;
        text-transform: uppercase;
    }

    .summary-grid strong {
        color: #000;
        font-weight: 700;
    }

    /* ── Tabele ── */
    table {
        font-size: 9px !important;
        width: 100%;
        table-layout: fixed;
        border-collapse: collapse;
    }

    th {
        background: #000 !important;
        color: #fff !important;
        padding: 3px 5px !important;
        font-size: 8px !important;
        font-weight: 700;
        text-align: left;
        border: 1px solid #000 !important;
    }

    td {
        border: 1px solid #888 !important;
        padding: 3px 5px !important;
        word-break: break-word;
        overflow-wrap: break-word;
        font-size: 9px !important;
    }

    tr:nth-child(even) td {
        background: #efefef !important;
    }

    /* ── Statusy ── */
    .status {
        font-size: 8px !important;
        padding: 1px 5px !important;
        border: 1px solid #000 !important;
        border-radius: 2px !important;
        background: #fff !important;
        color: #000 !important;
        font-weight: 700;
    }

    /* ── Grupy wzorców ── */
    .bar-group {
        margin-bottom: 5px !important;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .bar-group-title {
        display: flex;
        align-items: center;
        gap: 6px;
        font-size: 9px !important;
        font-weight: 700;
        margin-bottom: 2px !important;
        background: #ddd !important;
        padding: 2px 6px !important;
        border: 1px solid #000;
    }

    .repeat-badge {
        font-size: 9px !important;
        background: #000 !important;
        color: #fff !important;
        border-radius: 2px !important;
        padding: 1px 5px !important;
    }

    /* ── Wiersz danych tabeli plan cięcia ── */
    .viz-row td {
        padding: 3px 0 !important;
        border-left: none !important;
        border-right: none !important;
        border-bottom: 1px solid #ccc !important;
        border-top: none !important;
    }

    .bar-card {
        padding: 2px 0 !important;
    }

    /* ── Pasek wizualizacji — monochromatyczny ── */
    .cut-bar {
        width: 100%;
        overflow: hidden;
        min-height: 20px !important;
        display: flex;
        border: 1.5px solid #000 !important;
        border-radius: 0 !important;
    }

    .piece {
        flex-shrink: 1;
        min-width: 0;
        font-size: 7px !important;
        font-weight: 700;
        min-height: 20px !important;
        background: #fff !important;
        color: #000 !important;
        border-right: 1.5px solid #000 !important;
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;
    }

    .piece:nth-child(4n+1) { background: #fff !important; }
    .piece:nth-child(4n+2) { background: #ddd !important; }
    .piece:nth-child(4n+3) { background: #bbb !important; }
    .piece:nth-child(4n+0) { background: #f5f5f5 !important; }

    .piece span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        padding: 0 2px;
        color: #000 !important;
        font-weight: 700;
    }

    .waste {
        flex-shrink: 1;
        min-width: 0;
        font-size: 7px !important;
        min-height: 20px !important;
        background: repeating-linear-gradient(
            45deg,
            #fff,
            #fff 2px,
            #ccc 2px,
            #ccc 4px
        ) !important;
        color: #666 !important;
        display: flex;
        align-items: center;
        justify-content: center;
        border-left: 1px solid #999 !important;
    }

    .waste span {
        font-size: 7px !important;
        white-space: nowrap;
        overflow: hidden;
        padding: 0 2px;
    }

    .kerf {
        flex-shrink: 0;
        width: 2px !important;
        min-width: 2px !important;
        background: #000 !important;
        border: none !important;
    }

    /* ── Legenda (piece-list) ── */
    .piece-list {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 3px !important;
        margin-top: 3px !important;
    }

    .piece-badge {
        font-size: 8px !important;
        padding: 2px 5px !important;
        border-radius: 2px !important;
        background: #000 !important;
        color: #fff !important;
        border: none !important;
    }

    a { color: #000; text-decoration: none; }
}
