/* ==========================================================================
   Variables y Reseteo
   ========================================================================== */
:root {
    --color-primary: #075e54;
    --color-primary-dark: #054943;
    --color-secondary: #25d366;
    --color-accent: #128c7e;
    --color-background: #f0f2f5;
    --color-card-bg: #ffffff;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-border: #e2e8f0;
    --color-border-light: #f1f5f9;
    --color-danger: #dc2626;
    --color-success: #16a34a;
    --color-warning: #f59e0b;
    --color-info: #3b82f6;

    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 25px -5px rgb(0 0 0 / 0.12), 0 8px 10px -6px rgb(0 0 0 / 0.08);
    --radius: 0.5rem; /* 8px */
    --radius-lg: 0.875rem; /* 14px */
    --sidebar-width: 240px;
}

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

html { scroll-behavior: smooth; }

body {
    font-family: var(--font-sans);
    background-color: var(--color-background);
    color: var(--color-text);
    display: flex;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

a { color: inherit; }

/* ==========================================================================
   Layout Principal (Sidebar, Topbar, Content)
   ========================================================================== */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: linear-gradient(180deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform .25s ease;
}
.sidebar-logo {
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, .1);
}
.sidebar-logo h1 {
    color: #fff;
    font-size: 18px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}
.sidebar-logo p {
    color: rgba(255, 255, 255, .6);
    font-size: 11px;
    margin-top: 2px;
}
.sidebar nav { padding: 12px 0; flex: 1; overflow-y: auto; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: rgba(255, 255, 255, .8);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background .15s, color .15s;
    border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.nav-item.active {
    background: rgba(255, 255, 255, .15);
    color: #fff;
    border-left-color: var(--color-secondary);
}
.nav-item .icon { width: 20px; height: 20px; stroke-width: 2; }
.nav-section {
    padding: 16px 20px 4px;
    font-size: 11px;
    font-weight: 700;
    color: rgba(255, 255, 255, .4);
    text-transform: uppercase;
    letter-spacing: .08em;
}
.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255, 255, 255, .1);
    font-size: 12px;
    color: rgba(255, 255, 255, .6);
}

.sidebar-toggle {
    display: none;
    position: fixed;
    top: 14px;
    left: 16px;
    z-index: 110;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    background: var(--color-primary);
    color: #fff;
    border: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-md);
}
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .45);
    z-index: 99;
}

.main {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0;
}
.topbar {
    background-color: var(--color-card-bg);
    border-bottom: 1px solid var(--color-border);
    padding: 14px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar h2 { font-size: 18px; font-weight: 600; color: var(--color-text); }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.content { padding: 28px; flex: 1; }

/* ==========================================================================
   Componentes UI (Cards, Tables, Buttons, Forms)
   ========================================================================== */
.card {
    background-color: var(--color-card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 24px;
    transition: box-shadow .2s ease;
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-header h3 { font-size: 15px; font-weight: 600; color: var(--color-text); }
.card-header .card-actions { display: flex; gap: 8px; }
.card-body { padding: 20px; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
th {
    background-color: #f8fafc;
    text-align: left;
    padding: 10px 16px;
    color: var(--color-text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}
td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border-light);
    vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background-color: #fafbff; }
.empty { text-align: center; padding: 40px; color: var(--color-text-muted); font-size: 14px; }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    text-transform: capitalize;
}
.badge-green { background-color: #dcfce7; color: #15803d; }
.badge-blue { background-color: #dbeafe; color: #1d4ed8; }
.badge-orange { background-color: #ffedd5; color: #c2410c; }
.badge-red { background-color: #fee2e2; color: var(--color-danger); }
.badge-gray { background-color: #f1f5f9; color: #475569; }
.badge-purple { background-color: #ede9fe; color: #6d28d9; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    transition: all .2s;
}
.btn:hover { filter: brightness(95%); transform: translateY(-1px); }
.btn:active { filter: brightness(90%); transform: scale(0.98); }
.btn-primary { background-color: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.btn-primary:hover { background-color: var(--color-primary-dark); border-color: var(--color-primary-dark); }
.btn-secondary { background-color: var(--color-secondary); color: #fff; border-color: var(--color-secondary); }
.btn-green { background-color: var(--color-success); color: #fff; border-color: var(--color-success); }
.btn-outline { background-color: var(--color-card-bg); color: #475569; border: 1px solid var(--color-border); }
.btn-outline:hover { background-color: #f8fafc; border-color: #d1d5db; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-danger { background-color: var(--color-danger); color: #fff; border-color: var(--color-danger); }

.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #374151;
    margin-bottom: 6px;
}
.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    color: var(--color-text);
    outline: none;
    background-color: var(--color-card-bg);
    transition: border-color .2s, box-shadow .2s;
}
.form-control:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(7, 94, 84, .1);
}
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    margin-bottom: 20px;
    border: 1px solid transparent;
    display: flex;
    align-items: center;
    gap: 8px;
}
.alert-success { background-color: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.alert-danger, .alert-error { background-color: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.alert-info { background-color: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }

/* ==========================================================================
   Páginas Específicas y Utilitarios
   ========================================================================== */
/* --- Login / Register (split screen) --- */
.auth-page {
    width: 100%;
    min-height: 100vh;
    display: flex;
    background-color: var(--color-card-bg);
}
.auth-visual {
    flex: 1 1 46%;
    max-width: 560px;
    background: linear-gradient(160deg, var(--color-primary) 0%, var(--color-accent) 55%, var(--color-secondary) 130%);
    color: #fff;
    padding: 56px 48px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
}
.auth-visual::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: radial-gradient(circle at 1px 1px, rgba(255,255,255,.18) 1px, transparent 0);
    background-size: 22px 22px;
    opacity: .5;
}
.auth-visual > * { position: relative; z-index: 1; }
.auth-visual-brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; }
.auth-visual h2 { font-size: 30px; line-height: 1.3; margin: 40px 0 16px; font-weight: 700; }
.auth-visual p.lead { font-size: 15px; color: rgba(255,255,255,.85); max-width: 380px; }
.auth-benefits { list-style: none; margin-top: 32px; display: flex; flex-direction: column; gap: 16px; }
.auth-benefits li { display: flex; align-items: flex-start; gap: 12px; font-size: 14px; color: rgba(255,255,255,.95); }
.auth-benefits li .check {
    flex-shrink: 0;
    width: 24px; height: 24px;
    border-radius: 50%;
    background: rgba(255,255,255,.18);
    display: flex; align-items: center; justify-content: center;
}
.auth-quote {
    background: rgba(255,255,255,.12);
    border-radius: var(--radius);
    padding: 16px 18px;
    font-size: 13px;
    color: rgba(255,255,255,.9);
    backdrop-filter: blur(2px);
}
.auth-quote strong { display: block; margin-top: 8px; font-size: 12px; color: #fff; }

.auth-form-side {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    background-image: radial-gradient(circle at 1px 1px, var(--color-border) 1px, transparent 0);
    background-size: 20px 20px;
}
.auth-card {
    background: var(--color-card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 40px;
    width: 400px;
    max-width: 95vw;
}
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo h1 { font-size: 24px; color: var(--color-primary); font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px; }
.auth-logo p { color: var(--color-text-muted); font-size: 14px; margin-top: 4px; }
.auth-step-label {
    display: flex; justify-content: space-between; align-items: baseline;
    border-bottom: 1px solid var(--color-border-light);
    padding-bottom: 6px; margin-bottom: 16px;
}
.auth-step-label p { font-size: 13px; font-weight: 600; color: var(--color-text); }
.auth-step-label span { font-size: 11px; color: var(--color-text-muted); }

@media (max-width: 900px) {
    .auth-visual { display: none; }
    .auth-form-side { flex: 1 1 100%; }
}

/* --- Chat --- */
.chat-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 8px;
    word-break: break-word;
}
.chat-bubble.in {
    background-color: var(--color-card-bg);
    border-radius: 0 16px 16px 16px;
    align-self: flex-start;
    box-shadow: var(--shadow-sm);
}
.chat-bubble.out {
    background-color: #dcf8c6;
    border-radius: 16px 0 16px 16px;
    align-self: flex-end;
}
.chat-time { font-size: 11px; color: var(--color-text-muted); margin-top: 4px; text-align: right; }

/* --- Utilitarios --- */
.text-muted { color: var(--color-text-muted); }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.items-center { align-items: center; }
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}
.tag {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 500;
    margin: 2px;
}
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 24px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }

/* ==========================================================================
   Responsive (sidebar colapsable en pantallas pequeñas)
   ========================================================================== */
@media (max-width: 880px) {
    .sidebar-toggle { display: flex; }
    .sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar.open ~ .sidebar-overlay { display: block; }
    .main { margin-left: 0; }
    .topbar { padding-left: 64px; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
