/* ============================================================
   DevPortal — Components
   ============================================================ */

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--space-2); height: var(--control-h); padding: 0 var(--space-4);
  border: 1px solid transparent; border-radius: var(--r-sm);
  font-size: var(--fs-sm); font-weight: 600; line-height: 1;
  cursor: pointer; white-space: nowrap; user-select: none;
  transition: background .14s, border-color .14s, color .14s, box-shadow .14s, transform .06s;
}
.btn:active { transform: translateY(.5px); }
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn.sm { height: calc(26px * var(--d)); padding: 0 var(--space-3); font-size: var(--fs-xs); }
.btn.lg { height: calc(40px * var(--d)); padding: 0 var(--space-6); font-size: var(--fs-md); }
.btn.icon { padding: 0; width: var(--control-h); }
.btn.icon.sm { width: calc(26px * var(--d)); }
.btn.block { width: 100%; }

.btn-primary { background: var(--accent); color: var(--accent-fg); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--accent-600); }
.btn-primary:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--surface-2); border-color: var(--text-3); }

.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }

.btn-soft { background: var(--accent-soft); color: var(--accent); }
.btn-soft:hover { background: color-mix(in srgb, var(--accent) 20%, var(--surface)); }

.btn-danger { background: var(--err); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--err) 84%, #000); }
.btn-danger-ghost { background: transparent; color: var(--err); }
.btn-danger-ghost:hover { background: var(--err-bg); }

.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px var(--space-2); border-radius: var(--r-pill);
  font-size: var(--fs-2xs); font-weight: 700; line-height: 1.5;
  letter-spacing: .02em; white-space: nowrap;
}
.badge svg { width: 11px; height: 11px; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge-warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge-err { background: var(--err-bg); color: var(--err-fg); }
.badge-info { background: var(--info-bg); color: var(--info-fg); }
.badge-neutral { background: var(--surface-3); color: var(--text-2); }
.badge-custom { background: var(--cat-custom-bg); color: var(--cat-custom); }
.badge-opensource { background: var(--cat-opensource-bg); color: var(--cat-opensource); }
.badge-komersial { background: var(--cat-komersial-bg); color: var(--cat-komersial); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge.outline { background: transparent; box-shadow: inset 0 0 0 1px var(--border-strong); color: var(--text-2); }

/* status dot stand-alone */
.sdot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; position: relative; }
.sdot.ok { background: var(--ok); }
.sdot.warn { background: var(--warn); }
.sdot.err { background: var(--err); }
.sdot.ok::after {
  content: ""; position: absolute; inset: -3px; border-radius: 50%;
  background: var(--ok); opacity: .3; animation: pulse 2s infinite;
}
@keyframes pulse { 0% { transform: scale(.8); opacity: .4; } 70% { transform: scale(1.6); opacity: 0; } 100% { opacity: 0; } }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
}
.card-pad { padding: var(--space-5); }
.card-hd {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}
.card-hd h3 { font-size: var(--fs-md); font-weight: 700; }
.card-title { font-size: var(--fs-md); font-weight: 700; }
.card-sub { font-size: var(--fs-xs); color: var(--text-2); }

.hoverable { transition: box-shadow .16s, transform .16s, border-color .16s; cursor: pointer; }
.hoverable:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: var(--border-strong); }

/* ---------- Inputs ---------- */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.label { font-size: var(--fs-xs); font-weight: 600; color: var(--text-2); }
.label .req { color: var(--err); }
.input, .select, .textarea {
  width: 100%; height: var(--control-h); padding: 0 var(--space-3);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  font-size: var(--fs-sm); outline: none;
  transition: border-color .14s, box-shadow .14s;
}
.textarea { height: auto; padding: var(--space-3); resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:disabled { background: var(--surface-2); color: var(--text-3); cursor: not-allowed; }
.select { appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='%238b90a6' d='M0 0h10L5 6z'/></svg>");
  background-repeat: no-repeat; background-position: right var(--space-3) center; padding-right: 26px;
}
.input-group { position: relative; display: flex; align-items: center; }
.input-group > svg { position: absolute; left: var(--space-3); width: 15px; height: 15px; color: var(--text-3); pointer-events: none; }
.input-group .input { padding-left: 30px; }
.hint { font-size: var(--fs-2xs); color: var(--text-3); }
.hint.err { color: var(--err-fg); }

/* checkbox / switch */
.switch { position: relative; width: 34px; height: 19px; flex-shrink: 0; border: 0; border-radius: 999px; background: var(--border-strong); cursor: pointer; transition: background .16s; padding: 0; }
.switch[data-on="1"] { background: var(--accent); }
.switch i { position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .16s; }
.switch[data-on="1"] i { transform: translateX(15px); }
.switch.sm { width: 28px; height: 16px; }
.switch.sm i { width: 12px; height: 12px; }
.switch.sm[data-on="1"] i { transform: translateX(12px); }

.checkbox { width: 16px; height: 16px; border-radius: var(--r-xs); border: 1.5px solid var(--border-strong); background: var(--surface); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; transition: background .12s, border-color .12s; }
.checkbox[data-on="1"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.checkbox svg { width: 11px; height: 11px; opacity: 0; }
.checkbox[data-on="1"] svg { opacity: 1; }

/* segmented control */
.seg { display: inline-flex; padding: 2px; gap: 2px; background: var(--surface-3); border-radius: var(--r-sm); }
.seg button { border: 0; background: transparent; color: var(--text-2); font-size: var(--fs-xs); font-weight: 600; padding: 0 var(--space-3); height: calc(26px * var(--d)); border-radius: calc(var(--r-sm) - 1px); cursor: pointer; transition: background .12s, color .12s; display: inline-flex; align-items: center; gap: 5px; }
.seg button svg { width: 13px; height: 13px; }
.seg button[data-on="1"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.seg button:hover:not([data-on="1"]) { color: var(--text); }

/* ---------- Avatar ---------- */
.avatar { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; font-weight: 700; color: #fff; flex-shrink: 0; overflow: hidden; background: var(--accent); position: relative; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sq { border-radius: var(--r-sm); }
.avatar-xs { width: 22px; height: 22px; font-size: 9px; }
.avatar-sm { width: 28px; height: 28px; font-size: 11px; }
.avatar-md { width: 36px; height: 36px; font-size: 13px; }
.avatar-lg { width: 52px; height: 52px; font-size: 18px; }
.avatar-stack { display: flex; }
.avatar-stack .avatar { box-shadow: 0 0 0 2px var(--surface); margin-left: -7px; }
.avatar-stack .avatar:first-child { margin-left: 0; }

/* ---------- App icon tile ---------- */
.app-tile { display: inline-flex; align-items: center; justify-content: center; border-radius: var(--r-md); flex-shrink: 0; font-weight: 800; color: #fff; position: relative; overflow: hidden; }
.app-tile svg { width: 56%; height: 56%; }
.app-tile-sm { width: 32px; height: 32px; font-size: 13px; }
.app-tile-md { width: 40px; height: 40px; font-size: 16px; }
.app-tile-lg { width: 48px; height: 48px; font-size: 19px; }

/* ---------- Table ---------- */
.tbl-wrap { width: 100%; overflow: auto; border-radius: var(--r-lg); }
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); }
.tbl th, .tbl td { text-align: left; padding: var(--space-2) var(--space-4); border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl thead th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2);
  font-size: var(--fs-2xs); font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-3); user-select: none; height: calc(32px * var(--d));
}
.tbl thead th.sortable { cursor: pointer; }
.tbl thead th.sortable:hover { color: var(--text); }
.tbl thead th .th-in { display: inline-flex; align-items: center; gap: 4px; }
.tbl thead th svg { width: 12px; height: 12px; }
.tbl tbody tr { transition: background .1s; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl td { height: var(--row-h); color: var(--text); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl .col-num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl-check { width: 34px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); }
.tabs.pad { padding: 0 var(--space-5); }
.tab { position: relative; border: 0; background: transparent; color: var(--text-2); font-size: var(--fs-sm); font-weight: 600; padding: var(--space-3) var(--space-4); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; transition: color .12s; white-space: nowrap; }
.tab svg { width: 15px; height: 15px; }
.tab:hover { color: var(--text); }
.tab[data-on="1"] { color: var(--accent); }
.tab[data-on="1"]::after { content: ""; position: absolute; left: var(--space-3); right: var(--space-3); bottom: -1px; height: 2px; background: var(--accent); border-radius: 2px 2px 0 0; }
.tab .tab-count { font-size: var(--fs-2xs); background: var(--surface-3); color: var(--text-2); padding: 1px 6px; border-radius: 999px; font-weight: 700; }
.tab[data-on="1"] .tab-count { background: var(--accent-soft); color: var(--accent); }

/* ---------- Tooltip ---------- */
.tip { position: relative; display: inline-flex; }
.tip-pop {
  position: absolute; z-index: 100; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--surface); font-size: var(--fs-2xs); font-weight: 600;
  padding: 4px 8px; border-radius: var(--r-xs); white-space: nowrap; pointer-events: none;
  box-shadow: var(--shadow-md); animation: popIn .12s ease backwards;
}
.tip-pop::after { content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%); border: 4px solid transparent; border-top-color: var(--text); }

/* ---------- Empty state ---------- */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: var(--space-7) var(--space-5); gap: var(--space-3); }
.empty-ico { width: 52px; height: 52px; border-radius: var(--r-lg); display: flex; align-items: center; justify-content: center; background: var(--surface-3); color: var(--text-3); }
.empty-ico svg { width: 24px; height: 24px; }
.empty h4 { font-size: var(--fs-md); font-weight: 700; }
.empty p { font-size: var(--fs-sm); color: var(--text-2); max-width: 320px; }

/* ---------- Skeleton ---------- */
.skel { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%); background-size: 400px 100%; animation: shimmer 1.4s infinite linear; border-radius: var(--r-xs); }

/* ---------- Divider / KV ---------- */
.divider { height: 1px; background: var(--border); margin: var(--space-4) 0; }
.kv { display: grid; grid-template-columns: minmax(110px, auto) 1fr; gap: var(--space-2) var(--space-4); font-size: var(--fs-sm); }
.kv dt { color: var(--text-3); font-weight: 600; font-size: var(--fs-xs); align-self: center; }
.kv dd { margin: 0; color: var(--text); }

/* ---------- Progress ---------- */
.progress { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 999px; background: var(--accent); transition: width .4s cubic-bezier(.3,.7,.4,1); }

/* ---------- Pagination ---------- */
.pager { display: flex; align-items: center; gap: var(--space-2); }
.pager button { min-width: calc(28px * var(--d)); height: calc(28px * var(--d)); border: 1px solid var(--border); background: var(--surface); border-radius: var(--r-sm); color: var(--text-2); font-size: var(--fs-xs); font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; padding: 0 6px; }
.pager button:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.pager button[data-on="1"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.pager button:disabled { opacity: .4; cursor: not-allowed; }
