/* Ksiegowy - Modern Flat Blue & White */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

:root {
    --primary: #2563EB;
    --primary-hover: #1D4ED8;
    --primary-light: #DBEAFE;
    --primary-50: #EFF6FF;
    --bg: #F0F4F8;
    --bg2: #E8EDF2;
    --white: #FFFFFF;
    --card: #FFFFFF;
    --text: #1E293B;
    --text2: #64748B;
    --text3: #94A3B8;
    --danger: #EF4444;
    --danger-light: #FEE2E2;
    --warning: #F59E0B;
    --warning-light: #FEF3C7;
    --success: #10B981;
    --success-light: #D1FAE5;
    --border: #E2E8F0;
    --input-bg: #F8FAFC;
    --sidebar-w: 240px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--primary); text-decoration: none; transition: color .15s; }
a:hover { color: var(--primary-hover); }

/* ========== Sidebar ========== */
.sidebar {
    width: var(--sidebar-w);
    background: var(--white);
    padding: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.sidebar-header {
    padding: 24px 24px 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar .logo {
    font-size: 20px;
    font-weight: 800;
    color: var(--primary);
    padding: 24px 24px 20px;
    letter-spacing: -0.3px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border);
}

.sidebar .logo .logo-icon {
    width: 32px;
    height: 32px;
    background: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    font-weight: 700;
    flex-shrink: 0;
}

.sidebar-nav {
    padding: 12px 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.sidebar-nav .nav-section {
    padding: 12px 20px 6px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text3);
}

.sidebar a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: var(--text2);
    font-size: 14px;
    font-weight: 500;
    transition: all .15s;
    margin: 1px 8px;
    border-radius: var(--radius-sm);
    text-decoration: none;
}

.sidebar a:hover {
    color: var(--primary);
    background: var(--primary-50);
}

.sidebar a.active {
    color: var(--primary);
    background: var(--primary-light);
    font-weight: 600;
}

.sidebar a .nav-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    opacity: .7;
}

.sidebar a.active .nav-icon { opacity: 1; }
.sidebar a:hover .nav-icon { opacity: 1; }

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.sidebar-footer a {
    color: var(--text3);
    font-size: 13px;
    margin: 0;
    padding: 8px 12px;
}

.sidebar-footer a:hover { color: var(--danger); background: var(--danger-light); }

/* ========== Content ========== */
.content {
    margin-left: var(--sidebar-w);
    padding: 32px 40px;
    flex: 1;
    min-height: 100vh;
    max-width: 1280px;
    overflow-x: hidden;
    min-width: 0;
}

.content h1 {
    font-size: 26px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 24px;
    letter-spacing: -0.3px;
}

.content h2 {
    font-size: 17px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 16px;
    letter-spacing: -0.2px;
}

.content h3 {
    font-size: 13px;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 600;
    margin-bottom: 12px;
}

/* ========== Alerts ========== */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert::before {
    font-size: 16px;
    flex-shrink: 0;
}

.alert-success {
    background: var(--success-light);
    color: #065F46;
    border: 1px solid #A7F3D0;
}
.alert-success::before { content: '\2713'; }

.alert-error {
    background: var(--danger-light);
    color: #991B1B;
    border: 1px solid #FECACA;
}
.alert-error::before { content: '\2717'; }

.alert-warning {
    background: var(--warning-light);
    color: #92400E;
    border: 1px solid #FDE68A;
}
.alert-warning::before { content: '\26A0'; }

/* ========== Cards ========== */
.card {
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow .2s;
    overflow: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.card:hover { box-shadow: var(--shadow); }

.cards-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 20px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    transition: all .2s;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--primary);
    border-radius: var(--radius) var(--radius) 0 0;
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.stat-card .value {
    font-size: 30px;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.5px;
    line-height: 1.2;
}

.stat-card .label {
    font-size: 11px;
    color: var(--text2);
    margin-top: 6px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 600;
}

/* ========== Tables ========== */
table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

th, td {
    padding: 12px 14px;
    text-align: left;
    font-size: 13px;
}

th {
    color: var(--text2);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.6px;
    border-bottom: 2px solid var(--border);
    background: var(--input-bg);
    white-space: nowrap;
}

th:first-child { border-radius: var(--radius-xs) 0 0 0; }
th:last-child { border-radius: 0 var(--radius-xs) 0 0; }

td { border-bottom: 1px solid var(--border); }

tr:last-child td { border-bottom: none; }

tr:hover td { background: var(--primary-50); }

/* ========== Forms ========== */
.form-group {
    margin-bottom: 18px;
    min-width: 0;
}

.form-group label {
    display: block;
    font-size: 12px;
    color: var(--text2);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

input, select, textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--input-bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    transition: all .15s;
}

input[type="checkbox"] {
    width: auto;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--white);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

input::placeholder { color: var(--text3); }
textarea { resize: vertical; min-height: 70px; }
select { cursor: pointer; appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748B' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}
select option { background: var(--white); color: var(--text); }

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.form-row-3 { grid-template-columns: repeat(3, 1fr); }
.form-row-4 { grid-template-columns: repeat(4, 1fr); }

/* ========== Buttons ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all .15s;
    text-align: center;
    font-family: inherit;
    letter-spacing: -0.1px;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 1px 2px rgba(37,99,235,0.3);
}
.btn-primary:hover {
    background: var(--primary-hover);
    color: white;
    box-shadow: 0 2px 8px rgba(37,99,235,0.35);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--white);
    color: var(--text);
    border: 1.5px solid var(--border);
}
.btn-secondary:hover {
    background: var(--primary-50);
    border-color: var(--primary);
    color: var(--primary);
}

.btn-danger {
    background: var(--white);
    color: var(--danger);
    border: 1.5px solid var(--danger);
}
.btn-danger:hover {
    background: var(--danger);
    color: white;
}

.btn-success {
    background: var(--success);
    color: white;
}
.btn-success:hover { background: #059669; color: white; }

.btn-sm {
    padding: 7px 14px;
    font-size: 12px;
    font-weight: 600;
}

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ========== Badges ========== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-draft { background: #F1F5F9; color: var(--text2); }
.badge-pending { background: var(--warning-light); color: #92400E; }
.badge-sent { background: var(--primary-light); color: #1E40AF; }
.badge-accepted { background: var(--success-light); color: #065F46; }
.badge-error { background: var(--danger-light); color: #991B1B; }
.badge-downloaded { background: #EDE9FE; color: #5B21B6; }
.badge-sprzedaz { background: var(--primary-light); color: #1E40AF; }
.badge-zakup { background: #FEF3C7; color: #92400E; }

/* ========== Filters ========== */
.filters {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    margin-bottom: 24px;
    flex-wrap: wrap;
    background: var(--white);
    padding: 20px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.filters .form-group { margin-bottom: 0; }
.filters input, .filters select { width: auto; min-width: 150px; }

/* ========== Login ========== */
.login-wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    width: 100%;
    background: linear-gradient(135deg, #EFF6FF 0%, #DBEAFE 30%, #E0F2FE 60%, #F0F4F8 100%);
    position: relative;
}

.login-wrap::before {
    content: '';
    position: absolute;
    top: -40%;
    right: -20%;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(37,99,235,0.08) 0%, transparent 70%);
}

.login-wrap::after {
    content: '';
    position: absolute;
    bottom: -30%;
    left: -15%;
    width: 500px;
    height: 500px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(37,99,235,0.05) 0%, transparent 70%);
}

.login-box {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 48px 40px;
    width: 420px;
    box-shadow: var(--shadow-lg);
    position: relative;
    z-index: 1;
}

.login-box .login-logo {
    width: 56px;
    height: 56px;
    background: var(--primary);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 22px;
    font-weight: 800;
    margin: 0 auto 20px;
    box-shadow: 0 4px 12px rgba(37,99,235,0.3);
}

.login-box h1 {
    text-align: center;
    color: var(--text);
    margin-bottom: 8px;
    font-size: 24px;
    font-weight: 700;
}

.login-box .login-subtitle {
    text-align: center;
    color: var(--text2);
    font-size: 14px;
    margin-bottom: 32px;
}

.login-box .btn-primary {
    width: 100%;
    padding: 12px;
    font-size: 15px;
    margin-top: 8px;
}

/* ========== Invoice form items ========== */
.items-table {
    width: 100%;
    margin: 16px 0;
}

.items-table th {
    padding: 10px 6px;
    font-size: 10px;
    background: var(--primary-50);
}

.items-table td {
    padding: 4px;
    border: none;
}

.items-table input, .items-table select {
    padding: 8px 10px;
    font-size: 13px;
    border-radius: var(--radius-xs);
}

.items-table .col-nr { width: 40px; }
.items-table .col-opis { width: 30%; }
.items-table .col-jedn { width: 60px; }
.items-table .col-ilosc { width: 80px; }
.items-table .col-cena { width: 100px; }
.items-table .col-vat { width: 70px; }
.items-table .col-netto { width: 100px; }
.items-table .col-brutto { width: 100px; }
.items-table .col-del { width: 40px; }

.items-table .remove-row {
    background: none;
    border: 1px solid var(--border);
    color: var(--text3);
    cursor: pointer;
    font-size: 16px;
    padding: 4px 10px;
    border-radius: var(--radius-xs);
    transition: all .15s;
    line-height: 1;
}

.items-table .remove-row:hover {
    color: var(--danger);
    border-color: var(--danger);
    background: var(--danger-light);
}

.totals-row td {
    font-weight: 700;
    font-size: 14px;
    padding-top: 14px;
    border-top: 2px solid var(--primary);
    color: var(--primary);
}

/* ========== Invoice detail ========== */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.detail-section h3 {
    font-size: 12px;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 14px;
    font-weight: 700;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--primary-light);
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 14px;
    border-bottom: 1px solid #F1F5F9;
}

.detail-row:last-child { border-bottom: none; }
.detail-row .label { color: var(--text2); font-weight: 500; }

/* ========== Modal ========== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15,23,42,0.4);
    backdrop-filter: blur(4px);
    z-index: 200;
    justify-content: center;
    align-items: center;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 32px;
    width: 540px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalIn .2s ease-out;
}

@keyframes modalIn {
    from { transform: translateY(20px) scale(0.98); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal h2 {
    margin-bottom: 24px;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

/* ========== KSeF log ========== */
.log-entry {
    font-size: 12px;
    padding: 10px 14px;
    background: var(--input-bg);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    font-family: 'JetBrains Mono', 'Consolas', monospace;
    border-left: 3px solid var(--primary);
    display: flex;
    gap: 12px;
    align-items: center;
}

.log-entry .time { color: var(--text3); font-size: 11px; }
.log-entry .action { color: var(--primary); font-weight: 700; }

/* ========== Page header ========== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.page-header h1 { margin-bottom: 0; }

/* ========== Empty state ========== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text3);
}

.empty-state .empty-icon {
    font-size: 40px;
    margin-bottom: 12px;
    opacity: 0.5;
}

/* ========== Utility ========== */
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text2); }
.text-accent { color: var(--primary); }
.text-danger { color: var(--danger); }
.flex-between { display: flex; justify-content: space-between; align-items: center; }

.divider {
    height: 1px;
    background: var(--border);
    margin: 20px 0;
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ========== Responsive ========== */
@media (max-width: 768px) {
    .sidebar { width: 64px; overflow: hidden; }
    .sidebar .logo span { display: none; }
    .sidebar a span { display: none; }
    .sidebar a { justify-content: center; padding: 12px; margin: 1px 4px; }
    .sidebar-nav .nav-section { display: none; }
    .sidebar-footer a span { display: none; }
    .sidebar-footer a { justify-content: center; }
    .content { margin-left: 64px; padding: 20px 16px; }
    .form-row, .form-row-3, .form-row-4 { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .cards-row { grid-template-columns: 1fr 1fr; }
    .page-header { flex-direction: column; gap: 12px; align-items: flex-start; }
    .filters { flex-direction: column; }
    .filters input, .filters select { width: 100%; }
}

@media (max-width: 480px) {
    .cards-row { grid-template-columns: 1fr; }
    .login-box { width: 100%; margin: 16px; padding: 32px 24px; }
}
