/* ============================================================================
   Creaciones Vida — Sistema de Gestión
   Diseño limpio y profesional con accesibilidad mejorada
   ============================================================================ */

/* === Variables base === */
:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #e0e7ff;
    --secondary: #db2777;
    --success: #059669;
    --success-light: #d1fae5;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --info: #0284c7;
    --info-light: #e0f2fe;

    --bg: #f9fafb;
    --card: #ffffff;
    --border: #e5e7eb;
    --text: #111827;
    --text-muted: #6b7280;
    --text-light: #9ca3af;

    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 20px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);

    --sidebar-width: 260px;
    --sidebar-bg: #1f2937;
    --sidebar-bg-dark: #111827;
    --sidebar-text: #d1d5db;
    --sidebar-text-bright: #ffffff;
    --sidebar-accent: #818cf8;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

code {
    background: var(--bg);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-size: 0.9em;
    color: var(--text);
    font-weight: 500;
}

/* === Layout === */
body { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex; flex-direction: column;
    position: fixed; height: 100vh; left: 0; top: 0;
    z-index: 100;
}

.sidebar-header {
    padding: 1.25rem 1.25rem;
    display: flex; align-items: center; gap: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-logo {
    width: 40px; height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    color: white; font-size: 1.1rem;
    flex-shrink: 0;
}

.sidebar-brand h2 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--sidebar-text-bright);
    line-height: 1.2;
}

.sidebar-brand p {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 0.1rem;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0.75rem;
    overflow-y: auto;
}

.nav-item {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.7rem 0.85rem;
    margin-bottom: 0.2rem;
    color: var(--sidebar-text);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.15s;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--sidebar-text-bright);
}

.nav-item.active {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
}

.nav-item i {
    width: 20px;
    text-align: center;
    font-size: 1rem;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex; align-items: center; gap: 0.75rem;
}

.user-info {
    flex: 1; display: flex; align-items: center; gap: 0.6rem;
    min-width: 0;
}

.user-avatar {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, var(--secondary), var(--primary));
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: white; font-weight: 700; font-size: 0.9rem;
    flex-shrink: 0;
}

.user-name {
    font-size: 0.85rem;
    color: var(--sidebar-text-bright);
    font-weight: 600;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-role {
    font-size: 0.7rem;
    color: var(--text-light);
}

.btn-logout {
    color: var(--text-light);
    padding: 0.5rem 0.6rem;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    min-height: 36px;
    min-width: 36px;
    display: flex; align-items: center; justify-content: center;
}

.btn-logout:hover {
    background: var(--danger);
    color: white;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex; flex-direction: column;
    min-height: 100vh;
}

.topbar {
    background: var(--card);
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    position: sticky; top: 0; z-index: 50;
}

.menu-toggle {
    display: none;
    background: var(--primary); border: none;
    color: white; font-size: 1.2rem;
    cursor: pointer;
    width: 40px; height: 40px;
    border-radius: var(--radius-sm);
    margin-right: 1rem;
}

.topbar-title h1 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
}

.topbar-actions {
    margin-left: auto;
    display: flex; gap: 0.5rem; align-items: center;
}

.btn-logout-header {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.5rem 0.9rem;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.9rem;
    min-height: 40px;
}

.btn-logout-header:hover {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.content {
    padding: 2rem;
    flex: 1;
    max-width: 1400px;
    width: 100%;
}

/* === Welcome banner === */
.welcome-banner {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    padding: 1.75rem 2rem;
    border-radius: var(--radius-lg);
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-md);
}

.welcome-banner h1 {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.welcome-banner p {
    opacity: 0.9;
    font-size: 1rem;
}

/* === Stats Grid === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--card);
    padding: 1.25rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex; align-items: center; gap: 1rem;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid var(--border);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 48px; height: 48px;
    border-radius: var(--radius-sm);
    background: var(--primary-light);
    color: var(--primary);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.stat-card.success .stat-icon { background: var(--success-light); color: var(--success); }
.stat-card.warning .stat-icon { background: var(--warning-light); color: var(--warning); }
.stat-card.danger .stat-icon { background: var(--danger-light); color: var(--danger); }

.stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.1;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.1rem;
}

/* === Dashboard grid === */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

/* === Cards === */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1.25rem;
    overflow: hidden;
    border: 1px solid var(--border);
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: 0.5rem;
    background: linear-gradient(180deg, #fafbff 0%, transparent 100%);
}

.card-header h2 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
    display: flex; align-items: center; gap: 0.5rem;
}

.card-header h2 i {
    color: var(--primary);
    font-size: 0.95rem;
}

.card-body { padding: 1.25rem; }

/* === Page header === */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.page-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    display: flex; align-items: center; gap: 0.6rem;
    color: var(--text);
}

.page-header h1 i {
    color: var(--primary);
    font-size: 1.4rem;
}

.page-header > div {
    display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap;
}

/* === Buttons === */
.btn {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.55rem 1rem;
    background: var(--card); color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem; font-weight: 500; cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    font-family: inherit;
    min-height: 40px;
}

.btn:hover { background: var(--bg); transform: translateY(-1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; min-height: 32px; }

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    color: white;
}

.btn-success {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.btn-danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.btn-secondary {
    background: var(--bg);
}

/* === Forms === */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem 1.25rem;
}

.form-group { display: flex; flex-direction: column; }
.form-group-wide { grid-column: 1 / -1; }

.form-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.3rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: inherit;
    background: var(--card);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
    min-height: 42px;
}

.form-group textarea {
    min-height: 90px;
    resize: vertical;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.discount-input { max-width: 160px; }

.form-actions {
    display: flex; gap: 0.5rem;
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

.search-form { display: flex; gap: 0.5rem; flex: 1; flex-wrap: wrap; }
.search-input { flex: 1; min-width: 200px; max-width: 500px; }

/* === Tables === */
.table {
    width: 100%; border-collapse: collapse;
    font-size: 0.9rem;
}

.table th, .table td {
    padding: 0.75rem 0.85rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.table th {
    background: var(--bg);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.05em;
}

.table tbody tr:hover { background: var(--bg); }
.table tr.row-active { background: var(--warning-light); }
.table tr.row-warning { background: var(--danger-light); }

.text-right { text-align: right; }
.text-muted { color: var(--text-muted); font-size: 0.9rem; }
.text-warning { color: var(--danger); font-weight: 600; }

/* === Badges === */
.badge {
    display: inline-block;
    padding: 0.25rem 0.65rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-info { background: var(--info-light); color: var(--info); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-secondary { background: var(--bg); color: var(--text-muted); }

/* === Alerts === */
.alert {
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    border: 1px solid;
    display: flex; align-items: center; gap: 0.5rem;
    font-size: 0.95rem;
    font-weight: 500;
}

.alert-success { background: var(--success-light); color: var(--success); border-color: var(--success); }
.alert-error { background: var(--danger-light); color: var(--danger); border-color: var(--danger); }
.alert-warning { background: var(--warning-light); color: var(--warning); border-color: var(--warning); }
.alert-info { background: var(--info-light); color: var(--info); border-color: var(--info); }

/* === Empty state === */
.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.empty-state i { font-size: 3rem; opacity: 0.3; display: block; margin-bottom: 0.75rem; }

/* === Info grid === */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 0.5rem 1.5rem;
    padding: 1rem 0;
}

.info-grid > div { padding: 0.4rem 0; font-size: 0.95rem; }

/* === Totals === */
.totals {
    max-width: 420px;
    margin-left: auto;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.total-row {
    display: flex; justify-content: space-between;
    padding: 0.5rem 0;
    font-size: 0.95rem;
}

.total-grand {
    border-top: 2px solid var(--border);
    margin-top: 0.5rem;
    padding-top: 0.75rem;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--primary-dark);
}

/* === Tabs === */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.tab {
    padding: 0.75rem 1.25rem;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    font-weight: 500;
    font-size: 0.95rem;
}

.tab:hover { color: var(--text); background: var(--bg); }
.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

/* === Event list === */
.event-list { list-style: none; }
.event-list li {
    display: flex; align-items: center; gap: 0.85rem;
    padding: 0.75rem 0; border-bottom: 1px solid var(--border);
    font-size: 0.95rem;
}
.event-list li:last-child { border-bottom: none; }

.event-time {
    font-weight: 600; min-width: 90px;
    color: var(--primary); font-size: 1rem;
}

.event-content { flex: 1; }
.event-content small {
    color: var(--text-muted);
    display: block;
    font-size: 0.8rem;
}

/* === Calendar === */
.calendar { width: 100%; }
.calendar-header, .calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.calendar-header > div {
    text-align: center; font-weight: 600; padding: 0.5rem;
    background: var(--bg); color: var(--text-muted);
    font-size: 0.8rem; text-transform: uppercase;
    border: 1px solid var(--border);
}
.calendar-day {
    min-height: 100px;
    padding: 0.4rem;
    border: 1px solid var(--border);
    background: var(--card);
    overflow: hidden;
}
.calendar-day.empty { background: var(--bg); }
.calendar-day.today { background: var(--warning-light); border: 2px solid var(--warning); }
.day-number { font-weight: 600; font-size: 0.9rem; margin-bottom: 0.3rem; }
.calendar-day.today .day-number { color: var(--warning); }
.event-pill {
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
    background: var(--primary);
    color: white;
    border-radius: 4px;
    margin-bottom: 0.15rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.event-pill small { opacity: 0.85; }
.event-more { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.2rem; }

/* === Distribution bars === */
.dist-row {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.4rem 0;
}
.dist-label { min-width: 120px; font-size: 0.85rem; }
.dist-bar { flex: 1; height: 18px; background: var(--bg); border-radius: 9px; overflow: hidden; border: 1px solid var(--border); }
.dist-fill { height: 100%; background: var(--primary); border-radius: 9px; transition: width 0.3s; }
.dist-fill.estado-en_proceso { background: var(--warning); }
.dist-fill.estado-lista { background: var(--success); }
.dist-fill.estado-entregada { background: var(--info); }
.dist-fill.estado-cancelada { background: var(--danger); }
.dist-value { min-width: 30px; text-align: right; font-weight: 600; }

/* === Forms (status, pago, movimiento) === */
.status-form, .pago-form, .movimiento-form {
    background: var(--bg);
    padding: 1rem;
    border-radius: var(--radius-sm);
    display: flex; flex-wrap: wrap; gap: 0.5rem;
    align-items: end;
    margin: 0.5rem 0;
    border: 1px solid var(--border);
}

/* === Filter form === */
.filter-form {
    display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap;
}
.filter-form input {
    padding: 0.4rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    min-height: 38px;
}

/* === Mini chart === */
.mini-chart {
    display: flex; align-items: end; gap: 2px;
    height: 180px; padding: 1rem 0;
    overflow-x: auto;
}
.mini-chart .bar {
    min-width: 20px;
    background: linear-gradient(180deg, var(--primary) 0%, var(--secondary) 100%);
    border-radius: 4px 4px 0 0;
    position: relative;
    transition: height 0.3s;
    flex: 0 0 auto;
}
.mini-chart .bar small {
    position: absolute;
    bottom: -18px; left: 50%; transform: translateX(-50%);
    font-size: 0.65rem; color: var(--text-muted);
    white-space: nowrap;
    font-weight: 500;
}

/* === Accessibility bar === */
.accessibility-bar {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex; flex-direction: column;
    gap: 0.5rem;
    z-index: 1000;
}

.access-button {
    width: 44px; height: 44px;
    background: var(--primary);
    color: white;
    border: 2px solid white;
    border-radius: 50%;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    display: flex; align-items: center; justify-content: center;
}

.access-button:hover { background: var(--primary-dark); transform: scale(1.05); }
.access-button:focus { outline: 3px solid var(--secondary); outline-offset: 2px; }

/* === High contrast mode === */
body.high-contrast {
    --bg: #000000;
    --card: #1a1a1a;
    --text: #ffffff;
    --text-muted: #d0d0d0;
    --border: #ffffff;
    --primary: #ffff00;
    --secondary: #00ffff;
    --success: #00ff00;
    --warning: #ff8800;
    --danger: #ff0040;
    --sidebar-bg: #000000;
    --sidebar-text: #ffffff;
    --sidebar-text-bright: #ffff00;
}

body.high-contrast .sidebar { border-right: 2px solid white; }
body.high-contrast .nav-item { border: 1px solid white; }
body.high-contrast .nav-item.active { background: var(--primary); color: #000; }
body.high-contrast .btn { background: var(--primary); color: #000; border: 2px solid white; }
body.high-contrast .stat-card { background: #1a1a1a; border: 2px solid white; }
body.high-contrast input, body.high-contrast select, body.high-contrast textarea {
    background: #000 !important; color: white !important; border: 2px solid white !important;
}

/* === Modo de fuente grande === */
body.large-font { font-size: 17px; line-height: 1.7; }
body.large-font .stat-value { font-size: 1.8rem; }
body.large-font .stat-icon { width: 54px; height: 54px; font-size: 1.4rem; }

body.extra-large-font { font-size: 19px; line-height: 1.7; }
body.extra-large-font .stat-value { font-size: 2rem; }
body.extra-large-font .stat-icon { width: 58px; height: 58px; font-size: 1.5rem; }

/* === Responsive === */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); transition: transform 0.3s; }
    body.sidebar-open .sidebar { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .menu-toggle { display: flex; align-items: center; justify-content: center; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .info-grid { grid-template-columns: 1fr; }
    .calendar-day { min-height: 60px; }
    .content { padding: 1rem; }
    .welcome-banner { padding: 1.25rem; }
    .welcome-banner h1 { font-size: 1.3rem; }
}
