@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&display=swap');

:root {
    --bg-dark: #0b0f19;
    --bg-card: rgba(17, 24, 39, 0.7);
    --bg-card-hover: rgba(31, 41, 55, 0.8);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.15);
    
    --primary: #06b6d4;      /* Dental/Medical Teal */
    --primary-glow: rgba(6, 182, 212, 0.3);
    --secondary: #8b5cf6;    /* Accent Violet */
    --secondary-glow: rgba(139, 92, 246, 0.3);
    --accent: #3b82f6;       /* Blue */
    --success: #10b981;      /* Green */
    --danger: #ef4444;       /* Red */
    --warning: #f59e0b;      /* Yellow */
    
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --text-dark: #111827;
    
    --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 20px rgba(6, 182, 212, 0.25);
    
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color-scheme: dark;
}

[hidden] {
    display: none !important;
}

html[data-theme="light"] {
    --bg-dark: #eef4fb;
    --bg-card: rgba(255, 255, 255, 0.82);
    --bg-card-hover: rgba(255, 255, 255, 0.96);
    --border-color: rgba(15, 23, 42, 0.12);
    --border-hover: rgba(15, 23, 42, 0.22);
    --text-main: #152033;
    --text-muted: #60708a;
    --text-dark: #111827;
    --shadow-sm: 0 2px 8px rgba(30, 64, 100, 0.08);
    --shadow-lg: 0 14px 34px rgba(30, 64, 100, 0.12);
    color-scheme: light;
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-dark);
    background-image: 
        radial-gradient(at 0% 0%, rgba(139, 92, 246, 0.12) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(6, 182, 212, 0.12) 0px, transparent 50%);
    background-attachment: fixed;
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
}

html[data-theme="light"] body {
    background-image:
        radial-gradient(at 0% 0%, rgba(139, 92, 246, 0.10) 0, transparent 50%),
        radial-gradient(at 100% 100%, rgba(6, 182, 212, 0.12) 0, transparent 50%);
}

html[data-theme="light"] .logo {
    background: linear-gradient(135deg, #172033, var(--primary));
    -webkit-background-clip: text;
}

html[data-theme="light"] .btn-secondary {
    background: rgba(255, 255, 255, 0.72);
}

html[data-theme="light"] input,
html[data-theme="light"] select,
html[data-theme="light"] textarea {
    color: var(--text-main);
    background-color: rgba(255, 255, 255, 0.9);
}

/* Glassmorphism utility */
.glass-panel {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    transition: var(--transition-smooth);
}

.glass-panel:hover {
    border-color: var(--border-hover);
}

/* Scrollbar styles */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Base button styles */
button {
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 500;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    transition: var(--transition-smooth);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    box-shadow: 0 4px 15px rgba(6, 182, 212, 0.2);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(6, 182, 212, 0.4), var(--shadow-glow);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--border-hover);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger), #b91c1c);
    color: white;
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

/* Grid & Layout Utilities */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    background: linear-gradient(135deg, #fff, var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo i {
    font-size: 1.75rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-credit {
    display: block;
    margin-top: 0.15rem;
    color: var(--text-muted);
    -webkit-text-fill-color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 500;
    letter-spacing: 0.08em;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    border-radius: 50px;
    font-size: 0.85rem;
    font-weight: 600;
}

.status-online {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-offline {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.theme-toggle {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    flex: 0 0 auto;
}

.header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.65rem;
}

.area-login-shell {
    min-height: calc(100vh - 170px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.area-login-card {
    width: min(430px, 100%);
    padding: 2rem;
}

.area-login-card h1 {
    margin-bottom: 0.45rem;
}

.area-login-card p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
    font-size: 0.9rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    padding: 0.8rem 0.9rem;
    font: inherit;
}

.login-error {
    min-height: 1.3rem;
    margin: 0.55rem 0;
    color: var(--danger);
}

.chat-launcher {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 9000;
    width: 56px;
    height: 56px;
    padding: 0;
    border-radius: 50%;
    transition: transform .2s ease, background .2s ease, box-shadow .2s ease;
}

.chat-launcher.has-unread {
    background: var(--danger);
    box-shadow: 0 0 0 5px rgba(239, 68, 68, 0.18), 0 10px 30px rgba(239, 68, 68, 0.35);
    animation: chat-unread-pulse 1.8s ease-in-out infinite;
}

@keyframes chat-unread-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.07); }
}

.chat-launcher .chat-unread {
    position: absolute;
    right: -3px;
    top: -3px;
    min-width: 21px;
    height: 21px;
    padding: 0 5px;
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
    background: var(--danger);
    color: white;
    font-size: 0.72rem;
    font-weight: 700;
}

.chat-panel {
    position: fixed;
    right: 1.25rem;
    bottom: 5.4rem;
    z-index: 8999;
    width: min(390px, calc(100vw - 2rem));
    height: min(560px, calc(100vh - 7rem));
    display: none;
    grid-template-rows: auto auto 1fr auto;
    overflow: hidden;
}

.chat-panel.active { display: grid; }

.chat-conversations-view,
.chat-thread-view {
    min-height: 0;
    height: 100%;
    display: none;
}

.chat-conversations-view.active {
    display: grid;
    grid-template-rows: auto 1fr;
}

.chat-thread-view.active {
    display: grid;
    grid-template-rows: auto 1fr auto;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.chat-header button { padding: 0.3rem; }
.chat-header small { display: block; margin-top: .12rem; color: var(--text-muted); font-size: .72rem; }
.chat-list-header strong { font-size: 1.2rem; }

.chat-conversation-list {
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.chat-conversation-item {
    width: 100%;
    min-height: 72px;
    padding: .72rem .85rem;
    display: grid;
    grid-template-columns: 48px minmax(0,1fr) auto;
    align-items: center;
    gap: .75rem;
    border: 0;
    border-bottom: 1px solid var(--border-color);
    border-radius: 0;
    color: var(--text-main);
    background: transparent;
    text-align: left;
    cursor: pointer;
    transition: background .18s ease;
}

.chat-conversation-item:hover,
.chat-conversation-item.has-unread { background: rgba(6,182,212,.055); }
.chat-conversation-avatar,
.chat-thread-avatar { display: grid; place-items: center; border-radius: 50%; color: #fff; background: linear-gradient(135deg,var(--primary),var(--secondary)); font-weight: 800; }
.chat-conversation-avatar { width: 48px; height: 48px; font-size: 1rem; }
.chat-conversation-content { min-width: 0; display: grid; gap: .16rem; }
.chat-conversation-top { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; }
.chat-conversation-top strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .95rem; }
.chat-conversation-top time { flex: 0 0 auto; color: var(--text-muted); font-size: .67rem; }
.chat-conversation-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); font-size: .79rem; }
.chat-conversation-status { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--primary); font-size: .67rem; }
.chat-conversation-unread { min-width: 23px; height: 23px; padding: 0 .36rem; display: grid; place-items: center; border-radius: 999px; color: #fff; background: var(--primary); font-size: .69rem; font-weight: 800; }

.chat-thread-header { display: grid; grid-template-columns: auto 38px minmax(0,1fr) auto; gap: .58rem; }
.chat-back-button { width: 34px; height: 34px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 50%; color: var(--text-main); background: transparent; cursor: pointer; }
.chat-back-button:hover { background: rgba(255,255,255,.07); }
.chat-thread-avatar { width: 38px; height: 38px; font-size: .82rem; }
.chat-thread-identity { min-width: 0; }
.chat-thread-identity strong,
.chat-thread-identity small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-destination {
    display: grid;
    gap: 0.35rem;
    padding: 0.65rem 1rem;
    color: var(--text-muted);
    font-size: 0.78rem;
    border-bottom: 1px solid var(--border-color);
}

.chat-destination select {
    width: 100%;
    padding: 0.55rem 0.65rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card-hover);
    color: var(--text-main);
}

.chat-empty { color: var(--text-muted); text-align: center; margin: auto; }

.chat-notification {
    position: fixed;
    inset: 50% auto auto 50%;
    transform: translate(-50%, -46%) scale(0.94);
    z-index: 9200;
    width: min(520px, calc(100vw - 2rem));
    padding: 1.4rem;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 1rem;
    opacity: 0;
    pointer-events: none;
    border: 2px solid rgba(6, 182, 212, 0.45);
    box-shadow: var(--shadow-glow), 0 24px 70px rgba(0,0,0,.4);
    transition: .25s ease;
    visibility: hidden;
}
.chat-notification.active { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); visibility: visible; }
.chat-notification-icon { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; color: white; background: linear-gradient(135deg,var(--primary),var(--accent)); }
.chat-notification small { color: var(--primary); font-weight: 800; letter-spacing: .12em; }
.chat-notification strong { display: block; font-size: 1.25rem; margin: .25rem 0; }
.chat-notification p { color: var(--text-muted); overflow-wrap: anywhere; }
.chat-notification-actions { display: flex; gap: .6rem; margin-top: 1rem; }
@media(max-width:520px){.chat-notification{grid-template-columns:1fr}.chat-notification-icon{width:44px;height:44px}.chat-notification-actions button{flex:1}}

.chat-messages {
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}

.chat-message {
    padding: 0.7rem 0.8rem;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
}

html[data-theme="light"] .chat-message { background: rgba(241, 245, 249, 0.92); }
.chat-message { width: fit-content; max-width: 86%; border-radius: 14px 14px 14px 5px; }
.chat-message.mine { align-self: flex-end; border-color: rgba(6, 182, 212, 0.38); border-radius: 14px 14px 5px 14px; background: rgba(6,182,212,.09); }
.chat-message strong { color: var(--primary); font-size: 0.82rem; }
.chat-message time { float: right; color: var(--text-muted); font-size: 0.72rem; }
.chat-message p { margin-top: 0.3rem; overflow-wrap: anywhere; }
.chat-receipt { display: block; margin-top: .35rem; text-align: right; color: var(--text-muted); font-size: .7rem; }
.chat-message.mine .chat-receipt { color: var(--primary); }

.chat-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.55rem;
    padding: 0.8rem;
    border-top: 1px solid var(--border-color);
}

.chat-form input {
    min-width: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    padding: 0.7rem;
    font: inherit;
}

@media (max-width: 640px) {
    .container { padding: 1rem; }
    .chat-panel { right: 0.6rem; bottom: 4.8rem; width: calc(100vw - 1.2rem); }
    .chat-launcher { right: 0.8rem; bottom: 0.8rem; }
}
