/* ─── Results Modal (Glassmorphism) ─── */
.modal-overlay {
  position: fixed;
  top: 0; 
  left: 84px; /* PC & Mobile Collapsed Sidebar Width */
  width: calc(100% - 84px);
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(12px);
  z-index: 99999;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 60px 0;
  transition: all 0.4s ease;
}

/* If sidebar is expanded, shift modal further */
body:has(.sidebar:not(.collapsed)) .modal-overlay {
  left: 240px;
  width: calc(100% - 240px);
}

/* ─── Responsive: 1024px (Tablets & Mobile sidebar sync) ─── */
@media (max-width: 1024px) {
  .modal-overlay {
    left: 70px !important;
    width: calc(100% - 70px) !important;
  }
  
  body:has(.sidebar:not(.collapsed)) .modal-overlay {
    left: 100% !important; /* Sidebar occupies full screen on mobile */
    width: 0 !important;
  }
}

/* ─── Responsive: 480px (Standard Mobile sidebar sync) ─── */
@media (max-width: 480px) {
  .modal-overlay {
    left: 60px !important;
    width: calc(100% - 60px) !important;
  }
}


.modal-overlay.hide {
  opacity: 0;
  pointer-events: none;
}

.training-layout.is-training .grid-3x3 {
  filter: none !important;
}

.progress-container.is-training {
  animation: none !important;
  opacity: 1 !important;
}

.modal-content {
  background: rgba(25, 25, 35, 0.95); /* Slightly darker for contrast */
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 32px;
  width: 90%;
  max-width: 680px;
  padding: 40px;
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.8);
  position: relative;
  overflow: visible;
  backdrop-filter: blur(30px);
}

.modal-close {
  position: absolute;
  top: 25px;
  right: 25px;
  background: rgba(255, 255, 255, 0.05);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  z-index: 10;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  transform: rotate(90deg);
}

/* Remove previous segment padding overrides */
.modal-header, .modal-body, .modal-footer {
  padding: 0;
}

.modal-header { padding-bottom: 0; }
.modal-body { padding-top: 20px; padding-bottom: 20px; }

/* Header & Tabs */
.modal-header h2 {
  font-size: 32px;
  letter-spacing: 4px;
  font-weight: 900;
  text-align: center;
  margin-bottom: 30px;
  color: #fff;
}

.modal-tabs {
  display: flex;
  gap: 10px;
  background: rgba(255, 255, 255, 0.05);
  padding: 6px;
  border-radius: 12px;
  margin-bottom: 40px;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 8px;
  padding: 12px;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s;
}

.tab-btn.active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--accent);
}

/* Tab Content Logic */
.modal-body {
  min-height: 280px; /* Prevent collapse */
  padding: 20px 0;
  display: flex;
  flex-direction: column;
}

.modal-body .tab-content {
  display: none;
  width: 100%;
  max-height: 450px; /* Increased to fit cards + graph */
  overflow-y: auto;
  padding-right: 10px; /* Space for scrollbar */
  animation: fadeIn 0.4s ease forwards;
}

/* Custom Scrollbar for modal tabs */
.modal-body .tab-content::-webkit-scrollbar {
  width: 4px;
}
.modal-body .tab-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}
.modal-body .tab-content::-webkit-scrollbar-track {
  background: transparent;
}

.modal-body .tab-content.show {
  display: block !important;
}

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

/* Brief Summary Styles */
.summary-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 40px;
}

.stat-main {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--text-dim);
  text-transform: uppercase;
}

.stat-value {
  font-size: 48px;
  font-weight: 900;
  color: #fff;
}

.action-btn-small {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  margin-left: 8px;
  transition: 0.3s;
}

.action-btn-small.accent {
  background: var(--accent);
  color: #000;
  font-weight: 800;
  border: none;
}

/* Note Panel */
.note-panel {
  background: rgba(255, 255, 255, 0.04);
  border-radius: 16px;
  margin: 30px 0;
  max-height: 200px;
  overflow: hidden;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(255, 255, 255, 0.08); /* Separator feel */
}

.note-panel.hide {
  max-height: 0;
  margin-bottom: 0;
  opacity: 0;
  pointer-events: none;
}

#note-input {
  background: transparent;
  border: none;
  padding: 15px 20px;
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  resize: none;
  height: 90px;
  outline: none;
}

.note-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  width: calc(100% - 60px);
  margin: 0 auto;
}

.note-footer {
  padding: 12px 20px;
  display: flex;
  justify-content: flex-end;
}

/* Progress Bar */
.progress-section {
  margin-top: 20px;
}

.bar-label {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  letter-spacing: 1px;
  font-weight: 700;
}

.accuracy-value-highlight {
  font-size: 20px;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 0 15px var(--accent-glow);
}

.progress-bar-wrap {
  height: 12px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 20px;
}

.progress-bar-inner {
  height: 100%;
  background: linear-gradient(90deg, #FFC107, #FF8F00);
  width: 0;
  transition: width 1.5s cubic-bezier(0.1, 0, 0, 1);
  box-shadow: 0 0 20px rgba(255, 193, 7, 0.4);
}

.progress-stats {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 700;
}

.correct-count { color: #4CAF50; }
.mistake-count { color: #F44336; }

/* Detailed Stats Grid */
.detailed-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.stat-card {
  background: rgba(255, 255, 255, 0.04);
  padding: 24px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.card-label { font-size: 10px; color: var(--text-dim); letter-spacing: 1px; }
.card-value { font-size: 24px; font-weight: 900; color: #fff; display: block; margin-top: 5px; }

/* Graph Enhancements */
.graph-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 25px; /* Reduced from 40px */
  margin-bottom: 15px;
  gap: 15px;
}

.graph-filters {
  display: flex;
  gap: 6px;
  align-items: center;
  background: rgba(255, 255, 255, 0.03);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.filter-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: 0.3s;
  white-space: nowrap;
}

.filter-btn.active {
  background: rgba(255, 205, 48, 0.1);
  color: var(--accent);
}

/* Date Picker as a Button */
#graph-date-picker {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 11px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  width: auto;
  min-width: 120px;
  transition: all 0.3s;
}

#graph-date-picker:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 205, 48, 0.3);
}

/* Graph Containers */
.graph-wrapper {
  position: relative;
  width: 100%;
  background: rgba(0, 0, 0, 0.1);
  border-radius: 16px;
  padding: 10px;
  min-height: 140px; /* Reduced height */
  display: flex;
  align-items: center;
  justify-content: center;
}

.graph-tooltip {
  position: absolute;
  background: rgba(10, 10, 15, 0.95);
  border: 1px solid var(--accent); /* Full gold border */
  padding: 16px 20px;
  border-radius: 16px;
  color: #fff;
  pointer-events: none;
  z-index: 1100;
  box-shadow: 0 20px 40px rgba(0,0,0,0.8);
  backdrop-filter: blur(15px);
  min-width: 240px;
  transition: opacity 0.1s ease;
}

.graph-tooltip.hide {
  opacity: 0;
  visibility: hidden;
}

.tooltip-date {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
  font-weight: 900;
  color: var(--accent);
  margin-bottom: 8px;
  letter-spacing: 2px;
  font-size: 10px;
  text-transform: uppercase;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  padding-bottom: 6px;
}

.tooltip-time {
  color: rgba(255, 255, 255, 0.45);
  font-weight: 400;
  letter-spacing: 1px;
}

.tooltip-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 11px;
  gap: 16px;
}

.stat-label {
  color: var(--text-dim);
  font-weight: 700;
  font-size: 10px;
  white-space: nowrap;
}

.tooltip-val {
  font-weight: 900;
  color: #fff;
  font-size: 12px;
  text-align: right;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 40px;
  right: 40px;
  transform: translateY(20px);
  background: #FFCD30;
  color: #000;
  padding: 16px 32px;
  border-radius: 16px;
  font-family: 'Montserrat', sans-serif;
  font-weight: 900;
  font-size: 14px;
  letter-spacing: 1.5px;
  z-index: 10001;
  box-shadow: 0 20px 40px rgba(255,205,48,0.3);
  opacity: 0;
  pointer-events: none;
  transition: all 0.5s cubic-bezier(0.19, 1, 0.22, 1);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Custom Calendar Styles */
.calendar-popover {
  position: absolute;
  top: 45px;
  right: 0;
  background: #1a1a2e;
  border: 1px solid var(--accent);
  border-radius: 20px;
  padding: 20px;
  z-index: 2000;
  box-shadow: 0 30px 70px rgba(0,0,0,0.9);
  width: 260px;
  backdrop-filter: blur(25px);
  animation: calendarFade 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes calendarFade {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1024px) {
  .calendar-popover {
    position: absolute !important;
    top: 100% !important;
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    width: 280px !important;
    margin-top: 10px !important;
    z-index: 2000 !important;
    box-shadow: 0 20px 50px rgba(0,0,0,0.85) !important;
    animation: calendarFadeUnder 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
  }
}

@keyframes calendarFadeUnder {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.calendar-header {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
  color: var(--accent);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.calendar-grid {
  display: grid !important;
  grid-template-columns: repeat(7, 1fr) !important;
  gap: 4px !important;
  width: 100% !important;
  margin-top: 10px !important;
}

.cal-day-label { 
  font-size: 10px; 
  color: rgba(255,255,255,0.3); 
  text-align: center; 
  font-weight: 900;
  margin-bottom: 10px;
}

.cal-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #fff;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s;
}

.cal-day:hover { background: rgba(255,205,48,0.2); color: var(--accent); }
.cal-day.today { background: rgba(255,205,48,0.1); color: var(--accent); font-weight: 900; border: 1px solid rgba(255,205,48,0.3); }


/* Error Analysis Mini Grid */
.mini-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  width: 40px;
  height: 40px;
  background: rgba(255,255,255,0.05);
  padding: 2px;
  border-radius: 4px;
}

.mini-cell {
  background: rgba(255,255,255,0.05);
  border-radius: 1px;
}

.mini-cell.active {
  background: var(--accent);
  box-shadow: 0 0 5px var(--accent);
}

.trial-info {
  display: flex;
  align-items: center;
  gap: 15px;
}

.trial-details {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sound-title {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 1px;
}

.trial-status { font-weight: 900; }
.trial-status.correct { color: #4CAF50; }
.trial-status.error { color: #F44336; }

/* Analysis List */
.analysis-list {
  padding-right: 5px;
}

.analysis-list::-webkit-scrollbar { width: 4px; }
.analysis-list::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 2px; }

.trial-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 13px;
}

/* Footer / Continue */
.modal-footer {
  margin-top: 40px;
  padding-top: 30px;
  border-top: 1px solid rgba(255, 255, 255, 0.08); /* Divider with edges */
}

.btn-primary-large {
  position: relative;
  overflow: hidden;
  width: 100%;
  padding: 18px;
  background: #FFCD30;
  border: none;
  border-radius: 12px;
  
  font-family: 'Montserrat', sans-serif;
  font-size: 14px;
  font-weight: 900;
  color: #1a1a2e;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.25s ease;
  box-shadow: 0 0 20px 4px rgba(255, 205, 48, 0.3);
  outline: none;
}

/* Shimmer sweep effect like in popup */
.btn-primary-large::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(
    120deg,
    transparent 0%,
    rgba(255, 255, 255, 0.40) 50%,
    transparent 100%
  );
  transition: left 0.5s ease;
}

.btn-primary-large:hover {
  transform: scale(1.02);
  box-shadow: 0 0 30px 8px rgba(255, 205, 48, 0.5),
              0 0 60px 16px rgba(255, 205, 48, 0.15);
}

.btn-primary-large:hover::before {
  left: 100%;
}

.btn-primary-large:active {
  transform: scale(0.98);
  box-shadow: 0 0 12px 2px rgba(255, 205, 48, 0.4);
  transition-duration: 0.08s;
}

/* --- Tutorial Suggestion Modal --- */
#tutorial-suggestion-modal {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 20px !important;
}

#tutorial-suggestion-modal.hide {
    display: none !important;
}

.tutorial-content {
    max-width: 420px !important;
    padding: 40px !important;
    text-align: center;
}

.tutorial-modal-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.tutorial-icon-wrap {
    width: 64px;
    height: 64px;
    background: rgba(255, 205, 48, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    margin-bottom: 8px;
}

.tutorial-icon-wrap svg {
    width: 32px;
    height: 32px;
    animation: bounce 2s infinite ease-in-out;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.tutorial-content p {
    color: var(--text-dim);
    line-height: 1.6;
    margin-bottom: 32px;
    font-size: 14px;
}

.tutorial-content .warning-actions {
    display: flex;
    gap: 12px;
}

.tutorial-content .btn-secondary-large {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    padding: 14px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
}

.tutorial-content .btn-secondary-large:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.tutorial-content .btn-primary-large {
    flex: 1.5;
    padding: 14px;
    font-size: 12px;
}

/* ─── Responsive: 768px (Mobile & Tablets) ─── */
@media (max-width: 768px) {
    .modal-overlay {
        padding: 20px 0;
    }

    .modal-content {
        width: 95%;
        padding: 30px 20px;
        border-radius: 24px;
    }

    .modal-header h2 {
        font-size: 24px;
        margin-bottom: 20px;
        letter-spacing: 2px;
    }

    .modal-tabs {
        flex-wrap: wrap;
        gap: 6px;
    }

    .tab-btn {
        padding: 10px 8px;
        font-size: 11px;
    }

    .summary-top {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 20px;
        margin-bottom: 30px;
    }

    .stat-value {
        font-size: 40px;
    }

    .summary-actions {
        display: flex;
        gap: 10px;
        width: 100%;
        justify-content: center;
    }

    .action-btn-small {
        margin-left: 0;
        flex: 1;
        padding: 12px;
        font-size: 10px;
    }

    .detailed-grid {
        grid-template-columns: 1fr; /* Vertical stack for better readability */
        gap: 12px;
    }
    
    .stat-card {
        padding: 16px;
    }

    .card-value {
        font-size: 20px;
    }

    .graph-header {
        flex-direction: column;
        gap: 15px;
        margin-top: 40px;
    }

    .graph-filters {
        flex-wrap: wrap;
        justify-content: center;
    }

    .modal-footer {
        margin-top: 30px;
        padding-top: 20px;
    }

    .btn-primary-large {
        padding: 16px;
        font-size: 13px;
    }

    .trial-row {
        padding: 12px 8px;
    }
}

/* ─── Responsive: 480px (Standard Mobile) ─── */
@media (max-width: 480px) {
    .modal-header h2 {
        font-size: 20px;
    }

    .tab-btn {
        font-size: 10px;
    }

    .stat-value {
        font-size: 32px;
    }

    .progress-stats {
        font-size: 12px;
    }
    
    .trial-row {
        padding: 10px 6px;
        font-size: 11px;
    }

    .mini-grid {
        width: 32px;
        height: 32px;
    }
}

/* ─── Calendar Input Centering & Dynamic Width on max-width 769px ─── */
@media (max-width: 769px) {
    #graph-date-picker::placeholder {
        color: transparent !important;
        opacity: 0 !important;
    }
    
    /* When empty, make the date picker wrapper and input compact (like a square button) */
    .date-input-wrapper:has(#graph-date-picker:placeholder-shown) {
        width: 42px !important;
        transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }
    
    #graph-date-picker:placeholder-shown {
        width: 42px !important;
        min-width: 42px !important;
        padding: 8px 0 !important;
        text-align: center !important;
        transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    .date-input-wrapper:has(#graph-date-picker:placeholder-shown) i,
    .date-input-wrapper:has(#graph-date-picker:placeholder-shown) svg {
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        transition: all 0.3s ease !important;
    }

    /* When a date is selected, let it expand nicely to fit the date range text */
    .date-input-wrapper:not(:has(#graph-date-picker:placeholder-shown)) {
        width: 145px !important;
        transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    #graph-date-picker:not(:placeholder-shown) {
        width: 145px !important;
        min-width: 145px !important;
        padding: 8px 10px 8px 32px !important; /* Slightly reduced left padding to fit text better */
        font-size: 10px !important; /* Slightly smaller font to fit range like "05/18 - 05/25" */
        transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    .date-input-wrapper:not(:has(#graph-date-picker:placeholder-shown)) i,
    .date-input-wrapper:not(:has(#graph-date-picker:placeholder-shown)) svg {
        left: 12px !important;
        transform: translateY(-50%) !important;
        transition: all 0.3s ease !important;
    }
}

/* ─── Graph Tooltip Adaptions for 1024px & 480px Viewports ─── */
@media (max-width: 1024px) {
    .graph-tooltip {
        min-width: 200px !important;
        padding: 12px 16px !important;
        border-radius: 12px !important;
    }
    
    .tooltip-row {
        margin-bottom: 6px !important;
    }
}

@media (max-width: 480px) {
    .graph-tooltip {
        min-width: 170px !important;
        padding: 10px 12px !important;
        border-radius: 10px !important;
    }
    
    .tooltip-date {
        margin-bottom: 6px !important;
        padding-bottom: 4px !important;
        font-size: 9px !important;
    }
    
    .tooltip-row {
        margin-bottom: 4px !important;
        gap: 10px !important;
    }
    
    .stat-label {
        font-size: 9px !important;
    }
    
    .tooltip-val {
        font-size: 10px !important;
    }
}
