@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600&family=Sora:wght@400;500;600&display=swap');

:root {
    --bg: #0c1016;
    --bg-2: #0f1621;
    --panel: rgba(255, 255, 255, 0.06);
    --panel-strong: rgba(255, 255, 255, 0.12);
    --text: #f7f7ff;
    --muted: #b7bcc7;
    --accent: #d3a85b;
    --accent-2: #7cd4ff;
    --border: rgba(255, 255, 255, 0.08);
    --success: #49d17e;
    --warning: #ffbf5a;
    --danger: #ff6b6b;
    --shadow: rgba(0, 0, 0, 0.35);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

* { border-radius: 0 !important; }

html,
body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

html {
    background-color: #0b0f15;
}

body {
    font-family: 'Manrope', system-ui, sans-serif;
    background: radial-gradient(circle at 20% 20%, rgba(211, 168, 91, 0.1), transparent 38%),
                radial-gradient(circle at 80% 10%, rgba(124, 212, 255, 0.12), transparent 35%),
                linear-gradient(160deg, var(--bg) 0%, var(--bg-2) 60%, #0b0f15 100%);
    background-color: #0b0f15;
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
    -webkit-text-size-adjust: 100%;
}

img,
svg,
canvas,
video {
    max-width: 100%;
    height: auto;
}

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

.app {
    width: 100%;
    max-width: 1600px;
    margin: 28px auto 60px;
    padding: 0 24px;
}

.app,
.topbar,
.content,
.card,
.grid,
.form,
.form-row,
.actions,
.key-actions,
.table {
    min-width: 0;
}

.form-row > *,
.grid > * {
    min-width: 0;
}

.topbar {
    position: relative;
    display: grid;
    gap: 12px;
    padding: 18px 20px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: 0 20px 60px var(--shadow);
    backdrop-filter: blur(12px);
}

.topbar-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    width: 100%;
    min-width: 0;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    color: var(--accent);
}

.brand-logo {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    opacity: 0.92;
    filter: drop-shadow(0 0 8px rgba(211, 168, 91, 0.4));
}

.brand-label {
    font-family: 'Sora', system-ui, sans-serif;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-size: 0.9rem;
    min-width: 0;
    overflow-wrap: anywhere;
}

.topbar-actions {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
    max-width: 100%;
    min-width: 0;
}

.app-switcher {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.03);
    max-width: 100%;
    min-width: 0;
}

.app-switcher a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border: 1px solid transparent;
    color: var(--muted);
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    transition: all 200ms ease;
    white-space: nowrap;
}

.app-switcher a:hover {
    color: var(--text);
    border-color: var(--border);
    background: rgba(255, 255, 255, 0.04);
}

.app-switcher a.is-active {
    color: var(--accent);
    border-color: rgba(211, 168, 91, 0.4);
    background: rgba(211, 168, 91, 0.12);
}

.menu-toggle {
    width: 42px;
    min-width: 42px;
    height: 42px;
    padding: 0;
    border-color: var(--border);
}

.menu-toggle-icon {
    width: 18px;
    height: 18px;
    object-fit: contain;
    opacity: 0.88;
}

.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;
}

.topbar-menu {
    position: absolute;
    right: 20px;
    top: calc(100% + 10px);
    z-index: 20;
    width: min(300px, calc(100vw - 48px));
    max-width: calc(100vw - 24px);
    padding: 12px;
    border: 1px solid var(--border);
    background: rgba(11, 16, 24, 0.97);
    box-shadow: 0 20px 45px var(--shadow);
    backdrop-filter: blur(12px);
    display: grid;
    gap: 10px;
}

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

.nav a {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.02);
    color: var(--muted);
    transition: all 200ms ease;
    font-size: 0.9rem;
    overflow-wrap: anywhere;
}

.nav a:hover {
    border-color: rgba(211, 168, 91, 0.4);
    color: var(--text);
    background: rgba(211, 168, 91, 0.12);
}

.nav a.is-active {
    border-color: rgba(211, 168, 91, 0.5);
    color: var(--accent);
    background: rgba(211, 168, 91, 0.16);
}

.user-chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px;
    background: var(--panel-strong);
    border: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--muted);
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
}

.topbar-menu .user-chip {
    width: 100%;
}

.card p,
.card span,
.card strong,
.card a,
.table th,
.table td,
.flash,
.badge,
.btn,
.user-chip,
.nav a,
.app-switcher a {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.content {
    margin-top: 22px;
    display: grid;
    gap: 18px;
}

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 18px 20px;
    box-shadow: 0 12px 40px var(--shadow);
}

.card h2 {
    font-family: 'Sora', system-ui, sans-serif;
    font-size: 1.1rem;
    margin-bottom: 12px;
}

.grid {
    display: grid;
    gap: 14px;
}

.grid.cols-3 {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.grid.cols-2 {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.stat {
    padding: 16px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.03);
}

.stat strong {
    font-size: 1.6rem;
    display: block;
    margin-bottom: 6px;
}

.stat span {
    color: var(--muted);
    font-size: 0.9rem;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    display: table;
}

.table th,
.table td {
    text-align: left;
    padding: 8px 8px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.table th {
    color: var(--muted);
    font-size: 0.85rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.table.table-keys th:first-child,
.table.table-keys td[data-label="Tipo"] {
    white-space: nowrap;
    overflow-wrap: normal;
    word-break: normal;
}

.table-sort-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    text-decoration: none;
}

.table-sort-link:hover {
    color: var(--text);
}

.table-sort-link.is-active {
    color: var(--accent);
}

.table-sort-indicator {
    font-size: 0.75rem;
    line-height: 1;
}

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

.row-link {
    cursor: pointer;
}

.row-link:hover {
    background: rgba(255, 255, 255, 0.04);
}

.hide-mobile {
    display: table-cell;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.04);
    white-space: nowrap;
    overflow-wrap: normal;
    word-break: normal;
}

.badge.success { color: var(--success); }
.badge.warning { color: var(--warning); }
.badge.danger { color: var(--danger); }

.branch-chip {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border: 1px solid var(--border);
    font-size: 0.8rem;
    letter-spacing: 0.02em;
    background: rgba(255, 255, 255, 0.04);
    white-space: nowrap;
    overflow-wrap: normal;
    word-break: normal;
}

.branch-qpracas {
    color: #f7d08a;
    border-color: rgba(247, 208, 138, 0.6);
    background: rgba(247, 208, 138, 0.12);
}

.branch-beiramar {
    color: #7cd4ff;
    border-color: rgba(124, 212, 255, 0.6);
    background: rgba(124, 212, 255, 0.12);
}

.branch-centro {
    color: #b8ff99;
    border-color: rgba(184, 255, 153, 0.6);
    background: rgba(184, 255, 153, 0.12);
}

.branch-praiacal {
    color: #ff9aa2;
    border-color: rgba(255, 154, 162, 0.6);
    background: rgba(255, 154, 162, 0.12);
}

.form {
    display: grid;
    gap: 12px;
}

.search-toolbar {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.search-toolbar-input {
    flex: 1 1 360px;
    min-width: 0;
}

.search-inline {
    display: flex;
    align-items: stretch;
    gap: 10px;
}

.search-inline input {
    flex: 1 1 auto;
    min-width: 0;
}

.search-toolbar-action {
    white-space: nowrap;
}

.filter-toggle {
    width: 48px;
    min-width: 48px;
    padding: 0;
    font-size: 1.15rem;
    line-height: 1;
}

.filter-toggle[aria-expanded="true"] {
    border-color: rgba(211, 168, 91, 0.4);
    background: linear-gradient(120deg, rgba(211, 168, 91, 0.18), rgba(124, 212, 255, 0.12));
}

.advanced-filters {
    display: grid;
    gap: 12px;
}

.form-row {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

label {
    font-size: 0.85rem;
    color: var(--muted);
    display: block;
    margin-bottom: 6px;
}

input,
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: rgba(9, 12, 18, 0.7);
    color: var(--text);
    font-family: inherit;
}

.field-compact {
    width: 240px;
    max-width: 100%;
}

.user-search-wrap {
    width: 240px;
    max-width: 100%;
}

.user-search-results {
    width: 100%;
    max-height: 180px;
    overflow-y: auto;
    border: 1px solid var(--border);
    background: rgba(9, 12, 18, 0.92);
    padding: 6px;
    display: grid;
    gap: 6px;
}

.user-search-item {
    width: 100%;
    text-align: left;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    padding: 8px 10px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
}

.user-search-item:hover {
    border-color: rgba(211, 168, 91, 0.45);
    background: rgba(211, 168, 91, 0.12);
}

.user-search-empty {
    color: var(--muted);
    font-size: 0.85rem;
    padding: 6px 4px;
}

textarea {
    min-height: 90px;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 10px;
}

.actions .btn,
.actions a.btn {
    max-width: 100%;
    white-space: normal;
    text-align: center;
}

.tool-card {
    display: grid;
    gap: 14px;
}

.tool-stats {
    margin-bottom: 4px;
}

.table-actions {
    align-items: center;
    gap: 8px;
}

.inline-form {
    display: inline-flex;
}

.key-actions {
    display: grid;
    gap: 14px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid transparent;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 200ms ease;
}

.btn:hover {
    border-color: var(--border);
    transform: translateY(-1px);
}

.btn-primary {
    background: linear-gradient(120deg, rgba(211, 168, 91, 0.18), rgba(124, 212, 255, 0.12));
    border-color: rgba(211, 168, 91, 0.4);
}

.btn-danger {
    background: rgba(255, 107, 107, 0.15);
    border-color: rgba(255, 107, 107, 0.4);
}

.btn-ghost {
    background: transparent;
    border-color: var(--border);
}

.flash {
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
}

.flash.success { border-color: rgba(73, 209, 126, 0.4); color: var(--success); }
.flash.error { border-color: rgba(255, 107, 107, 0.4); color: var(--danger); }

.is-hidden {
    display: none !important;
}

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

.auth-card {
    width: min(420px, 92vw);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 24px;
    box-shadow: 0 18px 50px var(--shadow);
}

.auth-card h1 {
    font-family: 'Sora', system-ui, sans-serif;
    font-size: 1.4rem;
    margin-bottom: 12px;
}

.auth-logo {
    width: 180px;
    height: auto;
    display: block;
    margin: 0 auto 14px;
    border-radius: 12px;
    background: var(--panel-strong);
    padding: 10px;
    border: 1px solid var(--border);
    box-shadow: 0 10px 30px var(--shadow);
}

.auth-card p {
    color: var(--muted);
    margin-bottom: 16px;
}

.auth-footer {
    margin-top: 14px;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 0.9rem;
    color: var(--muted);
}

@media (max-width: 980px) {
    .topbar-actions {
        width: 100%;
        justify-content: space-between;
    }

    .app-switcher {
        flex: 1 1 auto;
        overflow-x: auto;
        scrollbar-width: thin;
    }

    .app-switcher a {
        flex: 0 0 auto;
    }

    .topbar-menu {
        right: 12px;
        width: min(300px, calc(100vw - 24px));
    }

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

@media (max-width: 720px) {
    .app {
        padding: 0 12px;
    }
    
    .topbar {
        position: sticky;
        top: 12px;
        z-index: 10;
    }

    .topbar-actions {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        width: 100%;
    }

    .app-switcher {
        width: 100%;
    }

    .app-switcher a {
        padding: 7px 10px;
        font-size: 0.72rem;
    }

    .menu-toggle {
        width: 40px;
        min-width: 40px;
        height: 40px;
    }

    .topbar-menu {
        right: 12px;
        width: calc(100% - 24px);
    }

    .topbar-menu .user-chip {
        width: 100%;
    }

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

    .search-toolbar {
        align-items: stretch;
    }

    .search-toolbar-input {
        width: 100%;
    }

    .search-toolbar-action {
        width: 100%;
    }

    .search-inline {
        gap: 8px;
    }

    .filter-toggle {
        flex: 0 0 48px;
    }

    .card {
        padding: 14px;
    }

    .actions {
        flex-direction: column;
        align-items: stretch;
    }

    .actions .btn,
    .actions select,
    .actions input,
    .actions textarea {
        width: 100%;
    }

    .table-actions {
        flex-direction: row;
    }

    .table-actions .btn,
    .table-actions .inline-form {
        width: auto;
    }

    input,
    select,
    textarea,
    button {
        font-size: 16px;
    }

    .table th,
    .table td {
        padding: 8px 6px;
    }

    .table {
        font-size: 0.85rem;
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table.table-keys {
        display: block;
        overflow: visible;
        border-collapse: separate;
    }

    .table-sort-mobile {
        display: flex;
        align-items: center;
        gap: 8px;
        flex-wrap: wrap;
        margin-bottom: 10px;
        color: var(--muted);
        font-size: 0.82rem;
    }

    .table-sort-mobile .table-sort-link {
        border: 1px solid var(--border);
        padding: 6px 10px;
        font-size: 0.82rem;
        text-transform: uppercase;
        letter-spacing: 0.04em;
    }

    .table.table-keys thead {
        display: none;
    }

    .table.table-keys tbody {
        display: grid;
        gap: 10px;
    }

    .table.table-keys tr {
        display: block;
        border: 1px solid var(--border);
        background: rgba(255, 255, 255, 0.02);
        padding: 10px 12px;
    }

    .table.table-keys td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 10px;
        padding: 8px 0;
        border-bottom: 1px solid var(--border);
        white-space: normal;
        word-break: break-word;
    }

    .table.table-keys td:last-child {
        border-bottom: 0;
    }

    .table.table-keys td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 0.72rem;
        letter-spacing: 0.06em;
        text-transform: uppercase;
        flex: 0 0 38%;
        max-width: 38%;
    }

    .table.table-keys .hide-mobile {
        display: none !important;
    }

    .table.table-keys .table-empty-row {
        padding: 12px;
    }

    .table.table-keys .table-empty-row td {
        display: block;
        padding: 0;
        border: 0;
    }

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

    .field-compact {
        width: 100%;
    }

    .user-search-wrap {
        width: 100%;
    }

    .hide-mobile {
        display: none !important;
    }
}
