:root {
  --bg: #f4f5f7; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e3e6eb;
  --primary: #2457d6; --primary-dark: #1b44ab; --danger: #c62828; --ok-bg: #e8f5e9; --ok: #1b5e20;
  --err-bg: #fdecea; --new: #e67e00; --radius: 8px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* Fejléc */
.topbar { background: #1d2330; color: #fff; }
.topbar .wrap { display: flex; align-items: center; gap: 24px; height: 56px; }
.topbar .brand { color: #fff; font-weight: 700; font-size: 1.1rem; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { color: #c9cfdb; padding: 6px 12px; border-radius: 6px; }
.topbar nav a.active, .topbar nav a:hover { background: #333b4d; color: #fff; text-decoration: none; }
.topbar .user { color: #c9cfdb; font-size: .9rem; }
.topbar .user a { color: #fff; }
main.wrap { padding-top: 24px; padding-bottom: 80px; }

/* Elemek */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card.narrow { width: 100%; max-width: 380px; }
.card.empty, td.empty { text-align: center; color: var(--muted); padding: 32px; }
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar h1 { flex: 1; }
.search input { width: 240px; }
.flash { background: var(--ok-bg); color: var(--ok); padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; }
.flash.error { background: var(--err-bg); color: var(--danger); }
.hint { color: var(--muted); font-size: .9rem; margin-top: -4px; }
.tag { display: inline-block; font-size: .72rem; padding: 1px 6px; border-radius: 10px; background: #eceff3; color: var(--muted); vertical-align: middle; }
.tag.new { background: #fff3e0; color: var(--new); margin-top: 3px; }

input, textarea, select { font: inherit; padding: 7px 9px; border: 1px solid #cfd4dc; border-radius: 6px; background: #fff; color: var(--text); width: 100%; }
input:focus, textarea:focus { outline: 2px solid #b8cbf5; border-color: var(--primary); }
label { display: block; font-size: .85rem; color: var(--muted); }
label input, label textarea, label select { margin-top: 4px; color: var(--text); }
form > label { margin-bottom: 12px; }
label.check { display: flex; align-items: center; gap: 6px; align-self: end; padding-bottom: 8px; }
label.check input { width: auto; margin: 0; }

.btn { display: inline-block; font: inherit; padding: 8px 16px; border: 1px solid #cfd4dc; background: #fff; color: var(--text); border-radius: 6px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f0f2f5; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; }
.danger { color: var(--danger) !important; }

.grid-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.grid-form label { flex: 0 1 150px; }
.grid-form label.grow { flex: 1 1 240px; }
.form-actions { display: flex; gap: 8px; }
.form-actions.sticky { position: sticky; bottom: 0; justify-content: flex-end; background: var(--bg); padding: 12px 0; border-top: 1px solid var(--line); }

/* Táblák */
.table-wrap { overflow-x: auto; }
.card.table-wrap { padding: 0; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.list th, .list td { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.list tbody tr:hover { background: #fafbfc; }
.list tr.inactive td { color: var(--muted); }
.r { text-align: right; }
.actions { white-space: nowrap; text-align: right; }
.actions > * { margin-left: 12px; }
.actions form { display: inline; }

.items { margin-bottom: 12px; min-width: 950px; }
.items th, .items td { padding: 6px 4px; vertical-align: top; }
.items td.r { padding-top: 13px; white-space: nowrap; }
.items .c-name { min-width: 260px; }
.items .c-qty, .items .c-disc, .items .c-vat { width: 80px; }
.items .c-unit { width: 80px; }
.items .c-price { width: 120px; }
.items .c-mk { width: 80px; }
.items input { text-align: left; }
.items .f-qty, .items .f-price, .items .f-pur, .items .f-mk, .items .f-disc, .items .f-vat { text-align: right; }
.items input[readonly] { background: #f4f5f7; color: var(--muted); }
.items .del { font-size: 1rem; padding: 8px; }

.totals { margin-left: auto; max-width: 400px; margin-top: 8px; }
.totals div > span { padding-right: 16px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand { border-top: 2px solid var(--text); margin-top: 4px; padding-top: 8px; font-size: 1.15rem; }
.totals .internal { color: var(--muted); font-size: .9rem; }
.totals .internal:first-of-type, .totals .grand + .internal { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.totals .internal-note { color: var(--muted); font-size: .75rem; display: block; }

/* Login */
body.center { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
body.center h1 { margin-bottom: 16px; }
body.center .btn { width: 100%; }

/* Nyomtatható nézet */
.print-page { background: #e9ebef; }
.print-bar { display: flex; gap: 8px; justify-content: center; padding: 16px; }
.sheet { background: #fff; max-width: 210mm; margin: 0 auto 32px; padding: 18mm 16mm; box-shadow: 0 2px 12px rgba(0,0,0,.08); font-size: 13px; }
.sheet-head { display: flex; justify-content: space-between; gap: 24px; border-bottom: 2px solid var(--text); padding-bottom: 16px; }
.sheet-head h1 { font-size: 1.8rem; letter-spacing: .08em; }
.company { font-size: 1.2rem; font-weight: 700; margin-bottom: 4px; }
.customer, .notes { margin: 20px 0; }
.label { font-size: .75rem; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; margin-bottom: 4px; }
.print-items th, .print-items td { padding: 7px 6px; border-bottom: 1px solid var(--line); }
.print-items thead th { border-bottom: 1.5px solid var(--text); }
.print-items td.r { white-space: nowrap; }
.signature { display: flex; justify-content: flex-end; margin-top: 60px; }
.signature div { border-top: 1px solid var(--text); padding-top: 6px; min-width: 200px; text-align: center; }

@media print {
  .noprint { display: none !important; }
  .print-page { background: #fff; }
  .sheet { box-shadow: none; margin: 0; padding: 0; max-width: none; }
  @page { size: A4; margin: 15mm; }
}
@media (max-width: 640px) {
  .topbar .wrap { gap: 12px; }
  .topbar .user { display: none; }
  .search input { width: 100%; }
}

/* Partnerek, e-mail, beállítások */
.tag.sent { background: #e8f5e9; color: var(--ok); }
.list.clickable tbody tr { cursor: pointer; }
.partner-card { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.partner-card .full { grid-column: 1 / -1; }
.partner-card .label, .card .label { display: block; }
main h2 { margin-top: 8px; }
code { background: #eceff3; padding: 1px 5px; border-radius: 4px; font-size: .85em; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.sheet .qdoc { font-size: 13px; }

/* Ikongombok felirattal (tooltip) */
td.actions > .icon-btn, td.actions > form { margin-left: 2px; }
.icon-btn { position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 6px; border: 0; background: none; padding: 0;
  color: var(--muted); cursor: pointer; vertical-align: middle; }
.icon-btn:hover { background: #eef1f6; color: var(--primary); text-decoration: none; }
.icon-btn.danger { color: var(--muted) !important; }
.icon-btn.danger:hover { background: var(--err-bg); color: var(--danger) !important; }
.icon-btn .ico { display: block; }
.icon-btn[data-tip]::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%;
  transform: translateX(-50%); background: #1d2330; color: #fff; font-size: .75rem; line-height: 1.2;
  padding: 4px 8px; border-radius: 4px; white-space: nowrap; pointer-events: none; opacity: 0;
  transition: opacity .12s; z-index: 10; }
.icon-btn[data-tip]:hover::after { opacity: 1; }
.list td.actions { padding-top: 4px; padding-bottom: 4px; }
.card.table-wrap { overflow: visible; }
@media (max-width: 1150px) { .card.table-wrap { overflow-x: auto; } }

/* Modal ablak (árajánlat megtekintés) */
body.modal-open { overflow: hidden; }
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 20, 30, .55); }
.modal-dialog { position: relative; width: min(900px, 96vw); height: 94vh; background: #e9ebef;
  border-radius: 10px; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal-dialog iframe { width: 100%; height: 100%; border: 0; display: block; }
.modal-close { position: absolute; top: 10px; right: 12px; z-index: 2; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.modal-close[data-tip]::after { bottom: auto; top: calc(100% + 6px); }
.in-modal .print-bar { position: sticky; top: 0; z-index: 1; background: #e9ebef; padding: 12px 56px 12px 16px; }
.in-modal .sheet { margin-bottom: 16px; }
@media (max-width: 700px) { .modal-dialog { width: 100vw; height: 100vh; border-radius: 0; } .sheet { padding: 8mm; } }

/* Állapot címkék */
.status { display: inline-flex; align-items: center; gap: 4px; font-size: .8rem; font-weight: 600; padding: 2px 9px;
  border-radius: 999px; white-space: nowrap; cursor: default; }
.status small { font-weight: 400; opacity: .8; }
.status .ico { width: 13px; height: 13px; }
.st-open     { background: #eceff3; color: #5b6472; }
.st-sent     { background: #e3edff; color: #1f4fbf; }
.st-expired  { background: #fff1dc; color: #b45309; }
.st-invoiced { background: #e2f5e8; color: #17703a; }
h1 .status { font-size: .8rem; vertical-align: middle; margin-left: 8px; }

/* Szűrőfülek */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; }
.tab { padding: 6px 12px; border-radius: 999px; color: var(--muted); font-size: .9rem; border: 1px solid transparent; }
.tab:hover { background: #fff; border-color: var(--line); text-decoration: none; }
.tab.active { background: #fff; border-color: var(--line); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.tab .count { display: inline-block; min-width: 20px; text-align: center; font-size: .75rem; padding: 0 6px; border-radius: 999px; background: #eceff3; margin-left: 2px; }
.tab-invoiced.active .count { background: #e2f5e8; color: #17703a; }
.tab-expired.active .count { background: #fff1dc; color: #b45309; }
.tab-sent.active .count { background: #e3edff; color: #1f4fbf; }

/* Számlázott sor */
.list tr.row-invoiced td { background: #fbfdfb; }
.list tr.row-invoiced td:first-child { box-shadow: inset 3px 0 0 #2e9d5b; }

/* Ikongomb változatok */
.icon-btn.ok:hover   { background: #e2f5e8; color: #17703a; }
.icon-btn.warn:hover { background: #fff1dc; color: #b45309; }
.icon-btn.disabled { opacity: .35; cursor: not-allowed; }
.icon-btn.disabled:hover { background: none; color: var(--muted); }
.icon-btn.disabled[data-tip]:hover::after { opacity: 1; }

/* Számlázás ablak */
.dlg { border: 0; border-radius: 12px; padding: 24px; width: min(440px, 92vw); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.dlg::backdrop { background: rgba(15, 20, 30, .5); }
.dlg h2 { margin: 6px 0 8px; }
.dlg .muted { font-size: .9rem; line-height: 1.5; }
.dlg-icon { width: 44px; height: 44px; border-radius: 50%; background: #e2f5e8; color: #17703a; display: flex; align-items: center; justify-content: center; }
.dlg-icon .ico { width: 22px; height: 22px; }
.ok-btn { background: #2e9d5b; border-color: #2e9d5b; color: #fff; display: inline-flex; align-items: center; gap: 6px; }
.ok-btn:hover { background: #237a47; }
.ok-btn .ico { width: 16px; height: 16px; }

/* Zárolt szerkesztő */
.locked-banner { display: flex; align-items: center; gap: 14px; background: #e2f5e8; color: #17703a; border: 1px solid #bfe5cc;
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; line-height: 1.45; }
.locked-banner > .ico { width: 26px; height: 26px; flex: none; }
.locked-banner > div { flex: 1; }
.locked-banner .btn { display: inline-flex; align-items: center; gap: 6px; }
.locked-banner .btn .ico { width: 16px; height: 16px; }
fieldset.plain { border: 0; margin: 0; padding: 0; min-width: 0; }
.is-locked input, .is-locked textarea, .is-locked select { background: #f6f7f9; color: var(--text); }

/* Pecsét a megtekintésen (csak képernyőn) */
.sheet { position: relative; }
.stamp { position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%) rotate(-14deg); z-index: 3; pointer-events: none;
  border: 4px double rgba(46, 157, 91, .75); color: rgba(46, 157, 91, .8); border-radius: 10px; padding: 8px 22px;
  text-align: center; text-transform: uppercase; background: rgba(255,255,255,.55); }
.stamp-title { display: block; font-size: 2.2rem; font-weight: 800; letter-spacing: .18em; line-height: 1.1; }
.stamp-sub { display: block; font-size: .85rem; font-weight: 600; letter-spacing: .08em; }

/* Listákban a cellák ne törjenek (kivéve a nevek) */
.list th, .list td { white-space: nowrap; }
.list td.wrap { white-space: normal; min-width: 140px; }
.list th, .list td { padding-left: 12px; padding-right: 12px; }
.list td.actions { padding-right: 8px; }
td.actions .icon-btn { width: 30px; height: 30px; margin-left: 0; }
td.actions > form { margin-left: 0; }
.list td.wrap { width: 100%; }

/* ================= Szerepkörök, menü ================= */
.nav-badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 999px;
  background: #e5484d; color: #fff; font-size: .72rem; font-weight: 700; line-height: 18px; text-align: center; }
.topbar .user-link { color: #fff; }
.role-chip { display: inline-block; font-size: .68rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  padding: 1px 7px; border-radius: 999px; vertical-align: middle; }
.role-admin { background: #ede4ff; color: #6a2fd1; }
.role-contractor { background: #e3edff; color: #1f4fbf; }
.role-client { background: #e2f5e8; color: #17703a; }
.topbar .role-chip { background: rgba(255,255,255,.14); color: #dfe4ee; }
.role-pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.role-card { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 8px; padding: 12px; cursor: pointer; color: var(--text); }
.role-card:has(input:checked) { border-color: var(--primary); box-shadow: 0 0 0 3px #dfe8fb; }
.role-card input { width: auto; margin-top: 3px; }
.card.narrow-wide { max-width: 560px; }
.list tr.inactive td { opacity: .55; }
.small { font-size: .82rem; }

/* ================= Hibajegy állapotok ================= */
.tst-new         { background: #e3edff; color: #1f4fbf; }
.tst-in_progress { background: #fff1dc; color: #b45309; }
.tst-waiting     { background: #eceff3; color: #5b6472; }
.tst-done        { background: #f3e8ff; color: #7c3aed; }
.tst-closed      { background: #e2f5e8; color: #17703a; }
.prio { font-size: .78rem; font-weight: 700; padding: 1px 8px; border-radius: 4px; }
.prio-high { background: #fde8e8; color: #c62828; }
.prio-low  { background: #eceff3; color: #6b7280; }
.list tr.trow-done td:first-child { box-shadow: inset 3px 0 0 #7c3aed; }
.list tr.trow-new td:first-child  { box-shadow: inset 3px 0 0 #2457d6; }
.list tr.trow-closed td { color: var(--muted); }
.tab-t-done.active .count { background: #f3e8ff; color: #7c3aed; }

.attention { display: flex; align-items: center; gap: 14px; background: #f5efff; border: 1px solid #e2d4fb; color: #5b21b6;
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px; line-height: 1.45; }
.attention > .ico { width: 24px; height: 24px; flex: none; }
.attention > div { flex: 1; }

/* ================= Hibajegy adatlap ================= */
.ticket-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
@media (max-width: 900px) { .ticket-layout { grid-template-columns: 1fr; } .ticket-side { order: -1; } }
.ticket-desc { white-space: normal; line-height: 1.55; font-size: 1rem; }
.ticket-desc-head { margin-bottom: 8px; }
.side-card h2 { margin-bottom: 8px; }
.side-card label { margin-bottom: 10px; }
.side-row { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); align-items: center; text-align: right; }
.side-row:last-child { border-bottom: 0; }
.side-row .label { margin: 0; text-align: left; }
.progress-steps { display: flex; gap: 4px; padding: 4px 0 8px; }
.progress-steps .step { flex: 1; height: 5px; border-radius: 3px; background: #e3e6eb; }
.progress-steps .step.on { background: var(--primary); }

.timeline { list-style: none; margin: 0 0 16px; padding: 0 0 0 4px; }
.timeline li { position: relative; }
.tl-sys { display: flex; align-items: center; gap: 10px; padding: 7px 0; color: var(--muted); font-size: .9rem; flex-wrap: wrap; }
.tl-sys time, .bubble-head time { margin-left: auto; font-size: .8rem; color: var(--muted); }
.tl-sys b { color: var(--text); }
.tl-dot { width: 28px; height: 28px; border-radius: 50%; background: #eceff3; color: #5b6472; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.tl-dot .ico { width: 15px; height: 15px; }
.st-dot-done { background: #f3e8ff; color: #7c3aed; } .st-dot-closed { background: #e2f5e8; color: #17703a; }
.st-dot-in_progress { background: #fff1dc; color: #b45309; }
.tl-sys .status { font-size: .75rem; }
.tl-msg { margin: 6px 0 12px 38px; }
.bubble-head { display: flex; gap: 8px; align-items: center; font-size: .88rem; margin-bottom: 4px; }
.bubble { background: #fff; border: 1px solid var(--line); border-radius: 4px 12px 12px 12px; padding: 10px 14px; line-height: 1.5; }
.from-staff .bubble { background: #f3f7ff; border-color: #dbe5fb; }

.reply-box textarea { margin-bottom: 8px; }
.reply-actions { flex-wrap: wrap; align-items: center; }
.status-btn.sb-done { border-color: #c9b2f5; color: #6d28d9; }
.status-btn.sb-in_progress { border-color: #f5cf98; color: #b45309; }
.status-btn.sb-closed { border-color: #a9dcbb; color: #17703a; }

.approve-box { background: #fff; border: 2px solid #c9b2f5; border-radius: 12px; padding: 16px 18px; margin-bottom: 16px;
  box-shadow: 0 4px 16px rgba(124, 58, 237, .08); }
.approve-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; line-height: 1.45; }
.approve-head .dlg-icon { background: #f3e8ff; color: #7c3aed; flex: none; }
.approve-box textarea { margin-bottom: 10px; }
.approve-box textarea.need { border-color: var(--danger); outline: 2px solid #f6c9c9; }
.approve-box .btn { display: inline-flex; align-items: center; gap: 6px; }
.approve-box .btn .ico { width: 16px; height: 16px; }
.closed-note { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: #e2f5e8; color: #17703a; border-radius: var(--radius); padding: 12px 16px; }

.file-drop { display: flex !important; align-items: center; gap: 8px; border: 1.5px dashed #c9cfd8; border-radius: 8px; padding: 12px 14px; margin-top: 12px; cursor: pointer; color: var(--muted); position: relative; }
.file-drop:hover { border-color: var(--primary); color: var(--primary); }
.file-drop input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }
.small-drop { padding: 7px 12px; margin-top: 0; font-size: .88rem; }
.file-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.att-img img { width: 110px; height: 82px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; }
.att-file { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; background: #fff; }
.att-file span { display: flex; flex-direction: column; font-size: .85rem; }
.att-file small { color: var(--muted); }

.two-col { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 18px; margin-bottom: 8px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
.list td.break { white-space: normal; overflow-wrap: anywhere; min-width: 160px; max-width: 320px; }
