:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --bg-gradient-start: #0f172a;
  --bg-gradient-end: #1e1b4b;
  --glass-bg: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.1);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem;
  overflow-x: hidden;
}

.dashboard-container {
  width: 95vw;
  max-width: 1500px;
  display: flex;
  flex-direction: column;
  gap: 3rem;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 1rem;
  animation: fadeInDown 0.8s ease-out;
}

header h1 {
  font-size: 2.8rem;
  font-weight: 800;
  background: linear-gradient(to right, #818cf8, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.05em;
  margin-bottom: 0.5rem;
}

header p {
  color: var(--text-muted);
  font-size: 1.1rem;
}

/* Stats Row */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
}

.stat-card {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 1.5rem;
  text-align: center;
  transition: transform 0.3s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
}

.stat-title {
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.stat-value {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--text-main);
}

/* Core Dashboard Layout */
.dashboard-grid {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  width: 100%;
}

@media (min-width: 900px) {
  .dashboard-grid {
    display: grid;
    grid-template-columns: minmax(400px, 480px) 1fr;
    align-items: start;
  }
}

.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 2.2rem;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
  animation: fadeInUp 0.6s ease-out;
}

.panel-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.8rem;
}

.panel-title {
  font-size: 1.25rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0;
}

/* Input Form & Hero Upload */
.divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 1.8rem 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 1px;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.divider:not(:empty)::before {
  margin-right: 1rem;
}

.divider:not(:empty)::after {
  margin-left: 1rem;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.input-field {
  width: 100%;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  color: var(--text-main);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
  font-family: inherit;
  resize: vertical;
}

.input-field:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0.85rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

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

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-main);
}

.btn-danger {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
}

/* Upload Action Buttons (Files vs Folder) */
.upload-buttons-row {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.upload-buttons-row .btn-secondary {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem;
}

.hidden-file {
  display: none !important;
}

/* Drag and Drop Zone */
.upload-zone {
  border: 2px dashed var(--glass-border);
  border-radius: 12px;
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  background: rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.08);
}

.upload-zone svg {
  color: var(--text-muted);
  width: 44px;
  height: 44px;
  margin-bottom: 0.3rem;
  transition: color 0.3s;
}

.upload-zone:hover svg, .upload-zone.dragover svg {
  color: var(--primary);
}

.upload-zone p {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.upload-zone .browse-text {
  color: var(--primary);
  font-weight: 600;
}

/* Selected File Chips & Badge */
.selected-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  font-size: 0.88rem;
  color: var(--text-main);
  margin-top: 0.5rem;
}

.chip-counter {
  background: var(--primary);
  color: white;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.8rem;
}

/* Jobs List */
.jobs-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.job-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 1.3rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  animation: slideIn 0.4s ease-out forwards;
}

.job-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.job-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 70%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.job-meta-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.85rem;
}

.job-filename-line {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.job-filename-text {
  color: #cbd5e1;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.job-caption-pill {
  display: inline-flex;
  align-items: flex-start;
  gap: 0.45rem;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.28);
  border-radius: 8px;
  padding: 0.35rem 0.65rem;
  font-size: 0.82rem;
  color: #e0e7ff;
  line-height: 1.35;
  word-break: break-word;
}

.job-eta-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: #fcd34d;
  font-weight: 600;
  background: rgba(245, 158, 11, 0.12);
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  font-size: 0.8rem;
}

.history-meta-caption {
  margin-top: 0.35rem;
  font-size: 0.82rem;
  color: #c7d2fe;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.2);
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  display: inline-block;
  max-width: 100%;
  word-break: break-word;
}

.history-meta-filename {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.badge {
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge.downloading { background: rgba(99, 102, 241, 0.2); color: #818cf8; }
.badge.transcribing, .badge.processing { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }
.badge.completed { background: rgba(16, 185, 129, 0.2); color: #6ee7b7; }
.badge.error { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }

/* Progress Bar */
.progress-container {
  width: 100%;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 999px;
  height: 9px;
  overflow: hidden;
  position: relative;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #818cf8, #c084fc);
  border-radius: 999px;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.progress-bar::after {
  content: "";
  position: absolute;
  top: 0; left: 0; bottom: 0; right: 0;
  background: linear-gradient(90deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.2) 50%, rgba(255,255,255,0) 100%);
  transform: translateX(-100%);
  animation: shimmer 2s infinite;
}

.job-details {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 2rem;
  min-height: 200px;
}

.empty-state svg {
  margin-bottom: 1rem;
  color: var(--glass-border);
}

.empty-state h3 {
  color: var(--text-main);
  margin-bottom: 0.5rem;
  font-weight: 600;
}

/* History Table (Recent Transcripts) */
.history-table {
  width: 100%;
  border-collapse: collapse;
}

.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--glass-border);
  transition: background 0.2s;
}

.history-row:last-child {
  border-bottom: none;
}

.history-row:hover {
  background: rgba(255, 255, 255, 0.02);
}

.history-info {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 1;
}

.history-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

/* Modal Dialog */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

.modal-box {
  background: #1e1b4b;
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 2rem;
  max-width: 480px;
  width: 90%;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.modal-box h3 {
  font-size: 1.3rem;
  margin-bottom: 0.75rem;
  color: var(--text-main);
}

.modal-box p {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 1.5rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
}

/* Animations */
@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes shimmer {
  100% { transform: translateX(100%); }
}

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

@media (max-width: 600px) {
  .history-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }
  .history-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

/* --- Authentication & Login Page Styles --- */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  width: 100%;
  animation: fadeIn 0.8s ease-out;
}

.login-card {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: 3rem 2.5rem;
  width: 100%;
  max-width: 460px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.login-icon {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, #2AABEE, #229ED9);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.5rem auto;
  box-shadow: 0 8px 24px rgba(42, 171, 238, 0.35);
}

.login-icon svg {
  width: 34px;
  height: 34px;
  fill: #fff;
}

.login-card h2 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  background: linear-gradient(to right, #ffffff, #cbd5e1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 2rem;
}

.telegram-widget-box {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 1.5rem 0;
  min-height: 48px;
  background: transparent !important;
}

.telegram-widget-box iframe {
  background: transparent !important;
  color-scheme: light !important;
  border-radius: 9999px !important;
  overflow: hidden !important;
  box-shadow: 0 4px 15px rgba(42, 171, 238, 0.25);
}

.auth-alert {
  padding: 0.85rem 1.2rem;
  border-radius: 12px;
  font-size: 0.88rem;
  margin-bottom: 1.5rem;
  text-align: left;
  line-height: 1.4;
}

.auth-alert.danger {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

.auth-alert.info {
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.35);
  color: #c7d2fe;
}

.passkey-drawer {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--glass-border);
}

.passkey-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.82rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: color 0.2s ease;
}

.passkey-toggle:hover {
  color: var(--text-main);
}

.passkey-form {
  display: none;
  margin-top: 1rem;
  flex-direction: column;
  gap: 0.75rem;
}

.passkey-form.open {
  display: flex;
}

/* User Badge in Dashboard Header */
.header-top-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  width: 100%;
  margin-bottom: -1rem;
}

.user-profile-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  padding: 0.4rem 0.9rem;
  border-radius: 9999px;
  font-size: 0.85rem;
}

.user-profile-badge .avatar-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

.user-profile-badge .user-name {
  font-weight: 600;
  color: var(--text-main);
}

.user-profile-badge .logout-link {
  color: var(--text-muted);
  text-decoration: none;
  display: flex;
  align-items: center;
  padding: 0.2rem 0.4rem;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.user-profile-badge .logout-link:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

/* RBAC Roles and User Badges */
.role-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  letter-spacing: 0.02em;
}

.role-badge.role-owner {
  background: rgba(234, 179, 8, 0.18);
  color: #facc15;
  border: 1px solid rgba(234, 179, 8, 0.4);
  box-shadow: 0 0 8px rgba(234, 179, 8, 0.25);
}

.role-badge.role-admin {
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.4);
}

.role-badge.role-user {
  background: rgba(148, 163, 184, 0.15);
  color: #cbd5e1;
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.btn-manage-users {
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
  border: 1px solid rgba(99, 102, 241, 0.35);
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.2s ease;
}

.btn-manage-users:hover {
  background: rgba(99, 102, 241, 0.3);
  color: #fff;
  border-color: #818cf8;
}

.user-filter-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255, 255, 255, 0.04);
  padding: 0.25rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
}

.user-filter-select {
  background: rgba(15, 23, 42, 0.85);
  color: var(--text-main);
  border: 1px solid var(--glass-border);
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  font-size: 0.8rem;
  outline: none;
  cursor: pointer;
}

.user-filter-select:focus {
  border-color: var(--primary);
}

.job-user-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  font-weight: 600;
  color: #93c5fd;
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.25);
  padding: 1px 6px;
  border-radius: 4px;
}

/* Admin Users Modal */
.modal-lg {
  max-width: 680px;
  width: 90%;
}

.modal-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.6rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 0.4rem;
  transition: color 0.2s ease;
}

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

.add-user-form {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
}

.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.users-table th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--glass-border);
  font-weight: 600;
}

.users-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  vertical-align: middle;
}

.users-table tr:hover {
  background: rgba(255, 255, 255, 0.02);
}
