/* Schubfach und Dialoge: Import, eigene Dialoge, Anhaenge, Vorschau, Lightbox, Auftraege, Feldgruppen.
   Teil des frueheren portal.css (Refactoring 23.11.2026). portal.html laedt
   die Teile in DIESER Reihenfolge — die Kaskade bleibt dieselbe. */
    /* drawer */
    .scrim {
      position: fixed;
      inset: 0;
      background: rgba(10, 15, 28, .5);
      backdrop-filter: blur(5px);
      -webkit-backdrop-filter: blur(5px);
      opacity: 0;
      pointer-events: none;
      transition: .25s;
      z-index: 40
    }

    .scrim.show {
      opacity: 1;
      pointer-events: auto
    }

    /* Import dialog (centered modal) */
    .impdlg {
      position: fixed;
      top: 50%; left: 50%;
      transform: translate(-50%, -46%);
      width: 640px; max-width: 94vw;
      max-height: 88vh;
      background: var(--surface);
      border: 1px solid var(--line);
      border-radius: 20px;
      box-shadow: 0 32px 90px rgba(10, 15, 28, .35);
      z-index: 60;
      display: none;
      flex-direction: column;
      overflow: hidden;
    }
    .impdlg.show { display: flex; animation: impIn .28s cubic-bezier(.22,1,.36,1) }
    @keyframes impIn { from { opacity: 0; transform: translate(-50%,-42%) } to { opacity: 1; transform: translate(-50%,-50%) } }
    @media (prefers-reduced-motion: reduce) { .impdlg.show { animation: none } }
    .impdlg.show { transform: translate(-50%, -50%) }
    .impdlg-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px 14px; border-bottom: 1px solid var(--line) }
    .impdlg-head h2 { margin: 0; font-size: 18px }
    .impdlg-body { padding: 20px 22px; overflow-y: auto }
    .impdlg-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 22px; border-top: 1px solid var(--line) }

    /* Custom confirm/prompt/alert dialog (replaces the browser's native ones) */
    .uidlg-back { position: fixed; inset: 0; z-index: 900; display: none; align-items: center; justify-content: center; padding: 20px; background: rgba(10, 15, 28, .42); backdrop-filter: blur(2px); }
    .uidlg-back.show { display: flex; }
    .uidlg { width: 420px; max-width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 32px 90px rgba(10, 15, 28, .38); overflow: hidden; animation: uidlgIn .22s cubic-bezier(.22, 1, .36, 1); }
    @keyframes uidlgIn { from { opacity: 0; transform: translateY(10px) scale(.98) } to { opacity: 1; transform: none } }
    @media (prefers-reduced-motion: reduce) { .uidlg { animation: none } }
    .uidlg-body { padding: 24px 24px 20px; }
    .uidlg-ic { font-size: 26px; line-height: 1; margin-bottom: 10px; }
    .uidlg-title { font-size: 16px; font-weight: 700; color: var(--ink); margin: 0 0 6px; }
    .uidlg-msg { font-size: 14px; line-height: 1.55; color: var(--muted); margin: 0; white-space: pre-line; }
    .uidlg-input { width: 100%; margin-top: 14px; padding: 10px 12px; font-size: 14px; font-family: inherit; color: var(--ink); background: var(--bg, #fff); border: 1px solid var(--line); border-radius: 10px; }
    .uidlg-input:focus { outline: none; border-color: var(--brand); }
    .uidlg-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px 18px; }
    .uidlg-btn { padding: 10px 18px; font-size: 14px; font-weight: 700; font-family: inherit; border-radius: 10px; border: 1px solid var(--line); cursor: pointer; background: var(--surface); color: var(--ink); }
    .uidlg-btn:hover { border-color: var(--brand); }
    .uidlg-btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
    .uidlg-btn.primary:hover { background: var(--brand-d); }
    .uidlg-btn.danger { background: #dc2626; border-color: #dc2626; color: #fff; }
    .uidlg-btn.danger:hover { background: #b91c1c; }
    .imp-drop {
      display: flex; flex-direction: column; align-items: center; justify-content: center;
      text-align: center; padding: 30px 20px; border: 2px dashed var(--line);
      border-radius: 14px; cursor: pointer; color: var(--muted);
      transition: border-color .18s, background .18s;
    }
    .imp-drop:hover, .imp-drop.drag { border-color: var(--brand); background: var(--brand-soft); color: var(--brand) }
    .imp-map { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px }
    .imp-map .row { display: flex; flex-direction: column; gap: 4px }
    .imp-map .row .lab { font-size: 12px }
    .imp-prev-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px }
    table.imp-prev { border-collapse: collapse; width: 100%; font-size: 12.5px }
    table.imp-prev th, table.imp-prev td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis }
    table.imp-prev th { color: var(--muted); font-weight: 700; background: var(--brand-soft) }
    table.imp-prev tr:last-child td { border-bottom: 0 }
    @media (max-width: 560px) { .imp-map { grid-template-columns: 1fr } }

    /* Anhänge / adjuntos download chips in the lead drawer */
    .att-chip { display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
      padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
      color: var(--ink); font: inherit; font-size: 13.5px; cursor: pointer; transition: border-color .15s, background .15s }
    .att-chip:hover { border-color: var(--brand); background: var(--brand-soft) }
    .att-chip .att-ic { font-size: 17px; flex: 0 0 auto }
    .att-chip .att-nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600 }
    .att-chip .att-sz { color: var(--muted); font-size: 12px; flex: 0 0 auto }
    .att-chip .att-dl { color: var(--brand); font-size: 15px; flex: 0 0 auto }
    /* Preview cards: image thumbnail / audio player + download in the lead drawer */
    .att-card { border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 6px; background: var(--bg) }
    .att-thumb { max-width: 170px; max-height: 170px; border-radius: 8px; cursor: pointer; border: 1px solid var(--line); background: var(--surface); object-fit: cover }
    .att-audio { width: 100%; max-width: 270px; height: 38px }
    /* Inline PDF: the whole page rendered by the browser, no download needed to
       know whether the file is the invoice or the floor plan. */
    .att-pdf { width: 100%; height: 320px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface) }
    .att-pdf-open { align-self: flex-start }
    /* Lightbox */
    .lightbox { position: fixed; inset: 0; z-index: 10000; background: rgba(8, 10, 16, .88); display: flex; flex-direction: column; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px) }
    .lightbox.hidden { display: none }
    .lb-bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; color: #EAEDF3 }
    .lb-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; font-weight: 600 }
    .lb-tab, .lb-x { color: #EAEDF3 !important; border-color: rgba(255,255,255,.25) !important; text-decoration: none; font-size: 13px }
    /* .btn-ghost bringt einen hellen Hintergrund mit — auf dem dunklen Schleier
       stand dann helle Schrift auf weißem Knopf (09.10.2026). */
    .lb-tab, .lb-x { background: rgba(255,255,255,.12) !important; width: auto; padding: 8px 14px; border-radius: 10px; border: 1px solid rgba(255,255,255,.25) }
    .lb-tab:hover, .lb-x:hover { background: rgba(255,255,255,.22) !important }
    .lb-body { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 0 14px 14px }
    .lb-body img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; box-shadow: 0 24px 60px rgba(0,0,0,.6) }
    .lb-body iframe { width: 100%; height: 100%; border: 0; border-radius: 8px; background: #fff }
    .att-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap }
    .att-meta .att-nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: var(--ink) }
    .att-dlbtn { background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 3px 9px; font-size: 12px; cursor: pointer; color: var(--brand) }
    .att-dlbtn:hover { background: var(--brand-soft); border-color: var(--brand) }

    /* Aufträge: Board/Woche toggle + weekly grid */
    .au-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface) }
    .au-tg { border: 0; background: transparent; font: inherit; font-size: 13px; font-weight: 600; color: var(--muted); padding: 7px 16px; cursor: pointer }
    .au-tg.active { background: var(--accent); color: #fff }
    table.au-week { border-collapse: collapse; width: 100%; min-width: 720px }
    table.au-week th, table.au-week td { border: 1px solid var(--line); vertical-align: top; padding: 6px }
    table.au-week thead th { background: var(--brand-soft); font-size: 12px; font-weight: 700; text-align: center; padding: 8px 6px }
    table.au-week thead th.today { background: var(--accent); color: #fff }
    table.au-week td.wname, table.au-week th.wname { text-align: left; font-weight: 700; font-size: 13px; width: 150px; background: var(--surface); position: sticky; left: 0; z-index: 1 }
    table.au-week td { height: 62px }
    .au-cell { display: flex; flex-direction: column; gap: 4px }
    .au-chip { display: block; text-align: left; width: 100%; border: 0; border-left: 3px solid var(--brand); background: var(--brand-soft); border-radius: 5px; padding: 4px 7px; font: inherit; font-size: 11.5px; font-weight: 600; color: var(--ink); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
    .au-chip.st-offen { border-left-color: #d97706; background: #fff7ed }
    .au-chip.st-in_arbeit { border-left-color: #2563eb; background: #eff6ff }
    .au-chip.st-erledigt { border-left-color: #16a34a; background: #f0fdf4; opacity: .75 }
    /* Aufträge: Listen-Ansicht (wie Posteingang, ganze Zeile sichtbar) */
    #au_list table { width: 100%; border-collapse: collapse; font-size: 13px }
    #au_list th, #au_list td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle }
    #au_list th { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); white-space: nowrap }
    #au_list tbody tr { cursor: pointer }
    #au_list tbody tr:hover { background: var(--brand-soft) }
    #au_list td.au-name { font-weight: 600 }
    #au_list td.au-topic { color: var(--muted); max-width: 340px }
    #au_list .au-pill { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 99px; white-space: nowrap }
    #au_list .au-pill.st-offen { color: #b45309; background: #fff7ed; border: 1px solid #fed7aa }
    #au_list .au-pill.st-in_arbeit { color: #1d4ed8; background: #eff6ff; border: 1px solid #bfdbfe }
    #au_list .au-pill.st-erledigt { color: #15803d; background: #f0fdf4; border: 1px solid #bbf7d0 }
    #au_list .au-empty { padding: 16px 12px; color: var(--muted); font-size: 13px }

    .drawer {
      position: fixed;
      top: 0;
      right: 0;
      height: 100%;
      width: 580px;
      max-width: 94vw;
      background: var(--surface);
      box-shadow: -24px 0 80px rgba(10, 15, 28, .28);
      border-radius: 22px 0 0 22px;
      transform: translateX(100%);
      transition: transform .32s cubic-bezier(.22, 1, .36, 1);
      z-index: 50;
      display: flex;
      flex-direction: column;
      overflow: hidden
    }

    .drawer.show {
      transform: none
    }

    .drawer.show .drawer-body { animation: rise .3s cubic-bezier(.22, 1, .36, 1) }
    @keyframes rise { from { opacity: 0; transform: translateY(10px) } to { opacity: 1; transform: none } }
    @media (prefers-reduced-motion: reduce) {
      .drawer, .drawer.show .drawer-body { transition: none; animation: none }
    }

    .drawer-head {
      padding: 24px 24px 18px;
      background: linear-gradient(150deg, var(--brand-soft) 0%, transparent 62%);
      border-bottom: 1px solid var(--line);
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      gap: 12px
    }

    .drawer-head .av {
      width: 54px;
      height: 54px;
      border-radius: 16px;
      color: #fff;
      font-weight: 700;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 22px;
      margin-bottom: 12px;
      box-shadow: 0 6px 18px rgba(10, 15, 28, .12)
    }

    .drawer-head h2 {
      margin: 0;
      font-size: 20px;
      font-weight: 800;
      letter-spacing: -.02em;
      text-wrap: balance
    }

    .drawer-head .who {
      color: var(--muted);
      font-size: 12.5px;
      margin-top: 3px
    }

    /* quick actions: call / mail the lead in one tap */
    .qacts { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap }
    .qact {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 7px 13px;
      border-radius: 999px;
      background: var(--surface);
      border: 1px solid var(--line);
      color: var(--ink);
      font-size: 12.5px;
      font-weight: 600;
      text-decoration: none;
      box-shadow: var(--shadow);
      transition: .15s
    }
    .qact:hover { border-color: var(--brand); color: var(--brand-d); transform: translateY(-1px) }
    /* "Lesen zuerst": bigger contact buttons + a header chip summary */
    .qacts .qact { flex: 1; justify-content: center; padding: 11px 14px; font-size: 13.5px; font-weight: 700; border-radius: 12px }
    .qact.prim { background: var(--brand); border-color: var(--brand); color: #fff }
    .qact.prim:hover { color: #fff; filter: brightness(1.05) }
    .dchips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px }
    .dchip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; padding: 4px 10px; border-radius: 999px; letter-spacing: .01em }
    /* grouped admin actions popover in the drawer toolbar */
    .actions-wrap { position: relative; display: inline-flex }
    .actions-menu { position: absolute; bottom: calc(100% + 8px); right: 0; z-index: 30; min-width: 190px;
      background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
      padding: 6px; display: flex; flex-direction: column; gap: 4px }
    .actions-menu.hidden { display: none }
    .actions-menu .btn-ghost { justify-content: flex-start; width: 100%; box-shadow: none }

    .drawer-body {
      padding: 18px 20px 22px;
      overflow: auto;
      flex: 1;
      background: var(--bg);
      display: flex;
      flex-direction: column;
      gap: 12px
    }

    /* grouped field cards */
    .fgroup {
      background: var(--surface);
      border: 1px solid var(--line);
      border-radius: 18px;
      padding: 16px 17px 18px;
      box-shadow: var(--shadow);
      transition: border-color .2s, box-shadow .2s
    }
    details.fgroup:hover { border-color: color-mix(in srgb, var(--brand) 22%, var(--line)) }
    .fgroup > .gh {
      font-size: 11px;
      font-weight: 800;
      letter-spacing: .1em;
      text-transform: uppercase;
      color: var(--muted);
      display: flex;
      align-items: center;
      gap: 8px;
      margin: 0
    }
    .fgroup > .gh::before {
      content: '';
      width: 7px; height: 7px; border-radius: 50%;
      background: var(--accent);
      box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 16%, transparent);
      flex: none
    }
    /* fgroups are collapsible modules: click the header to open/close */
    details.fgroup > summary.gh { cursor: pointer; list-style: none; user-select: none }
    details.fgroup > summary.gh::-webkit-details-marker { display: none }
    details.fgroup > summary.gh::after {
      content: '▾';
      margin-left: auto;
      color: var(--muted);
      font-size: 12px;
      transition: transform .18s
    }
    details.fgroup:not([open]) > summary.gh::after { transform: rotate(-90deg) }
    details.fgroup[open] > summary.gh { margin-bottom: 12px }
    details.fgroup:not([open]) { padding-bottom: 16px }
    summary.gh:hover { color: var(--ink) }
    .fgroup.fb { border-left: 4px solid #dc2626 }
    .fgroup.ai { border: 1px solid color-mix(in srgb, var(--brand) 35%, var(--line)); background: linear-gradient(165deg, var(--brand-soft) 0%, var(--surface) 34%) }

    .drawer-foot {
      padding: 14px 20px;
      border-top: 1px solid var(--line);
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      background: color-mix(in srgb, var(--surface) 82%, transparent);
      backdrop-filter: blur(10px);
      -webkit-backdrop-filter: blur(10px)
    }
    .drawer-foot > * { min-width: 0 }
    .drawer-foot .btn-ghost { padding: 12px 13px; white-space: nowrap }
    /* Speichern fills the remaining space; wraps to its own full row if tight */
    .drawer-foot .btn-primary { width: auto; flex: 1 1 150px }

    .lab {
      font-size: 11.5px;
      font-weight: 700;
      color: var(--muted);
      text-transform: uppercase;
      letter-spacing: .07em;
      margin: 14px 0 6px
    }

    .lab:first-child {
      margin-top: 0
    }

    .inp,
    .txt,
    .sel {
      width: 100%;
      padding: 11px 13px;
      border: 1.5px solid var(--line);
      border-radius: 12px;
      font-size: 14px;
      outline: none;
      background: var(--field);
      transition: border-color .15s, box-shadow .15s, background .15s
    }
    .inp:hover, .txt:hover, .sel:hover { border-color: color-mix(in srgb, var(--brand) 40%, var(--line)) }

    .sel-sm {
      width: auto;
      max-width: 180px;
      padding: 9px 11px;
      font-size: 13px;
      background: var(--surface);
      box-shadow: var(--shadow)
    }

    .inp:focus,
    .txt:focus,
    .sel:focus {
      border-color: var(--brand);
      background: var(--field-focus);
      box-shadow: 0 0 0 4px var(--brand-soft)
    }

    .txt {
      min-height: 90px;
      resize: vertical
    }

    .status-grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 8px
    }

    .status-opt {
      padding: 10px 8px;
      border: 1.5px solid var(--line);
      border-radius: 999px;
      text-align: center;
      font-size: 12px;
      font-weight: 700;
      color: var(--muted);
      background: var(--field);
      transition: border-color .13s, color .13s, background .13s, transform .1s;
      cursor: pointer
    }
    .status-opt:hover { border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); color: var(--ink); background: var(--surface) }
    .status-opt:active { transform: scale(.96) }

    .status-opt.on {
      border-color: transparent;
      color: #fff;
      box-shadow: 0 6px 16px rgba(10, 15, 28, .22)
    }

    .btn-ghost {
      background: var(--surface);
      color: #4A443A;
      border: 1px solid var(--line);
      padding: 12px 16px;
      border-radius: 12px;
      font-weight: 600;
      font-size: 14px;
      transition: .14s
    }
    .btn-ghost:hover { border-color: color-mix(in srgb, var(--brand) 35%, var(--line)) }

    .btn-ghost:hover {
      background: #f8fafc
    }

    .grow {
      flex: 1
    }

    .toast {
      position: fixed;
      bottom: 24px;
      left: 50%;
      transform: translateX(-50%) translateY(10px);
      background: var(--ink);
      color: #fff;
      padding: 12px 18px;
      border-radius: 12px;
      font-size: 14px;
      font-weight: 500;
      opacity: 0;
      pointer-events: none;
      transition: .2s;
      z-index: 60;
      box-shadow: var(--shadow-lg)
    }

    .toast.show {
      opacity: 1;
      transform: translateX(-50%)
    }

    /* Dark theme: --ink is near-white there, so the pill flips to a light
       background — the text must flip to dark to stay readable. */
    [data-theme="dark"] .toast {
      color: #1a2535
    }

    @media(max-width:760px) {
      .topbar {
        flex-wrap: wrap;
        gap: 8px
      }

      .agrid {
        grid-template-columns: 1fr !important
      }
    }
