:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --text: #1a1f2e;
    --muted: #5c667a;
    --border: #d8dee8;
    --primary: #1f6feb;
    --primary-hover: #1758c2;
    --secondary: #eef2f7;
    --danger: #c0392b;
    --success-bg: #e8f5e9;
    --success-text: #1b5e20;
    --error-bg: #fdecea;
    --error-text: #b71c1c;
    --radius: 10px;
    --shadow: 0 2px 8px rgba(26, 31, 46, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.container {
    width: min(1100px, 92vw);
    margin: 0 auto;
    padding: 1.5rem 0 3rem;
}

.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 0;
}

.brand {
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
}

.main-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem 1rem;
}

.main-nav a {
    color: var(--muted);
    text-decoration: none;
}

.main-nav a:hover {
    color: var(--primary);
}

.user-badge {
    font-size: 0.875rem;
    color: var(--muted);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.page-header h1 {
    margin: 0 0 0.25rem;
}

.back-link {
    display: inline-block;
    margin-bottom: 0.5rem;
    color: var(--muted);
    text-decoration: none;
}

.property-address {
    font-size: 1.1rem;
    color: var(--muted);
    margin: 0;
}

.muted {
    color: var(--muted);
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}

.card-muted {
    opacity: 0.85;
}

.card h2 {
    margin: 0 0 1rem;
    font-size: 1.1rem;
}

.card h3 {
    margin: 0;
    font-size: 1rem;
}

.login-card {
    max-width: 400px;
    margin: 4rem auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
}

.form label {
    display: block;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.form input[type="text"],
.form input[type="password"],
.form input[type="file"],
.form select,
.form textarea,
.money-input {
    width: 100%;
    margin-top: 0.35rem;
    padding: 0.55rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font: inherit;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.form-grid .full-width {
    grid-column: 1 / -1;
}

.btn {
    display: inline-block;
    padding: 0.55rem 1rem;
    border-radius: 6px;
    border: none;
    font: inherit;
    cursor: pointer;
    text-decoration: none;
    background: var(--secondary);
    color: var(--text);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary:hover {
    background: #dde4ee;
}

.btn-danger {
    background: #fdecea;
    color: var(--danger);
}

.btn-sm {
    padding: 0.35rem 0.65rem;
    font-size: 0.875rem;
}

.form-section-title {
    margin: 1.25rem 0 0.5rem;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.35rem;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.checkbox-row input[type="checkbox"] {
    width: auto;
}

.danger-zone {
    border-color: #f3c6c0;
}

.table-wrap {
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    background: #f8fafc;
    font-size: 0.875rem;
    color: var(--muted);
}

.actions {
    white-space: nowrap;
}

.alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
}

.alert-success {
    background: var(--success-bg);
    color: var(--success-text);
}

.alert-error {
    background: var(--error-bg);
    color: var(--error-text);
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px dashed var(--border);
}

.hint {
    font-size: 0.875rem;
    color: var(--muted);
    margin: 0.5rem 0 0;
}

.tenant-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.tenant-name {
    font-weight: 600;
    margin: 0.25rem 0;
}

.deposit-field {
    min-width: 180px;
}

.deductions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.deduction-row {
    display: grid;
    grid-template-columns: 140px 1fr 120px 40px;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    align-items: center;
}

@media (max-width: 700px) {
    .deduction-row {
        grid-template-columns: 1fr;
    }
}

.tenant-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.tenant-summary .label {
    color: var(--muted);
    font-size: 0.875rem;
}

.refund-line {
    font-size: 1.05rem;
}

.refund-value.negative {
    color: var(--danger);
}

.common-card h3 {
    margin: 0 0 0.75rem;
    font-size: 1rem;
}

.common-description-field {
    display: block;
    margin-bottom: 1rem;
}

.common-generated-summary {
    margin: 1rem 0 1.25rem;
    padding: 1rem;
    background: #f0f7ff;
    border: 1px solid #c5d9f5;
    border-radius: 8px;
}

.common-generated-summary h3 {
    margin: 0 0 0.35rem;
    font-size: 0.95rem;
}

.common-description-preview {
    margin-top: 0.5rem;
    padding: 0.75rem 0.85rem;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    white-space: pre-wrap;
    line-height: 1.5;
    font-size: 0.92rem;
}

.common-description-preview.is-empty {
    color: var(--muted);
    font-style: italic;
}

.common-description-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
}

.protocol-common-summary {
    margin-bottom: 1rem;
}

.protocol-common-text {
    margin: 0.35rem 0 0;
    white-space: pre-wrap;
}

.protocol-tenant-common-note {
    font-size: 0.9rem;
    line-height: 1.45;
    color: var(--muted);
    padding-top: 0 !important;
}

.common-items-block {
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.common-item-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: flex-start;
}

.common-item-row .common-kind-label {
    flex: 0 0 130px;
}

.common-item-row .common-item-description {
    flex: 1 1 140px;
    min-width: 120px;
}

.common-item-row .common-item-amount {
    flex: 0 0 100px;
}

.common-item-row .cost-scope.common-item-scope {
    flex: 1 1 100%;
}

.common-item-row .common-item-split {
    flex: 1 1 180px;
    min-width: 150px;
}

.deduction-row-extended {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: flex-start;
}

.deduction-row-extended .deduction-kind-select {
    flex: 0 0 140px;
}

.deduction-room-scope-wrap {
    flex: 1 1 100%;
}

.deduction-room-scope-wrap.is-hidden {
    display: none;
}

.deduction-row-extended .deduction-description {
    flex: 1 1 200px;
    min-width: 140px;
}

.deduction-row-extended .deduction-amount {
    flex: 0 0 120px;
}

.cost-scope {
    padding: 0.5rem 0.65rem;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.cost-scope-mode-label {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.75rem;
    margin-bottom: 0.35rem;
}

.cost-scope-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
}

.cost-scope-mode {
    min-width: 220px;
    font-size: 0.85rem;
}

.cost-scope-zones {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 1rem;
    margin-top: 0.35rem;
}

.cost-scope-zone-option {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    cursor: pointer;
}

.common-item-split {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.common-item-split-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
}

.common-item-split-rooms {
    min-height: 4.5rem;
    font-size: 0.85rem;
}

.common-items-split-hint {
    margin-top: 0.75rem;
}

.common-kind-label {
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.55rem 0;
}

.split-rooms-select {
    width: 100%;
    min-height: 8rem;
    padding: 0.35rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font: inherit;
    background: #fff;
}

.split-rooms-select option {
    padding: 0.35rem 0.5rem;
}

.split-rooms-select option:checked {
    background: #dbeafe linear-gradient(#dbeafe, #dbeafe);
    color: var(--text);
}

.field-hint {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
    margin-top: 0.35rem;
}

.ocr-tool {
    margin: 0.5rem 0 1rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #f8fafc;
}

.ocr-status {
    margin-top: 0.65rem;
    padding: 0.6rem 0.75rem;
    border-radius: 6px;
    background: #eef5ff;
    color: #1e3a5f;
    white-space: pre-wrap;
}

.ocr-details {
    margin-top: 0.75rem;
}

.ocr-text-preview {
    margin-top: 0.5rem;
    padding: 0.75rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    white-space: pre-wrap;
}

.contract-ocr-status {
    margin-top: 1rem;
}

.ocr-requeue-form {
    margin-top: 0.75rem;
}

.common-summary-grid {
    margin-top: 1rem;
}

.split-rooms-field {
    min-width: 220px;
}

#common_total[readonly] {
    background: #f8fafc;
    cursor: default;
}

.alert-info {
    background: #eef5ff;
    color: #1e3a5f;
    border: 1px solid #c5d9f5;
}

.status-badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}

.status-draft {
    background: #fef3c7;
    color: #92400e;
}

.status-final {
    background: #dcfce7;
    color: #166534;
}

.status-active {
    background: #dbeafe;
    color: #1e40af;
}

.status-planned {
    background: #f3f4f6;
    color: #4b5563;
}

.settlement-status-draft {
    color: #92400e;
}

.settlement-status-final {
    color: #166534;
}

.finalize-card {
    margin-top: 1rem;
    border: 2px solid #86efac;
    background: #f0fdf4;
}

.finalize-card h2 {
    margin: 0 0 0.5rem;
    font-size: 1rem;
}

.btn-success {
    background: #16a34a;
    color: #fff;
}

.btn-success:hover {
    background: #15803d;
}

.protocol-draft-notice {
    margin-bottom: 1rem;
}

.protocol-final-badge {
    display: inline-block;
    margin-bottom: 1rem;
    padding: 0.35rem 0.75rem;
    background: #dcfce7;
    color: #166534;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.9rem;
}

.finalize-form {
    margin-bottom: 2rem;
}

.card-info {
    background: #eef5ff;
    border-color: #c5d9f5;
}

.summary-card {
    position: sticky;
    bottom: 0;
    z-index: 30;
    margin: 0.75rem 0 0;
    padding: 0.55rem 1rem;
    background: linear-gradient(180deg, #1e3a5f 0%, #152a45 100%);
    border: 1px solid #0f2440;
    border-top: 3px solid #3b82f6;
    border-radius: 10px 10px 0 0;
    box-shadow: 0 -6px 24px rgba(15, 42, 74, 0.28);
}

.summary-card.summary-card {
    color: #f1f5f9;
}

.summary-bar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.summary-bar-total {
    display: flex;
    align-items: baseline;
    gap: 0.65rem;
    flex-wrap: wrap;
    min-width: 0;
}

.summary-bar-label {
    font-size: 0.85rem;
    color: #cbd5e1;
    white-space: nowrap;
}

.summary-bar-amount {
    font-size: 1.15rem;
    color: #fff;
    letter-spacing: 0.01em;
}

.summary-bar-actions {
    margin: 0;
    flex-shrink: 0;
}

.summary-bar-actions .btn-primary {
    padding: 0.45rem 0.9rem;
    font-size: 0.9rem;
}

.summary-bar-link {
    background: rgba(255, 255, 255, 0.12);
    color: #e2e8f0;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.45rem 0.75rem;
    font-size: 0.9rem;
}

.summary-bar-link:hover {
    background: rgba(255, 255, 255, 0.2);
}

.settlement-form {
    padding-bottom: 0.5rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.code-block {
    background: #1a1f2e;
    color: #e6edf3;
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
}

.protocol-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.protocol-pdf-body {
    background: #fff;
    max-width: 100%;
}

.protocol-header {
    margin-bottom: 2rem;
}

.protocol-item {
    break-inside: avoid;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.protocol-table {
    width: 100%;
    margin: 1rem 0;
    table-layout: fixed;
    border-collapse: collapse;
}

.protocol-table td:first-child {
    width: 68%;
    padding-right: 0.75rem;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.protocol-table td {
    padding: 0.4rem 0;
    border: none;
    vertical-align: top;
}

.protocol-table .amount {
    width: 32%;
    text-align: right;
    white-space: nowrap;
}

.protocol-table .total-row td {
    padding-top: 0.75rem;
    border-top: 2px solid var(--text);
}

/* Lista nieruchomości – wyszukiwarka + akordeon */
.property-search-card {
    padding: 1.25rem;
}

.property-search-label {
    display: block;
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.property-search-input {
    width: 100%;
    margin-top: 0.4rem;
    padding: 0.75rem 1rem;
    font-size: 1.05rem;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.property-search-input:focus {
    outline: 2px solid rgba(31, 111, 235, 0.35);
    border-color: var(--primary);
}

.property-search-hint,
.property-search-empty {
    margin: 0.75rem 0 0;
    font-size: 0.875rem;
    color: var(--muted);
}

.property-search-empty {
    color: var(--danger);
}

.property-accordion {
    margin-top: 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.property-accordion-item {
    border-bottom: 1px solid var(--border);
}

.property-accordion-item:last-child {
    border-bottom: none;
}

.property-accordion-trigger {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 0.75rem 1rem;
    align-items: center;
    padding: 0.9rem 1rem;
    border: none;
    background: var(--surface);
    text-align: left;
    font: inherit;
    cursor: pointer;
}

.property-accordion-trigger:hover,
.property-accordion-item.is-open .property-accordion-trigger {
    background: #f8fafc;
}

.property-accordion-title {
    font-weight: 600;
    line-height: 1.35;
}

.property-accordion-meta {
    font-size: 0.85rem;
    color: var(--muted);
    white-space: nowrap;
}

.property-accordion-chevron {
    width: 0.55rem;
    height: 0.55rem;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(45deg);
    transition: transform 0.15s ease;
}

.property-accordion-item.is-open .property-accordion-chevron {
    transform: rotate(-135deg);
    margin-top: 0.25rem;
}

.property-accordion-panel {
    padding: 0 1rem 1rem;
    background: #fafbfc;
    border-top: 1px solid var(--border);
}

.property-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem 1.25rem;
    margin: 0.75rem 0 1rem;
}

.property-details dt {
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 0.15rem;
}

.property-details dd {
    margin: 0;
    font-weight: 600;
}

.property-accordion-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.son-sync-steps {
    margin: 0 0 1rem;
    padding-left: 1.25rem;
    line-height: 1.6;
}

.son-sync-status-card h2 {
    margin-top: 0;
}

.son-sync-stats {
    margin: 0.5rem 0 0;
}

.son-sync-run-form {
    margin-top: 0.75rem;
}

@media (max-width: 640px) {
    .property-accordion-trigger {
        grid-template-columns: 1fr auto;
    }

    .property-accordion-meta {
        grid-column: 1 / -1;
    }

    .property-accordion-chevron {
        justify-self: end;
        grid-row: 1;
        grid-column: 2;
    }
}

.page-header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.dashboard-hero {
    align-items: flex-end;
}

.dashboard-hero h1 {
    margin-bottom: 0.35rem;
}

.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.module-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 100%;
}

.module-card-top h2 {
    margin: 0.75rem 0 0.5rem;
}

.module-card-top p {
    margin: 0;
}

.module-card-active {
    border-color: #b7d3ff;
    box-shadow: 0 2px 10px rgba(31, 111, 235, 0.08);
}

.module-card-planned {
    background: #fbfcfe;
}

.module-card-actions {
    margin-top: 1rem;
}

.tenant-management-intro {
    margin-bottom: 1rem;
}

.tenant-room-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.tenant-room-card-highlight {
    box-shadow: 0 0 0 2px var(--primary);
}

.tenant-room-header {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.tenant-room-header h2 {
    margin: 0 0 0.25rem;
    font-size: 1.1rem;
}

.tenant-current-name {
    margin: 0;
    font-weight: 600;
}

.tenant-current-meta {
    margin: 0.25rem 0 0;
    font-size: 0.875rem;
}

.tenant-settlement-badge {
    display: inline-block;
    margin: 0.5rem 0 0;
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: #1e40af;
    background: #eff6ff;
    border-radius: 4px;
}

.tenant-form-grid {
    margin-bottom: 0.75rem;
}

.tenant-form-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.tenant-clear-form {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px dashed var(--border);
}

.tenant-clear-hint {
    margin: 0.75rem 0 0;
}
