:root {
    --app-touch-min: 44px;
    --app-safe-bottom: env(safe-area-inset-bottom, 0px);
    --app-safe-left: env(safe-area-inset-left, 0px);
    --app-safe-right: env(safe-area-inset-right, 0px);
    --footer-height: 52px;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding-left: var(--app-safe-left);
    padding-right: var(--app-safe-right);
    padding-bottom: calc(var(--footer-height) + var(--app-safe-bottom));
}

main {
    flex: 1;
}

.login-page {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: linear-gradient(135deg, #0d6efd 0%, #212529 100%);
}

.page-footer {
    position: fixed;
    left: var(--app-safe-left);
    right: var(--app-safe-right);
    bottom: 0;
    z-index: 200;
    height: calc(var(--footer-height) + var(--app-safe-bottom));
    padding: 0.65rem 0;
    padding-bottom: calc(0.65rem + var(--app-safe-bottom));
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    background: rgba(248, 249, 250, 0.98);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.06);
}

.page-footer-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    height: 100%;
}

.footer-copyright {
    font-size: 0.8rem;
    color: #6c757d;
    white-space: nowrap;
}

.intercard-logo {
    height: 28px;
    width: auto;
    max-width: 120px;
    object-fit: contain;
    opacity: 0.95;
}

.login-card {
    width: 100%;
    max-width: 420px;
    border: none;
    box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.25);
}

.app-hero {
    background: linear-gradient(135deg, #0d6efd 0%, #212529 100%);
    color: #fff;
    padding: 1.75rem 0 2.25rem;
    margin-bottom: -1rem;
}

.app-hero h1,
.app-hero p {
    color: #fff;
}

.app-hero .text-muted {
    color: rgba(255, 255, 255, 0.75) !important;
}

.app-content {
    position: relative;
    z-index: 1;
}

.navbar-app {
    background: linear-gradient(135deg, #0b5ed7 0%, #1a1d20 100%) !important;
    padding-top: max(0.5rem, env(safe-area-inset-top, 0px));
}

.brand-link {
    display: inline-flex;
    align-items: center;
    padding: 0;
    margin-right: 0.5rem;
}

.brand-logo {
    height: 44px;
    width: auto;
    max-width: 200px;
    object-fit: contain;
}

.login-logo {
    display: block;
    width: min(100%, 340px);
    height: auto;
    margin: 0 auto;
}

.navbar-mobile {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.navbar-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-left: auto;
}

.navbar-user {
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.875rem;
    max-width: 8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-nav,
.btn-touch,
.site-list-actions .btn,
.navbar-actions .btn,
.mobile-stack-table .btn {
    min-height: var(--app-touch-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}

.site-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-left: 0;
    border-right: 0;
}

.site-list-item:first-child {
    border-top: 0;
}

.site-list-item:last-child {
    border-bottom: 0;
}

.site-list-name {
    font-weight: 600;
    color: #212529;
    line-height: 1.35;
}

.site-list-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    flex-shrink: 0;
}

.content-card {
    border: none;
    border-radius: 1rem;
    box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.08);
    overflow: hidden;
}

.stat-badge {
    font-size: 0.9rem;
}

.history-message {
    white-space: pre-wrap;
    word-break: break-word;
}

.table td {
    vertical-align: middle;
}

.mac-input {
    min-width: 0;
    width: 100%;
    max-width: 220px;
    font-size: 16px;
}

.qr-reader-box {
    width: 100%;
    min-height: 280px;
    overflow: hidden;
    border-radius: 0.75rem;
}

@media (max-width: 767.98px) {
    .mac-cell .mac-input {
        max-width: none;
    }
}

.form-control,
.form-select {
    font-size: 16px;
}

.unlock-toast {
    position: fixed;
    left: 1rem;
    right: 1rem;
    bottom: calc(var(--footer-height) + 1rem + var(--app-safe-bottom));
    z-index: 1080;
    display: none;
}

.mobile-stack-table td.empty-cell::before {
    display: none;
}

@media (max-width: 767.98px) {
    .site-list-item {
        flex-direction: column;
        align-items: stretch;
    }

    .site-list-actions {
        width: 100%;
    }

    .site-list-actions .btn {
        flex: 1 1 calc(50% - 0.25rem);
    }

    .app-hero h1 {
        font-size: 1.35rem;
    }

    .mobile-stack-table thead {
        display: none;
    }

    .mobile-stack-table tbody,
    .mobile-stack-table tr,
    .mobile-stack-table td {
        display: block;
        width: 100%;
    }

    .mobile-stack-table tr {
        margin-bottom: 0.85rem;
        padding: 0.85rem 1rem;
        background: #fff;
        border: 1px solid rgba(0, 0, 0, 0.08);
        border-radius: 0.85rem;
    }

    .mobile-stack-table tr.table-empty-row {
        padding: 2rem 1rem;
        text-align: center;
    }

    .mobile-stack-table td {
        border: 0;
        padding: 0.35rem 0;
        text-align: right;
    }

    .mobile-stack-table td::before {
        content: attr(data-label);
        float: left;
        font-weight: 600;
        color: #6c757d;
        text-align: left;
        max-width: 45%;
        padding-right: 0.75rem;
    }

    .mobile-stack-table td.action-cell {
        margin-top: 0.75rem;
        padding-top: 0.75rem;
        border-top: 1px solid rgba(0, 0, 0, 0.08);
        text-align: center;
    }

    .mobile-stack-table td.action-cell::before {
        display: none;
    }

    .mobile-stack-table td.action-cell .btn,
    .mobile-stack-table td.action-cell form {
        width: 100%;
    }

    .mobile-stack-table td.action-cell .btn {
        width: 100%;
    }

    .mobile-stack-table td.mac-cell::before {
        float: none;
        display: block;
        max-width: none;
        margin-bottom: 0.5rem;
        text-align: left;
    }

    .mobile-stack-table td.mac-cell {
        text-align: left;
    }

    .mobile-stack-table td.mac-cell .mac-input {
        max-width: none;
    }

    .table-responsive {
        overflow: visible;
    }
}

@media (min-width: 768px) {
    .unlock-toast {
        left: auto;
        right: 1.5rem;
        max-width: 320px;
    }
}
