:root {
    --primary: #0f766e;
    --primary-dark: #0b5d56;
    --accent: #2563eb;
    --bg: #f1f5f4;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e2e8f0;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* ---------- Login / Registro ---------- */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: 0 10px 30px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 420px;
    padding: 32px;
}

.auth-title {
    text-align: center;
    margin-bottom: 4px;
    color: var(--primary-dark);
}

.auth-subtitle {
    text-align: center;
    color: var(--muted);
    margin-bottom: 24px;
    font-size: 14px;
}

.tabs {
    display: flex;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    padding: 10px 0;
    font-size: 15px;
    cursor: pointer;
    color: var(--muted);
    border-bottom: 3px solid transparent;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ---------- Formularios ---------- */
label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin: 12px 0 4px;
    color: var(--text);
}

input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    color: var(--text);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.btn {
    display: inline-block;
    border: none;
    border-radius: 8px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .15s ease;
}

.btn:hover { opacity: 0.9; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--accent); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; margin-top: 18px; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

.alert {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin: 12px 0;
}
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-success { background: #dcfce7; color: #166534; }

/* ---------- Layout principal (dashboard) ---------- */
.topbar {
    background: var(--primary);
    color: #fff;
    padding: 14px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.topbar h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}

.topbar .btn-outline {
    border-color: rgba(255,255,255,0.5);
    color: #fff;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px;
}

.section { display: none; }
.section.active { display: block; }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}

.section-header h2 { margin: 0; color: var(--primary-dark); }

.search-box { max-width: 320px; }

/* ---------- Tarjetas / Tabla ---------- */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.card h3 {
    margin: 0 0 4px;
    font-size: 16px;
    color: var(--text);
}

.card .subtitle {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 8px;
}

.card .meta {
    font-size: 13px;
    color: var(--muted);
    margin: 2px 0;
}

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-muted { background: #e5e7eb; color: #374151; }

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
}

th, td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

th {
    background: #f8fafc;
    font-weight: 700;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 40px 0;
    font-size: 14px;
}

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}

.modal-overlay.active { display: flex; }

.modal {
    background: #fff;
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 460px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal h3 { margin-top: 0; color: var(--primary-dark); }

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 18px;
}

.autocomplete-results {
    border: 1px solid var(--border);
    border-radius: 8px;
    max-height: 180px;
    overflow-y: auto;
    margin-top: 4px;
    background: #fff;
}

.autocomplete-results div {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

.autocomplete-results div:last-child { border-bottom: none; }
.autocomplete-results div:hover { background: #f1f5f4; }

.hidden { display: none !important; }

.text-muted { color: var(--muted); font-size: 13px; }

.tabs-secondary {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.tabs-secondary button {
    background: #fff;
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
}

.tabs-secondary button.active {
    border-color: var(--primary);
    color: var(--primary);
    background: #f0fdfa;
}

/* ==========================================================================
   TOPBAR con menú de perfil (dashboard)
   ========================================================================== */
.topbar {
    position: sticky;
    top: 0;
    z-index: 160;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.hamburger-btn {
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.28);
    color: #fff;
    width: 38px;
    height: 38px;
    border-radius: 9px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s ease;
}
.hamburger-btn:hover { background: rgba(255,255,255,0.24); }

.topbar-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.profile-menu { position: relative; }

.profile-trigger {
    display: flex;
    align-items: center;
    gap: 9px;
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.28);
    color: #fff;
    padding: 5px 12px 5px 6px;
    border-radius: 24px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: background .15s ease;
}
.profile-trigger:hover { background: rgba(255,255,255,0.24); }

.profile-avatar {
    width: 27px;
    height: 27px;
    border-radius: 50%;
    background: #fff;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.profile-name {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-trigger .caret {
    font-size: 10px;
    opacity: .85;
    transition: transform .18s ease;
}
.profile-menu.open .profile-trigger .caret { transform: rotate(180deg); }

.profile-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 14px 32px rgba(15,23,42,0.18);
    min-width: 200px;
    padding: 6px;
    display: none;
    flex-direction: column;
    gap: 2px;
    z-index: 200;
    border: 1px solid var(--border);
}
.profile-menu.open .profile-dropdown { display: flex; }

.profile-dropdown button {
    background: none;
    border: none;
    text-align: left;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 9px;
}
.profile-dropdown button:hover { background: var(--bg); }
.profile-dropdown .dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 4px;
}
.profile-dropdown button.danger { color: var(--danger); }
.profile-dropdown button.danger:hover { background: #fee2e2; }

/* ==========================================================================
   SIDEBAR (navegación vertical del dashboard)
   ========================================================================== */
.app-body {
    display: flex;
    align-items: stretch;
}

.sidebar {
    width: 252px;
    flex-shrink: 0;
    background: #fff;
    border-right: 1px solid var(--border);
    transition: width .2s ease, border-color .2s ease;
    overflow: hidden;
}

.sidebar.collapsed {
    width: 0;
    border-right-color: transparent;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    padding: 16px 12px;
    gap: 3px;
    width: 252px;
}

.sidebar-nav .nav-group-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--muted);
    padding: 14px 10px 6px;
}
.sidebar-nav .nav-group-label:first-child { padding-top: 4px; }

.sidebar-nav button.nav-btn {
    display: flex;
    align-items: center;
    gap: 11px;
    background: none;
    border: 1px solid transparent;
    padding: 11px 12px;
    border-radius: 9px;
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--muted);
    text-align: left;
    width: 100%;
    white-space: nowrap;
}
.sidebar-nav button.nav-btn:hover { background: var(--bg); color: var(--text); }
.sidebar-nav button.nav-btn.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 10px rgba(15,118,110,0.25);
}
.sidebar-nav button.nav-btn .nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}
.sidebar-nav button.nav-btn .nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.sidebar-nav button.nav-btn .nav-badge {
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 20px;
    min-width: 18px;
    text-align: center;
    flex-shrink: 0;
}
.sidebar-nav button.nav-btn.active .nav-badge { background: rgba(255,255,255,0.9); color: var(--primary-dark); }
.sidebar-nav button.nav-btn .nav-badge:empty { display: none; }

.main-area {
    flex: 1;
    min-width: 0;
}

@media (max-width: 860px) {
    .app-body { position: relative; }
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 150;
        padding-top: 62px;
        box-shadow: 4px 0 24px rgba(15,23,42,0.18);
    }
    .sidebar.collapsed { box-shadow: none; }
    .profile-name { display: none; }
}

/* ==========================================================================
   MI PERFIL (modal)
   ========================================================================== */
.perfil-section-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--muted);
    margin: 18px 0 8px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}
.perfil-section-title:first-of-type { border-top: none; padding-top: 0; margin-top: 6px; }

/* ==========================================================================
   HISTORIAL DE TRANSACCIONES
   ========================================================================== */
.historial-filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.historial-filters select,
.historial-filters input[type="date"] {
    width: auto;
    min-width: 150px;
}

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

.trx-id {
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 12.5px;
    font-weight: 700;
    color: var(--primary-dark);
    background: #f0fdfa;
    padding: 2px 8px;
    border-radius: 6px;
    white-space: nowrap;
}
