/* ============================================================
   DIALOG
   ============================================================ */

.subject-dialog {
  width: min(540px, calc(100vw - 30px));

  padding: 0;

  border: 1px solid var(--border-strong);

  border-radius: 20px;

  color: var(--text-primary);

  background: linear-gradient(180deg, #151b2b, #0e1320);

  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.55);
}

.subject-dialog::backdrop {
  background: rgba(2, 4, 10, 0.75);

  backdrop-filter: blur(5px);
}

.subject-form {
  padding: 22px;
}

.dialog-header {
  display: flex;

  align-items: flex-start;
  justify-content: space-between;

  gap: 20px;

  margin-bottom: 22px;
}

.eyebrow {
  display: block;

  margin-bottom: 5px;

  color: var(--purple-light);

  font-size: 10px;
  font-weight: 800;

  text-transform: uppercase;

  letter-spacing: 0.12em;
}

.dialog-header h2 {
  margin: 0;

  font-size: 22px;

  letter-spacing: -0.035em;
}

.form-grid {
  display: grid;

  grid-template-columns: repeat(2, minmax(0, 1fr));

  gap: 15px;
}

.form-field {
  display: flex;

  flex-direction: column;

  gap: 7px;
}

.form-field.full-width {
  grid-column: 1 / -1;
}

.form-field>span {
  color: var(--text-secondary);

  font-size: 11px;
  font-weight: 700;
}

.form-field input,
.form-field select {
  width: 100%;

  min-height: 43px;

  padding: 0 12px;

  border: 1px solid var(--border);

  border-radius: 10px;

  outline: none;

  color: var(--text-primary);

  background: rgba(0, 0, 0, 0.18);

  transition:
    border-color var(--transition),
    box-shadow var(--transition);
}

.form-field input::placeholder {
  color: #5d667b;
}

.form-field input:focus,
.form-field select:focus {
  border-color: rgba(102, 131, 255, 0.55);

  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.08);
}

.form-field select option {
  background: #101523;
}

.dialog-actions {
  display: flex;

  align-items: center;
  justify-content: flex-end;

  gap: 9px;

  margin-top: 23px;
}

/* ============================================================
   TOAST
   ============================================================ */

.toast {
  position: fixed;

  left: 50%;
  bottom: 28px;

  z-index: 100;

  transform: translate(-50%, 30px);

  min-width: 200px;

  max-width: calc(100vw - 30px);

  padding: 11px 15px;

  border: 1px solid var(--border-strong);

  border-radius: 11px;

  color: white;

  background: rgba(22, 27, 42, 0.96);

  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.38);

  opacity: 0;

  pointer-events: none;

  transition:
    opacity 180ms ease,
    transform 180ms ease;

  font-size: 12px;

  text-align: center;
}

.toast.show {
  opacity: 1;

  transform: translate(-50%, 0);
}

/* ============================================================
   LOADING OVERLAY
   ============================================================ */

.loading-overlay {
  position: fixed;

  inset: 0;

  z-index: 200;

  display: grid;

  place-items: center;

  background: rgba(5, 7, 13, 0.55);

  backdrop-filter: blur(3px);
}

.loading-card {
  display: flex;

  align-items: center;

  gap: 11px;

  padding: 13px 16px;

  border: 1px solid var(--border);

  border-radius: 12px;

  background: #121827;

  box-shadow: var(--shadow);

  color: var(--text-secondary);

  font-size: 12px;
}

.spinner {
  width: 17px;
  height: 17px;

  border: 2px solid rgba(255, 255, 255, 0.1);

  border-top-color: var(--blue);

  border-radius: 50%;

  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ============================================================
   TABLET
   ============================================================ */

@media (max-width: 1100px) {
  .subjects-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ============================================================
   MOBILE
   ============================================================ */

@media (max-width: 700px) {
  .app-shell {
    padding: 18px 14px 100px;
  }

  .topbar {
    align-items: flex-start;
  }

  .brand-area p {
    display: none;
  }

  .connection-status {
    margin-top: 3px;
  }

  .summary-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .work-hours-panel {
    padding: 12px;
  }

  .work-hours-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .work-hours-chart {
    height: 66px;
  }

  .work-hours-form-grid {
    grid-template-columns: 1fr;
  }

  .subjects-grid {
    grid-template-columns: 1fr;

    gap: 14px;
  }

  .card-header {
    padding: 18px 16px 14px;
  }

  .card-body {
    padding: 0 16px;
  }

  .card-footer {
    padding: 13px 16px 16px;
  }

  .edit-mode-panel {
    margin: 0 16px 14px;
  }

  .fab {
    left: auto;
    right: 16px;
    bottom: 16px;

    width: 52px;
    height: 52px;
  }

  .work-hours-dialog {
    width: calc(100vw - 20px);

    max-height: calc(100vh - 20px);

    border-radius: 16px;
  }

  .work-hours-dialog-card {
    padding: 18px;
  }
}

/* ============================================================
   SMALL MOBILE
   ============================================================ */

@media (max-width: 430px) {
  .card-title {
    max-width: 200px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-field.full-width {
    grid-column: auto;
  }

  .dialog-actions {
    flex-direction: column-reverse;
  }

  .dialog-actions button {
    width: 100%;
  }
}

/* ============================================================
   STUDY PROGRESS BAR
   ============================================================ */

.study-progress {
  margin-top: 14px;
  width: 100%;
  padding-left: 20px;
  padding-right: 20px;
}

/* Header */

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

.progress-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.progress-percent {
  font-size: 0.75rem;
  color: var(--text-primary);
}

/* Track */

.progress-track {
  width: 100%;
  height: 7px;

  overflow: hidden;

  border-radius: 999px;

  background: rgba(255, 255, 255, 0.08);
}

/* Fill */

.progress-fill {
  height: 100%;

  min-width: 0;

  border-radius: inherit;

  background: linear-gradient(90deg, #3b82f6, #8b5cf6);

  transition: width 0.35s ease;
}

/* Bottom information */

.progress-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;

  margin-top: 6px;

  font-size: 0.68rem;

  color: var(--text-muted);
}

/* ============================================================
   MOBILE COLLAPSIBLE SUBJECT CARDS
   ============================================================ */

/*
 * Desktop:
 * Normal card behavior remains unchanged.
 */
.mobile-card-toggle {
  display: none;
}

/* ============================================================
   MOBILE
   ============================================================ */

@media (max-width: 600px) {
  .subject-card {
    position: relative;
    overflow: hidden;

    transition:
      max-height 0.3s ease,
      padding 0.3s ease,
      transform 0.2s ease;
  }

  /* --------------------------------------------------------
       MOBILE CARD HEADER
    -------------------------------------------------------- */

  .card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;

    gap: 10px;
  }

  .card-title-area {
    min-width: 0;
    flex: 1;
  }

  /*
     * Dropdown button
     */

  .mobile-card-toggle {
    display: flex;

    align-items: center;
    justify-content: center;

    flex: 0 0 36px;

    width: 36px;
    height: 36px;

    padding: 0;

    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;

    background: rgba(255, 255, 255, 0.04);

    color: var(--text-primary);

    cursor: pointer;

    -webkit-tap-highlight-color: transparent;
  }

  .mobile-card-toggle:active {
    transform: scale(0.94);
  }

  .mobile-card-chevron {
    display: block;

    font-size: 11px;
    line-height: 1;

    transition: transform 0.25s ease;
  }

  /* ========================================================
       COMPACT STATE
       ======================================================== */

  /*
     * Hide the functional card body and footer.
     *
     * The card header remains visible.
     */
  .subject-card:not(.mobile-expanded) .card-body,
  .subject-card:not(.mobile-expanded) .card-footer,
  .subject-card:not(.mobile-expanded) .edit-pool {
    display: none;
  }

  /*
     * Progress bar remains visible in compact mode.
     */

  .subject-card:not(.mobile-expanded) .study-progress {
    display: block;
  }

  /*
     * Give compact cards a clean small-card appearance.
     */

  .subject-card:not(.mobile-expanded) {
    padding-bottom: 14px;
  }

  /*
     * Don't show the detailed progress summary in compact mode.
     * Keep only the visual bar + percentage.
     */

  .subject-card:not(.mobile-expanded) .progress-summary {
    display: none;
  }

  .subject-card:not(.mobile-expanded) .progress-header {
    margin-bottom: 6px;
  }

  /* ========================================================
       EXPANDED STATE
       ======================================================== */

  .subject-card.mobile-expanded {
    /*
         * Normal card content becomes available.
         */
    padding-bottom: 16px;
  }

  .subject-card.mobile-expanded .card-body,
  .subject-card.mobile-expanded .card-footer,
  .subject-card.mobile-expanded .edit-pool {
    display: block;
  }

  /*
     * The progress bar remains visible in expanded state.
     */

  .subject-card.mobile-expanded .study-progress {
    display: block;
  }

  /*
     * Normal progress information is restored.
     */

  .subject-card.mobile-expanded .progress-summary {
    display: flex;
  }

  /*
     * Expanded card can use full available width.
     */

  .subject-card.mobile-expanded {
    width: 100%;
  }

  /* ========================================================
       EDIT MODE
       ======================================================== */

  /*
     * If the user enters Edit Mode, automatically keep
     * the card expanded.
     */

  .subject-card.editing {
    display: block;
  }

  .subject-card.editing .card-body,
  .subject-card.editing .card-footer,
  .subject-card.editing .edit-pool {
    display: block;
  }

  /*
     * Edit mode should never hide the lesson controls.
     */

  .subject-card.editing .mobile-card-toggle {
    display: flex;
  }

  /* ========================================================
       SMALL SCREEN SPACING
       ======================================================== */

  .subject-card {
    margin-bottom: 12px;
  }

  .card-title {
    font-size: 1rem;
  }

  .card-code {
    font-size: 0.78rem;
  }

  .card-meta {
    gap: 6px;
  }

  .credit-pill,
  .complexity-badge {
    font-size: 0.68rem;
  }
}

