/* Modern Academic Glassmorphism Theme */
:root {
  --bg-color: #0b1120;
  --panel-bg: rgba(30, 41, 59, 0.75);
  --panel-border: rgba(255, 255, 255, 0.1);
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent-gold: #f59e0b;
  --accent-gold-light: rgba(245, 158, 11, 0.15);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #10b981;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --user-msg-bg: #1e3a8a;
  --ai-msg-bg: #1e293b;
  --border-radius: 16px;
  --font-family: 'Noto Sans SC', system-ui, -apple-system, sans-serif;
}

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

body {
  background-color: var(--bg-color);
  background-image: 
    radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.12) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(245, 158, 11, 0.08) 0px, transparent 50%);
  color: var(--text-main);
  font-family: var(--font-family);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.app-container {
  width: 100%;
  max-width: 1350px;
  height: 92vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: var(--border-radius);
  padding: 16px 24px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-icon {
  font-size: 2.2rem;
}

.logo h1 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: 0.5px;
}

.subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Main Layout */
.main-content {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 18px;
  flex: 1;
  min-height: 0; /* Important for flex scrolling */
}

/* Sidebar & Cards */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.card {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: var(--border-radius);
  padding: 20px;
}

.card h2 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent-gold);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Role Selection Grid */
.role-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.role-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.role-card:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.role-card.active {
  background: var(--accent-gold-light);
  border-color: var(--accent-gold);
  box-shadow: 0 0 15px rgba(245, 158, 11, 0.2);
}

.role-icon {
  font-size: 1.6rem;
}

.role-info h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

.role-info p {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Instruction Card */
.instruction-desc {
  font-size: 0.88rem;
  line-height: 1.55;
  color: #cbd5e1;
  background: rgba(0, 0, 0, 0.2);
  padding: 12px;
  border-radius: 8px;
  border-left: 3px solid var(--accent-gold);
}

/* Custom Role Setup */
.form-group {
  margin-bottom: 12px;
}

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

textarea, input[type="number"] {
  width: 100%;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text-main);
  padding: 10px;
  font-family: inherit;
  font-size: 0.85rem;
}

textarea {
  height: 90px;
  resize: none;
}

textarea:focus, input[type="number"]:focus {
  outline: none;
  border-color: var(--primary);
}

.field-tip {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}


/* File Upload */
.upload-tip {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.file-upload-box {
  position: relative;
}

.file-upload-box input[type="file"] {
  position: absolute;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.file-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px;
  border: 2px dashed var(--panel-border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.15);
  color: var(--text-muted);
  font-size: 0.82rem;
  transition: all 0.2s ease;
}

.file-upload-box:hover .file-dropzone {
  border-color: var(--primary);
  color: var(--text-main);
}

.upload-icon {
  font-size: 1.4rem;
}

.file-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid var(--success);
  border-radius: 8px;
  padding: 8px 12px;
  margin-top: 10px;
  font-size: 0.82rem;
  color: #6ee7b7;
}

/* Main Chat Container */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--panel-border);
  background: rgba(15, 23, 42, 0.5);
}

.chat-status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  font-size: 0.95rem;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.status-dot.green {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

/* Chat Feed */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.system-welcome-msg {
  display: flex;
  gap: 14px;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.25);
  border-radius: 12px;
  padding: 16px;
  font-size: 0.9rem;
  line-height: 1.5;
}

.welcome-icon {
  font-size: 1.5rem;
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 80%;
}

.msg-row.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-row.ai {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-author {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  padding: 0 4px;
}

.msg-bubble {
  padding: 14px 18px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-row.user .msg-bubble {
  background: var(--user-msg-bg);
  color: #eff6ff;
  border-bottom-right-radius: 4px;
}

.msg-row.ai .msg-bubble {
  background: var(--ai-msg-bg);
  border: 1px solid var(--panel-border);
  color: #f1f5f9;
  border-bottom-left-radius: 4px;
}

/* TTS Player Overlay Bar */
.tts-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(245, 158, 11, 0.15);
  border-top: 1px solid var(--accent-gold);
  border-bottom: 1px solid var(--accent-gold);
  padding: 8px 24px;
  font-size: 0.85rem;
  color: var(--accent-gold);
}

.pulse-wave {
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 0.8; }
}

/* Input Controls Area */
.input-controls-area {
  padding: 18px 24px;
  background: rgba(15, 23, 42, 0.8);
  border-top: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.segments-preview {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.82rem;
}

.segments-label {
  color: var(--text-muted);
  margin-bottom: 6px;
}

.segments-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 140px;
  overflow-y: auto;
}

.segment-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.04);
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.segment-num {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-gold);
  white-space: nowrap;
}

.segment-input {
  flex: 1;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  color: #f8fafc;
  padding: 8px 10px;
  font-size: 0.85rem;
  transition: all 0.2s ease;
  height: auto;
  min-height: 68px;
  line-height: 1.45;
  resize: vertical;
  font-family: inherit;
}

.segment-input:focus {
  outline: none;
  border-color: var(--accent-gold);
  background: rgba(15, 23, 42, 0.95);
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.15);
}

.del-seg-btn {
  background: transparent;
  border: none;
  color: var(--danger);
  font-size: 1.25rem;
  font-weight: bold;
  cursor: pointer;
  padding: 0 6px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.del-seg-btn:hover {
  opacity: 1;
}

/* Control Bar */
.control-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

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

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

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

.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.15);
}

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

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
}

.btn-icon:hover {
  color: var(--danger);
}

.btn-text {
  background: none;
  border: none;
  color: var(--accent-gold);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.82rem;
}

/* Record Button */
.btn-record {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 12px 24px;
  border-radius: 30px;
  font-weight: 600;
}

.btn-record:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.25);
  transform: scale(1.02);
}

.btn-record.recording {
  background: var(--danger);
  color: white;
  animation: pulse-red 1.2s infinite;
}

@keyframes pulse-red {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
  70% { box-shadow: 0 0 0 12px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.rec-dot {
  width: 10px;
  height: 10px;
  background: var(--danger);
  border-radius: 50%;
}

.btn-record.recording .rec-dot {
  background: white;
}

.rec-status {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-submit {
  padding: 12px 24px;
  border-radius: 30px;
}

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

/* Responsive Layout for Mobile Devices */
@media (max-width: 768px) {
  body {
    padding: 8px;
    height: auto;
    min-height: 100dvh;
  }

  .app-container {
    height: auto;
    min-height: 100dvh;
  }

  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions .btn {
    width: 100%;
    justify-content: center;
  }

  .main-content {
    grid-template-columns: 1fr;
    gap: 14px;
    height: auto;
    overflow: visible;
  }

  .sidebar {
    max-height: none;
    overflow-y: visible;
  }

  .chat-container {
    height: 520px;
    min-height: 460px;
  }

  .control-bar {
    flex-wrap: wrap;
    gap: 10px;
  }

  .btn-record, .btn-submit {
    flex: 1;
    min-width: 130px;
    justify-content: center;
    padding: 10px 16px;
    font-size: 0.85rem;
  }

  .rec-status {
    width: 100%;
    order: 3;
    font-size: 0.8rem;
    justify-content: center;
    text-align: center;
  }

  .role-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .role-card {
    padding: 10px;
    flex-direction: column;
    text-align: center;
  }

  .role-info h3 {
    font-size: 0.88rem;
  }

  .role-info p {
    font-size: 0.72rem;
  }
}

@media (max-width: 480px) {
  .role-grid {
    grid-template-columns: 1fr;
  }
}

/* Password Unlock Modal Overlay */
.password-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.password-modal-card {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 32px 26px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 0 35px rgba(245, 158, 11, 0.15);
}

.password-modal-icon {
  font-size: 3.5rem;
  margin-bottom: 12px;
}

.password-modal-card h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 10px;
}

.password-modal-desc {
  font-size: 0.86rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 20px;
}

.password-input-group {
  margin-bottom: 22px;
  text-align: left;
}

.password-input-group input {
  width: 100%;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text-main);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.password-input-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
}

.password-error-tip {
  color: #ef4444;
  font-size: 0.8rem;
  margin-top: 8px;
}

.password-modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.password-modal-actions .btn {
  flex: 1;
  padding: 12px;
  font-size: 0.92rem;
}
