/* Premium Telegram-style UI */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --bg-app: #0b0f14;
    --bg-sidebar: #131920;
    --bg-panel: #1a2129;
    --bg-bubble-in: #1e2630;
    --bg-bubble-out: #1d9a4e;
    --accent: #1d9a4e;
    --accent-bright: #2db35a;
    --accent-hover: #34c060;
    --text: #eef2f5;
    --text-muted: #7d8a99;
    --border: rgba(60, 70, 85, 0.6);
    --shadow: 0 12px 40px rgba(0,0,0,0.5);
    --radius: 14px;
    --radius-sm: 10px;
}

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

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg-app);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* Login */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: 
        radial-gradient(ellipse 80% 60% at 50% -10%, rgba(29, 154, 78, 0.12), transparent 60%),
        var(--bg-app);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 24px;
}

.login-card {
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 44px 36px;
    box-shadow: var(--shadow);
}

.login-header {
    text-align: center;
    margin-bottom: 36px;
}

.login-header .logo {
    font-size: 56px;
    margin-bottom: 20px;
    display: block;
}

.login-header h1 {
    font-size: 26px;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
}

.login-header p {
    color: var(--text-muted);
    font-size: 15px;
}

.login-form .form-group {
    margin-bottom: 22px;
}

.login-form label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.login-form input {
    width: 100%;
    padding: 14px 18px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 16px;
    transition: border-color 0.2s;
}

.login-form input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(29, 154, 78, 0.2);
}

.alert {
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 14px;
}

.alert-error {
    background: rgba(248, 81, 73, 0.12);
    border: 1px solid rgba(248, 81, 73, 0.4);
    color: #ff7b72;
}

.alert-success {
    background: rgba(29, 154, 78, 0.15);
    border: 1px solid rgba(29, 154, 78, 0.4);
    color: var(--accent-bright);
}

.btn {
    padding: 14px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-block {
    width: 100%;
}

/* App */
.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    width: 360px;
    min-width: 320px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 28px 24px;
    border-bottom: 1px solid var(--border);
}

.sidebar .logo {
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    font-size: 18px;
    letter-spacing: -0.02em;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    transition: color 0.2s;
}

.sidebar .logo:hover {
    color: var(--accent-bright);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
}

.chat-list-loading,
.chat-list-empty {
    padding: 48px 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 15px;
}

.chat-list-empty .hint {
    font-size: 14px;
    margin-top: 12px;
    opacity: 0.8;
}

.chat-list {
    padding: 8px 0;
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 16px 24px;
    cursor: pointer;
    transition: background 0.2s;
    text-decoration: none;
    color: inherit;
    border-radius: var(--radius-sm);
    margin: 2px 12px;
}

.chat-item:hover {
    background: rgba(255,255,255,0.05);
}

.chat-item.active {
    background: rgba(29, 154, 78, 0.14);
    border-left: 3px solid var(--accent);
    margin-left: 12px;
    padding-left: 21px;
}

.chat-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--accent) 0%, #1a7a3d 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 600;
    margin-right: 16px;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0,0,0,0.25);
}

.chat-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-avatar-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: white;
}

.chat-info {
    flex: 1;
    min-width: 0;
}

.chat-name-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
}

.chat-name {
    font-weight: 500;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.unread-badge {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0;
}

.chat-note-badge {
    font-size: 12px;
    color: var(--text-muted);
    background: rgba(255,255,255,0.08);
    padding: 2px 6px;
    border-radius: 4px;
    flex-shrink: 0;
}

.chat-preview {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.chat-item.unread .chat-name {
    font-weight: 600;
    color: var(--text);
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border);
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    transition: all 0.15s;
    font-size: 15px;
}

.nav-link:hover {
    color: var(--accent-bright);
    background: rgba(255,255,255,0.06);
}

/* Main */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-app);
    min-width: 0;
}

.welcome-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px;
    text-align: center;
    background: 
        radial-gradient(ellipse 60% 40% at 50% 30%, rgba(29, 154, 78, 0.08) 0%, transparent 60%),
        var(--bg-app);
}

.welcome-icon {
    font-size: 80px;
    margin-bottom: 24px;
    opacity: 0.4;
}

.welcome-view h2 {
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 10px;
    color: var(--text);
}

.welcome-view p {
    color: var(--text-muted);
    font-size: 15px;
    max-width: 300px;
    line-height: 1.6;
}

/* Chat */
.chat-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-header {
    padding: 22px 28px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 20px;
    background: var(--bg-sidebar);
}

.back-btn {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 22px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.back-btn:hover {
    color: var(--accent-bright);
    background: rgba(255,255,255,0.06);
}

.chat-header h2 {
    flex: 1;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
}

.notes-toggle-btn {
    padding: 8px 14px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.notes-toggle-btn:hover {
    color: var(--accent-bright);
    border-color: rgba(29, 154, 78, 0.4);
}

.notes-toggle-btn.has-notes {
    color: var(--accent-bright);
}

.chat-notes-panel {
    padding: 20px 28px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    display: none;
}

.chat-notes-panel.open {
    display: block;
}

.notes-list {
    max-height: 180px;
    overflow-y: auto;
    margin-bottom: 16px;
}

.notes-list:empty::before {
    content: 'No notes yet. Add one below for other agents.';
    display: block;
    color: var(--text-muted);
    font-size: 14px;
}

.note-item {
    padding: 12px 16px;
    background: var(--bg-sidebar);
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    border-left: 3px solid var(--accent);
}

.note-item:last-child {
    margin-bottom: 0;
}

.note-item .note-text {
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    white-space: pre-wrap;
}

.note-item .note-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}

.notes-add-form {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.notes-add-form textarea {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    min-height: 60px;
}

.notes-add-form textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.notes-add-form .btn-sm {
    padding: 10px 18px;
    font-size: 14px;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 32px;
    background: 
        radial-gradient(ellipse 50% 50% at 50% 50%, rgba(29, 154, 78, 0.03) 0%, transparent 70%),
        var(--bg-app);
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: auto;
    max-width: 680px;
    margin-left: auto;
    margin-right: auto;
}

.message {
    max-width: 70%;
    padding: 12px 18px 10px;
    border-radius: 18px;
    position: relative;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.message.incoming {
    align-self: flex-start;
    background: var(--bg-bubble-in);
    border: 1px solid rgba(255,255,255,0.04);
    border-bottom-left-radius: 6px;
}

.message.outgoing {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--bg-bubble-out) 0%, #1a8545 100%);
    border-bottom-right-radius: 6px;
}

.message-sender {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.message-sender.message-agent {
    color: rgba(255,255,255,0.9);
}

.message-text {
    word-wrap: break-word;
    white-space: pre-wrap;
    font-size: 15px;
    line-height: 1.55;
}

.message-media {
    margin-top: 10px;
    border-radius: 14px;
    overflow: hidden;
}

.message-media img,
.message-media video {
    max-width: 100%;
    max-height: 320px;
    display: block;
}

.message-media a {
    color: var(--accent-bright);
    font-size: 14px;
    text-decoration: none;
}

.message-media a:hover {
    text-decoration: underline;
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 10px;
}

.message-time {
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0.9;
}

.message.outgoing .message-time {
    color: rgba(255,255,255,0.75);
}

.message-status {
    font-size: 14px;
    opacity: 0.95;
    color: rgba(255,255,255,0.9);
}

.message-tokens {
    font-size: 11px;
    color: rgba(255,255,255,0.95);
    margin-left: 6px;
}

/* Composer */
.composer {
    padding: 24px 28px 32px;
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border);
}

.send-form {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 8px 8px 8px 22px;
    max-width: 720px;
    margin: 0 auto;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.send-form:focus-within {
    border-color: rgba(29, 154, 78, 0.5);
    box-shadow: 0 0 0 2px rgba(29, 154, 78, 0.15);
}

.send-form input[type="text"] {
    flex: 1;
    background: none;
    border: none;
    color: var(--text);
    font-size: 15px;
    padding: 12px 0;
}

.send-form input[type="text"]::placeholder {
    color: var(--text-muted);
}

.send-form input[type="text"]:focus {
    outline: none;
}

.attach-btn {
    cursor: pointer;
    font-size: 20px;
    opacity: 0.75;
    padding: 8px;
    transition: opacity 0.2s;
}

.attach-btn:hover {
    opacity: 1;
}

.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.send-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.06);
}

/* Settings */
.settings-container {
    max-width: 560px;
    padding: 48px;
}

.settings-container h1 {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 12px;
}

.settings-desc {
    color: var(--text-muted);
    margin-bottom: 36px;
    line-height: 1.6;
    font-size: 15px;
}

.settings-form .form-group {
    margin-bottom: 24px;
}

.settings-form label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-muted);
}

.settings-form input {
    width: 100%;
    padding: 14px 18px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 15px;
}

.settings-form input:focus {
    outline: none;
    border-color: var(--accent);
}

.settings-form .form-hint {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 8px;
}

.settings-container h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

.agents-table {
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}

.agents-table th,
.agents-table td {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.agents-table th {
    background: var(--bg-panel);
    color: var(--text-muted);
    font-weight: 500;
}

.agents-table .agent-stat {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.status-online {
    color: var(--accent-bright);
}

.status-offline {
    color: var(--text-muted);
}

/* New message notifications - slide in from right */
.notification-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

.notification-container > * {
    pointer-events: auto;
}

.notification-toast {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    cursor: pointer;
    min-width: 320px;
    max-width: 380px;
    animation: notification-slide-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    transform-origin: right center;
}

.notification-toast:hover {
    background: var(--bg-panel);
    border-color: rgba(29, 154, 78, 0.4);
}

.notification-toast.removing {
    animation: notification-slide-out 0.3s ease-in forwards;
}

.notification-toast .notification-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--accent) 0%, #1a7a3d 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    flex-shrink: 0;
    overflow: hidden;
}

.notification-toast .notification-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.notification-toast .notification-avatar .chat-avatar-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: white;
    font-weight: 600;
}

.notification-toast .notification-body {
    flex: 1;
    min-width: 0;
}

.notification-toast .notification-name {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 2px;
    color: var(--text);
}

.notification-toast .notification-preview {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notification-toast .notification-badge {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0;
    animation: notification-pulse 2s ease-in-out infinite;
}

@keyframes notification-slide-in {
    from {
        opacity: 0;
        transform: translateX(120%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes notification-slide-out {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(120%);
    }
}

@keyframes notification-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

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

::-webkit-scrollbar-track {
    background: transparent;
}

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

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