@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap");

:root {
  --bg: #f1f4f8;
  --card: #ffffff;
  --ink: #111827;
  --text: #1f2430;
  --muted: #8b92a4;
  --line: #e9edf3;
  --line-soft: #f1f4f8;
  --blue: #4b9dff;
  --blue-soft: #eaf3ff;
  --purple: #b98bff;
  --purple-soft: #f2eaff;
  --green: #28bd83;
  --green-soft: #e3f7ee;
  --amber: #ff9f43;
  --amber-soft: #fff1e0;
  --red: #ff5d6c;
  --red-soft: #fff0f1;
  --r-lg: 22px;   /* cards */
  --r-md: 16px;   /* inner containers */
  --r-ctl: 14px;  /* form controls */
  --r-pill: 999px;
  --shadow: 0 20px 48px rgba(31, 36, 48, .07);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body {
  font-family: "Poppins", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden], .hidden { display: none !important; }

/* ===== Login ===== */
#loginScreen {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; background: #f6f7f9;
}
.loginCard { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 12px; }
.loginLogo { width: 182px; height: auto; align-self: center; margin-bottom: 10px; }
.loginService {
  align-self: center; margin: -4px 0 8px; color: #667085;
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
}
.formRow { width: 100%; }
#loginScreen input {
  width: 100%; height: 50px; padding: 0 14px;
  border: 1px solid #d8dee8; border-radius: var(--r-ctl); background: #fff;
  color: var(--ink); font-size: 14px; font-weight: 500; outline: none;
}
#loginScreen input:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(17,24,39,.08); }
.authSubmit {
  width: 100%; height: 46px; border: 0; border-radius: var(--r-pill);
  background: var(--ink); color: #fff; font-weight: 700;
}
.authSubmit:hover { background: #2d3748; }
#loginStatus { min-height: 18px; color: var(--muted); font-size: 12px; line-height: 1.45; text-align: center; }
#loginStatus .status.error { text-align: left; }

/* ===== Shell ===== */
#app { min-height: 100vh; display: flex; flex-direction: column; }
#header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px clamp(18px, 4vw, 44px);
  background: var(--card); border-bottom: 1px solid var(--line);
}
.hdBrand { display: flex; align-items: center; gap: 12px; }
.hdLogo { width: 110px; height: auto; }
.hdTag {
  color: var(--muted); font-size: 10px; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase; white-space: nowrap;
  padding: 5px 10px; border-radius: var(--r-pill); background: var(--line-soft);
}
.hdUser { display: flex; align-items: center; gap: 12px; min-width: 0; }
.hdEmail { color: var(--muted); font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.avatar {
  width: 38px; height: 38px; flex: 0 0 auto; display: grid; place-items: center;
  border-radius: 50%; background: linear-gradient(135deg, var(--blue), var(--purple));
  color: #fff; font-size: 13px; font-weight: 700;
}

/* ===== Stepper ===== */
#stepper {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 18px clamp(18px, 4vw, 44px) 4px;
  max-width: 1160px; width: 100%; margin: 0 auto;
}
.step {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 16px 10px 10px; border: 1px solid transparent; border-radius: var(--r-pill);
  background: transparent; text-align: left;
  transition: background .15s ease, border-color .15s ease, opacity .15s ease;
}
.step:disabled { opacity: .45; cursor: not-allowed; }
.step:not(:disabled):hover { background: var(--card); border-color: var(--line); }
.stepNum {
  width: 32px; height: 32px; flex: 0 0 auto; display: grid; place-items: center;
  border-radius: 50%; background: var(--card); border: 1px solid var(--line);
  color: var(--muted); font-size: 13px; font-weight: 700;
}
.step.active .stepNum { background: var(--ink); border-color: var(--ink); color: #fff; }
.step.done .stepNum { background: var(--green-soft); border-color: rgba(40,189,131,.35); color: #167857; }
.stepTxt { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.stepTxt strong { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; }
.step.active .stepTxt strong { color: var(--ink); }
.stepLine { width: 34px; height: 1px; background: #d8dee8; flex: 0 0 auto; }

.mt-md { margin-top: 12px; }
.mt-lg { margin-top: 18px; }

/* ===== Chapter picker ===== */
.pickerBar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 2px 2px 0; }
.pickerBar .select { flex: 1 1 240px; max-width: 460px; }

/* ===== Main / panels ===== */
#main {
  flex: 1; width: 100%; max-width: 1160px; margin: 0 auto;
  padding: 16px clamp(18px, 4vw, 44px) 120px;
}
.panel { display: flex; flex-direction: column; gap: 16px; }
.twoCol { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 22px 24px;
}
.cardHead { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.cardHead h2 { font-size: 16px; font-weight: 600; color: var(--text); letter-spacing: -.01em; }
.cardHead h2 .opt { color: var(--muted); font-weight: 500; font-size: 13px; }
.cardHead p, .helpText { color: var(--muted); font-size: 12px; line-height: 1.5; font-weight: 500; }
.cardHead p { margin-top: 3px; }


/* ===== Fields ===== */
.field { display: grid; gap: 7px; margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field > label, .pickerBar > label, .exField > label, .pairHead span {
  color: var(--muted); font-size: 10.5px; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase;
}
.input, .select, .textarea {
  width: 100%; border: 1px solid #d8dee8; border-radius: var(--r-ctl);
  background: #fff; color: var(--ink); outline: none;
  font-size: 13px; font-weight: 500;
}
.input, .select { min-height: 48px; padding: 0 14px; }
.textarea { min-height: 104px; padding: 13px 14px; resize: vertical; line-height: 1.55; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(17,24,39,.08); }
.grow { flex: 1; min-width: 180px; }

/* ===== Buttons / chips / pills ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid #d9e1e8; border-radius: var(--r-pill);
  background: #fff; color: #475569;
  padding: 11px 18px; font-size: 12.5px; font-weight: 700; line-height: 1;
  transition: background .15s ease, color .15s ease, transform .15s ease, opacity .15s ease;
}
.btn:hover { background: #f2f2f2; transform: translateY(-1px); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #2d3748; }
.btn.danger { color: var(--red); border-color: #ffd5da; }
.btn.danger:hover { background: var(--red-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--line-soft); }
.btn.small { padding: 8px 12px; font-size: 11.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.center { justify-content: center; }

.chipRow { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  min-height: 42px; padding: 0 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line); border-radius: var(--r-pill);
  background: var(--line-soft); color: #5b6273;
  font-size: 12px; font-weight: 700;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.chip:hover { border-color: #c3ccda; }
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }

.status {
  padding: 12px 14px; border-radius: var(--r-md);
  background: var(--line-soft); border: 1px solid var(--line);
  color: #5b6273; font-size: 12px; line-height: 1.45; font-weight: 500;
}
.status.ok { background: var(--green-soft); border-color: rgba(40,189,131,.25); color: #167857; }
.status.error { background: var(--red-soft); border-color: rgba(255,93,108,.25); color: var(--red); }
.status.info { background: var(--blue-soft); border-color: rgba(75,157,255,.25); color: #256fc3; }

/* ===== Model cards ===== */
.model-grid { display: grid; gap: 9px; }
.model-card {
  width: 100%; min-height: 62px;
  border: 1px solid var(--line); border-radius: var(--r-md); background: #fff;
  padding: 12px 14px; text-align: left;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.model-card.active { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(17,24,39,.08); }
.model-card strong { display: block; font-size: 13px; font-weight: 700; color: var(--text); }
.model-card span { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.model-card .mark { width: 20px; height: 20px; flex: 0 0 auto; border-radius: 50%; border: 2px solid #d8dee8; }
.model-card.active .mark { border-color: var(--ink); background: var(--ink); box-shadow: inset 0 0 0 3.5px #fff; }

/* ===== Resources ===== */
.resList { display: flex; flex-direction: column; gap: 10px; }
.resource {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 14px;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--line-soft);
}
.resource strong { display: block; font-size: 13px; font-weight: 700; color: var(--text); word-break: break-word; }
.resource .meta { margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.resource .meta .err { color: var(--red); }
.resTag {
  display: inline-flex; align-items: center; padding: 3px 8px; margin-right: 6px;
  border-radius: var(--r-pill); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em;
}
.resTag.done { background: var(--green-soft); color: #167857; }
.resTag.pending { background: var(--amber-soft); color: #b06e1d; }
.resTag.error { background: var(--red-soft); color: var(--red); }
.empty {
  padding: 26px 18px; border: 1px dashed #d8dee8; border-radius: var(--r-md);
  background: #fafbfc; color: var(--muted); font-size: 13px; text-align: center;
}
.empty.addZone { cursor: pointer; font-weight: 600; transition: border-color .15s ease, background .15s ease, color .15s ease; }
.empty.addZone:hover, .empty.addZone:focus-visible {
  border-color: var(--ink); background: #fff; color: var(--text); outline: none;
}

/* ===== Draft ===== */
.draftGrid { display: grid; gap: 14px; }
.exercise { border: 1px solid var(--line); border-radius: var(--r-md); padding: 16px 18px; background: var(--card); }
.exercise.invalid { border-color: rgba(255,93,108,.45); }
.exHead { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.exHead .row { gap: 8px; }
.exNum { color: var(--muted); font-size: 11px; font-weight: 700; }
.tag {
  display: inline-flex; align-items: center; min-height: 24px;
  border-radius: var(--r-pill); padding: 5px 10px;
  background: var(--blue-soft); color: #256fc3;
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em;
}
.tag.ok { background: var(--green-soft); color: #167857; }
.tag.warn { background: var(--red-soft); color: var(--red); }
.exFields { display: grid; gap: 10px; }
.exField { display: grid; gap: 5px; }
.exFields input {
  width: 100%; border: 1px solid #d8dee8; border-radius: var(--r-ctl);
  padding: 10px 12px; outline: none; font-size: 13px;
}
.exFields input:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(17,24,39,.06); }
.pairGrid { display: grid; gap: 8px; }
.pairRow { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pairHead { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.abcOpt { display: flex; align-items: center; gap: 9px; }
.abcOpt input[type="radio"] { width: 17px; height: 17px; accent-color: var(--ink); flex: 0 0 auto; cursor: pointer; }
.abcOpt .optLetter { width: 20px; color: var(--muted); font-size: 12px; font-weight: 700; flex: 0 0 auto; }
.abcOpt input[type="text"] { flex: 1; }

/* ===== Sticky action bar ===== */
#actionBar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 500;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 13px clamp(18px, 4vw, 44px);
  background: rgba(255,255,255,.92); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}
.abLeft { color: var(--muted); font-size: 12.5px; font-weight: 600; min-width: 0; }
.abLeft .warn { color: var(--red); }
.abLeft .ok { color: #167857; }
.abRight { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }

/* ===== Generation overlay ===== */
#genOverlay {
  position: fixed; inset: 0; z-index: 1500;
  display: flex; align-items: center; justify-content: center;
  background: rgba(31,36,48,.45); backdrop-filter: blur(3px); padding: 24px;
}
.genCard {
  width: 100%; max-width: 380px; background: var(--card);
  border-radius: var(--r-lg); box-shadow: var(--shadow);
  padding: 32px 28px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.genCard h3 { font-size: 17px; font-weight: 600; color: var(--text); }
.spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--ink);
  animation: spin .9s linear infinite; margin-bottom: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }
#genCancel { margin-top: 8px; }

/* ===== Restore banner ===== */
#restoreBanner {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 1600;
  display: flex; align-items: center; gap: 12px; max-width: min(560px, calc(100vw - 32px));
  padding: 12px 16px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-md); box-shadow: var(--shadow);
  font-size: 12.5px; font-weight: 600; color: var(--text);
}

/* ===== Toast ===== */
#toast {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 2000;
  max-width: min(480px, calc(100vw - 32px));
  padding: 12px 18px; border-radius: var(--r-md); box-shadow: var(--shadow);
  font-size: 12.5px; font-weight: 600; line-height: 1.45;
}
#toast.ok { background: var(--green-soft); border: 1px solid rgba(40,189,131,.3); color: #167857; }
#toast.error { background: var(--red-soft); border: 1px solid rgba(255,93,108,.3); color: var(--red); }

/* ===== Done ===== */
.doneCard { text-align: center; padding: 40px 28px; }
.doneIco {
  width: 58px; height: 58px; margin: 0 auto 14px; display: grid; place-items: center;
  border-radius: 50%; background: var(--green-soft); color: #167857;
  font-size: 26px; font-weight: 700;
}
.doneCard h2 { font-size: 19px; font-weight: 600; margin-bottom: 6px; }

/* ===== Responsive ===== */
@media (max-width: 940px) {
  .twoCol { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  #stepper { gap: 4px; padding-top: 12px; }
  .stepLine { width: 14px; }
  .stepTxt strong { font-size: 12px; }
  .step { padding: 8px 10px 8px 8px; }
  .hdEmail { display: none; }
  /* Logo + badge + avatar + button don't fit at this width and clipped "Wyloguj".
     The page title already says AI Generator, so the badge is the one to drop. */
  .hdTag { display: none; }
  .hdLogo { width: 92px; }
  #main { padding-bottom: 150px; }
  #actionBar { flex-direction: column; align-items: stretch; }
  .abRight { justify-content: stretch; }
  .abRight .btn { flex: 1; }
  .pairRow, .pairHead { grid-template-columns: 1fr; }
  .pairHead span:last-child { display: none; }
}
/* Below ~430px all three labels no longer fit, which clipped step 3 off-screen.
   Keep the numbered circles and show the label only for the step you're on. */
@media (max-width: 430px) {
  #stepper { gap: 2px; }
  .step { padding: 8px; gap: 8px; }
  .step .stepTxt { display: none; }
  .step.active .stepTxt { display: flex; }
  .stepLine { width: 10px; }
}
