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

body {
    background: #0f172a;
    color: #e2e8f0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    height: 100vh;
    display: flex;
    flex-direction: column;
    direction: rtl;
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Top bar */
#top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: #1e293b;
    border-bottom: 1px solid #334155;
    flex-shrink: 0;
}

.bar-right, .bar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    font-size: 1.1rem;
    font-weight: 700;
    color: #38bdf8;
}

.teacher-info {
    font-size: 0.85rem;
    color: #94a3b8;
    border-right: 1px solid #475569;
    padding-right: 12px;
}

.btn-logout {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1e293b;
    color: #64748b;
    border: 1px solid #334155;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-logout:hover {
    background: #7f1d1d;
    color: #fca5a5;
    border-color: #7f1d1d;
}

.status-chip {
    font-size: 0.8rem;
    padding: 4px 10px;
    border-radius: 12px;
    background: #334155;
    color: #94a3b8;
}

.status-chip.active {
    background: #166534;
    color: #4ade80;
}

.status-chip.error {
    background: #7f1d1d;
    color: #fca5a5;
}

.lang-label {
    font-size: 0.8rem;
    color: #94a3b8;
    font-weight: 600;
}

.server-url {
    font-size: 0.75rem;
    color: #475569;
    direction: ltr;
}

.label-inline {
    font-size: 0.85rem;
    color: #64748b;
    font-weight: 500;
}

.server-url-display {
    font-size: 0.85rem;
    color: #334155;
    font-weight: 600;
    direction: ltr;
    user-select: all;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 4px;
    transition: background 0.15s;
}

.server-url-display:hover {
    background: #e2e8f0;
}

.server-url-display.copied {
    background: #dcfce7;
    color: #166534;
}

/* Controls */
#controls {
    display: flex;
    gap: 16px;
    padding: 12px 20px;
    background: #1e293b;
    border-bottom: 1px solid #334155;
    flex-shrink: 0;
    align-items: flex-end;
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.control-group label {
    font-size: 0.75rem;
    color: #94a3b8;
}

.control-group input,
.control-group select {
    padding: 6px 10px;
    font-size: 0.85rem;
    background: #0f172a;
    color: #e2e8f0;
    border: 1px solid #334155;
    border-radius: 6px;
    outline: none;
    width: 200px;
}

.control-group input:focus,
.control-group select:focus {
    border-color: #38bdf8;
}

.control-btns {
    display: flex;
    gap: 8px;
    margin-right: auto;
}

.btn-primary {
    padding: 8px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-primary:hover:not(:disabled) { background: #1d4ed8; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-danger {
    padding: 8px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    background: #dc2626;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-danger:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-small {
    padding: 4px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    background: #334155;
    color: #e2e8f0;
    border: 1px solid #475569;
    border-radius: 6px;
    cursor: pointer;
}

.btn-small:hover:not(:disabled) { background: #475569; }
.btn-small:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-small.translate-active {
    background: #1d4ed8;
    color: #fff;
}

/* Main content */
#main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
}

#left-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-left: 1px solid #334155;
    overflow: hidden;
}

#right-panel {
    width: 280px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

/* Transcript section */
#transcript-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px 20px;
    overflow: hidden;
    border-bottom: 1px solid #334155;
}

#transcript-section h3 {
    font-size: 0.85rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 10px;
    flex-shrink: 0;
}

#transcript-area {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

#transcript-history {
    overflow-y: auto;
    flex-shrink: 1;
}

/* --- Current line: original + translation side by side --- */
#transcript-current-row {
    display: flex;
    align-items: baseline;
    gap: 16px;
    padding: 4px 8px;
    min-height: 2rem;
    flex-shrink: 0;
}

#transcript-current {
    flex: 1;
    min-width: 0;
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.6;
    color: #e2e8f0;
}

#transcript-current.partial {
    color: #94a3b8;
}

#transcript-current-translation {
    flex: 1;
    min-width: 0;
    font-size: 1.3rem;
    font-weight: 500;
    line-height: 1.6;
    color: #38bdf8;
}

#transcript-current-translation:empty {
    display: none;
}

/* --- History lines: side-by-side when translated, simple when not --- */
#transcript-history .line {
    display: flex;
    align-items: baseline;
    gap: 16px;
    font-size: 1.2rem;
    line-height: 1.6;
    color: #94a3b8;
    margin-bottom: 4px;
    padding: 4px 8px;
    border-radius: 4px;
}

.line-original {
    flex: 1;
    min-width: 0;
    color: #e2e8f0;
}

.line-translation {
    flex: 1;
    min-width: 0;
    color: #38bdf8;
    opacity: 0.85;
}

.line-translation:empty {
    display: none;
}

#mic-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 12px;
    flex-shrink: 0;
}

.btn-mic {
    padding: 8px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    background: #16a34a;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.btn-mic:hover { background: #15803d; }

.btn-mic.recording {
    background: #dc2626;
    animation: pulse-rec 1.5s infinite;
}

.btn-jetson {
    padding: 8px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    background: #7c3aed;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.btn-jetson:hover { background: #6d28d9; }

.btn-jetson.active {
    background: #dc2626;
    animation: pulse-rec 1.5s infinite;
}

.btn-api {
    padding: 8px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    background: #0284c7;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.btn-api:hover { background: #0369a1; }

.btn-api.active {
    background: #dc2626;
    animation: pulse-rec 1.5s infinite;
}

.btn-api:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-nvidia {
    padding: 8px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    background: #76b900;
    color: #000;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}
.btn-nvidia:hover { background: #8bd100; }
.btn-nvidia.active {
    background: #dc2626;
    color: #fff;
    animation: pulse-rec 1.5s infinite;
}
.btn-nvidia:disabled { opacity: 0.4; cursor: not-allowed; }

.controls-sep {
    color: #475569;
    font-size: 1.2rem;
    user-select: none;
}

.btn-overlay {
    padding: 8px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    background: #ca8a04;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.btn-overlay:hover { background: #a16207; }

.btn-overlay.active {
    background: #16a34a;
}

.btn-overlay:disabled { opacity: 0.4; cursor: not-allowed; }

@keyframes pulse-rec {
    50% { opacity: 0.7; }
}

#mic-status {
    font-size: 0.8rem;
    color: #94a3b8;
}

/* Messages section */
#messages-section {
    height: 200px;
    display: flex;
    flex-direction: column;
    padding: 16px 20px;
    overflow: hidden;
    flex-shrink: 0;
}

#messages-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    flex-shrink: 0;
}

#messages-header h3 {
    font-size: 0.85rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 8px;
}

#unread-badge {
    background: #dc2626;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

#message-filter {
    padding: 3px 8px;
    font-size: 0.75rem;
    background: #0f172a;
    color: #94a3b8;
    border: 1px solid #334155;
    border-radius: 4px;
    outline: none;
    direction: rtl;
}

#message-filter:focus {
    border-color: #38bdf8;
}

#messages-area {
    flex: 1;
    overflow-y: auto;
}

.message-item {
    display: flex;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    margin-bottom: 4px;
    background: #1e293b;
    font-size: 0.85rem;
    align-items: center;
}

.message-item.message-new {
    animation: msgFlash 1s ease-out;
}

@keyframes msgFlash {
    0% { background: #1e3a5f; }
    100% { background: #1e293b; }
}

.message-icon {
    font-size: 0.8rem;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
}

.message-sender {
    color: #38bdf8;
    font-weight: 600;
    white-space: nowrap;
}

.message-text {
    color: #e2e8f0;
    flex: 1;
}

.message-time {
    color: #475569;
    font-size: 0.75rem;
    white-space: nowrap;
    direction: ltr;
}

.placeholder-text {
    color: #475569;
    font-size: 0.85rem;
    text-align: center;
    padding: 1rem;
}

/* Students section */
#students-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px 20px;
    overflow: hidden;
    border-bottom: 1px solid #334155;
}

#students-section h3 {
    font-size: 0.85rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 10px;
    flex-shrink: 0;
}

#student-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
}

#student-list li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    font-size: 0.85rem;
    border-radius: 6px;
    margin-bottom: 2px;
}

#student-list li:not(.placeholder-text):hover {
    background: #1e293b;
}

.student-name {
    color: #e2e8f0;
}

.student-time {
    color: #475569;
    font-size: 0.7rem;
    margin-right: auto;
    direction: ltr;
}

/* Attendance dot styles */
.dot-present {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    flex-shrink: 0;
}

.dot-absent {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #475569;
    flex-shrink: 0;
}

.student-present {
    opacity: 1;
}

.student-absent {
    opacity: 0.5;
}

.attendance-count {
    font-size: 0.75rem;
    font-weight: 700;
    background: #1d4ed8;
    color: #fff;
    padding: 2px 8px;
    border-radius: 10px;
    margin-right: 6px;
}

.student-status-label {
    font-size: 0.7rem;
    margin-right: auto;
    font-weight: 600;
}

.present-label {
    color: #4ade80;
}

.absent-label {
    color: #64748b;
}


/* Quick-response management */
#qr-management {
    padding: 8px 20px;
    background: #1e293b;
    border-bottom: 1px solid #334155;
    flex-shrink: 0;
}

#qr-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#qr-header h4 {
    font-size: 0.8rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#qr-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 8px 0;
}

.qr-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: #334155;
    border-radius: 14px;
    font-size: 0.8rem;
}

.qr-text {
    color: #e2e8f0;
}

.qr-remove-btn {
    background: none;
    border: none;
    color: #dc2626;
    font-size: 0.7rem;
    cursor: pointer;
    padding: 0 2px;
}

.qr-remove-btn:hover {
    color: #fca5a5;
}

#qr-add {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

#qr-new-input {
    flex: 1;
    padding: 4px 8px;
    font-size: 0.8rem;
    background: #0f172a;
    color: #e2e8f0;
    border: 1px solid #334155;
    border-radius: 4px;
    outline: none;
    direction: rtl;
}

#qr-new-input:focus {
    border-color: #38bdf8;
}

/* Message speak button */
.msg-speak-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.8rem;
    padding: 2px 4px;
    border-radius: 4px;
    flex-shrink: 0;
}

.msg-speak-btn:hover {
    background: #334155;
}

/* Utility */
.hidden { display: none !important; }

/* Responsive */
@media (max-width: 768px) {
    #main-content {
        flex-direction: column;
    }
    #right-panel {
        width: 100%;
        flex-direction: row;
        height: auto;
        border-top: 1px solid #334155;
    }
    #students-section, #qr-section {
        flex: 1;
        border-bottom: none;
    }
    .control-group input,
    .control-group select {
        width: 140px;
    }
}
