/* FOUNDATION */

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    overflow-x: hidden;
}

img,
svg {
    max-width: 100%;
}

/* TABLET */

@media (max-width: 900px) {
    .container {
        width: 100%;
        max-width: 100%;
        padding-right: 18px;
        padding-left: 18px;
    }

    .nav-inner {
        display: grid;
        grid-template-columns: 1fr auto auto;
        grid-template-areas:
            "brand toggle actions"
            "menu menu menu";
        align-items: center;
        padding: 10px 14px;
        gap: 8px 10px;
    }

    .nav-brand {
        grid-area: brand;
        min-width: 0;
        font-size: 16px;
    }

    .nav-logo {
        width: 88px;
        max-height: 36px;
    }

    .nav-toggle {
        display: inline-flex;
        grid-area: toggle;
    }

    .nav-actions {
        grid-area: actions;
        gap: 8px;
        margin-left: 0;
    }

    .nav-user {
        max-width: 7rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 13px;
    }

    .nav-logout-form button.nav-logout {
        padding: 8px 12px;
        font-size: 13px;
    }

    .nav-menu {
        display: none;
        grid-area: menu;
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
        width: 100%;
        padding-top: 4px;
    }

    .nav-open .nav-menu {
        display: flex;
    }

    .nav-link {
        display: block;
        padding: 12px 14px;
        border-radius: 10px;
        font-size: 15px;
        text-align: left;
        line-height: 1.2;
    }

    .hero {
        padding: 36px 16px;
    }

    .hero h1 {
        font-size: 26px;
        line-height: 1.15;
    }

    .hero p {
        font-size: 15px;
        line-height: 1.5;
    }

    .grid,
    .dashboard-stats,
    .analytics-info-grid,
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .stat-value {
        font-size: 2rem;
    }

    .analytics-charts-row {
        grid-template-columns: 1fr;
    }

    .chart-wrapper {
        height: 240px;
    }

    .toolbar {
        align-items: flex-start;
        gap: 14px;
    }

    .toolbar-right {
        flex-wrap: wrap;
        justify-content: flex-start;
        width: 100%;
    }

    .toolbar-right > div {
        flex: 1 1 260px;
    }

    .toolbar-right input,
    .toolbar-right select {
        width: 100%;
    }
}

/* MOBILE */

@media (max-width: 760px) {
    body {
        font-size: 15px;
    }

    .container {
        padding-right: 12px;
        padding-left: 12px;
    }

    .hero {
        padding: 28px 14px;
        text-align: left;
    }

    .hero h1 {
        font-size: 28px;
        line-height: 1.15;
    }

    .hero p {
        font-size: 15px;
        line-height: 1.5;
    }

    .card,
    .category,
    .analytics-card,
    .analytics-chart-card {
        padding: 16px;
        border-radius: 16px;
    }

    .card h2 {
        font-size: 20px;
    }

    .card h3,
    .analytics-card h3,
    .analytics-chart-card h3 {
        font-size: 16px;
    }

    .hero {
        padding: 22px 14px;
    }

    .hero h1 {
        font-size: 22px;
    }

    /* GRIDS / FORMS */

    .grid,
    .dashboard-stats,
    .analytics-info-grid,
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .stat-value {
        font-size: 1.85rem;
    }

    .stat-card {
        padding: 1.1rem;
    }

    .category h3 {
        font-size: 24px;
    }

    form input,
    form select,
    form button,
    input,
    select,
    button {
        min-height: 44px;
        font-size: 15px;
    }

    form button,
    .card > button,
    .compact-btn {
        width: 100%;
    }

    .date-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .date-row input[type="date"] {
        width: 100%;
    }

    .date-help,
    .search-meta {
        font-size: 12px;
        line-height: 1.4;
    }

    /* TOOLBARS */

    .toolbar,
    .toolbar-right,
    .table-actions,
    .pagination,
    .qr-page-actions,
    .qr-logo-form {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar {
        gap: 12px;
    }

    .toolbar-right {
        display: flex;
        width: 100%;
        gap: 10px;
    }

    .toolbar-right > div {
        flex: none !important;
        width: 100%;
        min-width: 0 !important;
    }

    .toolbar-right input,
    .toolbar-right select {
        width: 100%;
        min-width: 0 !important;
    }

    .table-actions {
        gap: 10px;
    }

    .select-all-label {
        justify-content: flex-start;
        width: 100%;
    }

    .table-actions .compact-btn,
    .pagination button,
    .admin-export a,
    .admin-export button {
        width: 100%;
    }

    #selectedCount,
    #paginationInfo {
        text-align: center;
    }

    /* MOBILE TABLES AS CARDS */

    .table-scroll {
        overflow-x: visible;
    }

    .links-table {
        width: 100%;
        min-width: 0 !important;
        border-collapse: separate;
        border-spacing: 0 12px;
    }

    .links-table thead {
        display: none;
    }

    .links-table tbody,
    .links-table tr,
    .links-table td {
        display: block;
        width: 100%;
    }

    .links-table tr {
        padding: 14px;
        border: 1px solid var(--border-soft);
        border-radius: 16px;
        background: var(--card-bg);
        box-shadow: var(--shadow-soft);
    }

    .links-table tr[style*="display: none"] {
        display: none !important;
    }

    .links-table td {
        padding: 9px 0;
        border: none;
        font-size: 14px;
    }

    .links-table td::before {
        display: block;
        margin-bottom: 4px;
        color: #717d85;
        font-size: 11px;
        font-weight: 800;
        letter-spacing: 0.04em;
        text-transform: uppercase;
    }

    .links-table td:first-child {
        padding-bottom: 4px;
    }

    .links-table td:first-child::before {
        content: "Zaznacz";
    }

    .links-table .url-cell,
    .links-table .url-cell span {
        max-width: 100%;
    }

    .links-table .url-cell span {
        display: block;
        overflow: visible;
        text-overflow: unset;
        white-space: normal;
        word-break: break-word;
    }

    .links-table .expires-cell .status-badge {
        display: inline-flex;
    }

    .links-table .row-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .links-table .action-btn,
    .links-table .action-link {
        justify-content: center;
        width: 100%;
        min-height: 40px;
        font-size: 13px;
    }

    .links-table .action-btn span:first-child,
    .links-table .action-link span:first-child {
        display: inline;
    }

    .links-table #emptyRow {
        border-style: dashed;
        box-shadow: none;
        text-align: center;
    }

    .links-table #emptyRow td::before {
        display: none;
    }

    /* TABLE LABELS */

    .dashboard-table td:nth-child(2)::before {
        content: "Krótki link";
    }

    .dashboard-table td:nth-child(3)::before {
        content: "Adres docelowy";
    }

    .dashboard-table td:nth-child(4)::before {
        content: "Kliknięcia";
    }

    .dashboard-table td:nth-child(5)::before {
        content: "Wygasa";
    }

    .dashboard-table td:nth-child(6)::before {
        content: "Akcje";
    }

    .admin-table td:nth-child(2)::before {
        content: "Krótki link";
    }

    .admin-table td:nth-child(3)::before {
        content: "Adres docelowy";
    }

    .admin-table td:nth-child(4)::before {
        content: "Właściciel";
    }

    .admin-table td:nth-child(5)::before {
        content: "Kliknięcia";
    }

    .admin-table td:nth-child(6)::before {
        content: "Wygasa";
    }

    .admin-table td:nth-child(7)::before {
        content: "Akcje";
    }

    /* MODALS / QR / ANALYTICS */

    .modal-backdrop {
        align-items: flex-end;
        padding: 12px;
    }

    .modal {
        width: 100%;
        max-width: 100%;
        padding: 18px;
        border-radius: 18px 18px 0 0;
    }

    .modal-actions {
        flex-direction: column-reverse;
        gap: 8px;
    }

    .modal-actions button,
    #expiryModalDate {
        width: 100%;
    }

    .qr-container {
        text-align: center;
    }

    .qr-options,
    .qr-logo-upload {
        max-width: 100%;
    }

    .qr-color-row {
        flex-direction: column;
        align-items: stretch;
    }

    .qr-color-row input[type="color"] {
        width: 100%;
        height: 48px;
    }

    .qr-page-actions,
    .qr-logo-form {
        gap: 10px;
    }

    .qr-page-actions a,
    .qr-page-actions button,
    .qr-logo-form input[type="file"],
    .qr-logo-form button {
        width: 100%;
    }

    .qr-image {
        width: 100%;
        max-width: 320px;
        height: auto;
    }

    .analytics-charts-row {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .chart-wrapper {
        height: 230px;
    }

    .analytics-target-url {
        font-size: 13px;
    }
}

/* SMALL MOBILE */

@media (max-width: 430px) {
    .container {
        padding-right: 10px;
        padding-left: 10px;
    }

    .nav-user {
        display: none;
    }

    .nav-logo {
        width: 72px;
        max-height: 28px;
    }

    .hero h1 {
        font-size: 22px;
    }

    .hero p {
        font-size: 14px;
    }

    .card,
    .category,
    .analytics-card,
    .analytics-chart-card {
        padding: 14px;
    }

    .links-table .row-actions {
        grid-template-columns: 1fr;
    }

    .chart-wrapper {
        height: 210px;
    }

    .qr-image {
        max-width: 280px;
    }
}
