:root {
    --primary: #4f46e5;
    --primary-light: #818cf8;
    --primary-dark: #3730a3;
    --primary-bg: #eef2ff;
    --success: #10b981;
    --success-bg: #d1fae5;
    --danger: #ef4444;
    --danger-bg: #fee2e2;
    --warning: #f59e0b;
    --warning-bg: #fef3c7;
    --info: #06b6d4;
    --info-bg: #cffafe;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --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 -2px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.1);
    --sidebar-width: 260px;
    --header-height: 64px;
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-100);
    color: var(--gray-800);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--primary-dark); }

/* Layout with Sidebar */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--gray-900);
    color: white;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    overflow-y: auto;
}
.sidebar-brand {
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}
.sidebar-brand-text {
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}
.sidebar-nav {
    padding: 1rem 0.75rem;
    flex: 1;
}
.sidebar-section {
    margin-bottom: 1.5rem;
}
.sidebar-section-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-400);
    padding: 0 0.75rem;
    margin-bottom: 0.5rem;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--gray-300);
    font-size: 0.875rem;
    font-weight: 500;
    transition: var(--transition);
    margin-bottom: 2px;
}
.sidebar-link:hover {
    background: rgba(255,255,255,0.08);
    color: white;
    text-decoration: none;
}
.sidebar-link.active {
    background: var(--primary);
    color: white;
}
.sidebar-link-icon {
    width: 20px;
    text-align: center;
    font-size: 1rem;
}
.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.sidebar-avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}
.sidebar-user-info { flex: 1; }
.sidebar-user-name { font-size: 0.875rem; font-weight: 600; }
.sidebar-user-role { font-size: 0.75rem; color: var(--gray-400); }
.sidebar-logout {
    color: var(--gray-400);
    font-size: 1.125rem;
    padding: 0.25rem;
    border-radius: 6px;
    transition: var(--transition);
}
.sidebar-logout:hover { color: var(--danger); background: rgba(239,68,68,0.1); }

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

/* Top Header */
.top-header {
    height: var(--header-height);
    background: white;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
}
.top-header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.mobile-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--gray-600);
    cursor: pointer;
    padding: 0.25rem;
}
.top-header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.header-badge {
    position: relative;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    color: var(--gray-500);
    cursor: pointer;
    transition: var(--transition);
}
.header-badge:hover { background: var(--gray-100); color: var(--gray-700); }
.header-badge-dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    background: var(--danger);
    border-radius: 50%;
    border: 2px solid white;
}

/* Page Content */
.page-content {
    padding: 2rem;
}

/* Breadcrumbs */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    color: var(--gray-500);
    margin-bottom: 1.5rem;
}
.breadcrumb a { color: var(--gray-500); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb-sep { color: var(--gray-300); }
.breadcrumb-current { color: var(--gray-800); font-weight: 500; }

/* Page Header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.75rem;
    flex-wrap: wrap;
    gap: 1rem;
}
.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -0.025em;
}
.page-header-subtitle {
    font-size: 0.875rem;
    color: var(--gray-500);
    margin-top: 0.25rem;
}

/* Cards */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
    margin-bottom: 1.5rem;
    overflow: hidden;
}
.card-body { padding: 1.5rem; }
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--gray-100);
}
.card-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-800);
}
.card-footer {
    padding: 1rem 1.5rem;
    background: var(--gray-50);
    border-top: 1px solid var(--gray-100);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.75rem;
}
.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 1.5rem;
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    transition: var(--transition);
}
.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}
.stat-icon-blue { background: var(--primary-bg); }
.stat-icon-green { background: var(--success-bg); }
.stat-icon-orange { background: var(--warning-bg); }
.stat-icon-red { background: var(--danger-bg); }
.stat-info { flex: 1; }
.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--gray-900);
    line-height: 1.2;
}
.stat-label {
    font-size: 0.8125rem;
    color: var(--gray-500);
    margin-top: 0.25rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    line-height: 1.5;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-outline {
    background: white;
    border: 1px solid var(--gray-300);
    color: var(--gray-700);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }
.btn-ghost { background: transparent; color: var(--gray-600); }
.btn-ghost:hover { background: var(--gray-100); color: var(--gray-800); box-shadow: none; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.btn-xs { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    justify-content: center;
    border-radius: var(--radius-sm);
}

/* Forms */
.form-group { margin-bottom: 1.25rem; }
.form-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    margin-bottom: 0.375rem;
    color: var(--gray-700);
}
.form-control {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    transition: var(--transition);
    background: white;
    color: var(--gray-800);
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}
.form-control::placeholder { color: var(--gray-400); }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.75rem center; padding-right: 2.5rem; }
textarea.form-control { min-height: 100px; resize: vertical; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    cursor: pointer;
}
.form-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
}

/* Tables */
.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
    padding: 0.875rem 1rem;
    text-align: left;
    font-size: 0.875rem;
}
th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--gray-600);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--gray-200);
}
td { border-bottom: 1px solid var(--gray-100); color: var(--gray-700); }
tr:hover td { background: var(--gray-50); }
tr:last-child td { border-bottom: none; }

/* Alerts */
.alert {
    padding: 1rem 1.25rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.25rem;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border: 1px solid transparent;
}
.alert-success { background: var(--success-bg); color: #065f46; border-color: #a7f3d0; }
.alert-error { background: var(--danger-bg); color: #991b1b; border-color: #fecaca; }
.alert-info { background: var(--info-bg); color: #155e75; border-color: #a5f3fc; }
.alert-warning { background: var(--warning-bg); color: #92400e; border-color: #fde68a; }

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.625rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}
.badge-success { background: var(--success-bg); color: #065f46; }
.badge-danger { background: var(--danger-bg); color: #991b1b; }
.badge-warning { background: var(--warning-bg); color: #92400e; }
.badge-info { background: var(--info-bg); color: #155e75; }
.badge-primary { background: var(--primary-bg); color: var(--primary-dark); }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }

/* Cuidador - Action Grid */
.action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin: 1.5rem 0;
}
.action-card {
    background: white;
    border-radius: var(--radius);
    padding: 1.75rem 1.25rem;
    text-align: center;
    border: 1px solid var(--gray-200);
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    color: var(--gray-800);
}
.action-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-lg);
    transform: translateY(-4px);
    text-decoration: none;
    color: var(--gray-800);
}
.action-card .action-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    display: block;
}
.action-card .action-label {
    font-weight: 600;
    font-size: 0.875rem;
}
.action-card .action-desc {
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-top: 0.25rem;
}

/* Checklist */
.checklist-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    transition: var(--transition);
    background: white;
}
.checklist-item:hover { border-color: var(--gray-300); }
.checklist-item.done {
    background: var(--success-bg);
    border-color: #a7f3d0;
}
.checklist-item .check-btn {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    border: 2px solid var(--gray-300);
    background: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
    transition: var(--transition);
}
.checklist-item .check-btn:hover {
    border-color: var(--success);
    background: var(--success-bg);
}
.checklist-item.done .check-btn {
    background: var(--success);
    border-color: var(--success);
    color: white;
}
.checklist-info { flex: 1; }
.checklist-title { font-weight: 600; font-size: 0.9rem; }
.checklist-meta { font-size: 0.8rem; color: var(--gray-500); margin-top: 0.125rem; }

/* Filters */
.filters {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: end;
    padding: 1.25rem 1.5rem;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-100);
}
.filters .form-group { margin-bottom: 0; min-width: 150px; }

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--gray-500);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.5; }
.empty-state-text { font-size: 0.9375rem; }

/* Loading */
.loading { display: none; text-align: center; padding: 2rem; color: var(--gray-500); }
.loading.active { display: block; }
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 0.75rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* SOS Button */
.sos-btn {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--danger);
    color: white;
    border: none;
    font-size: 1.5rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(239,68,68,0.4);
    z-index: 300;
    transition: var(--transition);
    animation: pulse-sos 2s infinite;
}
.sos-btn:hover { transform: scale(1.1); box-shadow: 0 6px 20px rgba(239,68,68,0.5); }
@keyframes pulse-sos {
    0%, 100% { box-shadow: 0 4px 14px rgba(239,68,68,0.4); }
    50% { box-shadow: 0 4px 24px rgba(239,68,68,0.6); }
}

/* Responsive */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 150;
}

@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }
    .main-content { margin-left: 0; }
    .mobile-toggle { display: block; }
    .page-content { padding: 1.25rem; }
    .top-header { padding: 0 1.25rem; }
}

@media (max-width: 640px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
    .stat-card { padding: 1rem; flex-direction: column; align-items: center; text-align: center; }
    .stat-icon { width: 40px; height: 40px; font-size: 1.25rem; }
    .stat-value { font-size: 1.5rem; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .page-header h1 { font-size: 1.25rem; }
    .filters { flex-direction: column; }
    .action-grid { grid-template-columns: repeat(2, 1fr); }
    th, td { padding: 0.625rem 0.75rem; font-size: 0.8125rem; }
    .card-body { padding: 1rem; }
    .card-header { padding: 1rem; }
}

/* Login page */
.login-wrapper {
    min-height: 100vh;
    min-height: -webkit-fill-available;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #4f46e5 100%);
}
.login-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 2rem 1.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-xl);
}
.login-card h1 {
    text-align: center;
    margin-bottom: 0.25rem;
    font-size: 1.5rem;
    color: var(--gray-900);
    letter-spacing: -0.025em;
}
.login-card .login-subtitle {
    text-align: center;
    color: var(--gray-500);
    margin-bottom: 1.75rem;
    font-size: 0.875rem;
}
.login-logo {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    margin: 0 auto 1.25rem;
    box-shadow: 0 8px 16px rgba(79,70,229,0.3);
}
.login-card .form-control {
    font-size: 1rem;
    padding: 0.875rem 1rem;
    border-radius: var(--radius-sm);
    -webkit-appearance: none;
}
.login-card .btn {
    padding: 1rem;
    font-size: 1.0625rem;
    border-radius: var(--radius-sm);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
@media (min-width: 480px) {
    .login-card {
        padding: 2.5rem;
    }
    .login-card h1 { font-size: 1.75rem; }
    .login-logo { width: 64px; height: 64px; font-size: 2rem; }
}

/* Config page */
.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.25rem;
}
.config-card {
    background: white;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    padding: 1.5rem;
    transition: var(--transition);
}
.config-card:hover { box-shadow: var(--shadow-md); }
.config-card-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 1rem;
}
.config-card-title { font-weight: 600; font-size: 1rem; margin-bottom: 0.25rem; }
.config-card-desc { font-size: 0.8125rem; color: var(--gray-500); }

/* Status indicator */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 0.5rem;
}
.status-dot-online { background: var(--success); box-shadow: 0 0 0 3px rgba(16,185,129,0.2); }
.status-dot-offline { background: var(--gray-400); }
.status-dot-alert { background: var(--danger); animation: pulse-sos 2s infinite; }
