:root {
    --primary: #260559;
    --accent: #4C00FF;
    --bg-body: #F7F7F9;
    --bg-white: #FFFFFF;
    --text-main: #191825;
    --text-muted: #5C5B6B;
    --border-color: #E2E2E8;
    --gold: #FFD600;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-white);
    color: var(--text-main);
    font-size: 14px;
    line-height: 1.45;
}

/* Top Navbar */
.topbar {
    height: 60px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-white);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 32px; height: 100%; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--text-main); text-decoration: none; }
.brand img { max-height: 36px; width: auto; }
.brand-dot { width: 12px; height: 12px; border-radius: 3px; background: var(--accent); display: inline-block; }

.nav-tabs { display: flex; gap: 24px; height: 100%; }
.nav-tab {
    display: flex;
    align-items: center;
    height: 100%;
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 500;
    border-bottom: 3px solid transparent;
    transition: all 0.15s;
}
.nav-tab:hover { color: var(--text-main); }
.nav-tab.active { color: var(--text-main); font-weight: 600; border-bottom-color: var(--primary); }

.topbar-right { display: flex; align-items: center; gap: 16px; }
.session-pill {
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-body);
    padding: 4px 10px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}
.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #D5E8EB;
    color: #103C42;
    font-weight: 700;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Main Workspace Layout */
.workspace { display: flex; min-height: calc(100vh - 60px); }
.sidebar {
    width: 240px;
    background: var(--bg-body);
    border-right: 1px solid var(--border-color);
    padding: 20px 14px;
    flex-shrink: 0;
}
.btn-start {
    display: block;
    width: 100%;
    background: var(--primary);
    color: #fff;
    text-align: center;
    padding: 10px 16px;
    border-radius: 4px;
    font-weight: 600;
    text-decoration: none;
    margin-bottom: 22px;
    border: none;
    cursor: pointer;
}
.btn-start:hover { opacity: 0.92; }

.sidebar-section { margin-bottom: 22px; }
.sidebar-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0 10px 8px;
}
.sidebar-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border-radius: 4px;
    color: var(--text-main);
    text-decoration: none;
    margin-bottom: 2px;
    font-weight: 400;
}
.sidebar-link:hover { background: #EBEBF0; }
.sidebar-link.active { background: #E3E3EA; font-weight: 600; }
.count-badge { font-size: 11px; color: var(--text-muted); }

/* Elementos exclusivos de móvil (OCULTOS en escritorio) */
.mobile-filter-btn,
.sidebar-overlay,
.sidebar-close-btn {
    display: none !important;
}

/* Content Area */
.main-content { flex: 1; padding: 32px 40px; max-width: 1280px; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.page-title { font-size: 26px; font-weight: 500; letter-spacing: -0.02em; }

/* Filter Bar */
.filter-bar { display: flex; gap: 12px; margin-bottom: 20px; align-items: center; flex-wrap: wrap; }
.search-input {
    width: 320px;
    padding: 8px 12px;
    border: 1px solid #C4C4CE;
    border-radius: 4px;
    font-size: 14px;
}
.search-input:focus { outline: none; border-color: var(--accent); }
.btn-outline {
    background: #fff;
    border: 1px solid #C4C4CE;
    padding: 8px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-main);
    text-decoration: none;
}
.btn-outline:hover { background: var(--bg-body); }

/* Contracts Table */
.table-wrap { border-top: 1px solid var(--border-color); }
table { width: 100%; border-collapse: collapse; }
th {
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    padding: 12px 10px;
    border-bottom: 1px solid var(--border-color);
}
td { padding: 14px 10px; border-bottom: 1px solid var(--border-color); vertical-align: middle; }
tr:hover td { background-color: #FAFAFC; }

.star-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    color: #9E9EA8;
    line-height: 1;
}
.star-btn.active { color: #F5B400; }

.contract-title { font-weight: 600; color: var(--text-main); font-size: 14px; display: block; }
.contract-sub { font-size: 12px; color: var(--text-muted); display: block; margin-top: 2px; }

.tag {
    display: inline-block;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: #EFEFF5;
    color: var(--text-main);
    margin-right: 4px;
    margin-bottom: 2px;
    font-weight: 500;
}
.tag-accent { background: #EDE7FF; color: var(--accent); }

.btn-use {
    display: inline-block;
    background: var(--primary);
    color: #fff;
    padding: 7px 18px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 13px;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-use:hover { background: var(--accent); }

.menu-wrap { position: relative; display: inline-block; margin-left: 6px; }
.dots-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    padding: 4px 8px;
    color: var(--text-muted);
    border-radius: 4px;
}
.dots-btn:hover { background: #EBEBF0; }
.dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: 30px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.08);
    min-width: 170px;
    z-index: 30;
}
.dropdown.show { display: block; }
.dropdown button, .dropdown a {
    display: block;
    width: 100%;
    text-align: left;
    padding: 9px 14px;
    border: none;
    background: none;
    font-size: 13px;
    color: var(--text-main);
    cursor: pointer;
    text-decoration: none;
}
.dropdown button:hover, .dropdown a:hover { background: var(--bg-body); }

/* Login Box */
.login-page {
    min-height: 100vh;
    background: var(--bg-body);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.login-card {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 36px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.04);
}
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #C4C4CE;
    border-radius: 4px;
    font-size: 14px;
}
.alert { padding: 10px 14px; border-radius: 4px; margin-bottom: 16px; font-size: 13px; }
.alert-danger { background: #FDECEA; color: #A61B1B; border: 1px solid #F5C2C0; }
.alert-success { background: #E8F5E9; color: #1B5E20; border: 1px solid #C8E6C9; }

/* Admin Cards & Grids */
.admin-tabs { display: flex; gap: 8px; border-bottom: 1px solid var(--border-color); margin-bottom: 24px; }
.admin-tab {
    padding: 10px 18px;
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 3px solid transparent;
}
.admin-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.card-box {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 20px;
    margin-bottom: 24px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.checkbox-group { display: flex; flex-wrap: wrap; gap: 12px; padding: 8px 0; }
.checkbox-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-body);
    padding: 6px 12px;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    font-size: 13px;
    cursor: pointer;
}

/* Timeout Modal */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(25,24,37,0.55);
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal-backdrop.show { display: flex; }
.modal-box {
    background: #fff;
    padding: 28px;
    border-radius: 8px;
    max-width: 380px;
    width: 90%;
    text-align: center;
    box-shadow: 0 12px 32px rgba(0,0,0,0.18);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #191825;
    color: #fff;
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 13px;
    display: none;
    z-index: 90;
}

/* =========================================
   RESPONSIVE MÓVIL Y TABLET (<= 768px)
   ========================================= */
@media (max-width: 768px) {
    .topbar {
        padding: 8px 12px;
        height: auto;
        min-height: 56px;
        flex-wrap: wrap;
        gap: 8px;
    }
    .topbar-left { gap: 14px; }
    .nav-tabs { gap: 12px; }
    .nav-tab { font-size: 13px; padding: 6px 0; }
    .topbar-right { gap: 8px; }
    .user-name-label, .session-pill { display: none; }

    /* Botón y Drawer móvil */
    .mobile-filter-btn {
        display: inline-flex !important;
        align-items: center;
        gap: 8px;
        background: var(--bg-body);
        border: 1px solid #C4C4CE;
        padding: 8px 14px;
        border-radius: 4px;
        font-weight: 600;
        font-size: 13px;
        color: var(--text-main);
        cursor: pointer;
    }
    .sidebar-overlay.show {
        display: block !important;
        position: fixed;
        inset: 0;
        background: rgba(25, 24, 37, 0.45);
        z-index: 55;
    }
    .sidebar {
        position: fixed;
        top: 0;
        left: -270px;
        width: 260px;
        height: 100vh;
        z-index: 60;
        transition: left 0.22s ease;
        overflow-y: auto;
        box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    }
    .sidebar.open { left: 0; }
    .sidebar-close-btn {
        display: block !important;
        background: none;
        border: none;
        font-size: 20px;
        color: var(--text-muted);
        cursor: pointer;
        margin-left: auto;
    }

    /* Contenido y buscador */
    .main-content { padding: 18px 14px; width: 100%; }
    .page-header { margin-bottom: 14px; }
    .page-title { font-size: 21px; }
    .filter-bar { gap: 8px; }
    .search-input { width: 100%; flex: 1 1 100%; }

    /* Tabla convertida a tarjetas apiladas */
    .table-wrap { border-top: none; }
    table, thead, tbody, th, td, tr { display: block; width: 100%; }
    thead { display: none; }

    tbody tr {
        background: #fff;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        padding: 14px;
        margin-bottom: 12px;
        position: relative;
        box-shadow: 0 1px 4px rgba(0,0,0,0.03);
    }
    tbody td {
        border: none;
        padding: 4px 0;
        text-align: left !important;
    }

    /* Estrella en esquina superior derecha */
    tbody td:first-child {
        position: absolute;
        top: 12px;
        right: 12px;
        width: auto;
        padding: 0;
    }
    tbody td:nth-child(2) {
        padding-right: 28px;
        margin-bottom: 6px;
    }

    /* Botón Use a ancho cómodo */
    tbody td:last-child {
        margin-top: 10px;
        padding-top: 10px;
        border-top: 1px solid var(--bg-body);
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
    }
    tbody td:last-child .btn-use {
        flex: 1;
        text-align: center;
        padding: 10px 14px;
    }

    /* Admin en móvil */
    .grid-2 { grid-template-columns: 1fr; gap: 10px; }
    .admin-tabs {
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    .admin-tab { padding: 10px 12px; font-size: 13px; }
    .login-card { padding: 24px 20px; }
}