:root {
    --adca-blue: #1D4E89;
    --adca-blue-dark: #163a66;
    --adca-blue-light: #2a6cb8;
    --white: #ffffff;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-500: #64748b;
    --gray-700: #334155;
    --gray-900: #0f172a;
    --success: #15803d;
    --success-bg: #dcfce7;
    --danger: #b91c1c;
    --danger-bg: #fee2e2;
    --warning-bg: #fef3c7;
    --warning: #b45309;
    --shadow: 0 4px 24px rgba(29, 78, 137, 0.1);
    --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
    --radius: 16px;
    --app-header-h: 56px;
    --tabbar-h: 49px;
    --app-height: 100dvh;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom-env: env(safe-area-inset-bottom, 0px);
    /* iOS 26 por vezes reporta env()=0 — chão mínimo para home indicator */
    --safe-bottom-floor: max(env(safe-area-inset-bottom, 0px), 34px);
    --tabbar-total: calc(var(--tabbar-h) + var(--safe-bottom-floor));
}

html.is-standalone {
    --app-height: 100vh;
}

* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.5;
    min-height: var(--app-height, 100dvh);
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

body.app-shell {
    background: var(--gray-50);
    min-height: var(--app-height, 100dvh);
    touch-action: manipulation;
}

body.auth-shell {
    background: linear-gradient(165deg, #1D4E89 0%, #163a66 45%, var(--gray-50) 45%);
}

a {
    color: var(--adca-blue);
    text-decoration: none;
}

a:hover {
    color: var(--adca-blue-dark);
}

/* ---- App header ---- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(29, 78, 137, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--white);
    padding-top: var(--safe-top);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08);
}

.app-header-inner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: var(--app-header-h);
    padding: 0.5rem 1rem 0.625rem;
    max-width: 1200px;
    margin: 0 auto;
}

.app-header-logo {
    width: 36px;
    height: 36px;
    object-fit: contain;
    background: var(--white);
    border-radius: 10px;
    padding: 3px;
    flex-shrink: 0;
}

.app-header-titles {
    min-width: 0;
}

.app-header-app {
    display: block;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    opacity: 0.75;
    line-height: 1.2;
}

.app-header-page {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 700;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---- Desktop top navigation ---- */
.desktop-topbar {
    display: none;
    background: var(--adca-blue);
    color: var(--white);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 120;
}

.desktop-topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.desktop-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--white);
    flex-shrink: 0;
}

.desktop-brand:hover {
    color: var(--white);
    opacity: 0.95;
}

.desktop-brand-logo {
    height: 44px;
    width: auto;
    background: var(--white);
    border-radius: 8px;
    padding: 4px;
}

.desktop-brand-text {
    font-weight: 600;
    font-size: 0.95rem;
}

.desktop-nav {
    display: flex;
    gap: 0.35rem;
    flex: 1;
}

.desktop-nav-link {
    color: rgba(255, 255, 255, 0.88);
    padding: 0.5rem 0.875rem;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.9rem;
}

.desktop-nav-link:hover,
.desktop-nav-link.active {
    background: rgba(255, 255, 255, 0.15);
    color: var(--white);
}

.desktop-user {
    display: flex;
    align-items: center;
    gap: 0.875rem;
}

.desktop-user-name {
    font-size: 0.875rem;
    opacity: 0.92;
}

.mobile-header {
    display: block;
}

/* ---- Bottom navigation (mobile) ---- */
.bottom-nav {
    grid-template-columns: repeat(4, 1fr);
    background: #ffffff;
    border-top: 1px solid var(--gray-200);
    width: 100%;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    min-height: var(--tabbar-h);
    padding: 0.25rem 0.25rem 0;
    color: var(--gray-500);
    font-size: 0.625rem;
    font-weight: 600;
    line-height: 1;
    transition: color 0.15s;
    position: relative;
    z-index: 1;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    cursor: pointer;
}

.bottom-nav-item svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.bottom-nav-item.active {
    color: var(--adca-blue);
}

.bottom-nav-item.active svg {
    transform: scale(1.05);
}

.bottom-nav-item:active {
    opacity: 0.7;
}

.main {
    flex: 1 0 auto;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem 1rem 1.5rem;
}

.main-app {
    flex: 1 0 auto;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem 1.5rem 2rem;
}

.main-auth {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(1.5rem + var(--safe-top)) 1.25rem calc(1.5rem + var(--safe-bottom-floor));
    flex: 1;
}

.footer-auth {
    flex-shrink: 0;
    text-align: center;
    padding: 1rem 1.25rem calc(1rem + var(--safe-bottom-floor));
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.8125rem;
    background: transparent;
    border-top: none;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.app-shell .page-header h1 {
    display: none;
}

.page-header-compact {
    margin-bottom: 1.25rem;
}

.page-header-compact h1 {
    display: none;
}

.page-header h1 {
    margin: 0 0 0.25rem;
    font-size: 1.5rem;
    color: var(--adca-blue);
    font-weight: 700;
}

.page-header p {
    margin: 0;
    color: var(--gray-500);
    font-size: 0.875rem;
}

.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(226, 232, 240, 0.9);
    overflow: hidden;
}

.card-body {
    padding: 1.5rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.125rem 1.25rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(226, 232, 240, 0.9);
}

.stat-card .label {
    font-size: 0.875rem;
    color: var(--gray-500);
    margin-bottom: 0.25rem;
}

.stat-card .value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--adca-blue);
}

.stat-card.danger .value {
    color: var(--danger);
}

.stat-card.success .value {
    color: var(--success);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.9rem;
    border: none;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
    font-family: inherit;
    min-height: 44px;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--adca-blue);
    color: var(--white);
    box-shadow: 0 4px 14px rgba(29, 78, 137, 0.25);
}

.btn-primary:hover {
    background: var(--adca-blue-dark);
    color: var(--white);
}

.btn-outline {
    background: transparent;
    color: var(--white);
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--white);
}

.btn-secondary {
    background: var(--gray-100);
    color: var(--gray-700);
    border: 1px solid var(--gray-200);
}

.btn-secondary:hover {
    background: var(--gray-200);
}

.btn-danger {
    background: var(--danger);
    color: var(--white);
}

.btn-danger:hover {
    background: #991b1b;
    color: var(--white);
}

.btn-sm {
    padding: 0.4rem 0.875rem;
    font-size: 0.8125rem;
}

.btn-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

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

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

thead {
    background: var(--gray-50);
}

th, td {
    padding: 0.875rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}

th {
    font-weight: 600;
    color: var(--gray-700);
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

tbody tr:hover {
    background: var(--gray-50);
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success {
    background: var(--success-bg);
    color: var(--success);
}

.badge-danger {
    background: var(--danger-bg);
    color: var(--danger);
}

.badge-neutral {
    background: var(--gray-100);
    color: var(--gray-700);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.form-grid .full-width {
    grid-column: 1 / -1;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.form-group label {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--gray-700);
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--adca-blue);
    box-shadow: 0 0 0 3px rgba(29, 78, 137, 0.15);
}

.password-field {
    position: relative;
}

.password-field input {
    width: 100%;
    padding-right: 3rem;
}

.password-toggle {
    position: absolute;
    right: 0.35rem;
    top: 50%;
    transform: translateY(-50%);
    width: 2.5rem;
    height: 2.5rem;
    border: none;
    background: transparent;
    color: var(--gray-500);
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
}

.password-toggle:hover {
    color: var(--adca-blue);
    background: var(--gray-100);
}

.password-toggle svg {
    width: 20px;
    height: 20px;
}

.password-toggle .icon-eye-closed {
    display: none;
}

.password-toggle.is-visible .icon-eye-open {
    display: none;
}

.password-toggle.is-visible .icon-eye-closed {
    display: block;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--gray-200);
}

.filters {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
    align-items: center;
}

.filters input,
.filters select {
    padding: 0.5rem 0.875rem;
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    font-size: 0.875rem;
    font-family: inherit;
}

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

.alert {
    padding: 0.875rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid #bbf7d0;
}

.alert-error {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid #fecaca;
}

.alert-warning {
    background: var(--warning-bg);
    color: var(--warning);
    border: 1px solid #fde68a;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--white);
    border-radius: 20px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.6);
    padding: 2rem 1.5rem;
}

.auth-card .logo-wrap {
    text-align: center;
    margin-bottom: 1.5rem;
}

.auth-card .logo-wrap img {
    height: 100px;
    width: auto;
}

.auth-card h1 {
    text-align: center;
    margin: 0 0 0.25rem;
    font-size: 1.25rem;
    color: var(--adca-blue);
}

.auth-card .subtitle {
    text-align: center;
    color: var(--gray-500);
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
}

.auth-link {
    text-align: center;
    margin: 1rem 0 0;
    font-size: 0.875rem;
}

.account-layout {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.account-tabs {
    display: flex;
    gap: 0.625rem;
    flex-wrap: nowrap;
    margin-bottom: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
}

.account-tabs::-webkit-scrollbar {
    display: none;
}

.account-hero {
    margin-bottom: 0;
}

.account-section {
    margin-bottom: 0;
}

.account-section-body {
    padding: 1.75rem 1.5rem;
}

.account-panel + .account-panel {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--gray-200);
}

.account-app-note {
    margin: 0 0 1.25rem;
}

.btn-block {
    display: flex;
    width: 100%;
}

.form-actions-compact {
    margin-top: 1.25rem;
    padding-top: 0;
    border-top: none;
}

.account-tab {
    flex: 1 1 0;
    min-width: 0;
    text-align: center;
    text-decoration: none;
    padding: 0.625rem 0.75rem;
    border-radius: 999px;
    background: var(--white);
    border: 1px solid var(--gray-200);
    color: var(--gray-700);
    font-size: 0.8125rem;
    font-weight: 600;
    white-space: nowrap;
}

.account-tab.active {
    background: var(--adca-blue);
    border-color: var(--adca-blue);
    color: var(--white);
}

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--gray-500);
}

.empty-state p {
    margin-bottom: 1rem;
}

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

.text-muted {
    color: var(--gray-500);
    font-size: 0.875rem;
}

.section-title {
    margin: 0 0 1.25rem;
    font-size: 1.1rem;
    color: var(--adca-blue);
}

.tips-list {
    margin: 0 0 1.5rem;
    padding-left: 1.25rem;
    color: var(--gray-700);
    font-size: 0.9rem;
}

.tips-list li + li {
    margin-top: 0.35rem;
}

.import-layout {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 1.5rem;
    align-items: start;
}

.import-preview-card {
    position: sticky;
    top: 5.5rem;
}

.import-preview-image {
    width: 100%;
    height: auto;
    border-radius: 8px;
    border: 1px solid var(--gray-200);
    display: block;
}

.import-form input[type="file"] {
    padding: 0.75rem;
    border: 1px dashed var(--gray-300);
    border-radius: 12px;
    background: var(--gray-50);
    width: 100%;
}

.account-card {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.account-hero .card-body {
    padding: 1.25rem 1.5rem;
}

.account-info {
    flex: 1;
    min-width: 0;
}

.account-logout {
    flex-shrink: 0;
    white-space: nowrap;
}

.account-avatar {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: rgba(29, 78, 137, 0.1);
    color: var(--adca-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.account-avatar svg {
    width: 28px;
    height: 28px;
}

.account-info h2 {
    margin: 0 0 0.15rem;
    font-size: 1.05rem;
    color: var(--adca-blue);
}

.account-info p {
    margin: 0;
    color: var(--gray-500);
    font-size: 0.875rem;
}

/* Mobile: bottom nav fixo estilo iOS */
@media (max-width: 899px) {
    body.app-shell .desktop-topbar {
        display: none !important;
    }

    body.app-shell .bottom-nav.mobile-nav {
        display: grid;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 9999;
        padding-bottom: var(--safe-bottom-floor);
        box-shadow: 0 -1px 0 rgba(15, 23, 42, 0.06);
        transform: translateZ(0);
        pointer-events: auto;
    }

    body.app-shell .main.main-app {
        flex: 0 1 auto;
        position: relative;
        z-index: 1;
        max-width: none;
        margin: 0;
        width: 100%;
        padding: 0.875rem 0.875rem 1rem;
        padding-bottom: calc(var(--tabbar-total) + 16px);
    }

    .form-group input,
    .form-group select,
    .form-group textarea,
    .filters input,
    .filters select {
        font-size: 16px;
    }

    .account-card {
        flex-wrap: wrap;
        gap: 1rem;
    }

    .account-logout {
        width: 100%;
        justify-content: center;
        margin-top: 0.5rem;
    }

    .account-layout {
        gap: 1.25rem;
    }

    .account-section-body {
        padding: 1.25rem 1rem;
    }

    .account-panel + .account-panel {
        margin-top: 1.5rem;
        padding-top: 1.5rem;
    }
}

/* Desktop: menu em cima, sem bottom nav */
@media (min-width: 900px) {
    .desktop-topbar {
        display: block;
    }

    .mobile-header,
    .bottom-nav.mobile-nav {
        display: none !important;
    }

    .app-shell .page-header h1 {
        display: block;
    }

    .main-app {
        flex: 1 0 auto;
        padding: 2rem 1.5rem;
    }

    body.app-shell {
        background: var(--gray-50);
    }
}

@media (max-width: 768px) {
    .page-header {
        flex-direction: column;
        align-items: stretch;
    }

    .page-header .btn,
    .page-header .btn-group {
        width: 100%;
    }

    .page-header .btn-group {
        flex-direction: column;
    }

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

    .card-body {
        padding: 1rem;
    }

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

    .filters input,
    .filters select,
    .filters .btn {
        width: 100%;
        min-width: 0;
    }

    .search-input {
        min-width: 0;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
    }

    .form-actions .btn-danger {
        margin-left: 0 !important;
        order: 3;
    }

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

    .stat-card .value {
        font-size: 1.75rem;
    }

    table {
        font-size: 0.8125rem;
    }

    th, td {
        padding: 0.75rem 0.625rem;
    }

    .auth-card {
        padding: 1.5rem;
    }

    .import-layout {
        grid-template-columns: 1fr;
    }

    .import-preview-card {
        position: static;
    }

    .import-preview-card {
        top: auto;
    }
}

@media (max-width: 480px) {
    .app-header-page {
        font-size: 1rem;
    }
}
