/* ====================================================================
   Panel Działkowca – rodOS – Style CSS
   Glassmorphism Design System
   ==================================================================== */

/* ---- Zmienne ---- */
:root {
    --primary:        #059669;
    --primary-light:  #10b981;
    --primary-subtle: rgba(16, 185, 129, 0.12);
    --primary-glow:   rgba(5, 150, 105, 0.25);

    --bg-from:  #e0f2fe;
    --bg-to:    #dcfce7;

    --glass-bg:     rgba(255, 255, 255, 0.80);
    --glass-border: rgba(255, 255, 255, 0.50);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
    --glass-blur:   blur(16px);

    --text-main:  #0f172a;
    --text-sub:   #374151;
    --text-muted: #6b7280;

    --danger:     #ef4444;
    --danger-bg:  #fef2f2;
    --warning:    #f59e0b;
    --warning-bg: #fffbeb;
    --success:    #10b981;
    --success-bg: #f0fdf4;
    --info:       #3b82f6;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;

    --transition: 0.2s ease;
}

/* ---- Reset / Base ---- */
*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', system-ui, sans-serif;
    background: linear-gradient(135deg, var(--bg-from) 0%, var(--bg-to) 100%);
    background-size: cover;
    background-repeat: no-repeat;
    background-attachment: fixed;
    /* Poprawka uciętego tła na mobilkach: */
    min-height: -webkit-fill-available;
    color: var(--text-main);
    min-height: 100vh;
    font-size: 15px;
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

h1,h2,h3,h4 { margin: 0; font-weight: 700; line-height: 1.3; }
p { margin: 0; }
ul { list-style: none; padding: 0; margin: 0; }

/* ---- Utility ---- */
.hidden   { display: none !important; }
.text-muted { color: var(--text-muted); font-size: 0.875rem; }
.status-green { color: var(--success); }
.status-red   { color: var(--danger); }
.status-warn  { color: var(--warning); }

/* ---- Glass Card ---- */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--glass-shadow);
    padding: 1.75rem;
}

/* ====================================================================
   LOGIN SCREEN
   ==================================================================== */
#login-view.active {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-height: 100vh;
    position: relative;
    overflow: hidden;
}

.login-bg {
    position: absolute; inset: 0; z-index: 0;
    background: radial-gradient(ellipse at 20% 80%, rgba(16,185,129,0.18) 0%, transparent 60%),
                radial-gradient(ellipse at 80% 20%, rgba(59,130,246,0.12) 0%, transparent 60%);
}

.login-card {
    position: relative; z-index: 1;
    width: 100%; max-width: 420px;
    padding: 2.5rem;
}

.login-logo {
    display: flex; align-items: center; justify-content: center;
    gap: 0.625rem; margin-bottom: 1.5rem;
    font-size: 1.5rem; font-weight: 800; letter-spacing: -0.5px;
    color: var(--primary);
}
.brand-logo-img {
    height: 40px;
    max-width: 190px;
    width: auto;
    object-fit: contain;
}
.brand-logo-img-sidebar {
    height: 30px;
    max-width: 160px;
    width: auto;
    object-fit: contain;
}

.login-title {
    font-size: 1.75rem; text-align: center;
    margin-bottom: 0.375rem; letter-spacing: -0.5px;
}
.login-subtitle {
    text-align: center; color: var(--text-muted);
    font-size: 0.9rem; margin-bottom: 2rem;
}

/* ---- Form ---- */
.form-group { margin-bottom: 1.25rem; }
.form-group label {
    display: block; margin-bottom: 0.5rem;
    font-weight: 600; font-size: 0.85rem;
    color: var(--text-sub); letter-spacing: 0.02em;
    text-transform: uppercase;
}

.input-wrapper { position: relative; }
.input-icon {
    position: absolute; left: 0.875rem; top: 50%;
    transform: translateY(-50%); font-size: 1rem;
    pointer-events: none; user-select: none;
}
.input-wrapper input {
    width: 100%; padding: 0.75rem 1rem 0.75rem 2.75rem;
    border: 1.5px solid rgba(0,0,0,0.12);
    border-radius: var(--radius-md);
    font-size: 1rem; font-family: inherit; color: var(--text-main);
    background: rgba(255,255,255,0.7);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}
.input-wrapper input::placeholder { color: var(--text-muted); }
.input-wrapper input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
    background: rgba(255,255,255,0.95);
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 0.5rem; padding: 0.75rem 1.5rem;
    font-family: inherit; font-weight: 600; font-size: 0.95rem;
    border-radius: var(--radius-md); cursor: pointer;
    transition: all var(--transition); border: none;
    white-space: nowrap; text-decoration: none;
}
.btn-block { width: 100%; }

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white; box-shadow: 0 4px 12px var(--primary-glow);
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px var(--primary-glow);
}
.btn-primary:active { transform: translateY(0); }

.btn-outline {
    background: transparent; border: 1.5px solid var(--primary);
    color: var(--primary);
}
.btn-outline:hover { background: var(--primary-subtle); }

.btn-small { padding: 0.35rem 0.75rem; font-size: 0.8rem; border-radius: 6px; }
.btn-ghost {
    background: rgba(0,0,0,0.04); border: none; color: var(--text-muted);
    padding: 0.35rem 0.75rem; font-size: 0.8rem;
}
.btn-ghost:hover { background: rgba(0,0,0,0.08); color: var(--text-sub); }

/* ---- Alerts ---- */
.alert {
    display: flex; align-items: center; gap: 0.625rem;
    padding: 0.875rem 1rem; border-radius: var(--radius-sm);
    font-weight: 500; font-size: 0.9rem; margin-bottom: 1rem;
}
.alert-error { background: var(--danger-bg); color: #991b1b; border: 1px solid #fecaca; }

/* ---- Loader ---- */
.loader {
    width: 16px; height: 16px;
    border: 2px solid rgba(255,255,255,0.4);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ====================================================================
   DASHBOARD LAYOUT
   ==================================================================== */
#dashboard-view.active {
    display: flex; width: 100%;
    max-width: 1440px; margin: 0 auto;
    padding: 1.5rem; gap: 1.5rem;
    min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
    width: 260px; flex-shrink: 0;
    display: flex; flex-direction: column;
    padding: 1.5rem;
    height: calc(100vh - 3rem);
    position: sticky; top: 1.5rem;
}

.sidebar-header {
    padding-bottom: 1.25rem;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    margin-bottom: 1.25rem;
}
.sidebar-logo {
    font-size: 1.25rem; font-weight: 800;
    color: var(--primary); margin-bottom: 0.5rem;
    letter-spacing: -0.3px;
}
.sidebar-plot-info {
    font-size: 0.875rem; color: var(--text-muted);
    font-weight: 400;
}
.sidebar-plot-info strong { color: var(--text-sub); font-weight: 700; }

.nav-menu { flex-grow: 1; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
    display: flex; align-items: center; gap: 0.625rem;
    padding: 0.7rem 0.875rem; border-radius: var(--radius-md);
    cursor: pointer; font-weight: 500; font-size: 0.9rem;
    color: var(--text-muted); transition: all var(--transition);
    user-select: none;
}
.nav-icon { font-size: 1rem; flex-shrink: 0; }

.nav-item:hover {
    background: var(--primary-subtle);
    color: var(--primary);
}
.nav-item.active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    box-shadow: 0 4px 10px var(--primary-glow);
}

.sidebar-footer {
    padding-top: 1.25rem;
    border-top: 1px solid rgba(0,0,0,0.06);
    margin-top: auto;
}

/* ---- Main Content ---- */
.main-content {
    flex-grow: 1;
    min-width: 0;
    overflow-y: auto;
}

.section-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    margin-bottom: 1.75rem;
}
.section-header h2 { font-size: 1.75rem; letter-spacing: -0.5px; }

/* ---- Tabs ---- */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ====================================================================
   CONTENT SECTIONS (inside tabs)
   ==================================================================== */
.content-section { margin-bottom: 2rem; }

.section-title {
    display: flex; align-items: center; gap: 0.5rem;
    font-size: 1rem; font-weight: 700; color: var(--text-sub);
    margin-bottom: 1rem; letter-spacing: -0.2px;
}
.section-title-icon { font-size: 1.1rem; }

/* ====================================================================
   INFORMACJE O DZIAŁCE - GRID
   ==================================================================== */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0;
}

.info-item {
    display: flex; flex-direction: column; gap: 0.25rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    border-right: 1px solid rgba(0,0,0,0.05);
}
.info-item:nth-child(3n) { border-right: none; }

.info-label {
    font-size: 0.75rem; font-weight: 600; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.05em;
}
.info-value {
    font-size: 0.95rem; font-weight: 600; color: var(--text-main);
}

/* ====================================================================
   FINANSE - 4 KARTY
   ==================================================================== */
.finance-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

.finance-card {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--glass-shadow);
    padding: 1.5rem;
    display: flex; flex-direction: column; gap: 0.375rem;
    transition: transform var(--transition), box-shadow var(--transition);
}
.finance-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(0,0,0,0.12);
}

.finance-card-icon { font-size: 1.5rem; margin-bottom: 0.25rem; }
.finance-card-label {
    font-size: 0.78rem; font-weight: 700; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.05em;
}
.finance-card-value {
    font-size: 1.5rem; font-weight: 800; letter-spacing: -0.5px;
    color: var(--text-main);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.finance-card-status { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }

/* Kolory kart */
.finance-card-saldo       { border-left: 4px solid var(--primary); }
.finance-card-w-terminie  { border-left: 4px solid var(--info); }
.finance-card-po-terminie { border-left: 4px solid var(--warning); }
.finance-card-odsetki     { border-left: 4px solid var(--danger); }

.finance-card-saldo .finance-card-value.saldo-czerwony      { color: var(--danger); }
.finance-card-saldo .finance-card-value.saldo-zielony       { color: var(--success); }
.finance-card-po-terminie .finance-card-value.has-debt      { color: var(--danger); }
.finance-card-odsetki .finance-card-value.has-interest      { color: var(--danger); }

/* ====================================================================
   DETAIL / DEBT LIST
   ==================================================================== */
.detail-list li {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    font-size: 0.9rem;
}
.detail-list li:last-child { border-bottom: none; }
.detail-list-empty {
    color: var(--text-muted); font-style: italic;
    justify-content: center; padding: 2rem 1.25rem;
}

/* ====================================================================
   PAYMENTS LIST
   ==================================================================== */
.payments-list li {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    font-size: 0.9rem;
}
.payments-list li:last-child { border-bottom: none; }
.payments-list .pay-meta { color: var(--text-muted); font-size: 0.8rem; margin-top: 2px; }
.payments-list .pay-amount { font-weight: 700; font-size: 1rem; color: var(--success); }

/* ====================================================================
   TABLES
   ==================================================================== */
.table-container { overflow-x: auto; border-radius: var(--radius-lg) !important; }

.data-table {
    width: 100%; border-collapse: collapse; font-size: 0.875rem;
}
.data-table th {
    padding: 0.875rem 1.25rem; text-align: left;
    background: rgba(0,0,0,0.02); color: var(--text-muted);
    font-weight: 700; font-size: 0.72rem;
    text-transform: uppercase; letter-spacing: 0.07em;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    white-space: nowrap;
}
.data-table td {
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid rgba(0,0,0,0.04);
    color: var(--text-sub);
    vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: rgba(0,0,0,0.015); }
.data-table .nota-num { font-weight: 700; color: var(--text-main); font-size: 0.85rem; }
.data-table .nota-type { font-size: 0.75rem; color: var(--text-muted); display: block; margin-top: 2px; }

/* ---- Badges ---- */
.badge {
    display: inline-flex; align-items: center;
    padding: 0.2rem 0.6rem; border-radius: 9999px;
    font-size: 0.72rem; font-weight: 700; white-space: nowrap;
}
.badge-paid     { background: #d1fae5; color: #065f46; }
.badge-unpaid   { background: #fee2e2; color: #991b1b; }
.badge-partial  { background: #fef3c7; color: #92400e; }
.badge-overdue  { background: #fef2f2; color: #ef4444; border: 1px solid #fecaca; }
.badge-media    { background: var(--primary-subtle); color: var(--primary); }

/* ====================================================================
   LICZNIKI GRID
   ==================================================================== */
.liczniki-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 1.5rem;
}

.licznik-card {
    padding: 0; overflow: hidden;
}
.licznik-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1.25rem 1.5rem;
    background: rgba(0,0,0,0.025);
    border-bottom: 1px solid rgba(0,0,0,0.06);
}
.licznik-header-left h3 { font-size: 1rem; margin-bottom: 2px; }
.licznik-header-left p  { font-size: 0.8rem; color: var(--text-muted); }
.licznik-media-badge {
    display: flex; align-items: center; gap: 0.375rem;
    padding: 0.3rem 0.75rem; border-radius: 9999px;
    font-size: 0.78rem; font-weight: 700;
    background: var(--primary-subtle); color: var(--primary);
}
.licznik-media-badge.energia { background: #fef3c7; color: #92400e; }
.licznik-body { padding: 1.25rem 1.5rem; }

.chart-wrapper {
    height: 180px; margin-bottom: 1.5rem; position: relative;
}

/* ====================================================================
   PARKING GRID
   ==================================================================== */
.parking-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.25rem;
}

.parking-card {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--glass-shadow);
    overflow: hidden;
}

.parking-card-header {
    display: flex; align-items: center; gap: 1rem;
    padding: 1.25rem 1.5rem;
    background: linear-gradient(135deg, rgba(5,150,105,0.07) 0%, rgba(16,185,129,0.03) 100%);
    border-bottom: 1px solid rgba(0,0,0,0.06);
}
.parking-spot-number {
    display: flex; align-items: center; justify-content: center;
    width: 56px; height: 56px; border-radius: var(--radius-md);
    background: var(--primary); color: white;
    font-size: 1.1rem; font-weight: 800;
    flex-shrink: 0; box-shadow: 0 4px 12px var(--primary-glow);
}
.parking-card-title { font-size: 1.05rem; font-weight: 700; margin-bottom: 3px; }
.parking-card-subtitle { font-size: 0.8rem; color: var(--text-muted); }

.parking-card-body { padding: 1.25rem 1.5rem; }
.parking-detail-row {
    display: flex; align-items: center; gap: 0.625rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(0,0,0,0.04);
    font-size: 0.875rem;
}
.parking-detail-row:last-child { border-bottom: none; }
.parking-detail-icon { font-size: 1rem; flex-shrink: 0; width: 22px; text-align: center; }
.parking-detail-label { color: var(--text-muted); min-width: 110px; font-size: 0.8rem; }
.parking-detail-value { font-weight: 600; color: var(--text-sub); }

/* ====================================================================
   EMPTY STATES
   ==================================================================== */
.empty-state-box {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 0.75rem;
    padding: 3rem 2rem; text-align: center;
    color: var(--text-muted);
}
.empty-state-icon { font-size: 2.5rem; }
.empty-state-text { font-size: 0.9rem; }

/* ====================================================================
   RESPONSIVE
   ==================================================================== */
@media (max-width: 1100px) {
    .finance-cards { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
    #dashboard-view.active {
        flex-direction: column;
        padding: 0.75rem;
    }
    .sidebar {
        width: 100%; height: auto; position: relative; top: 0;
        flex-direction: column; align-items: stretch;
        padding: 1rem; gap: 0.75rem;
    }
    .sidebar-header { 
        margin-bottom: 0; padding-bottom: 0; border-bottom: none; 
        display: flex; justify-content: space-between; align-items: center;
    }
    .nav-menu { 
        flex-direction: column; flex-wrap: nowrap; gap: 0.5rem; 
        width: 100%; overflow: visible; 
    }
    .nav-item { 
        padding: 0.75rem 1rem; font-size: 0.95rem; 
        white-space: normal; flex-shrink: 0; 
        border: 1px solid rgba(0,0,0,0.05); 
        width: 100%;
    }
    .sidebar-footer { padding-top: 0; border-top: none; margin-top: 0; }
    .main-content { max-width: 100%; width: 100%; overflow: hidden; }
}

@media (max-width: 600px) {
    .finance-cards { grid-template-columns: 1fr; }
    .info-grid { grid-template-columns: 1fr; }
    .info-item { border-right: none !important; border-bottom: 1px solid rgba(0,0,0,0.05); }
    .info-item:last-child { border-bottom: none; }
    .liczniki-grid { grid-template-columns: 1fr; }
    .parking-grid  { grid-template-columns: 1fr; }
    
    .table-container { 
        width: 100%; 
        overflow-x: auto; 
        -webkit-overflow-scrolling: touch; 
    }
    .data-table th, .data-table td { padding: 0.75rem 0.5rem; font-size: 0.85rem; white-space: nowrap; }
    
    /* Zapobieganie łamaniu się kwot PLN i dat w tabelach na małych ekranach */
    .data-table th:nth-child(4), .data-table td:nth-child(4), /* Kwota */
    .data-table th:nth-child(5), .data-table td:nth-child(5) /* Pozostało */
    { min-width: 90px; text-align: right; }
    
    /* Listy na pulpicie - daty i kwoty bez zawijania */
    .detail-list li, .payments-list li { white-space: nowrap; }
    .payments-list li span:first-child { white-space: nowrap; }
    
    .btn { padding: 0.6rem 1rem; width: 100%; justify-content: center; margin-bottom: 0.25rem; }
    .btn-small, .btn-ghost { padding: 0.4rem 0.75rem; width: auto; display: inline-flex; }
    td > button, td > .btn { margin-bottom: 0.25rem; }
}
