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

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg: #f1f5f9;
    --bg-card: #ffffff;
    --bg-dark: #1e293b;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

.hidden { display: none !important; }

.screen {
    width: 100vw;
    height: 100vh;
}

/* ======== Login ======== */
.login-card {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 48px 40px;
    width: 400px;
    max-width: 90vw;
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.logo-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.login-logo h1 {
    font-size: 24px;
    font-weight: 700;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 4px;
}

.version-tag {
    font-size: 11px;
    color: var(--text-secondary);
    opacity: 0.7;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

/* ======== Buttons ======== */
.btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-text {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    padding: 6px 12px;
    border-radius: 6px;
}

.btn-text:hover { background: var(--border); }

.btn-small {
    padding: 8px 16px;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.btn-success { background: var(--success); }
.btn-success:hover { background: #16a34a; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #dc2626; }

.btn-tiny {
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    color: white;
    cursor: pointer;
}

/* ======== Top Bar ======== */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    height: 56px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar h2 {
    font-size: 18px;
    font-weight: 700;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.agent-badge {
    background: var(--primary);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    background: var(--text-secondary);
}

.status-dot.online { background: var(--success); }

/* ======== Dashboard Body ======== */
.dashboard-body {
    display: flex;
    height: calc(100vh - 56px);
}

/* ======== Sidebar ======== */
.sidebar {
    width: 300px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}

.sidebar-section {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-section.flex-1 {
    flex: 1;
    overflow-y: auto;
    border-bottom: 1px solid var(--border);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.section-header h3 {
    font-size: 14px;
    font-weight: 700;
}

.room-badge {
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 20px;
    background: var(--bg);
    color: var(--text-secondary);
    font-weight: 600;
}

.room-badge.connected {
    background: #dcfce7;
    color: #166534;
}

.count-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 20px;
    background: var(--primary);
    color: white;
    font-weight: 700;
    min-width: 22px;
    text-align: center;
}

/* Room controls */
.room-input-row {
    display: flex;
    gap: 8px;
}

.room-input-row input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
}

.room-input-row input:focus {
    border-color: var(--primary);
}

/* Call Queue */
.call-queue {
    min-height: 60px;
}

.queue-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    margin-bottom: 6px;
    background: var(--bg);
    cursor: default;
    transition: all 0.2s;
}

.queue-item.call-ringing {
    background: #fef3c7;
    border-left: 3px solid var(--warning);
    animation: ring-pulse 1.5s ease-in-out infinite;
}

.queue-item.call-active {
    background: #dcfce7;
    border-left: 3px solid var(--success);
}

.queue-item.call-hold {
    background: #e0e7ff;
    border-left: 3px solid var(--primary);
}

@keyframes ring-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

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

.queue-hotel {
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.queue-machine {
    font-size: 11px;
    color: var(--text-secondary);
}

.queue-item-meta {
    text-align: right;
    flex-shrink: 0;
}

.queue-state {
    display: block;
    font-size: 11px;
    font-weight: 700;
}

.call-ringing .queue-state { color: #b45309; }
.call-active .queue-state { color: #166534; }
.call-hold .queue-state { color: var(--primary); }

.queue-time {
    font-size: 11px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.queue-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

/* Call History */
.call-history {
    max-height: 200px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    border-radius: 8px;
    margin-bottom: 4px;
    background: var(--bg);
    font-size: 12px;
}

.history-hotel {
    font-weight: 600;
    margin-right: 4px;
}

.history-machine {
    color: var(--text-secondary);
}

.history-meta {
    display: flex;
    gap: 8px;
    color: var(--text-secondary);
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    padding: 20px 0;
}

/* ======== Main Content ======== */
.main-content {
    flex: 1;
    position: relative;
    overflow: hidden;
}

/* Idle / Waiting state */
.call-area-state {
    width: 100%;
    height: 100%;
}

.idle-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.idle-icon {
    font-size: 64px;
    margin-bottom: 16px;
    position: relative;
    z-index: 1;
}

.idle-content h2 {
    font-size: 24px;
    margin-bottom: 8px;
}

.idle-content p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.pulse-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -80px);
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 3px solid var(--primary);
    opacity: 0;
    animation: pulse 2.5s ease-out infinite;
}

@keyframes pulse {
    0% { transform: translate(-50%, -80px) scale(0.5); opacity: 0.6; }
    100% { transform: translate(-50%, -80px) scale(1.8); opacity: 0; }
}

/* ======== Video Call ======== */
.video-container {
    display: flex;
    height: calc(100% - 130px);
    padding: 16px;
    gap: 16px;
}

.video-panel {
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
    background: #0f172a;
}

.remote-video {
    flex: 1;
}

.local-video {
    width: 280px;
    flex-shrink: 0;
}

.video-wrap {
    width: 100%;
    height: 100%;
    position: relative;
}

.video-wrap video,
.video-wrap div[id^="video_"] {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
}

.video-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: rgba(255,255,255,0.5);
}

.placeholder-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.video-label {
    position: absolute;
    bottom: 10px;
    left: 12px;
    background: rgba(0,0,0,0.6);
    color: white;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
}

/* Call info bar */
.call-info-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    padding: 8px;
}

.call-timer {
    font-size: 18px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--primary);
}

.call-room-info, .call-info {
    font-size: 13px;
    color: var(--text-secondary);
}

.media-status {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Call controls */
.call-controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 12px;
}

.ctrl-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 20px;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 80px;
}

.ctrl-btn:hover {
    background: var(--border);
}

.ctrl-btn.active {
    background: var(--warning);
    border-color: var(--warning);
    color: white;
}

.ctrl-btn.warn {
    background: #fef3c7;
    border-color: var(--warning);
    color: #92400e;
}

.ctrl-btn.warn:hover {
    background: var(--warning);
    color: white;
}

.ctrl-btn.hangup {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
}

.ctrl-btn.hangup:hover {
    background: #dc2626;
}

.ctrl-icon {
    font-size: 22px;
}

.ctrl-label {
    font-size: 12px;
    font-weight: 600;
}

/* ======== Toast ======== */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--bg-dark);
    color: white;
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 14px;
    z-index: 9999;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease-out;
}

.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ======== Incoming Call Popup ======== */
.incoming-popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.incoming-popup-card {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 40px 48px;
    text-align: center;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
    position: relative;
    min-width: 320px;
    animation: popIn 0.3s ease-out;
}

@keyframes popIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.incoming-icon {
    font-size: 56px;
    margin-bottom: 12px;
    position: relative;
    z-index: 1;
    animation: ring-shake 0.5s ease-in-out infinite;
}

@keyframes ring-shake {
    0%, 100% { transform: rotate(0deg); }
    20% { transform: rotate(15deg); }
    40% { transform: rotate(-15deg); }
    60% { transform: rotate(10deg); }
    80% { transform: rotate(-10deg); }
}

.incoming-pulse-ring {
    position: absolute;
    top: 40px;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 3px solid var(--success);
    animation: incoming-pulse 1.5s ease-out infinite;
}

@keyframes incoming-pulse {
    0% { transform: translateX(-50%) scale(0.8); opacity: 0.8; }
    100% { transform: translateX(-50%) scale(2); opacity: 0; }
}

.incoming-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--success);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 16px;
}

.incoming-caller {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.incoming-machine {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.incoming-timer {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    margin-bottom: 28px;
}

.incoming-actions {
    display: flex;
    gap: 16px;
    justify-content: center;
}

.btn-incoming {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 32px;
    border: none;
    border-radius: 50px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    color: white;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-incoming:hover {
    transform: scale(1.05);
}

.btn-incoming.accept {
    background: var(--success);
    box-shadow: 0 4px 15px rgba(34, 197, 94, 0.4);
}

.btn-incoming.accept:hover {
    box-shadow: 0 6px 20px rgba(34, 197, 94, 0.5);
}

.btn-incoming.reject {
    background: var(--danger);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4);
}

.btn-incoming.reject:hover {
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.5);
}

.btn-incoming span {
    font-size: 20px;
}

/* ======== Responsive ======== */
@media (max-width: 768px) {
    .sidebar { width: 240px; }
    .local-video { width: 150px; }
}

@media (max-width: 600px) {
    .sidebar { display: none; }
}
