/*
 * Page-specific pieces. Keep this small: anything reused twice moves to components.css.
 */
@layer pages {
  /* Theme toggle shows the icon of the theme it will switch to */
  [data-theme="dark"] .theme-ico-dark,
  [data-theme="light"] .theme-ico-light { display: none; }

  /* «Ще»: highlight the saved theme preference */
  [data-theme-pref="dark"] .theme-seg [data-theme-set="dark"],
  [data-theme-pref="light"] .theme-seg [data-theme-set="light"],
  [data-theme-pref="system"] .theme-seg [data-theme-set="system"] {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 2px rgb(0 0 0 / .2);
  }
  .theme-seg { flex-wrap: wrap; }
  .theme-seg > * { flex: 1 1 auto; justify-content: center; white-space: nowrap; }
  @media (max-width: 419.98px) { .theme-seg .ico { display: none; } }

  /* ---------- Dashboard ---------- */
  .dash-greeting { font-size: 20px; font-weight: 700; letter-spacing: -.01em; margin-bottom: 12px; }

  .id-card-barcode { display: block; width: 100%; border: 0; cursor: zoom-in; }
  .id-card-barcode img { height: 56px; width: 100%; object-fit: fill; }

  .vendor-strip {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px 28px;
  }
  .vendor-strip-name { min-width: 160px; max-width: 240px; }
  .vendor-strip-stats { display: flex; flex-wrap: wrap; gap: 12px 28px; }
  .vendor-strip-stats .stat-v { font-size: 16px; }
  .vendor-strip-actions { margin-left: auto; display: flex; gap: 8px; }
  @media (max-width: 991.98px) {
    .vendor-strip { gap: 14px; }
    .vendor-strip-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; }
    .vendor-strip-actions { margin-left: 0; width: 100%; }
    .vendor-strip-actions .btn { flex: 1; }
  }

  .ref-table {
    display: grid;
    grid-template-columns: 24px minmax(40px, 1fr) auto 36px auto;
    gap: 8px 10px;
    align-items: center;
    font-size: 13px;
  }
  .ref-lvl { font-weight: 600; color: var(--subtle); }
  .ref-lvl.on { color: var(--primary); }
  .ref-bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
  .ref-bar > span { display: block; height: 100%; background: var(--primary); border-radius: 3px; }
  .ref-total { display: flex; justify-content: space-between; padding-top: 12px; margin-top: 12px; border-top: 1px solid var(--border); font-weight: 700; }

  .contact-k { width: 120px; flex: none; }
  @media (max-width: 575.98px) {
    .contact-row { flex-wrap: wrap; row-gap: 2px; }
    .contact-row .contact-k { width: 100%; }
  }
}

/* ---------- Team ---------- */
@layer pages {
  .team-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    & .seg { max-width: 100%; }
    @media (max-width: 991.98px) { padding: 12px 16px; }
  }
  .team-search { flex: 0 1 320px; min-height: 40px; @media (max-width: 991.98px) { flex-basis: 100%; } }
  .team-caption { padding: 12px 20px 0; @media (max-width: 991.98px) { padding-inline: 16px; } }

  .member-head, .member > summary {
    display: grid;
    grid-template-columns: minmax(0, 2.4fr) 110px minmax(0, 1fr) 80px 130px 18px;
    gap: 12px;
    align-items: center;
    padding: 0 20px;
  }
  .member-head { padding-block: 12px 8px; font-size: 12px; color: var(--muted); }
  .member { border-top: 1px solid var(--border); }
  .members .member:first-child { border-top: 0; }
  .member > summary {
    min-height: 60px;
    padding-block: 10px;
    list-style: none;
    cursor: pointer;
    &::-webkit-details-marker { display: none; }
    &:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
  }
  .member[open] > summary { background: var(--surface-2); }
  .member[open] .member-chev { transform: rotate(90deg); }
  .member-chev { transition: transform .15s; }
  .member-who { display: flex; align-items: center; gap: 12px; min-width: 0; }
  .member-who .avatar { position: relative; }
  .online { position: absolute; right: -2px; bottom: -2px; width: 10px; height: 10px; border-radius: 50%; background: var(--success); border: 2px solid var(--surface); }
  .member-team { display: inline-flex; align-items: center; justify-content: flex-end; gap: 6px; }
  .member-body { display: flex; flex-direction: column; gap: 12px; padding: 4px 20px 16px 68px; background: var(--surface-2); }
  .member-body .chip { background: var(--surface); }
  .member-facts { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--muted); }

  @media (max-width: 991.98px) {
    .member > summary { grid-template-columns: minmax(0, 1fr) auto auto 18px; padding-inline: 16px; gap: 10px; }
    .member-body { padding: 4px 16px 16px; }
  }
}

/* ---------- Invites ---------- */
@layer pages {
  .invite > summary { grid-template-columns: minmax(0, 1fr) auto 18px; }
  .invite-body { flex-direction: row; align-items: flex-start; gap: 16px; padding-left: 20px; }
  .invite-qr { background: #fff; border-radius: 12px; padding: 8px; flex: none; width: 160px; height: auto; }
  @media (max-width: 575.98px) {
    .invite-body { flex-direction: column; align-items: stretch; }
    .invite-qr { align-self: center; }
  }
}

/* ---------- Partner catalog ---------- */
@layer pages {
  .catalog-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
  .catalog-tools .seg { max-width: 100%; }
  .catalog-search { flex: 0 1 320px; min-height: 40px; background: var(--surface); @media (max-width: 991.98px) { flex-basis: 100%; } }
  .catalog { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--gap);
    @media (max-width: 575.98px) { grid-template-columns: 1fr; gap: 8px; } }
  .partner {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr) auto;
    grid-template-areas: "logo name chev" "logo tags chev" "desc desc desc" "stats stats stats";
    column-gap: 14px;
    row-gap: 4px;
    align-items: center;
    padding: 16px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    text-align: left;
    min-width: 0;
    transition: border-color .15s, background-color .15s;
    &:hover { border-color: var(--border-strong); background: color-mix(in srgb, var(--surface-2) 50%, var(--surface)); }
    @media (max-width: 575.98px) { padding: 12px; column-gap: 12px; grid-template-columns: 52px minmax(0, 1fr) auto; }
  }
  .partner-logo {
    grid-area: logo;
    width: 64px; height: 64px;
    border-radius: 14px;
    background: #fff;
    display: grid;
    place-items: center;
    overflow: hidden;
    border: 1px solid var(--border);
    & img { width: 100%; height: 100%; object-fit: contain; padding: 6px; }
    & b { font-size: 24px; color: #0c7a8f; }
    @media (max-width: 575.98px) { width: 52px; height: 52px; border-radius: 12px; }
  }
  .partner-logo-lg { width: 72px; height: 72px; flex: none; }
  .partner-name { grid-area: name; align-self: end; font-weight: 600; font-size: 15px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .partner-tags { grid-area: tags; align-self: start; display: flex; flex-wrap: wrap; gap: 4px; & .chip { height: 22px; font-size: 11px; } }
  .partner-chev { grid-area: chev; color: var(--subtle); }
  .partner-desc { grid-area: desc; margin-top: 10px; color: var(--muted); font-size: 13px; line-height: 1.4;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .partner-text { white-space: pre-line; color: var(--text); line-height: 1.55; overflow-wrap: anywhere; }
  .partner-facts { display: flex; flex-direction: column; border-top: 1px solid var(--border);
    & > div { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
    & .lbl { width: 72px; flex: none; padding-top: 2px; } }
  .partner-stats {
    grid-area: stats;
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
    margin-top: 12px;
    & > span { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 8px 12px; border-radius: 10px; background: var(--surface-2); }
    & b { font-size: 15px; font-variant-numeric: tabular-nums; }
  }

  .partner-dialog { --dialog-w: 560px; }
  .partner-hero { display: flex; align-items: center; gap: 14px; }
  .partner-hero h2 { font-size: 18px; line-height: 1.25; }
  .partner-rates { display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
    & > div { padding: 12px 14px; border-radius: 14px; background: var(--surface-2); } }
  .partner-actions { display: flex; flex-wrap: wrap; gap: 8px; & .btn { flex: 1 1 180px; } }
}

/* ---------- Vendor: new sale ---------- */
@layer pages {
  .sale-layout { display: grid; grid-template-columns: minmax(0, 560px) minmax(0, 340px); gap: var(--gap); align-items: start;
    @media (max-width: 991.98px) { grid-template-columns: 1fr; } }
  .input-lg { min-height: 52px; & input { font-size: 17px; min-height: 50px; } }
  .sale-price { font-size: 24px !important; font-weight: 700; }
  .sale-currency { font-size: 20px; color: var(--muted); }
  .sale-status {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 12px; border-radius: 12px;
    background: var(--surface-2); color: var(--muted); font-size: 14px;
    &[data-state="ok"] { background: var(--success-soft); color: var(--success); font-weight: 600; }
    &[data-state="error"] { background: var(--danger-soft); color: var(--danger); }
    &[data-state="warn"] { background: var(--warn-soft); color: var(--warn); }
  }
  .sale-preview { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 14px; background: var(--surface-2);
    & b { font-size: 17px; } }
  .sale-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; color: var(--muted); }
}

/* ---------- Vendor summary ---------- */
@layer pages {
  .vendor-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px 24px;
    & > div { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
    @media (max-width: 767.98px) { grid-template-columns: 1fr 1fr; } }
  .vendor-summary-due.is-debt .mid-num { color: var(--warn); }
  .vendor-summary-due.is-credit .mid-num { color: var(--success); }
}

/* ---------- Profile ---------- */
@layer pages {
  .profile-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--gap); align-items: start;
    @media (max-width: 991.98px) { grid-template-columns: 1fr; } }
  .phone-row {
    display: grid;
    grid-template-columns: 130px minmax(0, 1fr) auto 40px;
    grid-template-areas: "dial number messengers remove" "verified verified verified verified";
    gap: 8px;
    align-items: center;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
    &:last-child { border-bottom: 0; padding-bottom: 0; }
    @media (max-width: 767.98px) {
      grid-template-columns: 112px minmax(0, 1fr) 40px;
      grid-template-areas: "dial number remove" "messengers messengers messengers" "verified verified verified";
      &:has(.phone-remove[hidden]) .phone-number { grid-column-end: remove-end; }
    }
  }
  .phone-dial { grid-area: dial; }
  .phone-number { grid-area: number; }
  .phone-remove { grid-area: remove; }
  .phone-verified { grid-area: verified; justify-self: start; }
  .phone-row .form-errors { grid-column: 1 / -1; }
  .phone-dial, .phone-row .input {
    min-height: 44px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius);
    background: var(--surface); color: var(--text); font-size: 15px;
    &:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
  }
  .phone-messengers { grid-area: messengers; display: flex; gap: 6px; }
  .messenger {
    --brand: var(--primary);
    width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; cursor: pointer;
    border: 1px solid var(--border-strong); color: var(--subtle); transition: background-color .15s, color .15s, border-color .15s;
    & input { position: absolute; opacity: 0; pointer-events: none; }
    &:hover { color: var(--text); }
    &:has(input:checked) { color: var(--brand); border-color: var(--brand); background: color-mix(in srgb, var(--brand) 14%, transparent); }
    &:has(input:focus-visible) { box-shadow: var(--focus); }
  }
  .messenger-telegram { --brand: #29a9eb; }
  .messenger-viber { --brand: #7360f2; }
  .messenger-whatsapp { --brand: #25d366; }
  [data-theme="light"] .messenger-whatsapp { --brand: #128c4a; }
  .profile-actions { display: flex; justify-content: flex-end;
    @media (max-width: 991.98px) { & .btn { width: 100%; } } }
}

/* ---------- «Ще» / account page ---------- */
@layer pages {
  .more { display: flex; flex-direction: column; gap: 20px; max-width: 560px; }
  .more-profile { display: flex; flex-direction: column; gap: 12px; }
  .more-sections { display: flex; flex-direction: column; gap: 20px; }

  @media (min-width: 992px) {
    .more { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: var(--gap); align-items: stretch; max-width: 1100px; }
    .more-card { display: flex; flex-direction: column; gap: 20px; }
    .more-card > .btn { margin-top: auto; }
    .more-sections { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap); align-items: stretch; }
    /* On desktop each section is a card; the list inside loses its own frame */
    .more-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px 12px; }
    .more-section .menu-title { padding: 0 0 6px; font-size: 13px; }
    .more-section .menu { border: 0; border-radius: 0; background: none; margin: 0 -8px; }
    .more-section .menu-item { min-height: 46px; padding: 0 8px; border-radius: 10px; border-top-color: transparent; }
    .more-section .seg { margin: 6px 0 8px; }
  }
  .more-who { display: flex; align-items: center; gap: 14px; }
  .more-avatar { width: 64px; height: 64px; border-radius: 18px; font-size: 20px; }
  .more-idcard { display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: 14px; background: var(--surface-2);
    & .card-number { font-size: 16px; white-space: nowrap; } }
  /* Theme options as a list on desktop: check mark on the saved preference */
  .theme-check { visibility: hidden; color: var(--primary) !important; }
  [data-theme-pref="dark"] .theme-list [data-theme-set="dark"],
  [data-theme-pref="light"] .theme-list [data-theme-set="light"],
  [data-theme-pref="system"] .theme-list [data-theme-set="system"] {
    color: var(--text); font-weight: 600;
    & .theme-check { visibility: visible; }
  }
}
