* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Inter', sans-serif; }
body { background-color: #0f172a; color: #f8fafc; display: flex; height: 100vh; overflow: hidden; }

/* Sidebar Layout */
.sidebar { width: 260px; background: #1e293b; border-right: 1px solid #334155; display: flex; flex-direction: column; }
.logo { padding: 1.5rem; display: flex; align-items: center; gap: 10px; font-size: 1.25rem; font-weight: 700; color: #f8fafc; border-bottom: 1px solid #334155; }
.logo-icon { background: #0ea5e9; color: white; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 8px; font-size: 1.2rem;}
.menu { padding: 1rem 0; flex: 1; }
.menu-item { display: flex; align-items: center; gap: 12px; padding: 0.875rem 1.5rem; color: #94a3b8; text-decoration: none; font-weight: 500; transition: all 0.2s; position: relative;}
.menu-item:hover { color: #f8fafc; background: #334155; }
.menu-item.active { color: #38bdf8; background: rgba(56, 189, 248, 0.1); border-right: 3px solid #38bdf8; }
.menu-item ion-icon { font-size: 1.25rem; }
.badge { background: #ef4444; color: white; font-size: 0.75rem; padding: 2px 6px; border-radius: 99px; margin-left: auto; }

.main-content { flex: 1; display: flex; flex-direction: column; overflow-y: auto; background: #0f172a; }

/* Views System */
.view { display: none; height: 100%; flex-direction: column; }
.view.active-view { display: flex; }

/* Configurações Aba */
#view-config { padding: 2rem; overflow-y: auto;}
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; }
.topbar h1 { font-size: 1.5rem; font-weight: 600; }
.status-badge { padding: 0.5rem 1rem; border-radius: 999px; font-size: 0.875rem; font-weight: 600; background: #475569; }
.status-badge.waiting { background: #eab308; color: #1c1917; }
.status-badge.connected { background: #22c55e; color: #f8fafc; }

.dashboard-grid { display: grid; grid-template-columns: 1fr; gap: 1.5rem; max-width: 900px;}
@media(min-width: 1024px) { .dashboard-grid { grid-template-columns: 320px 1fr; align-items: start; } }

.card { background: #1e293b; padding: 1.5rem; border-radius: 12px; border: 1px solid #334155; }
.card h2 { font-size: 1.25rem; margin-bottom: 1.5rem; color: #38bdf8; }

.qr-container { background: #ffffff; padding: 1rem; border-radius: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 250px; text-align: center;}
.qr-text { color: #475569; margin-top: 1rem; font-weight: 600; }
#qrcode-img { max-width: 100%; border-radius: 4px; }
.spinner { border: 4px solid #e2e8f0; border-top: 4px solid #38bdf8; border-radius: 50%; width: 40px; height: 40px; animation: spin 1s linear infinite; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Formularios */
.section-title { font-size: 1rem; color: #cbd5e1; margin: 1.5rem 0 1rem 0; padding-bottom: 0.5rem; border-bottom: 1px solid #334155; }
.form-group { margin-bottom: 1rem; text-align: left; }
label { display: block; margin-bottom: 0.5rem; font-size: 0.875rem; color: #94a3b8; font-weight: 500; }
textarea, input[type="number"] { width: 100%; background: #0f172a; border: 1px solid #334155; border-radius: 8px; padding: 0.75rem; color: #f8fafc; font-size: 0.875rem; outline: none; transition: border 0.2s;}
textarea { resize: vertical; }
textarea:focus, input[type="number"]:focus { border-color: #38bdf8; }

.master-switch-group { display: flex; justify-content: space-between; align-items: center; background: #0f172a; padding: 1rem; border-radius: 8px; border: 1px solid #334155; }
.master-switch-group label:first-child { margin: 0; font-size: 1rem; color: #f8fafc; }

.switch { position: relative; display: inline-block; width: 44px; height: 24px; margin:0;}
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #475569; transition: .4s; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 4px; bottom: 4px; background-color: white; transition: .4s; }
input:checked + .slider { background-color: #22c55e; }
input:checked + .slider:before { transform: translateX(20px); }
.slider.round { border-radius: 34px; }
.slider.round:before { border-radius: 50%; }

.schedule-table { width: 100%; margin-bottom: 1.5rem; background: #0f172a; border-radius: 8px; border: 1px solid #334155; overflow: hidden; text-align: left;}
.schedule-row { display: grid; grid-template-columns: 0.8fr 1fr 2fr 2fr; gap: 10px; padding: 0.75rem 1rem; border-bottom: 1px solid #334155; align-items: center; }
.schedule-row.header { font-weight: 600; color: #94a3b8; font-size: 0.875rem; background: #1e293b;}
.schedule-row:last-child { border-bottom: none; }
.schedule-row span { font-size: 0.875rem; }
input[type="time"] { background: #1e293b; border: 1px solid #334155; color: #f8fafc; padding: 0.4rem; border-radius: 6px; outline: none; font-size: 0.875rem;}
input[type="time"]:disabled { opacity: 0.5; }

.btn-save { background: #0ea5e9; color: white; border: none; padding: 0.875rem; border-radius: 8px; font-weight: 600; cursor: pointer; width: 100%; transition: background 0.2s; }
.btn-save:hover { background: #0284c7; }
.feedback-msg { margin-top: 1rem; font-size: 0.875rem; color: #22c55e; display: none; text-align: center; }

/* Chat Layout */
.chat-layout { display: flex; height: 100%; width: 100%; }
.chat-sidebar { width: 340px; background: #1e293b; border-right: 1px solid #334155; display: flex; flex-direction: column; }
.chat-search { padding: 1.5rem 1rem; border-bottom: 1px solid #334155; }
.chat-search h2 { font-size: 1.25rem; font-weight: 600; }
.contact-list { flex: 1; overflow-y: auto; }
.no-chats { padding: 2rem 1rem; text-align: center; color: #64748b; font-size: 0.875rem; }

.contact-item { padding: 1rem; border-bottom: 1px solid #334155; cursor: pointer; display: flex; align-items: center; gap: 12px; transition: background 0.2s;}
.contact-item:hover { background: #334155; }
.contact-item.active { background: #334155; border-left: 3px solid #0ea5e9; }
.contact-avatar { width: 44px; height: 44px; background: #0ea5e9; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; font-weight: bold; }
.contact-info { flex: 1; overflow: hidden; }
.contact-name { font-weight: 600; color: #f8fafc; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;}
.contact-preview { font-size: 0.8rem; color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 4px; }
.contact-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px;}
.contact-time { font-size: 0.7rem; color: #64748b; }
.contact-unread { background: #22c55e; color: white; font-size: 0.7rem; padding: 2px 6px; border-radius: 99px; font-weight: 700;}

.chat-main { flex: 1; display: flex; flex-direction: column; background: #0f172a; }
.chat-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #64748b; gap: 1rem; font-size: 1.1rem; }
.chat-empty ion-icon { font-size: 4rem; opacity: 0.5; }

.chat-header { padding: 1rem 1.5rem; background: #1e293b; border-bottom: 1px solid #334155; display: flex; align-items: center; gap: 12px;}
.chat-header h3 { font-size: 1.1rem; }
.chat-header p { font-size: 0.8rem; color: #94a3b8;}

.chat-history { flex: 1; padding: 1.5rem; overflow-y: auto; display: flex; flex-direction: column; gap: 1rem; scroll-behavior: smooth;}
.msg-bubble { max-width: 75%; padding: 0.8rem 1rem; border-radius: 12px; font-size: 0.95rem; line-height: 1.4; position: relative; word-wrap: break-word;}
.msg-bubble.received { background: #1e293b; color: #f8fafc; align-self: flex-start; border-bottom-left-radius: 4px; border: 1px solid #334155; }
.msg-bubble.sent { background: #0ea5e9; color: white; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg-time { display: block; font-size: 0.65rem; margin-top: 6px; opacity: 0.7; text-align: right;}

/* PWA Banner */
.pwa-banner { position: fixed; top: 0; left: 0; right: 0; background: #0284c7; color: #fff; z-index: 1000; padding: 0.75rem 1rem; box-shadow: 0 4px 12px rgba(0,0,0,0.3); animation: slideDown 0.3s ease; }
@keyframes slideDown { from { transform: translateY(-100%); } to { transform: translateY(0); } }
.pwa-banner-content { display: flex; align-items: center; gap: 12px; max-width: 1200px; margin: 0 auto; }
.pwa-icon { font-size: 1.8rem; display: flex; align-items: center; }
.pwa-info { flex: 1; display: flex; flex-direction: column; font-size: 0.85rem; }
.pwa-info strong { font-size: 0.95rem; }
.btn-pwa { background: #ffffff; color: #0284c7; border: none; padding: 0.4rem 0.9rem; border-radius: 6px; font-weight: 700; font-size: 0.85rem; cursor: pointer; }
.btn-pwa-close { background: none; border: none; color: #ffffff; font-size: 1.5rem; cursor: pointer; padding: 0 4px; opacity: 0.8; }

/* Mobile Header & Bottom Navigation */
.mobile-header { display: none; background: #1e293b; border-bottom: 1px solid #334155; padding: 0.75rem 1rem; align-items: center; justify-content: space-between; }
.mobile-header .logo { padding: 0; border: none; }
.bottom-nav { display: none; position: fixed; bottom: 0; left: 0; right: 0; height: 60px; background: #1e293b; border-top: 1px solid #334155; z-index: 100; justify-content: space-around; align-items: center; padding-bottom: env(safe-area-inset-bottom); }
.bottom-nav-item { display: flex; flex-direction: column; align-items: center; justify-content: center; color: #94a3b8; text-decoration: none; font-size: 0.75rem; gap: 4px; flex: 1; height: 100%; position: relative; }
.bottom-nav-item.active { color: #38bdf8; font-weight: 600; }
.bottom-nav-item ion-icon { font-size: 1.4rem; }

/* Mobile Chat Header Back Button */
.btn-back-chat { display: none; background: none; border: none; color: #38bdf8; font-size: 1.5rem; cursor: pointer; padding-right: 0.5rem; align-items: center; }

/* Touch alvos mínimos 44px */
button, input, textarea, select { min-height: 44px; }
.switch { min-height: initial; }

/* Media Queries Responsivas */
@media (max-width: 768px) {
    body { flex-direction: column; height: 100vh; padding-bottom: 60px; }
    .sidebar { display: none; }
    .mobile-header { display: flex; }
    .bottom-nav { display: flex; }
    
    .main-content { flex: 1; overflow-y: auto; }
    #view-config { padding: 1rem; }
    .topbar { margin-bottom: 1rem; }
    .topbar h1 { font-size: 1.2rem; }
    
    /* Layout de Chat Mobile (Modo Alternado) */
    .chat-layout { position: relative; width: 100%; height: 100%; }
    .chat-sidebar { width: 100%; height: 100%; border-right: none; }
    .chat-main { display: none; width: 100%; height: 100%; position: absolute; top: 0; left: 0; z-index: 10; background: #0f172a; }
    
    /* Quando a conversa está ativa no mobile */
    .chat-layout.mobile-chat-active .chat-sidebar { display: none; }
    .chat-layout.mobile-chat-active .chat-main { display: flex; }
    .btn-back-chat { display: flex; }

    /* Tabela de Expediente Adaptativa para Telas Pequenas */
    .schedule-row { grid-template-columns: 1fr; gap: 8px; padding: 0.8rem; background: #1e293b; border-radius: 8px; margin-bottom: 8px; }
    .schedule-row.header { display: none; }
    .schedule-row span { font-weight: 600; color: #38bdf8; }
    
    .msg-bubble { max-width: 88%; }
    .chat-input-area { padding: 0.75rem; }
    .chat-input-area input { font-size: 0.95rem; }
}

@media (min-width: 769px) and (max-width: 1023px) {
    .sidebar { width: 200px; }
    .sidebar .logo span { font-size: 1rem; }
    .menu-item span { font-size: 0.9rem; }
    .chat-sidebar { width: 280px; }
}

