/* Shared module polish: keeps every iframe aligned with the cleaner Mock Test feel. */
:root {
  --dash-bg: #050b12;
  --dash-surface: #0d1117;
  --dash-surface-2: #111820;
  --dash-border: #253040;
  --dash-border-soft: #1d2733;
  --dash-text: #e6edf3;
  --dash-muted: #8b949e;
  --dash-blue: #58a6ff;
  --dash-green: #3fb950;
  --dash-red: #f85149;
  --dash-yellow: #d29922;
}

body {
  background:
    radial-gradient(circle at 18% -10%, rgba(88,166,255,0.10), transparent 28%),
    radial-gradient(circle at 88% 6%, rgba(63,185,80,0.07), transparent 24%),
    var(--dash-bg) !important;
  color: var(--dash-text);
  font-family: "Segoe UI", Arial, Helvetica, sans-serif !important;
}

header {
  background: linear-gradient(180deg, rgba(13,17,23,0.98), rgba(5,11,18,0.94)) !important;
  border-bottom: 1px solid var(--dash-border-soft) !important;
  box-shadow: 0 18px 45px rgba(0,0,0,0.18);
}

header h1 {
  color: #ffffff !important;
  font-weight: 800 !important;
  letter-spacing: 0.4px !important;
}

header p,
#datetime {
  color: var(--dash-muted) !important;
}

button,
input,
select,
textarea {
  border-radius: 10px !important;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, filter 0.18s ease !important;
}

input,
select,
textarea {
  background: var(--dash-surface) !important;
  color: var(--dash-text) !important;
  border: 1px solid var(--dash-border) !important;
  outline: none !important;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--dash-blue) !important;
  box-shadow: 0 0 0 3px rgba(88,166,255,0.14) !important;
}

button {
  cursor: pointer;
  font-weight: 700 !important;
  border: 1px solid rgba(88,166,255,0.18) !important;
  box-shadow: 0 10px 24px rgba(0,0,0,0.14);
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
  box-shadow: 0 14px 30px rgba(0,0,0,0.24);
}

button:active {
  transform: translateY(0) scale(0.98);
}

.controls,
.addRow,
.formBox,
.mgmtBox,
.panel,
.card,
.scoreCard,
.graphBox,
.chartBox,
.calendarBox,
.historyBox,
.mainBox,
.tableBox,
.rewardCard,
.timetableBox,
.copyBox,
.subject,
.subjectCard,
.meta,
.section,
.sum-box,
.weightBox,
.insights,
.reportBox,
.dayCell,
.quickMeals,
.quickHeader,
.mealsBox,
.mealItem,
.savedMealItem,
.gym-day,
.gym-ex,
.tasks,
.days,
.habits,
.calDay,
.subject-graph-container,
.chapter-box,
.stats .card {
  border-color: var(--dash-border-soft) !important;
  box-shadow: 0 14px 34px rgba(0,0,0,0.18), inset 0 1px 0 rgba(255,255,255,0.03) !important;
}

.card,
.scoreCard,
.rewardCard,
.panel,
.graphBox,
.chartBox,
.calendarBox,
.historyBox,
.mainBox,
.tableBox,
.mgmtBox,
.formBox,
.section,
.reportBox,
.timetableBox,
.copyBox {
  background: linear-gradient(145deg, var(--dash-surface), var(--dash-surface-2)) !important;
}

.card:hover,
.scoreCard:hover,
.rewardCard:hover,
.subjectCard:hover,
.panel:hover,
.graphBox:hover,
.chartBox:hover,
.gym-day:hover,
.mealItem:hover,
.savedMealItem:hover {
  border-color: rgba(88,166,255,0.42) !important;
  transform: translateY(-1px);
}

.card h2,
.scoreCard h2,
.rewardCard h2 {
  color: var(--dash-blue) !important;
  font-weight: 800 !important;
}

.card p,
.scoreCard p,
.rewardCard p,
small {
  color: var(--dash-muted) !important;
}

table {
  background: var(--dash-surface) !important;
  border-color: var(--dash-border-soft) !important;
}

th {
  color: var(--dash-muted) !important;
  background: #0a1017 !important;
}

td {
  border-color: var(--dash-border-soft) !important;
}

tr:hover td {
  background: rgba(88,166,255,0.06);
}

.moduleHelp {
  color: var(--dash-blue) !important;
}

@media (max-width: 820px) {
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  * {
    max-width: 100%;
  }

  body {
    min-width: 0;
    overflow-x: hidden;
    font-size: 16px;
  }

  button,
  input,
  select,
  textarea {
    font-size: 16px !important;
    min-height: 44px;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  button {
    touch-action: manipulation;
    white-space: normal !important;
    line-height: 1.2 !important;
    min-width: 0 !important;
    overflow: visible !important;
    text-align: center !important;
    padding: 10px 12px !important;
  }

  header {
    padding: 14px 12px !important;
  }

  h1,
  header h1 {
    font-size: clamp(22px, 7vw, 30px) !important;
    line-height: 1.12 !important;
    letter-spacing: 0.5px !important;
    overflow-wrap: anywhere;
  }

  header p,
  #datetime,
  #userEmail,
  footer {
    font-size: 12px !important;
  }

  .moduleHelp {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    margin-left: 4px !important;
    font-size: 18px !important;
    vertical-align: middle;
  }

  /* Parent dashboard shell */
  #app > header {
    padding-top: 72px !important;
  }

  #settingsBtn,
  #themeToggleBtn,
  #helpBtn,
  #feedbackBtn,
  #notifBtn,
  #logoutBtn {
    position: fixed !important;
    top: max(10px, env(safe-area-inset-top)) !important;
    height: 44px !important;
    border-radius: 14px !important;
    z-index: 2500 !important;
  }

  #settingsBtn,
  #themeToggleBtn,
  #helpBtn,
  #feedbackBtn,
  #notifBtn {
    width: 44px !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 18px !important;
  }

  #settingsBtn { left: 10px !important; }
  #themeToggleBtn { left: 62px !important; }
  #helpBtn { left: 114px !important; }
  #feedbackBtn { left: 166px !important; }
  #notifBtn { right: 74px !important; }

  #logoutBtn {
    right: 10px !important;
    width: 56px !important;
    padding: 0 8px !important;
    font-size: 12px !important;
  }

  .topLabel {
    display: none !important;
  }

  nav,
  .subnav {
    justify-content: flex-start !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    gap: 8px !important;
    margin: 12px 0 0 !important;
    padding: 0 12px 10px !important;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  nav::-webkit-scrollbar,
  .subnav::-webkit-scrollbar {
    display: none;
  }

  nav button,
  .subnav button {
    flex: 0 0 auto !important;
    min-height: 44px !important;
    padding: 10px 14px !important;
    border-radius: 999px !important;
    font-size: 13px !important;
    line-height: 1 !important;
    white-space: nowrap !important;
    scroll-snap-align: start;
  }

  iframe {
    height: calc(100dvh - 188px) !important;
    min-height: 520px;
    display: block;
  }

  body.compact iframe {
    height: calc(100dvh - 172px) !important;
  }

  #settingsPanel,
  #dashboardSettings,
  #adminPanel,
  #profileSettings,
  #helpPanel,
  #notifPanel {
    position: fixed !important;
    top: calc(max(10px, env(safe-area-inset-top)) + 54px) !important;
    left: 12px !important;
    right: 12px !important;
    width: auto !important;
    max-width: none !important;
    max-height: calc(100dvh - 82px) !important;
    transform: none !important;
    overflow-y: auto !important;
    z-index: 2600 !important;
  }

  #adminPanel {
    padding: 0 !important;
    max-height: calc(100dvh - 82px) !important;
  }

  .adminShell {
    grid-template-columns: 1fr !important;
    min-height: 0 !important;
  }

  .adminSidebar {
    border-right: 0 !important;
    border-bottom: 1px solid #2a3038 !important;
    padding: 12px !important;
  }

  .adminBrand {
    margin-bottom: 10px !important;
  }

  .adminNav {
    flex-direction: row !important;
    overflow-x: auto !important;
    padding-bottom: 4px !important;
    -webkit-overflow-scrolling: touch;
  }

  .adminNav button {
    flex: 0 0 auto !important;
    white-space: nowrap !important;
  }

  .adminMain {
    padding: 12px !important;
    max-height: calc(100dvh - 230px) !important;
  }

  .adminTopbar {
    align-items: stretch !important;
  }

  .adminGrid,
  .adminGrid.two,
  .adminSwitchGrid {
    grid-template-columns: 1fr !important;
  }

  .adminToolbar > * {
    flex: 1 1 100% !important;
    width: 100% !important;
  }

  .adminChart {
    min-width: 360px;
  }

  .adminTableWrap {
    overflow-x: auto !important;
  }

  .adminDetailModal {
    padding: 10px !important;
    align-items: flex-start !important;
  }

  .adminAnnouncementBanner {
    bottom: 10px !important;
    align-items: stretch !important;
  }

  #loginBox {
    padding: 18px;
  }

  #loginCard {
    width: min(100%, 380px) !important;
    padding: 22px !important;
  }

  .loginBtns {
    flex-direction: column;
  }

  #onboardingCard {
    width: calc(100vw - 28px) !important;
    max-width: 420px !important;
    padding: 24px 18px !important;
  }

  .onboarding-step h2 {
    font-size: 22px !important;
  }

  .onboarding-step p {
    font-size: 15px !important;
  }

  /* Module layout */
  .container {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 12px !important;
  }

  .controls,
  .addRow,
  .formBox {
    margin: 12px !important;
    gap: 8px !important;
    justify-content: flex-start !important;
    align-items: stretch !important;
  }

  .controls > *,
  .addRow > *,
  .formBox > * {
    flex: 1 1 140px !important;
    min-width: 0 !important;
  }

  .dashboard {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
    margin: 12px !important;
    max-width: none !important;
  }

  .card,
  .scoreCard {
    padding: 14px 10px !important;
    border-radius: 12px !important;
  }

  .card h2,
  .scoreCard h2 {
    font-size: 22px !important;
  }

  .card p,
  .scoreCard p {
    font-size: 12px !important;
  }

  .main,
  .graphs,
  .chartGrid,
  .gym-grid,
  .rewardGrid,
  .stats,
  .container,
  .scoreGrid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  .main,
  .graphs,
  .chartGrid,
  .calendarBox,
  .historyBox,
  .mainBox,
  .tableBox,
  .mgmtBox,
  .scoreGrid,
  .gym-template,
  .insights,
  .weightBox,
  .reportBox,
  .timetableBox {
    margin: 12px !important;
  }

  .panel,
  .tasks,
  .days,
  .graphBox,
  .chartBox,
  .mainBox,
  .calendarBox,
  .historyBox,
  .reportBox,
  .timetableBox,
  .copyBox,
  .mgmtBox,
  .formBox,
  .tableBox,
  .insights,
  .weightBox {
    border-radius: 12px !important;
    padding: 12px !important;
  }

  .days {
    min-height: 0 !important;
    max-height: none !important;
    height: auto !important;
    display: grid !important;
    grid-template-columns: repeat(7, minmax(40px, 1fr)) !important;
    gap: 6px !important;
    overflow: visible !important;
  }

  .day {
    min-height: 42px !important;
    border: 1px solid #30363d !important;
    border-radius: 10px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 6px !important;
    text-align: center !important;
  }

  .calendarGrid {
    gap: 6px !important;
  }

  .dayCell,
  .calDay {
    min-height: 42px !important;
    padding: 8px 4px !important;
    border-radius: 10px !important;
  }

  .field,
  .mealItem,
  .savedMealItem,
  .gym-ex,
  .task,
  .chapter-row,
  .addMealRow,
  .calHeader,
  .summaryHeader,
  .session {
    flex-wrap: wrap !important;
  }

  [style*="display:flex"],
  [style*="display: flex"] {
    flex-wrap: wrap !important;
    min-width: 0 !important;
  }

  [style*="display:flex"] > *,
  [style*="display: flex"] > * {
    min-width: 0 !important;
  }

  .summary,
  .stats {
    gap: 10px !important;
  }

  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns:1fr auto auto auto"],
  [style*="grid-template-columns: 1fr auto auto auto"] {
    grid-template-columns: 1fr !important;
  }

  [style*="min-width:150px"],
  [style*="min-width: 150px"],
  [style*="min-width:200px"],
  [style*="min-width: 200px"],
  [style*="min-width:240px"],
  [style*="min-width: 240px"],
  [style*="width:320px"],
  [style*="width: 320px"] {
    min-width: 0 !important;
    width: 100% !important;
  }

  .field {
    align-items: stretch !important;
  }

  .field input,
  .mealItem input,
  .addMealRow input,
  .controls input,
  .controls select,
  .controls button {
    width: 100% !important;
  }

  /* Diet: reveal full meal/macros data instead of truncating rows on phones */
  .mealItem,
  .savedMealItem {
    align-items: stretch !important;
    overflow: visible !important;
  }

  .mealItem span,
  .savedMealItem span {
    flex: 1 1 100% !important;
    width: 100% !important;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
    overflow-wrap: anywhere !important;
  }

  .mealItem input {
    flex: 1 1 calc(50% - 6px) !important;
    width: auto !important;
    min-width: 86px !important;
  }

  .mealActions,
  .savedMealItem {
    width: 100% !important;
  }

  .mealActions button,
  .savedMealItem button {
    flex: 1 1 0 !important;
    min-width: 88px !important;
  }

  .addMealRow label,
  .addMealRow button {
    flex: 1 1 100% !important;
  }

  .quickMeals.show {
    max-height: none !important;
    overflow: visible !important;
  }

  #macroList,
  #builderList {
    max-height: none !important;
    overflow: visible !important;
  }

  #maintPopup > div,
  #macroPopup > div {
    width: calc(100vw - 24px) !important;
    max-width: calc(100vw - 24px) !important;
    max-height: calc(100dvh - 32px) !important;
    overflow-y: auto !important;
  }

  .tasks > input,
  .tasks > button,
  .panel > input,
  .panel > button,
  .formBox button,
  .mgmtBox button,
  .summaryHeader button {
    width: 100% !important;
  }

  .task {
    align-items: stretch !important;
    gap: 8px !important;
  }

  .task input[type="text"] {
    flex: 1 1 180px !important;
    width: auto !important;
  }

  .task button,
  .mealActions button,
  .gym-ex button {
    flex: 0 0 auto !important;
    width: auto !important;
    min-width: 44px !important;
  }

  .fade-toggle.show,
  #mistakeForm.show,
  #notesForm.show {
    max-height: none !important;
    overflow: visible !important;
  }

  #mistakeForm,
  #notesForm {
    width: 100% !important;
  }

  #mistakeForm button,
  #notesForm button,
  #m_image,
  #n_image {
    width: 100% !important;
  }

  h2 button,
  h3 button {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-width: 72px !important;
    margin: 8px 0 0 0 !important;
    vertical-align: middle !important;
  }

  .session {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }

  .session input,
  .session select,
  .session textarea {
    width: 100% !important;
  }

  .graphBox,
  .chartBox,
  .weightBox {
    height: 310px !important;
  }

  .graphBox canvas,
  .chartBox canvas,
  .weightBox canvas {
    height: 245px !important;
  }

  .tableBox {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Partner: the ledger table lives in .main-box, so make it scrollable too */
  .main-box {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 680px;
  }

  th,
  td {
    padding: 10px 8px !important;
    font-size: 13px !important;
  }

  .weekFrame {
    height: 820px !important;
    min-height: 820px !important;
  }

  .overviewFrame {
    height: 1650px !important;
    min-height: 1650px !important;
  }
}

@media (max-width: 420px) {
  .dashboard {
    grid-template-columns: 1fr 1fr !important;
  }

  nav button,
  .subnav button {
    font-size: 12px !important;
    padding: 10px 12px !important;
  }

  .card h2,
  .scoreCard h2 {
    font-size: 20px !important;
  }

  .calendarGrid,
  .days {
    gap: 4px !important;
  }

  .day,
  .dayCell,
  .calDay {
    min-height: 38px !important;
    font-size: 12px !important;
  }

  /* Mobile screen overrides for assistant chat widget */
  #assistant-panel {
    width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    bottom: 0 !important;
    right: 0 !important;
    border-radius: 0 !important;
    border: none !important;
    z-index: 999999 !important;
  }

  #assistant-orb {
    z-index: 1000000 !important;
    bottom: 12px !important;
    right: 12px !important;
    width: 50px !important;
    height: 50px !important;
  }
}

/* Tablet screen assistant overrides */
@media (max-width: 768px) {
  #assistant-panel {
    width: calc(100vw - 32px);
    right: 16px;
    bottom: 90px;
    height: 500px;
    max-height: calc(100dvh - 110px);
  }
}

