:root {
    --bg-body: #f8fafc;
    --bg-sidebar: #ffffff;
    --bg-card: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --primary: #6366f1;
    --primary-light: #e0e7ff;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --chat-bg: #eef2ff;
    --bubble-in: #ffffff;
    --bubble-out: #6366f1;
    --bubble-out-text: #ffffff;
    --hover-bg: #f1f5f9;
}

* { box-sizing: border-box; margin: 0; padding: 0; outline: none; transition: all 0.2s ease-in-out; }

body {
    font-family: 'Plus Jakarta Sans', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    overflow: hidden;
}

/* SIDEBAR */
.sidebar { width: 280px; background: var(--bg-sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 24px; z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 40px; padding-left: 8px; }
.brand img { height: 45px; object-fit: contain; }
.nav-menu { display: flex; flex-direction: column; gap: 8px; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: 12px; color: var(--text-muted); cursor: pointer; font-weight: 500; font-size: 0.95rem; }
.nav-item:hover { background: #f1f5f9; color: var(--text-main); transform: translateX(4px); }
.nav-item.active { background: var(--primary); color: white; box-shadow: 0 8px 20px rgba(99, 102, 241, 0.2); }
.nav-item.active:hover { transform: none; }

/* MAIN */
.main { flex: 1; display: flex; flex-direction: column; position: relative; }
.header { height: 80px; padding: 0 40px; display: flex; align-items: center; justify-content: space-between; background: rgba(255,255,255,0.8); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); z-index: 10; }

/* VIEWS */
.view { display: none; height: calc(100vh - 80px); overflow-y: auto; padding: 30px 40px; animation: fadeIn 0.4s ease; }
.view.active { display: block; }

/* CHAT LAYOUT */
.chat-layout { display: grid; grid-template-columns: 320px 1fr; height: 100%; background: var(--bg-card); border-radius: 24px; border: 1px solid var(--border); overflow: hidden; box-shadow: 0 4px 20px rgba(0,0,0,0.02); }
.chat-sidebar { border-right: 1px solid var(--border); display: flex; flex-direction: column; background: #fff; }
.chat-search { padding: 20px; border-bottom: 1px solid var(--border); }
.search-input { width: 100%; padding: 12px 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-body); font-size: 0.9rem; }
.contact-list { flex: 1; overflow-y: auto; }
.contact-item { display: flex; align-items: center; padding: 15px 20px; cursor: pointer; border-bottom: 1px solid var(--bg-body); transition: 0.2s; }
.contact-item:hover { background: var(--hover-bg); }
.contact-item.active { background: var(--primary-light); border-right: 4px solid var(--primary); }
.avatar { width: 45px; height: 45px; border-radius: 50%; background: var(--primary); color: white; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 0.9rem; margin-right: 15px; flex-shrink: 0; }
.contact-info { flex: 1; overflow: hidden; }
.contact-name { font-weight: 700; color: var(--text-main); font-size: 0.95rem; margin-bottom: 4px; }
.contact-preview { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-time { font-size: 0.7rem; color: var(--text-muted); opacity: 0.7; }

.chat-main { display: flex; flex-direction: column; background: var(--chat-bg); position: relative; height: 100%; overflow: hidden; }
.chat-header-bar { height: 70px; background: #fff; border-bottom: 1px solid #e2e8f0; display: flex; align-items: center; padding: 0 24px; justify-content: space-between; flex-shrink: 0; }
.chat-messages { flex: 1; padding: 24px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.bubble { max-width: 70%; padding: 12px 18px; border-radius: 18px; font-size: 0.95rem; line-height: 1.5; position: relative; box-shadow: 0 2px 4px rgba(0,0,0,0.05); }
.bubble.in { background: var(--bubble-in); align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.out { background: var(--bubble-out); color: var(--bubble-out-text); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg-time { font-size: 0.65rem; opacity: 0.6; float: right; margin-top: 6px; margin-left: 10px; }
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-muted); }

/* DASHBOARD & WIDGETS */
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 24px; margin-bottom: 30px; }
.widget { background: var(--bg-card); padding: 24px; border-radius: 20px; border: 1px solid var(--border); display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.widget-value { font-size: 2.5rem; font-weight: 700; margin: 10px 0; }
.widget-label { font-size: 0.85rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; }

/* CARDS HOME */
.agenda-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
.dashboard-card { background: white; border: 1px solid var(--border); border-radius: 16px; padding: 20px; display: flex; align-items: center; gap: 15px; transition: transform 0.2s, box-shadow 0.2s; box-shadow: 0 2px 10px rgba(0,0,0,0.02); }
.dashboard-card:hover { transform: translateY(-3px); box-shadow: 0 10px 25px rgba(0,0,0,0.06); border-color: var(--primary-light); }
.card-icon { width: 48px; height: 48px; border-radius: 12px; background: linear-gradient(135deg, #e0e7ff, #f3e8ff); color: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 1.1rem; }
.card-info h4 { font-size: 1rem; font-weight: 700; color: var(--text-main); margin-bottom: 4px; }
.card-info p { font-size: 0.85rem; color: var(--text-muted); display: flex; align-items: center; gap: 5px; }
.card-badge { margin-left: auto; font-size: 0.75rem; font-weight: 600; background: #f1f5f9; color: var(--text-muted); padding: 4px 10px; border-radius: 20px; }

/* SETTINGS LAYOUT */
.settings-grid-layout { display: grid; grid-template-columns: repeat(auto-fit, minmax(350px, 1fr)); gap: 24px; align-items: start; }
.settings-card { background: white; border-radius: 20px; border: 1px solid var(--border); padding: 30px; margin-bottom: 20px; position: relative; }
.card-header { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 1px solid var(--bg-body); }
.card-header h4 { font-size: 1.1rem; font-weight: 700; color: var(--text-main); }

.icon-bg { width: 40px; height: 40px; background: var(--primary-light); color: var(--primary); border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.icon-bg.danger { background: #fee2e2; color: var(--danger); }

.form-group { margin-bottom: 15px; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text-main); margin-bottom: 6px; }
.form-group-row { display: flex; gap: 15px; }
.form-group-row .form-group, .form-group-row input { flex: 1; }
.help-text { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 10px; margin-top: -5px; }

.input { width: 100%; padding: 12px 16px; border: 1px solid var(--border); border-radius: 10px; font-family: inherit; margin-bottom: 15px; }
.textarea-large { height: 300px; line-height: 1.6; font-size: 0.9rem; resize: vertical; }
.textarea-medium { height: 100px; min-height: 100px; resize: vertical; line-height: 1.5; font-size: 0.9rem; }

.action-buttons { display: flex; gap: 10px; margin-bottom: 20px; }

/* BUTTONS */
.btn { padding: 12px 24px; border-radius: 12px; border: none; cursor: pointer; font-weight: 600; font-size: 0.9rem; display: inline-flex; align-items: center; gap: 8px; justify-content: center; width: 100%; transition: 0.2s; }
.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: white; border: 1px solid var(--border); color: var(--text-main); }
.btn-secondary:hover { background: var(--hover-bg); border-color: var(--text-muted); }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-icon { background: transparent; color: var(--text-muted); padding: 8px; border:none; cursor:pointer; width: auto; }
.btn-icon:hover { color: var(--danger); background: #fee2e2; border-radius:50%; }

/* MINI LIST */
.mini-list { margin-top: 10px; max-height: 300px; overflow-y: auto; border-top: 1px solid var(--border); }
.mini-item { background: #fff; padding: 12px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.2s; border-radius: 8px; margin-bottom: 4px; position: relative; }
.mini-item:hover { background: var(--hover-bg); padding-left: 16px; }
.mini-item.editing { background: var(--primary-light); border: 1px solid var(--primary); }
.mini-content { display: flex; flex-direction: column; gap: 4px; width: 90%; }
.mini-key { font-weight: 700; color: var(--primary); font-size: 0.9rem; }
.mini-val { font-size: 0.85rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.btn-mini-delete { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; color: #cbd5e1; cursor: pointer; padding: 5px; border-radius: 50%; transition: 0.2s; }
.btn-mini-delete:hover { background: #fee2e2; color: var(--danger); }

/* AGENDA */
.agenda-layout { display: grid; grid-template-columns: 300px 1fr; gap: 40px; height: 100%; }
.agenda-sidebar { display: flex; flex-direction: column; gap: 24px; }
.cal-widget { background: white; border-radius: 20px; padding: 24px; border: 1px solid var(--border); box-shadow: 0 4px 20px rgba(0,0,0,0.02); }
.cal-header { font-weight: 700; margin-bottom: 20px; display: flex; justify-content: space-between; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; text-align: center; font-size: 0.85rem; color: var(--text-muted); }
.cal-day { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; border-radius: 50%; cursor: pointer; }
.cal-day:hover { background: var(--hover-bg); }
.cal-day.active { background: var(--primary); color: white; font-weight: 700; }
.cal-day.has-event { position: relative; font-weight: 700; color: var(--text-main); }
.cal-day.has-event::after { content:''; position: absolute; bottom: 4px; width: 4px; height: 4px; background: var(--primary); border-radius: 50%; }

.timeline-container { overflow-y: auto; padding-right: 10px; }
.date-group { margin-bottom: 40px; }
.date-header { font-size: 0.9rem; font-weight: 700; color: var(--text-muted); margin-bottom: 20px; display: flex; align-items: center; gap: 15px; text-transform: uppercase; letter-spacing: 1px; }
.date-header::after { content:''; flex: 1; height: 1px; background: var(--border); }

.schedule-card { display: flex; align-items: center; background: white; border-radius: 16px; border: 1px solid var(--border); padding: 20px; margin-bottom: 16px; transition: 0.2s; position: relative; overflow: hidden; }
.schedule-card:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(0,0,0,0.05); border-color: var(--primary-light); }
.schedule-card::before { content:''; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--primary); }
.time-col { min-width: 80px; text-align: center; border-right: 1px solid var(--border); padding-right: 20px; margin-right: 20px; }
.time-hour { font-size: 1.2rem; font-weight: 800; color: var(--text-main); }
.time-ampm { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; }
.info-col { flex: 1; }
.client-name { font-size: 1.1rem; font-weight: 700; color: var(--text-main); margin-bottom: 5px; }
.service-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--text-muted); background: var(--bg-body); padding: 6px 12px; border-radius: 8px; }
.action-col { opacity: 0; transition: 0.2s; }
.schedule-card:hover .action-col { opacity: 1; }

.toast { position: fixed; bottom: 24px; right: 24px; background: #1f2937; color: white; padding: 12px 24px; border-radius: 12px; transform: translateY(150%); z-index: 200; }
.toast.show { transform: translateY(0); }
.qr-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(255,255,255,0.9); backdrop-filter: blur(5px); z-index: 50; display: none; flex-direction: column; align-items: center; justify-content: center; }
.qr-box { background: white; padding: 15px; border-radius: 20px; box-shadow: 0 20px 50px rgba(0,0,0,0.1); border: 1px solid var(--border); }

@media (max-width: 900px) {
    .sidebar { position: fixed; bottom: 0; width: 100%; height: 70px; flex-direction: row; padding: 0; border-top: 1px solid var(--border); }
    .brand { display: none; } .nav-menu { flex-direction: row; justify-content: space-around; padding: 0 10px; }
    .nav-item span { display: none; } .settings-grid-layout, .agenda-layout, .chat-layout { grid-template-columns: 1fr; } .main { padding-bottom: 80px; }
    .chat-sidebar { display: flex; } .chat-main { display: none; } .chat-main.active { display: flex; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 30; }
}