@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg-dark: #0f172a;
    --bg-light: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --glass: rgba(30, 41, 59, 0.7);
    --border: rgba(255, 255, 255, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

html {
    overflow-x: hidden;
    max-width: 100%;
}

body {
    background: linear-gradient(135deg, var(--bg-dark), var(--bg-light));
    min-height: 100vh;
    color: var(--text-main);
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    max-width: 100%;
}

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 2rem;
}

.card {
    background: var(--glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    padding: 2.5rem;
    border-radius: 1rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.logo-area {
    text-align: center;
    margin-bottom: 2rem;
}

.logo-area img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.form-input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text-main);
    font-size: 0.95rem;
    transition: all 0.3s ease;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.btn-primary {
    width: 100%;
    padding: 0.75rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-block;
    text-align: center;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.alert {
    padding: 0.75rem;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
    text-align: center;
}

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

/* Dashboard Layout */
.dashboard-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: var(--glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-toggle-btn {
    position: absolute;
    top: 1rem;
    right: -1rem;
    width: 2rem;
    height: 2rem;
    background: var(--primary);
    border: 2px solid var(--bg-light);
    border-radius: 50%;
    color: white;
    font-size: 0.8rem;
    display: none;
    /* Desktop only usually, but we'll show it inside sidebar */
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 101;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s;
}

@media (min-width: 769px) {

    /* Show only on desktop */
    .sidebar-toggle-btn {
        display: flex;
        right: 1rem;
        top: 1rem;
        border: none;
        background: rgba(255, 255, 255, 0.1);
    }

    .sidebar-toggle-btn:hover {
        background: var(--primary);
    }
}

/* Sidebar Collapsed State */
body.sidebar-collapsed .sidebar {
    width: 80px;
}

body.sidebar-collapsed .main-content {
    margin-left: 80px;
}

/* Move toggle button down when collapsed so it doesn't cover avatar */
body.sidebar-collapsed .sidebar-toggle-btn {
    top: 5rem;
    right: -10px;
    /* Center on the border line */
}

body.sidebar-collapsed .sidebar-toggle-btn i {
    transform: rotate(180deg);
}

body.sidebar-collapsed .user-details,
body.sidebar-collapsed .menu-title,
body.sidebar-collapsed .logout-container span,
body.sidebar-collapsed .logout-link span {
    display: none !important;
}

body.sidebar-collapsed .user-info {
    justify-content: center;
    padding: 1.5rem 0.5rem;
    margin-bottom: 1rem;
}

body.sidebar-collapsed .user-avatar {
    margin: 0;
    width: 45px;
    height: 45px;
    font-size: 1.4rem;
}

body.sidebar-collapsed .sidebar-header img {
    display: none;
}

body.sidebar-collapsed .menu-link {
    justify-content: center;
    padding: 0.8rem 0;
    font-size: 0;
    /* Hide text */
    position: relative;
    height: 48px;
    /* Force consistent height */
}

body.sidebar-collapsed .menu-link i.fa-solid:not(.fa-chevron-down) {
    margin-right: 0 !important;
    font-size: 1.4rem;
    /* Standardize icon size */
    width: 32px !important;
    /* Fixed width container for icon */
    height: 32px;
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: transparent !important;
    /* Remove any potential background mismatch */
}

body.sidebar-collapsed .fa-chevron-down {
    display: none;
}

/* Link Logout tweaks */
body.sidebar-collapsed .logout-link {
    font-size: 0;
    justify-content: center;
}

body.sidebar-collapsed .logout-link i {
    margin-right: 0 !important;
    font-size: 1.2rem;
}

/* Hide Banco Conectado box content or make it small icon */
body.sidebar-collapsed .logout-container>div:first-child {
    font-size: 0;
    padding: 0.5rem;
    display: flex;
    justify-content: center;
}

body.sidebar-collapsed .logout-container>div:first-child div {
    font-size: 0 !important;
}

body.sidebar-collapsed .logout-container>div:first-child i {
    font-size: 1rem !important;
    margin: 0 !important;
}

body.sidebar-collapsed .logout-container>div:nth-child(2) {
    display: none;
    /* Hide version */
}

/* Tooltip on hover for collapsed items */
body.sidebar-collapsed .menu-link:hover::after {
    content: attr(title);
    /* We need to add titles to links for this to work perfectly, but user didn't ask for tooltips yet. */
    /* Alternative: just highlight connection */
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-header img {
    max-width: 160px;
    width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
}

.user-info {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), #c084fc);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.2rem;
    color: white;
}

.user-details h3 {
    font-size: 0.9rem;
    font-weight: 600;
}

.user-details p {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.sidebar-menu {
    padding: 1rem 0;
    flex: 1;
    overflow-y: auto;
}

.menu-item {
    padding: 0 1rem;
    margin-bottom: 0.5rem;
}

.menu-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0.5rem 1rem;
    font-weight: 600;
}

.menu-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: var(--text-main);
    text-decoration: none;
    border-radius: 0.5rem;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.menu-link:hover,
.menu-link.active {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
}

.submenu {
    padding-left: 1.5rem;
    margin-top: 0.25rem;
}

.submenu .menu-link {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.submenu .menu-link:hover,
.submenu .menu-link.active {
    color: var(--primary);
    background: transparent;
}

.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 2rem;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
}

/* Tables */
.table-container {
    background: rgba(30, 41, 59, 0.4);
    border-radius: 0.75rem;
    border: 1px solid var(--border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    background: rgba(15, 23, 42, 0.4);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

td {
    color: var(--text-main);
    font-size: 0.9rem;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

.btn-sm {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
}

.actions {
    display: flex;
    gap: 0.5rem;
}

.btn-edit {
    color: #60a5fa;
    text-decoration: none;
    font-weight: 500;
}

.btn-edit:hover {
    text-decoration: underline;
}

.logout-container {
    padding: 1rem;
    border-top: 1px solid var(--border);
}

.logout-link {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem;
    color: #fca5a5;
    text-decoration: none;
    border-radius: 0.5rem;
    background: rgba(239, 68, 68, 0.1);
    transition: all 0.2s;
    font-weight: 500;
}

.logout-link:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* Mobile Responsiveness */
.mobile-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 90;
    display: none;
    backdrop-filter: blur(4px);
    transition: all 0.3s;
}

.mobile-overlay.active {
    display: block;
}

.btn-mobile-menu {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 1.5rem;
    cursor: pointer;
    margin-right: 1rem;
    padding: 0.5rem;
}

@media (max-width: 768px) {
    .dashboard-container {
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        left: -270px;
        /* Hide completely */
        top: 0;
        bottom: 0;
        transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    }

    .sidebar.active {
        left: 0;
    }

    .main-content {
        margin-left: 0;
        width: 100%;
        padding: 1.5rem;
    }

    .btn-mobile-menu {
        display: flex;
        position: fixed;
        bottom: 2rem;
        right: 2rem;
        z-index: 999;
        background: var(--primary);
        color: white;
        width: 3.5rem;
        height: 3.5rem;
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        font-size: 1.25rem;
        transition: transform 0.2s;
    }

    .btn-mobile-menu:active {
        transform: scale(0.95);
    }

    .page-header {
        align-items: center;
        margin-bottom: 1.5rem;
        /* Ensure title is visible even if we removed the button from flow */
        min-height: 3.5rem;
        display: flex;
    }

    .page-title {
        font-size: 1.25rem;
        /* No extra margin needed if button is bottom-right */
    }

    /* CARD VIEW FOR TABLES */
    .table-container {
        background: transparent;
        border: none;
        overflow: visible;
    }

    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
    }

    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    tr {
        margin-bottom: 1rem;
        background: rgba(30, 41, 59, 0.4);
        border: 1px solid var(--border);
        border-radius: 0.75rem;
        padding: 1rem;
    }

    td {
        border: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        position: relative;
        padding-left: 50%;
        text-align: right;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.75rem 0;
    }

    td:last-child {
        border-bottom: none;
    }

    td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        text-align: left;
        font-size: 0.85rem;
    }

    /* Adjust cards for mobile */
    .card {
        padding: 1.5rem;
    }

    .form-group label {
        font-size: 0.9rem;
    }
}

/* Prevenir zoom via CSS */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}