/* XJETON core — reusable UI components. Module CSS must NOT redefine these; it adds its own prefixed classes. */

/* ---------- buttons ---------- */
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px; border-radius: 11px; border: 1px solid transparent;
  font-weight: 700; font-size: 14px; letter-spacing: .01em; white-space: nowrap; user-select: none;
  transition: transform var(--t) var(--ease), background-color var(--t), border-color var(--t), box-shadow var(--t), opacity var(--t);
  -webkit-touch-callout: none;
}
.btn:active { transform: scale(.97); }
.btn[disabled], .btn.is-disabled { opacity: .5; pointer-events: none; }
.btn-primary { background: linear-gradient(180deg, #ffc23d, var(--brand-2)); color: var(--brand-ink); box-shadow: 0 6px 20px rgba(255, 138, 0, .28), inset 0 1px 0 rgba(255, 255, 255, .35); }
.btn-ok { background: linear-gradient(180deg, #25d68c, #12b472); color: #02150d; box-shadow: 0 6px 20px rgba(25, 195, 125, .25); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: rgba(255, 77, 94, .3); }
.btn-ghost { background: var(--surface-2); border-color: var(--line-2); color: var(--text); }
.btn-soft { background: var(--brand-soft); color: var(--brand); }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: 12.5px; border-radius: 9px; }
.btn-lg { min-height: 46px; padding: 0 22px; font-size: 14.5px; border-radius: 13px; }
.btn-block { width: 100%; }
.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, .25); border-top-color: currentColor; border-top-color: var(--brand-ink);
  animation: xj-spin .7s linear infinite;
}
.btn-ghost.is-loading::after, .btn-danger.is-loading::after { border-color: var(--line-2); border-top-color: var(--text); }
@media (hover: hover) {
  .btn-primary:hover { box-shadow: 0 10px 28px rgba(255, 138, 0, .4), inset 0 1px 0 rgba(255, 255, 255, .4); transform: translateY(-1px); }
  .btn-ghost:hover { background: var(--surface-3); }
  .btn-ok:hover { transform: translateY(-1px); }
}
@keyframes xj-spin { to { transform: rotate(360deg); } }

.icon-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 36px; height: 36px; padding: 0 8px; border-radius: 11px; color: var(--text-2);
  transition: background-color var(--t), color var(--t);
}
.icon-btn .ic { width: 20px; height: 20px; }
@media (hover: hover) { .icon-btn:hover { background: var(--surface-2); color: var(--text); } }
.icon-btn:active { background: var(--surface-3); }
.lang-code { font-size: 12px; font-weight: 800; letter-spacing: .04em; }

/* ---------- surfaces ---------- */
.card {
  position: relative; background: var(--surface); background-image: var(--card-shine);
  border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-sm);
}
.card-pad { padding: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 0; }
.card-title { font-size: 14px; font-weight: 800; letter-spacing: .01em; display: flex; align-items: center; gap: 8px; }
.card-title .ic { color: var(--brand); }
.card-body { padding: 12px 16px 16px; }
/* vertical rhythm between stacked blocks + side gutter for loose content straight inside a card */
.card + .card, .grid + .card, .card + .grid, .grid + .grid { margin-top: 16px; }
.grid > .card, .grid > .card + .card, .adm-cols > .card, .adm-cols > .card + .card, .adm-cols-eq > .card, .adm-cols-eq > .card + .card { margin-top: 0; }
[class="card"] > :not(.card-head):not(.card-body):not(.card-pad):not(.table-wrap):not(.sc-list):not(.card-flush):not(table):not(img):not(canvas):not(.empty):not(.tabs):not(.card-bleed) { margin-left: 16px; margin-right: 16px; }
[class="card"] > .card-head + :not(.card-body):not(.table-wrap):not(.empty):not(.card-flush) { margin-top: 12px; }
[class="card"] > :first-child:not(.card-head):not(.card-body):not(.card-pad):not(.table-wrap):not(.card-flush):not(.sc-list):not(.empty) { margin-top: 16px; }
[class="card"] > :last-child:not(.card-head):not(.table-wrap):not(.card-flush):not(.empty):not(.card-bleed) { margin-bottom: 16px; }
[class="card"] > * + :not(.card-head):not(.table-wrap):not(.empty):not(.card-flush):not(.card-bleed) { margin-top: 12px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.page-title { font-size: clamp(20px, 2.4vw, 25px); font-weight: 850; letter-spacing: -.02em; }
.page-sub { color: var(--muted); margin-top: 2px; }

.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)); }
@media (max-width: 900px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .g2, .g3 { grid-template-columns: minmax(0, 1fr); } .grid { gap: 12px; } }

/* ---------- stat tile ---------- */
.stat { padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-label { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stat-label .ic { width: 16px; height: 16px; }
.stat-value { font-size: clamp(18px, 2vw, 22px); font-weight: 850; letter-spacing: -.02em; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; }
.stat-sub { font-size: 12px; color: var(--muted); }

/* ---------- badges ---------- */
.pill, .badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: var(--r-pill);
  font-size: 11px; font-weight: 800; letter-spacing: .04em; line-height: 1.6; text-transform: uppercase;
}
.pill-hot { background: #ff3b4d; color: #fff; margin-left: auto; }
.pill-info { background: var(--info); color: #fff; margin-left: auto; min-width: 22px; justify-content: center; }
.badge { background: var(--surface-3); color: var(--text-2); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-bad { background: var(--danger-soft); color: var(--danger); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-brand { background: var(--brand-soft); color: var(--brand); }

.chip {
  display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 14px; border-radius: var(--r-pill);
  background: var(--surface-2); border: 1px solid var(--line); font-weight: 800; font-size: 14px; white-space: nowrap;
  font-variant-numeric: tabular-nums; transition: border-color var(--t), background-color var(--t);
}
.chip .ic { color: var(--brand); width: 18px; height: 18px; }
@media (hover: hover) { a.chip:hover { border-color: var(--brand); } }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 13px; font-weight: 700; color: var(--text-2); }
.hint { font-size: 12px; color: var(--muted); }
.err-text { font-size: 12.5px; color: var(--danger); font-weight: 600; }
.input, .select, .textarea {
  width: 100%; min-height: 42px; padding: 0 12px; border-radius: 11px;
  background: var(--surface-2); border: 1px solid var(--line-2); color: var(--text);
  font-size: 16px; /* >=16px stops iOS zoom-on-focus */
  transition: border-color var(--t), box-shadow var(--t), background-color var(--t);
  -webkit-appearance: none; appearance: none;
}
.textarea { padding: 12px 14px; min-height: 100px; resize: vertical; }
.select {
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.500 11 1.500' fill='none' stroke='%237f8ba4' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
.input::placeholder, .textarea::placeholder { color: var(--muted); opacity: .8; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); background: var(--surface); }
.input.is-invalid { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.input[disabled], .input[readonly] { opacity: .65; }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap > .ic { position: absolute; left: 14px; width: 19px; height: 19px; color: var(--muted); pointer-events: none; }
.input-wrap > .input { padding-left: 44px; }
.input-wrap .input-toggle { position: absolute; right: 6px; width: 40px; height: 40px; display: grid; place-items: center; color: var(--muted); border-radius: 10px; }
.input-wrap .input-toggle:hover { color: var(--text); }
.input-wrap .input-toggle + .input, .input-wrap > .input.has-toggle { padding-right: 48px; }

.check { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; color: var(--text-2); user-select: none; }
.check input { position: absolute; opacity: 0; width: 0; height: 0; }
.check .box {
  width: 22px; height: 22px; border-radius: 7px; border: 1.5px solid var(--line-2); background: var(--surface-2);
  display: grid; place-items: center; flex: none; transition: all var(--t);
}
.check .box .ic { width: 14px; height: 14px; stroke-width: 3; color: var(--brand-ink); opacity: 0; transform: scale(.5); transition: all var(--t); }
.check input:checked + .box { background: var(--brand); border-color: var(--brand); }
.check input:checked + .box .ic { opacity: 1; transform: none; }
.check input:focus-visible + .box { outline: 2px solid var(--brand); outline-offset: 2px; }

.switch { position: relative; display: inline-block; width: 46px; height: 28px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; left: 0; top: 0; right: 0; bottom: 0; border-radius: 28px; background: var(--surface-3); border: 1px solid var(--line-2); transition: all var(--t); }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .35); transition: transform var(--t) var(--ease); }
.switch input:checked + i { background: var(--ok); border-color: var(--ok); }
.switch input:checked + i::after { transform: translateX(18px); }
.switch input:focus-visible + i { outline: 2px solid var(--brand); outline-offset: 2px; }

.honeypot { position: absolute !important; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* ---------- segmented control / filter chips ---------- */
.seg { display: inline-flex; padding: 4px; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg-btn { flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 16px; border-radius: 9px; font-weight: 700; font-size: 14px; color: var(--text-2); white-space: nowrap; transition: all var(--t); }
.seg-btn.is-active { background: var(--surface-3); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
.seg-btn.is-active .ic { color: var(--brand); }
@media (hover: hover) { .seg-btn:hover { color: var(--text); } }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { min-width: 520px; }
.table th { text-align: left; font-size: 11.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
@media (hover: hover) { .table tbody tr:hover td { background: var(--surface-hover); } }
.table .t-right { text-align: right; }

/* ---------- dropdown ---------- */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 60; min-width: 210px; padding: 6px;
  background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 14px; box-shadow: var(--shadow);
  opacity: 0; visibility: hidden; transform: translateY(-6px) scale(.98); transform-origin: top right;
  transition: opacity var(--t), transform var(--t) var(--ease), visibility var(--t);
}
.dropdown-right { left: auto; right: 0; }
.dropdown.is-open > .dropdown-menu { opacity: 1; visibility: visible; transform: none; }
.dropdown-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; min-height: 42px; padding: 0 12px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--text-2); text-align: left; }
.dropdown-item > span { display: inline-flex; align-items: center; gap: 10px; }
.dropdown-item .ic { width: 19px; height: 19px; }
.dropdown-item.is-active { color: var(--brand); }
.dropdown-item.danger { color: var(--danger); }
@media (hover: hover) { .dropdown-item:hover { background: var(--surface-3); color: var(--text); } .dropdown-item.danger:hover { color: var(--danger); } }
.dropdown-head { padding: 10px 12px 8px; display: flex; flex-direction: column; }
.dropdown-head small { color: var(--muted); }
.dropdown-sep { height: 1px; background: var(--line); margin: 6px 4px; }

/* ---------- progress ---------- */
.progress { height: 8px; border-radius: 8px; background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; width: 0; border-radius: 8px; background: linear-gradient(90deg, var(--brand-2), var(--brand)); transition: width .8s var(--ease); }
.progress.ok > span { background: linear-gradient(90deg, #12b472, var(--ok)); }

/* ---------- avatar ---------- */
.avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: var(--surface-3); flex: none; }
.avatar-sm { width: 32px; height: 32px; }
.avatar-lg { width: 64px; height: 64px; }
.avatar-btn { width: 40px; height: 40px; border-radius: 50%; padding: 2px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); display: block; }
.avatar-btn img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; background: var(--surface-3); border: 2px solid var(--bg); }

/* ---------- banners, empty, skeleton ---------- */
.banner { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: var(--r-sm); margin-bottom: 16px; font-weight: 600; font-size: 14px; border: 1px solid var(--line-2); background: var(--info-soft); color: var(--text); }
.banner .ic { color: var(--info); }
.banner-warn { background: var(--warn-soft); } .banner-warn .ic { color: var(--warn); }
.banner-ok { background: var(--ok-soft); } .banner-ok .ic { color: var(--ok); }
.banner-bad { background: var(--danger-soft); } .banner-bad .ic { color: var(--danger); }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 40px 20px; color: var(--muted); }
.empty .ic { width: 44px; height: 44px; color: var(--line-2); stroke-width: 1.4; }
.empty b { color: var(--text-2); font-size: 16px; }

.skeleton { position: relative; overflow: hidden; background: var(--surface-2); border-radius: var(--r-sm); }
.skeleton::after { content: ""; position: absolute; top: 0; right: 0; bottom: 0; left: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .06), transparent); animation: xj-shimmer 1.4s infinite; }
@keyframes xj-shimmer { to { transform: translateX(100%); } }

/* ---------- toasts ---------- */
.toasts { position: fixed; top: calc(14px + var(--sat)); right: calc(14px + var(--sar)); z-index: 200; display: flex; flex-direction: column; gap: 10px; width: min(380px, calc(100vw - 28px)); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; border-radius: 14px;
  background: var(--surface-2); border: 1px solid var(--line-2); box-shadow: var(--shadow); font-weight: 600; font-size: 14px;
  animation: xj-toast-in .35s var(--ease) both;
}
.toast .ic { margin-top: 1px; }
.toast.ok { border-color: rgba(25, 195, 125, .45); } .toast.ok .ic { color: var(--ok); }
.toast.error, .toast.bad { border-color: rgba(255, 77, 94, .5); } .toast.error .ic, .toast.bad .ic { color: var(--danger); }
.toast.info .ic { color: var(--info); } .toast.warn .ic { color: var(--warn); }
.toast.is-out { animation: xj-toast-out .25s ease forwards; }
@keyframes xj-toast-in { from { opacity: 0; transform: translateY(-12px) scale(.96); } }
@keyframes xj-toast-out { to { opacity: 0; transform: translateY(-8px) scale(.96); } }
@media (max-width: 560px) { .toasts { left: 14px; right: 14px; width: auto; } }

/* ---------- modal ---------- */
.modal { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 150; display: grid; place-items: center; padding: 16px; background: var(--scrim); opacity: 0; visibility: hidden; transition: opacity .2s, visibility .2s; -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.modal.is-open { opacity: 1; visibility: visible; }
.modal-box { width: min(440px, 100%); max-height: calc(100dvh - 32px); overflow: auto; background: var(--surface); border: 1px solid var(--line-2); border-radius: 20px; padding: 22px; box-shadow: var(--shadow); transform: translateY(14px) scale(.97); transition: transform .28s var(--ease); }
.modal.is-open .modal-box { transform: none; }
.modal-box h3 { font-size: 18px; margin-bottom: 6px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; flex-wrap: wrap; }
@media (max-width: 560px) {
  .modal { align-items: end; padding: 0; }
  .modal-box { width: 100%; border-radius: 22px 22px 0 0; padding-bottom: calc(22px + var(--sab)); transform: translateY(100%); }
  .modal-actions .btn { flex: 1; }
}

/* ---------- error pages ---------- */
.err-page { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: 64px 16px; }
.err-code { font-size: clamp(72px, 16vw, 128px); font-weight: 900; line-height: 1; letter-spacing: -.04em; background: linear-gradient(180deg, var(--brand), var(--brand-2)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent; }
.err-code .ic { width: 96px; height: 96px; stroke-width: 1.3; stroke: var(--brand); }
.err-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; justify-content: center; }

/* ---------- tiny helpers used by many modules ---------- */
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }
.kv > span:first-child { color: var(--muted); }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.divider::before, .divider::after { content: ""; height: 1px; flex: 1; background: var(--line); }

.link { color: var(--brand); font-weight: 700; font-size: 13.5px; }
@media (hover: hover) { .link:hover { text-decoration: underline; } }
