/* ==========================================================================
   APP.CSS
   Application shell (workspace, profile, history, nicolatesla)
   ChatGPT-style layout: answer on top, input bar at bottom
   ========================================================================== */

/* --------------------------------------------------------------------------
   APP SHELL LAYOUT (sidebar + main)
   -------------------------------------------------------------------------- */

.page-app,
.page-profile,
.page-history,
.page-nicolatesla {
  min-height: 100vh;
  background: radial-gradient(circle at top, #020c24, #020617 55%, #01020e);
}

.app-shell {
  min-height: 100vh;
  height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  align-items: stretch;
}

/* Sidebar */

.app-sidebar {
  padding: 1.1rem 1.1rem 1rem;
  border-right: 1px solid rgba(15, 23, 42, 0.95);
  background: linear-gradient(160deg, #020b26, #020617);
  box-shadow: 8px 0 26px rgba(15, 23, 42, 0.9);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.app-sidebar-admin {
  background: linear-gradient(160deg, #020b26, #020617);
}

.sidebar-header {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sidebar-user {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar-user-email {
  font-size: 0.9rem;
  font-weight: 500;
}

.sidebar-user-plan,
#subscription-badge,
#profile-sidebar-subscription,
#history-sidebar-subscription {
  display: inline-flex;
  align-items: center;
  padding: 0.18rem 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  font-size: 0.78rem;
  color: var(--text-soft);
}

/* Sidebar nav */

.sidebar-nav {
  margin-top: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(15, 23, 42, 0.9);
}

.sidebar-nav-btn {
  text-align: left;
  width: 100%;
  padding: 0.42rem 0.55rem;
  border-radius: 0.65rem;
  font-size: 0.88rem;
  color: var(--text-soft);
  background: transparent;
  transition:
    background-color 0.14s ease-out,
    color 0.14s ease-out,
    box-shadow 0.14s ease-out;
}

.sidebar-nav-btn:hover {
  background: rgba(15, 23, 42, 0.95);
  color: #f9fafb;
}

.sidebar-nav-btn-active {
  background: radial-gradient(circle at top left, rgba(34, 211, 238, 0.15), #02091a);
  color: #f9fafb;
  box-shadow: 0 0 18px rgba(34, 211, 238, 0.35);
}

/* Sidebar usage */

.sidebar-usage {
  margin-top: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  font-size: 0.82rem;
}

.usage-block {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.usage-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--text-muted);
}

.usage-value {
  font-size: 0.88rem;
}

.usage-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.18rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.96);
  font-size: 0.82rem;
  color: var(--text-soft);
}

/* Sidebar footer */

.sidebar-footer {
  margin-top: auto;
  padding-top: 0.9rem;
  border-top: 1px solid rgba(15, 23, 42, 0.9);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sidebar-logout-btn {
  align-self: flex-start;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  border: 1px solid rgba(239, 68, 68, 0.7);
  color: #fecaca;
  background: rgba(127, 29, 29, 0.1);
  font-size: 0.82rem;
}

.sidebar-logout-btn:hover {
  background: rgba(127, 29, 29, 0.2);
}

.sidebar-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Main */

.app-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 1.3rem 1.4rem 1.2rem;
}

/* Topbar */

.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}

.topbar-title {
  font-size: 1.25rem;
  margin-bottom: 0.15rem;
}

.topbar-subtitle {
  font-size: 0.84rem;
}

/* Inner region: flex column so answer fills and input sticks to bottom */

.app-main-inner {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  /* important: prevent whole page from expanding */
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   WORKSPACE (app.html)
   -------------------------------------------------------------------------- */

/* Answer panel (top) */

.answer-panel {
  flex: 1 1 auto;
  min-height: 0;
  border-radius: 1rem;
  padding: 0.9rem 0.9rem;
  background: radial-gradient(circle at top, rgba(34, 211, 238, 0.1), #020b26);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;

  /* FIX: keep answer box at a fixed viewport height so it doesn't expand endlessly */
  height: 60vh;
  max-height: 60vh;
}

.answer-panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
}

.answer-title {
  font-size: 0.98rem;
  font-weight: 600;
}

.answer-status {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Scrollable container for answer / canvas */

.answer-container {
  margin-top: 0.2rem;
  flex: 1 1 auto;
  min-height: 0;
  border-radius: 0.8rem;
  background: rgba(15, 23, 42, 0.98);
  border: 1px solid rgba(15, 23, 42, 0.9);
  padding: 0.75rem 0.8rem;
  overflow-y: auto;
  /* scroll only inside box */
  max-height: 100%;
  /* respect parent height */
}

.answer-placeholder {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.answer-text {
  font-size: 0.92rem;
  white-space: pre-wrap;
}

/* formatted markdown inside answer */
.answer-text h1,
.answer-text h2,
.answer-text h3 {
  margin-top: 0.6rem;
  margin-bottom: 0.25rem;
  font-weight: 600;
}

.answer-text h1 {
  font-size: 1.1rem;
}

.answer-text h2 {
  font-size: 1.02rem;
}

.answer-text h3 {
  font-size: 0.98rem;
}

.answer-text p {
  margin: 0.15rem 0;
  line-height: 1.7;
}

.answer-text ul {
  margin: 0.25rem 0 0.25rem 1.2rem;
  padding-left: 0;
  list-style: disc;
}

.answer-text li {
  margin-bottom: 0.1rem;
}

/* Handwriting */

.handwriting-container {
  border-radius: 0.8rem;
  border: 1px dashed var(--border-subtle);
  background: radial-gradient(circle at top left, rgba(34, 211, 238, 0.08), #020617);
  margin-top: 0.4rem;
  overflow: hidden;
}

.handwriting-canvas {
  display: block;
  width: 100%;
  height: 260px;
}

/* Input shell (bottom) */

.app-input-shell {
  margin-top: 0.4rem;
  border-radius: 1rem;
  background: rgba(15, 23, 42, 0.98);
  border: 1px solid var(--border-subtle);
  padding: 0.7rem 0.8rem 0.75rem;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.85);
}

/* Mode toggle row */

.mode-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.55rem;
}

.mode-label {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.mode-toggle-group {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  border-radius: 999px;
  padding: 0.15rem;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.96);
}

.mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.8rem;
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--text-soft);
  cursor: pointer;
}

.mode-pill input {
  display: none;
}

/* JS will toggle class .mode-pill-active */
.mode-pill-active {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #020617 !important;
  box-shadow: 0 0 14px rgba(34, 211, 238, 0.45);
}

/* Input row – textarea full width, buttons below */

.input-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.55rem;
}

.question-input {
  flex: 1 1 auto;
  width: 100%;
  min-height: 110px;
  max-height: 220px;
  padding: 0.6rem 0.75rem;
  border-radius: 0.8rem;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.98);
  color: var(--text-primary);
  resize: vertical;
  font-size: 0.94rem;
  line-height: 1.5;
}

.question-input::placeholder {
  color: rgba(148, 163, 184, 0.75);
}

.question-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary-soft);
  outline: none;
}

/* Input actions */

.input-actions {
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  gap: 0.4rem;
}

#btn-save-answer[disabled] {
  opacity: 0.55;
  cursor: default;
}

/* --------------------------------------------------------------------------
   PROFILE PAGE
   -------------------------------------------------------------------------- */

.profile-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 1.2rem;
}

.profile-column .card {
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-card);
}

.detail-grid {
  margin-top: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.detail-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
  font-size: 0.9rem;
}

.detail-row dt {
  font-size: 0.84rem;
  color: var(--text-muted);
}

.detail-row dd {
  font-weight: 500;
}

.profile-actions {
  margin-top: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

/* --------------------------------------------------------------------------
   HISTORY PAGE
   -------------------------------------------------------------------------- */

.history-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}

.history-page-info {
  font-size: 0.84rem;
  color: var(--text-muted);
}

.history-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.history-empty {
  margin-top: 0.6rem;
  border-radius: 1rem;
  padding: 0.9rem 0.9rem;
  border: 1px dashed var(--border-subtle);
  background: rgba(15, 23, 42, 0.96);
  font-size: 0.9rem;
  color: var(--text-soft);
}

.history-list {
  margin-top: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.history-item {
  border-radius: 0.95rem;
  padding: 0.7rem 0.75rem;
  background: rgba(15, 23, 42, 0.98);
  border: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  gap: 0.9rem;
}

.history-item-main {
  flex: 1 1 auto;
  min-width: 0;
}

.history-item-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.history-item-question {
  font-size: 0.9rem;
  margin-bottom: 0.2rem;
}

.history-item-answer {
  font-size: 0.84rem;
  color: var(--text-soft);
  max-height: 3.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-actions {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.history-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
}

.history-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(10px);
}

.history-modal-dialog {
  position: relative;
  z-index: 81;
  max-width: 640px;
  margin: 4vh auto;
  padding: 1rem 1rem 0.9rem;
  border-radius: 1.1rem;
  background: rgba(15, 23, 42, 0.98);
  border: 1px solid var(--border-subtle);
  box-shadow: 0 26px 60px rgba(15, 23, 42, 0.98);
}

.history-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.3rem;
}

.history-modal-close-btn {
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  font-size: 0.8rem;
  color: var(--text-soft);
}

.history-modal-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.history-modal-body {
  max-height: 380px;
  overflow-y: auto;
  font-size: 0.9rem;
}

.history-modal-question-label,
.history-modal-answer-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
  margin-bottom: 0.15rem;
}

.history-modal-question {
  margin-bottom: 0.4rem;
}

.history-modal-answer {
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 0.9rem;
}

.history-modal-footer {
  margin-top: 0.6rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
}

/* --------------------------------------------------------------------------
   NICOLATESLA ADMIN PAGE
   -------------------------------------------------------------------------- */

.nicolatesla-section {
  border-radius: 1rem;
  padding: 0.9rem 0.95rem 0.95rem;
  background: rgba(15, 23, 42, 0.98);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-card);
  margin-bottom: 0.8rem;
}

.nicolatesla-section h2 {
  font-size: 1rem;
  margin-bottom: 0.45rem;
}

.admin-error-banner {
  padding: 0.55rem 0.7rem;
  border-radius: 0.8rem;
  border: 1px solid rgba(248, 113, 113, 0.8);
  background: rgba(127, 29, 29, 0.2);
  color: #fecaca;
  font-size: 0.85rem;
}

/* Summary grid */

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.7rem;
}

.summary-card {
  border-radius: 0.8rem;
  padding: 0.6rem 0.65rem;
  background: rgba(15, 23, 42, 0.98);
  border: 1px solid var(--border-subtle);
}

.summary-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.summary-value {
  margin-top: 0.2rem;
  font-size: 1.05rem;
  font-weight: 600;
}

/* Config form */

.config-form .input-group {
  margin-bottom: 0.6rem;
}

/* Users section */

.users-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.users-page-info {
  color: var(--text-muted);
}

.users-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.table-wrapper {
  border-radius: 0.8rem;
  border: 1px solid var(--border-subtle);
  overflow-x: auto;
  background: rgba(15, 23, 42, 0.98);
}

.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.users-table th,
.users-table td {
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid rgba(15, 23, 42, 0.9);
}

.users-table th {
  text-align: left;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.users-table tr:last-child td {
  border-bottom: none;
}

/* --------------------------------------------------------------------------
   RESPONSIVE BREAKPOINTS
   -------------------------------------------------------------------------- */

@media (max-width: 1024px) {
  .app-shell {
    grid-template-columns: 230px minmax(0, 1fr);
  }

  .profile-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  /* On phone/tablet: sidebar becomes a slim header-style nav bar */
  .app-sidebar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding-block: 0.6rem;
    padding-inline: 0.9rem;
  }

  /* Hide extra sidebar information so only nav (workspace/history/profile etc.)
     behaves like a header in small screens */
  .sidebar-header {
    display: none;
  }

  .sidebar-footer {
    display: none;
  }

  .sidebar-usage {
    display: none;
  }

  .sidebar-nav {
    border-top: none;
    margin-top: 0;
    padding-top: 0;
    flex-wrap: wrap;
    flex-direction: row;
  }

  .app-main {
    padding-inline: 1rem;
    padding-block: 1rem;
  }
}

@media (max-width: 640px) {

  /* Keep sidebar as a compact header row even on small phones */
  .app-topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .input-row {
    flex-direction: column;
    align-items: stretch;
  }

  .input-actions {
    flex-direction: row;
    justify-content: flex-end;
  }

  .history-item {
    flex-direction: column;
    align-items: stretch;
  }

  .summary-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .history-modal-dialog {
    margin-inline: 0.8rem;
  }
}

@media (max-width: 480px) {
  .app-main {
    padding-inline: 0.75rem;
  }

  .app-sidebar {
    padding-inline: 0.75rem;
  }

  .answer-panel {
    padding-inline: 0.8rem;
  }

  .app-input-shell {
    padding-inline: 0.65rem;
  }

  /* ===== EXPORT BUTTONS - FORCE VISIBILITY ===== */

.admin-export-actions .export-solid-btn {
  padding: 10px 20px !important;
  border-radius: 6px !important;
  background: #ffffff !important;
  color: #000 !important;
  font-weight: 600 !important;
  font-size: 15px !important;
  border: none !important;
  cursor: pointer !important;
  display: inline-block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.admin-export-buttons {
  display: flex !important;
  gap: 15px !important;
  align-items: center !important;
  justify-content: flex-start !important;
}

.admin-export-actions {
  display: flex !important;
  justify-content: space-between !important;
  align-items: center !important;
  padding: 20px !important;
  margin: 20px 0 !important;
  background: rgba(255, 255, 255, 0.05) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  border-radius: 10px !important;
}

}