:root {
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #1f2937;
    background: #f4f6f8;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
}

a {
    color: inherit;
}

/* Login e telas simples */

.login-shell,
.page-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.card {
    width: min(100%, 460px);
    background: #fff;
    border: 1px solid #dde3ea;
    border-radius: 16px;
    padding: 32px;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

h1 {
    margin: 0 0 12px;
    font-size: clamp(1.8rem, 4vw, 2.4rem);
}

.eyebrow {
    margin: 0 0 8px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.muted {
    color: #64748b;
}

.login-shell .button,
.page-shell .button {
    width: 100%;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: #111827;
    color: #fff;
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

.button:disabled {
    cursor: not-allowed;
    opacity: .55;
}

.message {
    min-height: 24px;
    margin-bottom: 0;
    color: #b42318;
}

.user-row {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 20px 0;
}

.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    background: #e2e8f0;
}

.link {
    color: inherit;
}

/* Painel administrativo */

.admin-page {
    min-height: 100vh;
    background: #f4f7fb;
    color: #132238;
}

.admin-shell {
    width: min(1400px, calc(100% - 40px));
    margin: 0 auto;
    padding: 40px 0 64px;
}

.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 28px;
}

.admin-header h1 {
    margin: 4px 0 0;
    font-size: clamp(1.8rem, 4vw, 2.5rem);
}

.user-area {
    display: flex;
    align-items: center;
    gap: 16px;
}

.admin-page .button {
    width: auto;
}

.button-primary {
    background: #173f70;
    color: #fff;
}

.button-secondary {
    border-color: #cbd5e1;
    background: #fff;
    color: #173f70;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.search-box {
    width: min(460px, 100%);
}

.search-box input {
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    color: #132238;
    font: inherit;
}

.search-box input:focus {
    border-color: #4f79a7;
    outline: 3px solid rgba(79, 121, 167, .16);
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(140px, 220px));
    gap: 16px;
    margin-bottom: 24px;
}

.summary-card {
    padding: 18px 20px;
    border: 1px solid #dbe3ed;
    border-radius: 12px;
    background: #fff;
}

.summary-card span {
    display: block;
    margin-bottom: 6px;
    color: #64748b;
    font-size: .9rem;
}

.summary-card strong {
    font-size: 1.8rem;
}

.table-card {
    overflow: hidden;
    border: 1px solid #dbe3ed;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .06);
}

.table-wrapper {
    overflow-x: auto;
}

.links-table {
    width: 100%;
    min-width: 980px;
    border-collapse: collapse;
}

.links-table th,
.links-table td {
    padding: 15px 18px;
    border-bottom: 1px solid #e8edf3;
    text-align: left;
    vertical-align: middle;
}

.links-table th {
    background: #f8fafc;
    color: #475569;
    font-size: .82rem;
    letter-spacing: .04em;
    text-transform: uppercase;
    white-space: nowrap;
}

.links-table tbody tr:hover {
    background: #f8fbff;
}

.links-table tbody tr:last-child td {
    border-bottom: 0;
}

.code-link {
    color: #174c87;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-weight: 700;
    text-decoration: none;
}

.code-link:hover {
    text-decoration: underline;
}

.number-column {
    text-align: right !important;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 9px;
    border-radius: 999px;
    font-size: .82rem;
    font-weight: 700;
    white-space: nowrap;
}

.status-badge::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.status-active {
    background: #dcfce7;
    color: #166534;
}

.status-inactive {
    background: #fee2e2;
    color: #991b1b;
}

.actions-column {
    white-space: nowrap;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 6px;
    padding: 7px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    background: #fff;
    color: #173f70;
    font: inherit;
    font-size: .86rem;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

.icon-button:hover {
    background: #eef4fa;
}

.no-results,
.empty-state,
.notice {
    padding: 32px;
    text-align: center;
}

.notice-error {
    border: 1px solid #fecaca;
    border-radius: 10px;
    background: #fef2f2;
    color: #991b1b;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 760px) {
    .admin-shell {
        width: min(100% - 24px, 1400px);
        padding-top: 24px;
    }

    .admin-header,
    .toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .user-area {
        flex-wrap: wrap;
    }

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

    .search-box {
        width: 100%;
    }
}

@media (max-width: 520px) {
    .summary-grid {
        grid-template-columns: 1fr;
    }
}

/* CRUD e modal */

.notice-success {
    margin-bottom: 20px;
    border: 1px solid #bbf7d0;
    border-radius: 10px;
    background: #f0fdf4;
    color: #166534;
}

.danger-button {
    border-color: #fecaca;
    color: #991b1b;
}

.danger-button:hover {
    background: #fef2f2;
}

.modal-dialog {
    width: min(620px, calc(100% - 32px));
    max-height: calc(100vh - 40px);
    padding: 0;
    border: 0;
    border-radius: 16px;
    background: #fff;
    color: #132238;
    box-shadow: 0 28px 80px rgba(15, 23, 42, .28);
}

.modal-dialog::backdrop {
    background: rgba(15, 23, 42, .58);
    backdrop-filter: blur(2px);
}

.link-form {
    display: grid;
    gap: 18px;
    padding: 28px;
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.modal-header h2 {
    margin: 4px 0 0;
    font-size: 1.6rem;
}

.close-button {
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #475569;
    font: inherit;
    font-size: 1.8rem;
    line-height: 1;
    cursor: pointer;
}

.close-button:hover {
    background: #f1f5f9;
}

.link-form label {
    display: grid;
    gap: 7px;
    color: #334155;
    font-weight: 700;
}

.link-form input[type="text"],
.link-form input[type="url"] {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    color: #132238;
    font: inherit;
}

.link-form input:focus {
    border-color: #4f79a7;
    outline: 3px solid rgba(79, 121, 167, .16);
}

.link-form input[readonly] {
    background: #f8fafc;
    color: #64748b;
}

.link-form small {
    color: #64748b;
    font-size: .82rem;
    font-weight: 400;
}

.code-field-row {
    display: flex;
    align-items: stretch;
}

.code-prefix {
    display: inline-flex;
    align-items: center;
    max-width: 55%;
    padding: 0 10px;
    overflow: hidden;
    border: 1px solid #cbd5e1;
    border-right: 0;
    border-radius: 8px 0 0 8px;
    background: #f8fafc;
    color: #64748b;
    font-size: .88rem;
    font-weight: 400;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.code-field-row input {
    border-radius: 0 8px 8px 0 !important;
}

.checkbox-field {
    display: flex !important;
    align-items: center;
    grid-template-columns: auto 1fr;
    gap: 10px !important;
}

.checkbox-field input {
    width: 18px;
    height: 18px;
}

.form-error {
    margin: 0;
    padding: 12px 14px;
    border: 1px solid #fecaca;
    border-radius: 8px;
    background: #fef2f2;
    color: #991b1b;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 4px;
}

.modal-actions .button {
    width: auto;
}

@media (max-width: 620px) {
    .link-form {
        padding: 22px;
    }

    .code-field-row {
        display: grid;
    }

    .code-prefix {
        max-width: none;
        min-height: 38px;
        border-right: 1px solid #cbd5e1;
        border-bottom: 0;
        border-radius: 8px 8px 0 0;
    }

    .code-field-row input {
        border-radius: 0 0 8px 8px !important;
    }

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

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

/* v0.5: filtros, ações compactas, QR Code e notificações */

.toolbar-controls {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
    width: min(760px, 100%);
}

.filter-group {
    display: inline-flex;
    padding: 3px;
    border: 1px solid #cbd5e1;
    border-radius: 9px;
    background: #fff;
}

.filter-button {
    min-height: 36px;
    padding: 6px 12px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #475569;
    font: inherit;
    font-size: .88rem;
    font-weight: 700;
    cursor: pointer;
}

.filter-button:hover {
    background: #f1f5f9;
}

.filter-button.is-active {
    background: #173f70;
    color: #fff;
}

.actions-column .icon-button {
    width: 36px;
    height: 36px;
    margin-right: 4px;
    padding: 0;
    font-size: 1.05rem;
    line-height: 1;
}

.actions-column .icon-button:last-child {
    margin-right: 0;
}

.qr-symbol {
    font-size: 1.18rem;
}

.qr-dialog {
    width: min(460px, calc(100% - 32px));
}

.qr-panel {
    display: grid;
    gap: 18px;
    padding: 28px;
    text-align: center;
}

.qr-panel .modal-header {
    text-align: left;
}

.qr-code {
    display: grid;
    place-items: center;
    width: 288px;
    min-height: 288px;
    margin: 0 auto;
    padding: 16px;
    border: 1px solid #dbe3ed;
    border-radius: 14px;
    background: #fff;
}

.qr-code canvas,
.qr-code img {
    display: block;
    width: 256px !important;
    height: 256px !important;
    max-width: 100%;
}

.qr-code-label {
    margin: 0;
    color: #173f70;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 1rem;
    font-weight: 800;
}

.qr-url {
    margin: -10px 0 0;
    overflow-wrap: anywhere;
    color: #64748b;
    font-size: .9rem;
}

.qr-actions {
    justify-content: center;
}

.toast {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 1000;
    max-width: min(360px, calc(100% - 44px));
    padding: 12px 16px;
    border-radius: 10px;
    background: #132238;
    color: #fff;
    box-shadow: 0 12px 34px rgba(15, 23, 42, .24);
    font-weight: 700;
}

@media (max-width: 900px) {
    .toolbar-controls {
        align-items: stretch;
        flex-direction: column;
        width: 100%;
    }

    .filter-group {
        align-self: flex-start;
    }
}

@media (max-width: 520px) {
    .filter-group {
        width: 100%;
    }

    .filter-button {
        flex: 1;
    }

    .qr-code {
        width: 100%;
        min-height: 0;
    }
}
