:root {
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: #e8eef7;
    background: #07111f;
    line-height: 1.45;
    color-scheme: dark;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-width: 0;
    background: #07111f;
    color: #e8eef7;
}

body {
    overflow-x: hidden;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
.button,
a,
summary {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

button:disabled {
    cursor: wait;
    opacity: .65;
}

.shell {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    padding: max(24px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
    padding-left: max(18px, env(safe-area-inset-left));
    background: #0b1f3a;
    border-right: 1px solid #17304e;
    display: flex;
    flex-direction: column;
    gap: 24px;
    overflow-y: auto;
}

.brand {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 800;
    font-size: 18px;
}

.brand img {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    object-fit: contain;
}

.sidebar nav {
    display: grid;
    gap: 8px;
}

.sidebar nav a,
.link-button {
    min-height: 44px;
    padding: 11px 12px;
    border-radius: 10px;
    color: #a9bcd3;
    background: transparent;
    border: 0;
    text-align: left;
    cursor: pointer;
}

.sidebar nav a:hover,
.link-button:hover,
.sidebar nav a:focus-visible,
.link-button:focus-visible {
    background: #102b4a;
    color: #fff;
    outline: none;
}

.logout-form {
    margin-top: auto;
}

.content {
    min-width: 0;
    width: 100%;
    padding: 32px;
    padding-right: max(32px, env(safe-area-inset-right));
    padding-bottom: max(32px, env(safe-area-inset-bottom));
}

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

.page-head > * {
    min-width: 0;
}

.page-head h1 {
    margin: 0 0 5px;
    font-size: clamp(24px, 2.4vw, 30px);
    line-height: 1.15;
}

.page-head p {
    margin: 0;
    color: #a9bcd3;
    overflow-wrap: anywhere;
}

.button,
button {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #24415f;
    background: #102338;
    color: #fff;
    border-radius: 9px;
    padding: 9px 13px;
    cursor: pointer;
    text-align: center;
}

.button:hover,
button:hover,
.button:focus-visible,
button:focus-visible {
    border-color: #397096;
    outline: none;
}

.primary {
    background: #1565c0;
    border-color: #1565c0;
}

.danger {
    background: #7f1d1d;
    border-color: #991b1b;
}

.toolbar {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.search {
    min-width: 0;
    display: flex;
    gap: 8px;
    flex: 1 1 420px;
}

.search input {
    min-width: 160px;
    flex: 1 1 auto;
}

.inline {
    display: inline;
}

.panel,
.card,
.stat {
    min-width: 0;
    background: #0d1d2f;
    border: 1px solid #18314e;
    border-radius: 14px;
}

.panel {
    padding: 14px 16px;
    margin-bottom: 16px;
}

.panel summary {
    min-height: 40px;
    display: flex;
    align-items: center;
    cursor: pointer;
    font-weight: 700;
}

.grid-form,
.form-card {
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.grid-form {
    padding-top: 16px;
}

.form-card {
    padding: 22px;
}

.wide,
.separator {
    grid-column: 1 / -1;
}

.separator {
    color: #7891aa;
    border-top: 1px solid #18314e;
    padding-top: 14px;
}

label {
    min-width: 0;
    display: grid;
    gap: 7px;
    color: #c6d3e2;
    font-size: 14px;
}

label > span,
.field-title {
    font-weight: 600;
}

label span small,
.field-help {
    font-weight: 400;
    color: #7891aa;
}

input,
select,
textarea {
    min-width: 0;
    width: 100%;
    min-height: 44px;
    background: #081725;
    border: 1px solid #24415f;
    color: #fff;
    border-radius: 9px;
    padding: 10px 12px;
    outline: none;
}

textarea {
    min-height: 110px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: #39bdf8;
    box-shadow: 0 0 0 3px #39bdf822;
}

.input-action-row {
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: stretch;
}

.extract-button {
    min-width: 190px;
    white-space: nowrap;
}

.extract-feedback {
    min-height: 20px;
    display: block;
    color: #7891aa;
}

.extract-feedback[data-state="success"] {
    color: #72e0b8;
}

.extract-feedback[data-state="error"] {
    color: #fca5a5;
}

.extract-feedback[data-state="working"] {
    color: #9bdcf8;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.table-wrap {
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid #18314e;
    border-radius: 14px;
    background: #0d1d2f;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 840px;
}

th,
td {
    text-align: left;
    padding: 12px 14px;
    border-bottom: 1px solid #18314e;
    font-size: 14px;
    vertical-align: middle;
}

th {
    color: #8fa8c2;
    font-weight: 700;
    background: #0b1a2b;
}

tr:last-child td {
    border-bottom: 0;
}

.truncate {
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.actions {
    display: flex;
    gap: 7px;
    align-items: center;
}

.actions form {
    display: inline-flex;
    margin: 0;
}

.badge {
    display: inline-block;
    border-radius: 999px;
    padding: 4px 8px;
    font-size: 12px;
    white-space: nowrap;
}

.badge.active {
    background: #123d32;
    color: #72e0b8;
}

.badge.expired {
    background: #4c1d1d;
    color: #fca5a5;
}

.pagination {
    display: flex;
    gap: 7px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.pagination a {
    min-width: 40px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 10px;
    border: 1px solid #24415f;
    border-radius: 7px;
}

.pagination .current {
    background: #1565c0;
    border-color: #1565c0;
}

.alert {
    padding: 12px 14px;
    border-radius: 10px;
    margin-bottom: 16px;
    background: #15304d;
    overflow-wrap: anywhere;
}

.alert.success {
    background: #123d32;
}

.alert.danger {
    background: #4c1d1d;
}

.stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.stat {
    padding: 16px;
    display: grid;
    gap: 6px;
    overflow-wrap: anywhere;
}

.stat strong {
    color: #8fa8c2;
}

.auth-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}

.login-card {
    width: min(420px, 100%);
    background: #0d1d2f;
    border: 1px solid #18314e;
    border-radius: 18px;
    padding: 28px;
}

.login-card form {
    display: grid;
    gap: 16px;
}

.login-card h1 {
    margin: 8px 0 4px;
}

.login-card p {
    margin: 0 0 18px;
    color: #a9bcd3;
}

.login-logo {
    width: 90px;
    height: 70px;
    object-fit: contain;
}

code {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    color: #9bdcf8;
    overflow-wrap: anywhere;
}

/* Ordenação interativa das tabelas */
th[aria-sort] {
    padding: 0;
}

.sortable {
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    color: #8fa8c2;
    white-space: nowrap;
    transition: background-color .15s ease, color .15s ease;
}

.sortable:hover,
.sortable:focus-visible {
    background: #102b4a;
    color: #fff;
    outline: none;
}

th[aria-sort="ascending"] .sortable,
th[aria-sort="descending"] .sortable {
    color: #fff;
    background: #0f263d;
}

.sort-indicator {
    min-width: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    line-height: 1;
    color: #39bdf8;
}

.sort-idle {
    flex-direction: column;
    gap: 0;
    opacity: .32;
    font-size: 8px;
}

.sort-active {
    font-size: 11px;
    opacity: 1;
}

.table-region {
    min-width: 0;
    transition: opacity .15s ease;
}

.table-region.is-loading {
    opacity: .55;
    pointer-events: none;
}

.table-region[aria-busy="true"] {
    cursor: progress;
}

.mobile-table-controls {
    display: none;
}

@media (max-width: 1100px) {
    .shell {
        grid-template-columns: 210px minmax(0, 1fr);
    }

    .content {
        padding: 24px;
        padding-right: max(24px, env(safe-area-inset-right));
        padding-bottom: max(24px, env(safe-area-inset-bottom));
    }
}

@media (max-width: 860px) {
    .shell {
        display: block;
    }

    .sidebar {
        position: relative;
        top: auto;
        height: auto;
        min-height: 0;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 12px;
        overflow: visible;
        border-right: 0;
        border-bottom: 1px solid #17304e;
        padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 14px max(14px, env(safe-area-inset-left));
    }

    .brand {
        margin: 0;
    }

    .sidebar nav {
        grid-column: 1 / -1;
        display: flex;
        gap: 8px;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        scrollbar-width: thin;
        padding-bottom: 2px;
    }

    .sidebar nav a {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .logout-form {
        margin: 0;
    }

    .content {
        padding: 20px max(14px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
    }

    .page-head {
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .grid-form,
    .form-card,
    .stats {
        grid-template-columns: 1fr;
    }

    .wide,
    .separator {
        grid-column: auto;
    }

    .toolbar {
        align-items: stretch;
    }

    .search {
        width: 100%;
        flex-basis: 100%;
    }

    input,
    select,
    textarea {
        /* Evita zoom automático do Safari/iOS ao focar campos. */
        font-size: 16px;
    }
}

@media (max-width: 760px) {
    .mobile-table-controls {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 10px;
        align-items: end;
        margin-bottom: 12px;
    }

    .mobile-sort-direction {
        white-space: nowrap;
    }

    .table-wrap {
        overflow: visible;
        border: 0;
        background: transparent;
        border-radius: 0;
    }

    table,
    tbody {
        display: block;
        width: 100%;
        min-width: 0;
    }

    thead {
        display: none;
    }

    tbody {
        display: grid;
        gap: 12px;
    }

    tbody tr {
        display: block;
        width: 100%;
        background: #0d1d2f;
        border: 1px solid #18314e;
        border-radius: 14px;
        overflow: hidden;
    }

    tbody td {
        width: 100%;
        min-width: 0;
        display: grid;
        grid-template-columns: minmax(108px, 34%) minmax(0, 1fr);
        gap: 12px;
        align-items: center;
        padding: 11px 13px;
        border-bottom: 1px solid #18314e;
        overflow-wrap: anywhere;
    }

    tbody td::before {
        content: attr(data-label);
        color: #8fa8c2;
        font-size: 12px;
        font-weight: 700;
        line-height: 1.3;
    }

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

    .truncate {
        max-width: none;
        white-space: normal;
        text-overflow: clip;
        overflow: visible;
    }

    .actions {
        display: grid;
        grid-template-columns: minmax(108px, 34%) repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .actions::before {
        grid-column: 1;
    }

    .actions > .button,
    .actions > form {
        width: 100%;
    }

    .actions > form button {
        width: 100%;
    }

    .empty-row td {
        display: block;
        text-align: center;
        padding: 20px 14px;
    }

    .empty-row td::before {
        content: none;
    }

    .pagination {
        justify-content: center;
    }
}

@media (max-width: 620px) {
    .sidebar nav {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        overflow: visible;
    }

    .sidebar nav a {
        text-align: center;
        white-space: normal;
    }

    .page-head {
        display: grid;
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .page-head > .button {
        width: 100%;
    }

    .search {
        display: grid;
        grid-template-columns: 1fr;
    }

    .toolbar > .inline,
    .toolbar > .inline button {
        width: 100%;
    }

    .input-action-row {
        grid-template-columns: 1fr;
    }

    .extract-button {
        width: 100%;
        min-width: 0;
        white-space: normal;
    }

    .form-actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .form-actions > * {
        width: 100%;
    }

    .login-card,
    .form-card {
        padding: 18px;
    }
}

@media (max-width: 480px) {
    .mobile-table-controls {
        grid-template-columns: 1fr;
    }

    .mobile-sort-direction {
        width: 100%;
    }

    tbody td {
        grid-template-columns: minmax(92px, 31%) minmax(0, 1fr);
        gap: 10px;
        padding: 10px 12px;
    }

    .actions {
        grid-template-columns: minmax(92px, 31%) minmax(0, 1fr);
    }

    .actions::before {
        grid-row: 1 / span 2;
        align-self: start;
        padding-top: 12px;
    }

    .actions > .button,
    .actions > form {
        grid-column: 2;
    }

    .pagination a {
        min-width: 44px;
        min-height: 44px;
    }
}

@media (max-width: 360px) {
    .brand span {
        font-size: 16px;
    }

    .sidebar nav {
        grid-template-columns: 1fr;
    }

    tbody td {
        display: block;
    }

    tbody td::before {
        display: block;
        margin-bottom: 5px;
    }

    .actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .actions::before,
    .actions > .button,
    .actions > form {
        grid-column: 1;
        grid-row: auto;
    }

    .actions::before {
        padding-top: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: .01ms !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
    }
}

/* v1.4 — navegação responsiva consolidada */
@media (max-width: 860px) {
    .sidebar {
        position: sticky;
        top: 0;
        z-index: 50;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 10px 12px;
        background: color-mix(in srgb, #0b1f3a 96%, transparent);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
    }

    .sidebar nav {
        width: 100%;
        grid-column: 1 / -1;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        overflow: visible;
        padding: 0;
    }

    .sidebar nav a {
        min-width: 0;
        width: 100%;
        text-align: center;
        white-space: normal;
        border: 1px solid #17304e;
        background: #0d233d;
    }

    .sidebar nav a:hover,
    .sidebar nav a:focus-visible {
        background: #123253;
    }

    .logout-form .link-button {
        min-width: 72px;
        text-align: center;
        border: 1px solid #17304e;
    }
}

@media (max-width: 620px) {
    .sidebar {
        gap: 10px;
        padding-top: max(10px, env(safe-area-inset-top));
        padding-right: max(10px, env(safe-area-inset-right));
        padding-bottom: 10px;
        padding-left: max(10px, env(safe-area-inset-left));
    }

    .brand img {
        width: 36px;
        height: 36px;
        flex-basis: 36px;
    }

    .brand {
        gap: 9px;
        font-size: 16px;
    }

    .sidebar nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .sidebar nav a,
    .link-button {
        min-height: 42px;
        padding: 9px 10px;
    }

    .content {
        padding-top: 16px;
    }
}

@media (max-width: 360px) {
    .sidebar nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .sidebar nav a {
        font-size: 14px;
    }

    .logout-form .link-button {
        min-width: 64px;
        padding-inline: 8px;
    }
}
