/* --- Buzzer PWA - Premium Theme v12.1.0 --- */

:root {
    --bg-light: #f8fafc; --text-light: #1e293b; --text-secondary-light: #64748b; --surface-light: #ffffff; --accent-light: #4f46e5; --danger-light: #dc2626; --success-light: #16a34a;
    --bg-dark: #0f172a; --text-dark: #e2e8f0; --text-secondary-dark: #94a3b8; --surface-dark: #1e293b; --accent-dark: #6366f1; --danger-dark: #ef4444; --success-dark: #22c55e;
    --shadow: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.12), 0 4px 6px -2px rgba(0,0,0,0.05);
}

@media (prefers-color-scheme: dark) { :root { --bg-color: var(--bg-dark); --text-color: var(--text-dark); --text-secondary: var(--text-secondary-dark); --surface-color: var(--surface-dark); --accent-color: var(--accent-dark); --danger-color: var(--danger-dark); --success-color: var(--success-dark); --subtle-border: 1px solid #333d52; } }
@media (prefers-color-scheme: light) { :root { --bg-color: var(--bg-light); --text-color: var(--text-light); --text-secondary: var(--text-secondary-light); --surface-color: var(--surface-light); --accent-color: var(--accent-light); --danger-color: var(--danger-light); --success-color: var(--success-light); --subtle-border: 1px solid #e5e7eb; } }

body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; margin: 0; background-color: var(--bg-color); color: var(--text-color); display: flex; justify-content: center; font-size: 16px; }
#app { width: 100%; max-width: 550px; min-height: 100vh; position: relative; }
.hidden { display: none !important; }
button:disabled { opacity: 0.5; cursor: not-allowed; filter: grayscale(50%); }

/* Loading Screen */
#loading-container { display: grid; place-items: center; height: 100vh; text-align: center; padding: 1.5rem; }
.loading-content { display: flex; flex-direction: column; align-items: center; }
.loading-logo { animation: pulse 1.5s ease-in-out infinite; }
#loading-container h1 { font-size: 2.8rem; margin: 0; font-weight: 700; }
.loading-text { color: var(--text-secondary); margin: 1rem 0; font-size: 1rem; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.7; transform: scale(0.95); } }

/* Auth Screen */
#auth-container { display: grid; place-items: center; height: 100vh; text-align: center; padding: 1.5rem; }
.auth-content { display: flex; flex-direction: column; align-items: center; }
.logo-img { width: 90px; height: 90px; margin-bottom: 1.5rem; border-radius: 22px; }
#auth-container h1 { font-size: 2.8rem; margin: 0; font-weight: 700; }
#auth-container p { color: var(--text-secondary); margin: 0.5rem 0 3.5rem 0; font-size: 1.1rem; }
#login-btn { background-color: var(--accent-color); color: white; border: none; padding: 16px 32px; border-radius: 14px; font-size: 1rem; font-weight: 500; cursor: pointer; }
#app-version-auth { margin-top: 4rem; font-size: 0.8rem; color: var(--text-secondary); }

/* Dashboard */
header { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.5rem; background-color: var(--surface-color); border-bottom: var(--subtle-border); position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow-lg); min-height: 70px; box-sizing: border-box; }
.header-brand { display: flex; align-items: center; gap: 1rem; }
.header-logo { width: 32px; height: 32px; flex-shrink: 0; }
.header-title { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
header h2 { font-size: 1.5rem; margin: 0; font-weight: 700; line-height: 1.2; }
.header-version { font-size: 0.7rem; color: var(--text-secondary); font-weight: 400; }
.header-user { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
#user-info { font-weight: 500; display: flex; flex-direction: column; gap: 0.1rem; text-align: right; min-width: 0; }
.user-name { font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: 0.7rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#logout-btn { background: none; border: 1px solid var(--subtle-border); color: var(--text-secondary); padding: 8px 14px; border-radius: 10px; cursor: pointer; white-space: nowrap; flex-shrink: 0; }
main { padding: 1.5rem; padding-bottom: 100px; } 
footer { text-align: center; padding: 1rem; font-size: 0.8rem; color: var(--text-secondary); display: flex; justify-content: center; align-items: center; gap: 0.5rem; }
.footer-separator { color: var(--text-secondary); }
.footer-link { background: none; border: none; color: var(--accent-color); font-size: 0.8rem; cursor: pointer; padding: 0; text-decoration: underline; transition: opacity 0.2s; }
.footer-link:hover { opacity: 0.7; }

/* Section Headers */
section { margin-bottom: 2rem; }
.section-header { display: flex; justify-content: space-between; align-items: center; border-bottom: var(--subtle-border); margin-bottom: 0.75rem; padding-bottom: 0.5rem; }
section h3 { font-size: 1.25rem; font-weight: 600; margin: 0; border-bottom: var(--subtle-border); padding-bottom: 0.5rem; margin-bottom: 0.75rem; }
.section-header h3 { border-bottom: none; padding-bottom: 0; margin-bottom: 0; }
.clear-btn { background: none; border: none; color: var(--text-secondary); cursor: pointer; font-size: 0.85rem; }

/* List Items */
#contacts-list, #buzz-history { display: flex; flex-direction: column; gap: 0.5rem; }
.contact-item { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.6rem 0.75rem; background-color: var(--surface-color); border-radius: 12px; box-shadow: var(--shadow); transition: transform 0.15s ease, box-shadow 0.15s ease, border 0.15s ease; }
.contact-item.dragging { opacity: 0.5; transform: scale(1.02); box-shadow: var(--shadow-lg); }
.contact-item.drag-over { border: 2px dashed var(--accent-color); padding: calc(0.6rem - 2px) calc(0.75rem - 2px); }
.drag-handle { color: var(--text-secondary); font-size: 0.9rem; cursor: grab; padding: 0.25rem; opacity: 0.4; user-select: none; flex-shrink: 0; letter-spacing: -2px; }
.drag-handle:hover { opacity: 0.8; }
.drag-handle:active { cursor: grabbing; }
.contact-info { display: flex; flex-direction: column; gap: 0.1rem; flex: 1; min-width: 0; }
.contact-name { font-size: 0.95rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-email { font-size: 0.75rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-meta { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.contact-version { font-size: 0.65rem; color: var(--accent-color); font-weight: 500; opacity: 0.8; }
.contact-status { font-size: 0.7rem; color: var(--text-secondary); }
.contact-status.pending { color: var(--accent-color); font-weight: 500; }
.contact-status.acknowledged { color: var(--success-color); }
.contact-actions { display: flex; align-items: center; gap: 0.3rem; flex-shrink: 0; }

/* Buzz & Delete Buttons */
.buzz-btn, .delete-btn { border: none; border-radius: 50%; width: 36px; height: 36px; display: grid; place-items: center; cursor: pointer; font-size: 1rem; transition: transform 0.2s, box-shadow 0.2s; flex-shrink: 0; }
.buzz-btn { background: var(--surface-color); border: 1px solid var(--accent-color); }
.buzz-btn:hover { transform: scale(1.05); background: rgba(99, 102, 241, 0.1); }
.buzz-btn svg { stroke: var(--accent-color); width: 16px; height: 16px; }
.delete-btn { background: none; border: 1px solid var(--subtle-border); color: var(--danger-color); }
.delete-btn svg { stroke: var(--danger-color); width: 14px; height: 14px; }
.delete-btn:hover { background: rgba(220, 38, 38, 0.1); }

/* History Items */
.history-item { padding: 0.75rem 1rem; background-color: var(--surface-color); border-radius: 12px; box-shadow: var(--shadow); }
.history-item.pending { border-left: 3px solid var(--accent-color); }
.history-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.25rem; }
.history-sender-info { display: flex; align-items: baseline; gap: 0.4rem; }
.history-sender { font-weight: 600; font-size: 0.95rem; }
.history-count { color: var(--accent-color); font-weight: 600; font-size: 0.85rem; }
.history-message { color: var(--text-secondary); font-style: italic; margin-bottom: 0.25rem; font-size: 0.9rem; }
.history-status { font-size: 0.75rem; color: var(--text-secondary); }
.history-actions { display: flex; gap: 0.4rem; }
.ack-btn, .dismiss-btn { border: none; border-radius: 50%; width: 32px; height: 32px; display: grid; place-items: center; cursor: pointer; font-size: 0.9rem; transition: transform 0.2s; }
.ack-btn { background: var(--success-color); color: white; }
.ack-btn:hover { transform: scale(1.1); }
.dismiss-btn { background: none; border: 1px solid var(--danger-color); color: var(--danger-color); }
.dismiss-btn:hover { background: rgba(220, 38, 38, 0.1); }

/* FABs */
.fab { position: fixed; width: 56px; height: 56px; border-radius: 50%; border: none; box-shadow: var(--shadow-lg); cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 1000; }
#invite-fab { bottom: 90px; right: 20px; background-color: var(--accent-color); color: white; font-size: 2rem; }
#hard-reset-btn { bottom: 20px; right: 20px; background-color: var(--surface-color); color: var(--text-color); border: var(--subtle-border); }

/* Modals */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); display: flex; justify-content: center; align-items: center; z-index: 2000; backdrop-filter: blur(4px); }
.modal { background: var(--surface-color); padding: 2rem; border-radius: 20px; width: 90%; max-width: 400px; text-align: center; box-shadow: var(--shadow-lg); max-height: 80vh; overflow-y: auto; }
.modal h3 { margin: 0 0 1rem 0; font-size: 1.4rem; }
.modal-input { width: 100%; padding: 12px; margin: 1rem 0; border: var(--subtle-border); border-radius: 8px; background: var(--bg-color); color: var(--text-color); font-size: 1rem; box-sizing: border-box; }
.modal-actions { display: flex; justify-content: center; gap: 1rem; flex-wrap: wrap; }
.modal-btn { padding: 10px 24px; border-radius: 12px; border: none; font-weight: 500; cursor: pointer; transition: transform 0.2s; }
.modal-btn:hover { transform: scale(1.02); }
.primary-btn { background-color: var(--accent-color); color: white; }
.secondary-btn { background: none; border: 1px solid var(--subtle-border); color: var(--text-secondary); }

/* Quick Messages Modal */
.quick-message-modal .modal { max-width: 350px; }
.qm-header { background: linear-gradient(135deg, var(--accent-color), #818cf8); color: white; margin: -2rem -2rem 1rem -2rem; padding: 1.5rem 2rem; border-radius: 20px 20px 0 0; }
.qm-header h3 { margin: 0; }
.quick-messages-list { display: flex; flex-direction: column; gap: 0.5rem; max-height: 200px; overflow-y: auto; margin-bottom: 1rem; }
.quick-message-btn { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: var(--bg-color); border: var(--subtle-border); border-radius: 12px; cursor: pointer; text-align: left; transition: all 0.2s; }
.quick-message-btn:hover { background: var(--surface-color); transform: translateX(4px); box-shadow: var(--shadow); }
.qm-text { flex: 1; }
.delete-message-btn { color: var(--danger-color); font-size: 1.2rem; padding: 0 0.5rem; opacity: 0.5; }
.delete-message-btn:hover { opacity: 1; }
.add-message-section { display: flex; gap: 0.5rem; margin-bottom: 1rem; align-items: stretch; }
.add-message-section .modal-input { margin: 0; flex: 1; min-width: 0; padding: 10px 12px; font-size: 0.9rem; }
.add-message-section .modal-btn { padding: 10px 12px; white-space: nowrap; font-size: 0.85rem; flex-shrink: 0; }

/* Contact History Modal */
.contact-history-modal .modal { max-width: 450px; max-height: 70vh; }
.history-modal-header { margin-bottom: 1rem; }
.history-modal-header h3 { margin: 0; font-size: 1.3rem; }
.contact-history-list { display: flex; flex-direction: column; gap: 0.75rem; max-height: 50vh; overflow-y: auto; margin-bottom: 1rem; }
.history-buzz-item { padding: 1rem; background: var(--bg-color); border-radius: 12px; border-left: 3px solid var(--accent-color); }
.history-buzz-item.received { border-left-color: var(--success-color); }
.buzz-direction { font-weight: 600; font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 0.25rem; }
.buzz-message-text { font-size: 1rem; margin-bottom: 0.25rem; }
.buzz-timestamp { font-size: 0.8rem; color: var(--text-secondary); }

/* Update Banner */
.update-banner { position: fixed; top: -100px; left: 0; right: 0; background: linear-gradient(135deg, var(--accent-color), #818cf8); color: white; padding: 1rem; box-shadow: var(--shadow-lg); z-index: 4000; transition: top 0.3s ease; }
.update-banner.show { top: 0; }
.update-content { max-width: 550px; margin: 0 auto; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.update-icon { font-size: 1.5rem; }
.update-text { flex: 1; font-weight: 500; min-width: 150px; }
.update-btn { background: white; color: var(--accent-color); border: none; padding: 8px 16px; border-radius: 8px; font-weight: 600; cursor: pointer; }
.update-dismiss { background: rgba(255,255,255,0.2); border: 1px solid rgba(255,255,255,0.4); color: white; font-size: 0.9rem; cursor: pointer; padding: 8px 16px; border-radius: 8px; font-weight: 500; }

/* Danger Button */
.danger-btn { background-color: var(--danger-color); color: white; }
.danger-btn:hover { opacity: 0.9; }

/* Backend Update Modal */
.backend-update-modal { backdrop-filter: blur(8px); }
.backend-update-modal .modal { border: 2px solid var(--danger-color); }

/* Toast Notifications */
.toast-notification { position: fixed; bottom: 160px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--surface-color); color: var(--text-color); padding: 12px 24px; border-radius: 30px; box-shadow: var(--shadow-lg); z-index: 3000; opacity: 0; transition: all 0.3s ease; }
.toast-notification.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Buzz Flash Effect - "Find My Device" style attention grabber */
.buzz-flash-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(99, 102, 241, 0.4); z-index: 9999; pointer-events: none; opacity: 0; transition: opacity 0.15s ease-out; }
.buzz-flash-overlay.active { animation: buzzFlash 2s ease-out forwards; }
@keyframes buzzFlash {
    0% { opacity: 0.6; background: rgba(99, 102, 241, 0.5); }
    15% { opacity: 0; }
    20% { opacity: 0.5; background: rgba(99, 102, 241, 0.45); }
    35% { opacity: 0; }
    40% { opacity: 0.4; background: rgba(99, 102, 241, 0.4); }
    55% { opacity: 0; }
    60% { opacity: 0.3; background: rgba(99, 102, 241, 0.35); }
    75% { opacity: 0; }
    100% { opacity: 0; }
}

/* Scrollbar styling */
.quick-messages-list::-webkit-scrollbar { width: 6px; }
.quick-messages-list::-webkit-scrollbar-track { background: transparent; }
.quick-messages-list::-webkit-scrollbar-thumb { background: var(--text-secondary); border-radius: 3px; }
.quick-messages-list::-webkit-scrollbar-thumb:hover { background: var(--text-color); }

/* Request modal */
.request-email { font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 1.5rem; }

/* PWA Install Banner */
.install-banner { position: fixed; bottom: 0; left: 0; right: 0; background: linear-gradient(135deg, var(--accent-color), #818cf8); color: white; padding: 1rem; box-shadow: var(--shadow-lg); z-index: 3000; transform: translateY(100%); transition: transform 0.3s ease; }
.install-banner.show { transform: translateY(0); }
.install-content { max-width: 550px; margin: 0 auto; display: flex; align-items: center; gap: 1rem; }
.install-icon { font-size: 1.5rem; flex-shrink: 0; }
.install-text { flex: 1; font-weight: 500; min-width: 0; }
.install-text h4 { margin: 0 0 0.25rem 0; font-size: 1rem; }
.install-text p { margin: 0; font-size: 0.85rem; opacity: 0.9; }
.install-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }
.install-btn { background: white; color: var(--accent-color); border: none; padding: 8px 16px; border-radius: 8px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.install-dismiss { background: none; border: none; color: white; font-size: 1.5rem; cursor: pointer; padding: 0 8px; }

/* Responsive Design - Mobile First */
@media (max-width: 768px) {
    /* Header responsiveness */
    header { padding: 0.75rem 1rem; gap: 0.5rem; flex-wrap: wrap; min-height: auto; }
    .header-brand { gap: 0.5rem; }
    .header-logo { width: 28px; height: 28px; }
    header h2 { font-size: 1.2rem; }
    .header-version { font-size: 0.65rem; }
    .header-user { gap: 0.5rem; }
    .user-name { font-size: 0.85rem; }
    .user-email { font-size: 0.65rem; }
    #logout-btn { padding: 6px 10px; font-size: 0.9rem; }
    
    /* Main content */
    main { padding: 1rem; }
    section h3 { font-size: 1.1rem; }
    
    /* Contact items - keep horizontal on mobile */
    .contact-item { padding: 0.6rem 0.75rem; gap: 0.5rem; }
    .contact-name { font-size: 0.9rem; }
    .contact-email { font-size: 0.7rem; }
    .buzz-btn, .delete-btn { width: 32px; height: 32px; }
    .buzz-btn svg { width: 14px; height: 14px; }
    .delete-btn svg { width: 12px; height: 12px; }
    
    /* Modals */
    .modal { padding: 1.5rem; width: 95%; max-width: 350px; }
    .modal h3 { font-size: 1.2rem; }
    .modal-actions { flex-direction: column; }
    .modal-btn { width: 100%; }
    
    /* Quick messages modal */
    .qm-header { margin: -1.5rem -1.5rem 1rem -1.5rem; padding: 1rem 1.5rem; }
    .add-message-section .modal-input { font-size: 0.85rem; padding: 8px 10px; }
    .add-message-section .modal-btn { padding: 8px 10px; font-size: 0.8rem; }
    
    /* Install banner */
    .install-content { flex-wrap: wrap; gap: 0.75rem; }
    .install-text h4 { font-size: 0.9rem; }
    .install-text p { font-size: 0.75rem; }
    .install-actions { width: 100%; justify-content: stretch; }
    .install-btn { flex: 1; }
}

@media (max-width: 480px) {
    /* Extra small screens */
    body { font-size: 14px; }
    header { padding: 0.5rem 0.75rem; }
    header h2 { font-size: 1.1rem; }
    .header-logo { width: 24px; height: 24px; }
    main { padding: 0.75rem; }
    section h3 { font-size: 1rem; }
    
    /* Contact actions */
    .contact-actions { gap: 0.25rem; }
    .buzz-btn, .delete-btn { width: 30px; height: 30px; }
    .buzz-btn svg { width: 12px; height: 12px; }
    .delete-btn svg { width: 11px; height: 11px; }
    
    /* FABs */
    .fab { width: 48px; height: 48px; }
    #invite-fab { bottom: 80px; right: 15px; }
    #hard-reset-btn { bottom: 15px; right: 15px; }
    
    /* Toast */
    .toast-notification { bottom: 140px; font-size: 0.9rem; padding: 10px 20px; }
}

@media (min-width: 769px) and (max-width: 1024px) {
    /* Tablet landscape */
    #app { max-width: 680px; }
}

/* Landscape orientation */
@media (max-height: 600px) and (orientation: landscape) {
    header { position: relative; }
    main { padding-bottom: 80px; }
    .fab { width: 48px; height: 48px; }
    #invite-fab { bottom: 70px; right: 15px; }
    #hard-reset-btn { bottom: 15px; right: 15px; }
}
