:root {
  --lav: #b38bd1;
  --lav-soft: #efe6f7;
  --lav-softer: #f7f2fb;
  --plum: #6f4596;
  --plum-dark: #4b2d68;
  --ink: #2c2433;
  --muted: #7a6f84;
  --line: #e6deee;
  --bg: #faf8fc;
  --white: #fff;
  --ok: #3c8a5f;
  --warn: #b5532d;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(60, 30, 90, .06), 0 6px 20px rgba(60, 30, 90, .06);
  --serif: 'Lora', Georgia, serif;
  --sans: 'Nunito Sans', system-ui, -apple-system, Segoe UI, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--sans); color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.5; }
a { color: var(--plum); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; color: var(--plum-dark); margin: 0 0 .4em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---- Top bar ---- */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 24px; background: var(--white); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--plum-dark); font-family: var(--serif); font-size: 1.1rem; font-weight: 600; }
.brand img { height: 34px; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a { padding: 7px 12px; border-radius: 8px; text-decoration: none; color: var(--ink); font-weight: 600; font-size: .92rem; }
.topbar nav a:hover { background: var(--lav-softer); }
.topbar nav a.on { background: var(--lav-soft); color: var(--plum-dark); }
.topbar nav a.muted { color: var(--muted); font-weight: 400; }
main { max-width: 1280px; margin: 0 auto; padding: 28px 24px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 0; }

/* ---- Controls ---- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 9px; background: var(--white); color: var(--ink); font: 600 .9rem var(--sans); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--lav); }
.btn.primary { background: var(--plum); border-color: var(--plum); color: #fff; }
.btn.primary:hover { background: var(--plum-dark); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--plum); }
.btn.ghost:hover { background: var(--lav-softer); }
.btn.danger { color: var(--warn); }
.btn.sm { padding: 5px 10px; font-size: .82rem; }
.btn.ai::before { content: '✦'; color: var(--lav); }
.btn.primary.ai::before { color: #fff; }
.btn[disabled] { opacity: .55; cursor: wait; }

label { display: block; font-size: .82rem; font-weight: 700; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--white); font: 400 .95rem var(--sans); color: var(--ink);
}
textarea { resize: vertical; min-height: 80px; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--lav-soft); border-color: var(--lav); }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }

.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.alert { background: #fdf0ea; color: var(--warn); border-radius: 8px; padding: 8px 12px; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; background: var(--lav-soft); color: var(--plum-dark); font-size: .75rem; font-weight: 700; }
.pill.gray { background: #eee9f1; color: var(--muted); }
.pill.ok { background: #e3f3ea; color: var(--ok); }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }

/* ---- Toast ---- */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--plum-dark); color: #fff; padding: 10px 18px; border-radius: 10px; opacity: 0; transition: .25s; z-index: 100; pointer-events: none; font-weight: 600; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--warn); }

/* ---- Login ---- */
body.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(140deg, var(--lav-softer), var(--lav-soft)); }
.login-card { width: min(360px, 92vw); background: var(--white); border-radius: 18px; padding: 32px; box-shadow: var(--shadow); display: grid; gap: 14px; text-align: center; }
.login-card img { width: 220px; margin: 0 auto; }
.login-card label { text-align: left; }

/* ---- Offer list ---- */
table.list { width: 100%; border-collapse: collapse; background: var(--white); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.list th, table.list td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list th { background: var(--lav-softer); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
table.list tr:last-child td { border-bottom: 0; }
table.list td.actions { text-align: right; white-space: nowrap; }
table.list a.title { font-weight: 700; text-decoration: none; color: var(--plum-dark); }

/* ---- Module library ---- */
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.filters input[type=search] { width: 280px; margin: 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--white); border-radius: 99px; padding: 5px 11px; font: 600 .8rem var(--sans); cursor: pointer; color: var(--ink); }
.chip.on { background: var(--plum); color: #fff; border-color: var(--plum); }
.mod-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.mod-card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; box-shadow: var(--shadow); }
.mod-card h3 { margin: 0; font-size: 1rem; }
.mod-card .meta { display: flex; gap: 10px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.mod-card .desc { font-size: .87rem; color: #4d4456; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.mod-card .foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; padding-top: 6px; }

/* ---- Dialog ---- */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(760px, 94vw); box-shadow: 0 20px 60px rgba(40, 20, 60, .25); }
dialog::backdrop { background: rgba(44, 36, 51, .45); }
dialog form, .dlg-body { padding: 22px 24px; }
.dlg-foot { display: flex; justify-content: space-between; gap: 8px; padding-top: 16px; margin-top: 8px; border-top: 1px solid var(--line); }

/* ---- Upload ---- */
.dropzone { border: 2px dashed var(--lav); border-radius: 16px; background: var(--lav-softer); padding: 44px 20px; text-align: center; cursor: pointer; transition: .15s; }
.dropzone.over { background: var(--lav-soft); border-color: var(--plum); }
.dropzone strong { font-family: var(--serif); font-size: 1.2rem; color: var(--plum-dark); display: block; margin-bottom: 4px; }
.queue { display: grid; gap: 8px; margin-top: 18px; }
.qrow { display: flex; align-items: center; gap: 12px; background: var(--white); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.qrow .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--lav-soft); border-top-color: var(--plum); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.review { margin-top: 26px; }
.rev-item { display: grid; grid-template-columns: 28px 1fr; gap: 10px; background: var(--white); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 10px; }
.rev-item.off { opacity: .45; }
.rev-item input[type=checkbox] { width: 18px; height: 18px; margin-top: 8px; accent-color: var(--plum); }
.rev-item details summary { cursor: pointer; color: var(--plum); font-size: .85rem; font-weight: 700; margin-top: 6px; }

/* ---- Builder ---- */
.builder { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 22px; align-items: start; }
.lib { position: sticky; top: 72px; max-height: calc(100vh - 92px); display: flex; flex-direction: column; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.lib-head { padding: 14px 14px 10px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.lib-head input { margin: 0; }
.lib-list { overflow-y: auto; padding: 10px; display: grid; gap: 6px; align-content: start; }
.lib-item { border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; background: var(--white); cursor: grab; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; }
.lib-item:hover { border-color: var(--lav); background: var(--lav-softer); }
.lib-item .t { font-weight: 700; font-size: .88rem; }
.lib-item .s { font-size: .76rem; color: var(--muted); grid-column: 1; }
.lib-item .add { grid-row: 1 / span 2; grid-column: 2; border: 0; background: var(--lav-soft); color: var(--plum-dark); width: 28px; height: 28px; border-radius: 50%; font-size: 1.1rem; cursor: pointer; font-weight: 700; }
.lib-group { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin: 8px 2px 2px; }

.panel { margin-bottom: 18px; }
.panel > summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary h2 { margin: 0; }
.panel > summary::after { content: '▾'; color: var(--muted); }
.panel:not([open]) > summary::after { content: '▸'; }
.panel[open] > summary { margin-bottom: 14px; }

.section { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.sec-head { display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--lav-softer); border-radius: var(--radius) var(--radius) 0 0; }
.sec-head input.sec-title { margin: 0; font-family: var(--serif); font-size: 1.1rem; font-weight: 600; color: var(--plum-dark); border-color: transparent; background: transparent; }
.sec-head input.sec-title:hover, .sec-head input.sec-title:focus { border-color: var(--line); background: var(--white); }
.handle { cursor: grab; color: var(--muted); font-size: 1.1rem; text-align: center; user-select: none; }
.sec-lead { padding: 10px 14px 0; }
.sec-lead textarea { min-height: 44px; font-size: .88rem; }
.drop { min-height: 70px; padding: 12px 14px 14px; display: grid; gap: 8px; }
.drop:empty::before { content: 'Húzz ide modulokat a bal oldali könyvtárból, vagy kattints a + jelre.'; display: block; text-align: center; color: var(--muted); font-size: .88rem; padding: 18px; border: 2px dashed var(--line); border-radius: 10px; }
.sortable-ghost { opacity: .35; }
.drop .lib-item { cursor: default; }

.item { border: 1px solid var(--line); border-radius: 10px; background: var(--white); }
.item-row { display: grid; grid-template-columns: 22px 1fr 110px 70px 130px auto; gap: 8px; align-items: center; padding: 8px 10px; }
.item-row input { margin: 0; padding: 6px 8px; font-size: .9rem; }
.item-row .ttl { font-weight: 700; }
.item-row .num { text-align: right; }
.item-row .tools { display: flex; gap: 2px; }
.icon-btn { border: 0; background: transparent; cursor: pointer; width: 30px; height: 30px; border-radius: 7px; color: var(--muted); font-size: 1rem; }
.icon-btn:hover { background: var(--lav-softer); color: var(--plum); }
.item-detail { display: none; padding: 4px 12px 14px 40px; border-top: 1px dashed var(--line); }
.item.open .item-detail { display: block; }
.item.open { border-color: var(--lav); }
.item-detail .ai-row { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.col-labels { display: grid; grid-template-columns: 22px 1fr 110px 70px 130px auto; gap: 8px; padding: 0 24px 0 24px; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.col-labels span:last-child { width: 92px; }

.sumbar { position: sticky; bottom: 0; z-index: 20; margin-top: 18px; display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; background: var(--plum-dark); color: #fff; padding: 12px 18px; border-radius: 14px; box-shadow: 0 -4px 24px rgba(60, 30, 90, .18); }
.sumbar .totals { display: flex; gap: 22px; flex-wrap: wrap; }
.sumbar .totals b { font-size: 1.1rem; }
.sumbar .totals span { opacity: .75; font-size: .82rem; display: block; }
.sumbar .btn { border-color: rgba(255, 255, 255, .25); }
.save-state { font-size: .8rem; opacity: .8; }

@media (max-width: 980px) {
  .builder { grid-template-columns: 1fr; }
  .lib { position: static; max-height: 360px; }
  .item-row, .col-labels { grid-template-columns: 22px 1fr 90px 56px 100px auto; }
  .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  main { padding: 18px 14px 80px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .item-row { grid-template-columns: 22px 1fr auto; }
  .item-row .hide-sm, .col-labels { display: none; }
  .filters input[type=search] { width: 100%; }
}
