/* EgyptAuth — components. Logical properties throughout so RTL mirrors without overrides. */

/* ---------- Icons ---------- */
.icon { width: 16px; height: 16px; fill: currentColor; stroke: none; vertical-align: middle; flex-shrink: 0; }
.icon .t { fill: var(--icon-tone, currentColor); opacity: var(--icon-tone-opacity, 0.2); transition: fill var(--t-fast), opacity var(--t-fast); }
.icon-sm { width: 14px; height: 14px; }
.icon-xs { width: 12px; height: 12px; }
.icon-lg { width: 20px; height: 20px; }
.icon-xl { width: 24px; height: 24px; }

/* ---------- Buttons ---------- */
.btn {
  --btn-bg: var(--raised);
  --btn-bg-hover: var(--hover);
  --btn-border: var(--border-strong);
  --btn-text: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding-inline: 12px; border-radius: var(--r);
  background: var(--btn-bg); color: var(--btn-text);
  border: 1px solid var(--btn-border);
  font-size: var(--fs-base); font-weight: 500; line-height: 1; white-space: nowrap;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease), opacity var(--t-fast);
  user-select: none; position: relative;
}
.btn:hover:not(:disabled) { background: var(--btn-bg-hover); }
.btn:active:not(:disabled) { transform: scale(0.985); }
.btn:disabled { opacity: 0.5; }
.btn .icon { width: 15px; height: 15px; margin-inline: -1px; }
.btn-primary { --btn-bg: var(--primary-bg); --btn-bg-hover: var(--primary-bg-hover); --btn-border: var(--primary-bg); --btn-text: var(--primary-text); }
.btn-ghost { --btn-bg: transparent; --btn-bg-hover: var(--hover); --btn-border: transparent; --btn-text: var(--text-2); }
.btn-ghost:hover:not(:disabled) { color: var(--text); }
.btn-danger { --btn-bg: transparent; --btn-bg-hover: var(--red-soft); --btn-border: var(--red-line); --btn-text: var(--red-text); }
.btn-danger-solid { --btn-bg: var(--red); --btn-bg-hover: var(--red-hover); --btn-border: var(--red); --btn-text: var(--on-solid); }
.btn-sm { height: 28px; padding-inline: 10px; font-size: var(--fs-sm); gap: 5px; }
.btn-sm .icon { width: 14px; height: 14px; }
.btn-lg { height: 38px; padding-inline: 16px; font-size: var(--fs-md); }
.btn-block { width: 100%; }
.btn-icon {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: var(--r);
  color: var(--text-3); transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.btn-icon:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.btn-icon:active:not(:disabled) { transform: scale(0.94); }
.btn-icon:disabled { opacity: 0.35; }
.btn-icon.danger:hover:not(:disabled) { color: var(--red-text); background: var(--red-soft); }
.btn-icon.sm { width: 24px; height: 24px; }
.btn-icon.sm .icon { width: 14px; height: 14px; }
.btn.is-busy { color: transparent !important; pointer-events: none; }
.btn.is-busy > :not(.spinner) { visibility: hidden; }
.btn.is-busy > .spinner { position: absolute; inset: 0; margin: auto; color: var(--btn-text); }
.btn-group { display: inline-flex; }
.btn-group > .btn { border-radius: 0; }
.btn-group > .btn:first-child { border-start-start-radius: var(--r); border-end-start-radius: var(--r); }
.btn-group > .btn:last-child { border-start-end-radius: var(--r); border-end-end-radius: var(--r); }
.btn-group > .btn + .btn { margin-inline-start: -1px; }

.link { color: var(--text); text-decoration: underline; text-decoration-color: var(--border-focus); text-underline-offset: 3px; transition: text-decoration-color var(--t-fast); }
.link:hover { text-decoration-color: var(--text-2); }
.link-accent { color: var(--accent-text); }

/* ---------- Spinner / skeleton / progress ---------- */
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid currentColor; border-inline-end-color: transparent; animation: spin 0.7s linear infinite; display: inline-block; flex-shrink: 0; opacity: 0.85; }
.spinner.lg { width: 20px; height: 20px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--skeleton-a) 0%, var(--skeleton-b) 50%, var(--skeleton-a) 100%); background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite; border-radius: var(--r-sm); height: 12px; }
@keyframes shimmer { 0% { background-position: 150% 0; } 100% { background-position: -50% 0; } }
.progress { height: 4px; background: var(--raised); border-radius: var(--r-pill); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--text-2); border-radius: inherit; transition: width var(--t-slow) var(--ease); }
.progress.ok > span { background: var(--green); }
.progress.warn > span { background: var(--amber); }
.progress.bad > span { background: var(--red); }

/* ---------- Form controls ---------- */
.input, .select, .textarea {
  display: block; width: 100%; height: 32px; padding-inline: 10px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r);
  font-size: var(--fs-base);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), background var(--t-fast);
}
.input::placeholder, .textarea::placeholder { color: var(--text-4); }
.input:hover:not(:disabled), .select:hover:not(:disabled), .textarea:hover:not(:disabled) { border-color: var(--border-focus); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.input:disabled, .select:disabled, .textarea:disabled { opacity: 0.55; cursor: not-allowed; }
.input[readonly] { background: var(--surface); }
.input.mono, .textarea.mono { font-family: var(--font-mono); font-size: 12px; }
.textarea { height: auto; min-height: 80px; padding-block: 8px; resize: vertical; line-height: 1.5; }
.select {
  appearance: none; -webkit-appearance: none; padding-inline-end: 28px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 15 5 5 5-5'/%3E%3Cpath d='m7 9 5-5 5 5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 7px center; background-size: 14px;
}
[dir="rtl"] .select { background-position: left 7px center; }
.select option { background: var(--raised); color: var(--text); }
.input-sm, .select.input-sm { height: 28px; font-size: var(--fs-sm); }
input[type="date"].input { color-scheme: inherit; }
input[type="number"].input { font-variant-numeric: tabular-nums; }

.input-wrap { position: relative; display: block; }
.input-wrap > .icon { position: absolute; inset-inline-start: 10px; top: 50%; transform: translateY(-50%); color: var(--text-4); pointer-events: none; }
.input-wrap > .input { padding-inline-start: 32px; }
.input-wrap > .input-addon { position: absolute; inset-inline-end: 4px; top: 50%; transform: translateY(-50%); }
.input-wrap.has-addon > .input { padding-inline-end: 36px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); display: flex; align-items: center; gap: 4px; }
.field-label .req { color: var(--red-text); }
.field-hint { font-size: var(--fs-sm); color: var(--text-3); }
.field-error { font-size: var(--fs-sm); color: var(--red-text); display: none; align-items: center; gap: 4px; }
.field.has-error .field-error { display: flex; }
.field.has-error .input, .field.has-error .select, .field.has-error .textarea { border-color: var(--red-line); }
.field.has-error .input:focus, .field.has-error .textarea:focus { box-shadow: 0 0 0 3px var(--red-soft); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s4); }
.form-grid > .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: minmax(0, 1fr); } .form-grid > * { grid-column: 1 / -1; } }
.form-section-title { grid-column: 1 / -1; font-size: var(--fs-md); font-weight: 600; color: var(--text); padding-top: var(--s3); padding-bottom: var(--s1); border-bottom: 1px solid var(--border); }


.checkbox {
  appearance: none; -webkit-appearance: none; width: 16px; height: 16px; flex-shrink: 0;
  border: 1px solid var(--border-focus); border-radius: var(--r-sm); background: var(--bg);
  display: inline-grid; place-items: center; cursor: pointer; transition: background var(--t-fast), border-color var(--t-fast);
}
.checkbox::after { content: ""; width: 9px; height: 5px; border: solid var(--on-solid); border-width: 0 0 1.75px 1.75px; transform: rotate(-45deg) translate(1px, -1px); opacity: 0; }
.checkbox:checked, .checkbox:indeterminate { background: var(--accent); border-color: var(--accent); }
.checkbox:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft, var(--selection)); }
.checkbox:checked::after { opacity: 1; }
.checkbox:indeterminate::after { opacity: 1; width: 8px; height: 0; border-width: 0 0 1.75px 0; transform: none; }
.checkbox:disabled { opacity: 0.4; cursor: not-allowed; }

.switch {
  appearance: none; -webkit-appearance: none; position: relative; width: 30px; height: 18px; flex-shrink: 0;
  background: var(--active); border: 1px solid var(--border-strong); border-radius: var(--r-pill); cursor: pointer;
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease);
}
.switch::after { content: ""; position: absolute; top: 2px; inset-inline-start: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--text-2); transition: transform var(--t) var(--ease), background var(--t); }
.switch:checked { background: var(--accent); border-color: var(--accent); }
.switch:checked::after { background: var(--switch-knob); transform: translateX(12px); }
[dir="rtl"] .switch:checked::after { transform: translateX(-12px); }
.switch:disabled { opacity: 0.45; cursor: not-allowed; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r); cursor: pointer; transition: background var(--t-fast); }
.toggle-row:hover { background: var(--surface); }
.toggle-row .t-label { display: block; color: var(--text); font-weight: 500; }
.toggle-row .t-hint { display: block; color: var(--text-3); font-size: var(--fs-sm); margin-top: 1px; }
.check-row { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 6px 8px; border-radius: var(--r); transition: background var(--t-fast); min-width: 0; }
.check-row:hover { background: var(--hover); }
.check-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px; max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--r); padding: 4px; }
@media (max-width: 560px) { .check-grid { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); min-width: 0; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: 12px 16px; border-bottom: 1px solid var(--border); min-height: 48px; }
.card-title { font-size: var(--fs-base); font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; min-width: 0; }
.card-title .icon { color: var(--text-3); }
.card-sub { font-size: var(--fs-sm); color: var(--text-3); margin-top: 1px; }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }
.card-footer { display: flex; align-items: center; justify-content: flex-end; gap: var(--s2); padding: 12px 16px; border-top: 1px solid var(--border); }
.card.is-interactive { transition: border-color var(--t-fast) var(--ease), background var(--t-fast); cursor: pointer; }
.card.is-interactive:hover { border-color: var(--border-strong); background: var(--card-hover); }

/* ---------- Stats ---------- */
.stat { padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.stat-label { font-size: var(--fs-sm); color: var(--text-3); display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; color: var(--text); font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat-foot { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-3); min-height: 18px; }
.stat-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); }
.stat-row > .stat + .stat { border-inline-start: 1px solid var(--border); }
.stat-row.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 1000px) {
  .stat-row, .stat-row.cols-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-row > .stat + .stat { border-inline-start: 0; }
  .stat-row > .stat:nth-child(even) { border-inline-start: 1px solid var(--border); }
  .stat-row > .stat:nth-child(n + 3) { border-top: 1px solid var(--border); }
}
.delta { display: inline-flex; align-items: center; gap: 2px; height: 18px; padding-inline: 5px; border-radius: var(--r-sm); font-size: var(--fs-xs); font-weight: 500; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.delta.up { color: var(--green-text); background: var(--green-soft); }
.delta.down { color: var(--red-text); background: var(--red-soft); }
.delta.flat { color: var(--text-3); background: var(--gray-soft); }
.delta .icon { width: 12px; height: 12px; --icon-tone-opacity: 0.35; }

/* ---------- Section headings ---------- */
.dash-section { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.section-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; min-width: 0; }
.section-title { margin: 0; font-size: var(--fs-md); font-weight: 600; color: var(--text); letter-spacing: -0.005em; }
.section-sub { font-size: var(--fs-sm); color: var(--text-3); }

/* ---------- KPI cards (dashboard) ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1100px) { .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .kpi-grid { grid-template-columns: minmax(0, 1fr); } }
.kpi {
  position: relative; overflow: hidden; isolation: isolate;
  display: flex; flex-direction: column; gap: 4px; min-width: 0; padding: 14px 16px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  transition: border-color var(--t-fast) var(--ease);
}
.kpi:hover { border-color: var(--border-strong); }
.kpi.has-spark { padding-bottom: 32px; }
.kpi-top { display: flex; align-items: center; gap: 8px; min-width: 0; margin-bottom: 4px; }
.kpi-icon {
  flex: none; display: grid; place-items: center; width: 20px; height: 24px;
  color: var(--text-3);
  --icon-tone: var(--gold); --icon-tone-opacity: 0.5;
}
.kpi-icon .icon { width: 20px; height: 20px; }
.kpi-icon.danger { color: var(--red-text); --icon-tone: var(--red); --icon-tone-opacity: 0.35; }
.kpi-label { min-width: 0; font-size: var(--fs-base); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi-delta { margin-inline-start: auto; display: inline-flex; align-items: center; gap: 6px; flex: none; }
.kpi-value { font-size: 26px; font-weight: 600; letter-spacing: -0.025em; line-height: 1.15; color: var(--text); font-variant-numeric: tabular-nums; }
.kpi-foot { display: flex; align-items: center; gap: 6px; min-width: 0; min-height: 18px; font-size: var(--fs-sm); color: var(--text-3); }
.kpi-meter { margin-top: 12px; }
.kpi-meter .progress > span { background: var(--gold); }
.kpi-meter .progress.bad > span { background: var(--red); }
.kpi-meter .progress.ok > span { background: var(--green); }

/* ---------- Sparkline (ui/sparkline.js) ---------- */
.spark { position: absolute; inset-inline: 0; bottom: 0; height: 44px; pointer-events: none; z-index: -1; --spark: var(--chart-accent); }
[dir="rtl"] .spark { transform: scaleX(-1); }
.spark svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; overflow: visible; }
.spark-area { -webkit-mask-image: linear-gradient(to bottom, #000 0%, transparent 100%); mask-image: linear-gradient(to bottom, #000 0%, transparent 100%); }
.spark-area path { fill: var(--spark); opacity: 0.2; }
.spark-line path { fill: none; stroke: var(--spark); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.spark.gold { --spark: var(--chart-gold); }
.spark.green { --spark: var(--chart-green); }
.spark.red { --spark: var(--chart-red); }
.spark.muted { --spark: var(--chart-gray); }
.spark.is-flat { --spark: var(--chart-gray); }
.spark.is-flat .spark-area { display: none; }
.spark.is-flat .spark-line path { stroke-dasharray: 3 4; opacity: 0.55; }

/* ---------- Badges / chips / dots ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 20px; padding-inline: 7px;
  border-radius: var(--r-sm); border: 1px solid var(--gray-line); background: var(--gray-soft);
  color: var(--text-2); font-size: var(--fs-sm); font-weight: 500; white-space: nowrap; line-height: 1;
}
.badge .dot { width: 6px; height: 6px; }
.badge .icon { width: 12px; height: 12px; }
.badge.green { color: var(--green-text); background: var(--green-soft); border-color: var(--green-line); }
.badge.red { color: var(--red-text); background: var(--red-soft); border-color: var(--red-line); }
.badge.amber { color: var(--amber-text); background: var(--amber-soft); border-color: var(--amber-line); }
.badge.blue { color: var(--blue-text); background: var(--blue-soft); border-color: var(--blue-line); }
.badge.outline { background: transparent; }
.badge.mono { font-family: var(--font-mono); font-size: 11px; }
.chip { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding-inline: 6px; border-radius: var(--r-sm); background: var(--raised); border: 1px solid var(--border); color: var(--text-2); font-size: var(--fs-xs); white-space: nowrap; max-width: 100%; }
.chip.mono { font-family: var(--font-mono); font-size: 11px; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--text-4); flex-shrink: 0; }
.vsep { display: inline-block; width: 1px; height: 12px; background: var(--border-strong); margin-inline: 6px; vertical-align: middle; flex-shrink: 0; }
.dot.green { background: var(--green); }
.dot.red { background: var(--red); }
.dot.amber { background: var(--amber); }
.dot.blue { background: var(--blue); }
.dot.live { background: var(--green); }
@keyframes live { 0% { box-shadow: 0 0 0 0 rgba(63, 182, 139, 0.45); } 70% { box-shadow: 0 0 0 5px rgba(63, 182, 139, 0); } 100% { box-shadow: 0 0 0 0 rgba(63, 182, 139, 0); } }
.kbd { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding-inline: 4px; border-radius: var(--r-sm); border: 1px solid var(--border-strong); border-bottom-width: 2px; background: var(--raised); color: var(--text-2); font-family: var(--font-mono); font-size: 10.5px; line-height: 1; direction: ltr; }

.country { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; min-width: 0; }
.country .cc { display: inline-grid; place-items: center; min-width: 24px; height: 16px; padding-inline: 3px; border-radius: 3px; background: var(--raised); border: 1px solid var(--border-strong); font-family: var(--font-mono); font-size: 10px; color: var(--text-2); letter-spacing: 0.02em; direction: ltr; }
.country .cn { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; }

.avatar { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: var(--r); background: var(--active); border: 1px solid var(--border-strong); color: var(--text); font-size: 10.5px; font-weight: 600; flex-shrink: 0; text-transform: uppercase; letter-spacing: 0.02em; }
.avatar.lg { width: 40px; height: 40px; font-size: 14px; border-radius: var(--r-lg); }
.avatar.sm { width: 20px; height: 20px; font-size: 9px; border-radius: var(--r-sm); }

/* ---------- Key/value, code, secret ---------- */
.kv { display: grid; grid-template-columns: minmax(110px, 34%) minmax(0, 1fr); gap: 8px 16px; font-size: var(--fs-base); }
.kv dt { color: var(--text-3); }
.kv dd { color: var(--text); min-width: 0; overflow-wrap: anywhere; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.code { background: var(--bg); border: 1px solid var(--border); border-radius: var(--r); padding: 10px 12px; font-family: var(--font-mono); font-size: 12px; line-height: 1.6; color: var(--text-2); overflow: auto; white-space: pre; direction: ltr; text-align: left; tab-size: 2; max-height: 360px; }
.code.wrap { white-space: pre-wrap; word-break: break-all; }
.code .k { color: var(--code-key); } .code .s { color: var(--green-text); } .code .n { color: var(--amber-text); } .code .c { color: var(--text-4); }
.secret { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 10px; padding-inline: 10px 6px; background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--r); min-width: 0; }
.secret > .value { flex: 1; min-width: 0; font-family: var(--font-mono); font-size: 12px; color: var(--text); direction: ltr; text-align: left; overflow-wrap: anywhere; user-select: all; }

/* ---------- Callouts ---------- */
.callout { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border-radius: var(--r); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); font-size: var(--fs-base); }
.callout > .icon { margin-top: 1px; color: var(--text-3); }
.callout strong { color: var(--text); font-weight: 500; }
.callout.info > .icon { color: var(--blue-text); }
.callout.warn { border-color: var(--amber-line); background: var(--tint-amber); }
.callout.warn > .icon { color: var(--amber-text); }
.callout.danger { border-color: var(--red-line); background: var(--tint-red); }
.callout.danger > .icon { color: var(--red-text); }
.callout.success { border-color: var(--green-line); background: var(--tint-green); }
.callout.success > .icon { color: var(--green-text); }

/* ---------- Empty / error states ---------- */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; padding: 48px 24px; }
.empty-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r-lg); border: 1px solid var(--border-strong); background: var(--raised); color: var(--text-3); }
.empty-icon.danger { color: var(--red-text); border-color: var(--red-line); background: var(--red-soft); }
.empty-title { color: var(--text); font-weight: 500; font-size: var(--fs-md); }
.empty-text { color: var(--text-3); max-width: 420px; }
.empty-actions { display: flex; gap: 8px; margin-top: 4px; }
.empty.compact { padding: 28px 16px; }

/* ---------- Tabs / segmented / sub-nav ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { position: relative; display: inline-flex; align-items: center; gap: 6px; height: 36px; padding-inline: 10px; color: var(--text-3); font-weight: 500; white-space: nowrap; transition: color var(--t-fast); border-radius: var(--r) var(--r) 0 0; }
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); }
.tab.is-active::after { content: ""; position: absolute; inset-inline: 8px; bottom: -1px; height: 2px; background: var(--gold); border-radius: 2px 2px 0 0; }
.tab .count { font-size: var(--fs-xs); color: var(--text-3); background: var(--raised); border: 1px solid var(--border); border-radius: var(--r-sm); padding-inline: 5px; line-height: 16px; font-variant-numeric: tabular-nums; }
.seg { display: inline-flex; padding: 2px; gap: 2px; background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--r); }
.seg > button { height: 26px; padding-inline: 10px; border-radius: var(--r-sm); color: var(--text-3); font-size: var(--fs-sm); font-weight: 500; transition: background var(--t-fast), color var(--t-fast); }
.seg > button:hover { color: var(--text); }
.seg > button.is-active { background: var(--active); color: var(--text); }
.subnav { display: flex; flex-direction: column; gap: 1px; }
.subnav-item { display: flex; align-items: center; gap: 8px; height: 30px; padding-inline: 10px; border-radius: var(--r); color: var(--text-3); font-weight: 500; transition: background var(--t-fast), color var(--t-fast); position: relative; width: 100%; }
.subnav-item:hover { background: var(--hover); color: var(--text); }
.subnav-item.is-active { color: var(--text); background: var(--raised); }
.subnav-item.is-active::before { content: ""; position: absolute; inset-inline-start: 0; top: 7px; bottom: 7px; width: 2px; border-radius: 2px; background: var(--gold); }
@media (max-width: 900px) { .subnav { flex-direction: row; overflow-x: auto; } .subnav-item { width: auto; white-space: nowrap; } .subnav-item.is-active::before { display: none; } }

/* ---------- Tables ---------- */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); min-width: 0; display: flex; flex-direction: column; }
.table-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.table-toolbar .search { width: 260px; max-width: 100%; }
.table-toolbar > .select, .table-toolbar > label:not(.search) > .input { width: auto; min-width: 150px; max-width: 240px; }
.table-toolbar .tools-end { display: flex; align-items: center; gap: 8px; margin-inline-start: auto; flex-wrap: wrap; }
@media (max-width: 640px) { .table-toolbar .search { width: 100%; } .table-toolbar .tools-end { margin-inline-start: 0; } }
.table-scroll { overflow: auto; position: relative; max-height: var(--table-max-h, max(360px, calc(100vh - 240px))); }
.table { width: 100%; font-size: var(--fs-base); }
.table thead th {
  position: sticky; top: 0; z-index: 2; background: var(--surface);
  text-align: start; font-weight: 500; font-size: var(--fs-sm); color: var(--text-3);
  height: 36px; padding-inline: 12px; white-space: nowrap; border-bottom: 1px solid var(--border);
}
.table tbody td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.row { display: table-row; transition: background var(--t-fast); }
.table tbody tr.row:hover { background: var(--row-hover); }
.table tbody tr.row.clickable { cursor: pointer; }
.table tbody tr.row:focus-visible { outline: none; box-shadow: inset 2px 0 0 var(--accent); background: var(--row-hover); border-radius: 0; }
[dir="rtl"] .table tbody tr.row:focus-visible { box-shadow: inset -2px 0 0 var(--accent); }
.table tbody tr.row.is-selected { background: var(--row-selected); }
.table tbody tr.row.is-expanded { background: var(--row-expanded); }
.table tbody tr.row.is-expanded td { border-bottom-color: transparent; }
.table tbody tr.expanded-row > td { background: var(--well); padding: 16px; }
.table .col-num, .table th.col-num { text-align: end; font-variant-numeric: tabular-nums; }
.table .col-check { width: 36px; padding-inline-end: 0; }
.table .col-actions { text-align: end; white-space: nowrap; width: 1%; }
.table .col-actions .row-actions { display: inline-flex; gap: 2px; justify-content: flex-end; }
.table .cell-primary { color: var(--text); font-weight: 500; }
.table .cell-sub { color: var(--text-3); font-size: var(--fs-sm); }
.sort-btn { display: inline-flex; align-items: center; gap: 4px; color: inherit; font: inherit; height: 24px; border-radius: var(--r-sm); }
.sort-btn:hover { color: var(--text); }
.sort-btn .icon { width: 12px; height: 12px; opacity: 0.4; }
.sort-btn.is-active { color: var(--text); }
.sort-btn.is-active .icon { opacity: 1; }
th.col-num .sort-btn { flex-direction: row-reverse; }
.table-footer { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--border); color: var(--text-3); font-size: var(--fs-sm); }
.table-footer .pager { display: flex; align-items: center; gap: 2px; }
.page-btn { min-width: 28px; height: 28px; padding-inline: 6px; display: inline-grid; place-items: center; border-radius: var(--r); color: var(--text-2); font-variant-numeric: tabular-nums; transition: background var(--t-fast), color var(--t-fast); }
.page-btn:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.page-btn.is-active { background: var(--raised); color: var(--text); box-shadow: inset 0 0 0 1px var(--border-strong); }
.page-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.batch-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--raised); }
.batch-bar .count { color: var(--text); font-weight: 500; margin-inline-end: 4px; }
.table .skeleton-row td { padding-block: 14px; }

/* ---------- Lists / feed ---------- */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); min-width: 0; }
.list-item:last-child { border-bottom: 0; }
.list-item.clickable { cursor: pointer; transition: background var(--t-fast); }
.list-item.clickable:hover { background: var(--row-hover); }
.feed-icon { display: grid; place-items: center; width: 26px; height: 26px; border-radius: var(--r); background: var(--raised); border: 1px solid var(--border); color: var(--text-3); flex-shrink: 0; }
.feed-icon.green { color: var(--green-text); }
.feed-icon.red { color: var(--red-text); }
.feed-icon.amber { color: var(--amber-text); }
.feed-icon.blue { color: var(--blue-text); }

/* ---------- Horizontal stacked bar ---------- */
.stackbar { display: flex; height: 8px; border-radius: var(--r-pill); overflow: hidden; background: var(--raised); gap: 2px; }
.stackbar > span { display: block; height: 100%; min-width: 2px; transition: flex-grow var(--t-slow) var(--ease); }
.legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px 16px; margin-top: 14px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: var(--fs-base); min-width: 0; }
.legend-item .swatch { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
.legend-item .lbl { color: var(--text-2); flex: 1; min-width: 0; }
.legend-item .val { color: var(--text); font-variant-numeric: tabular-nums; }
.legend-item .pct { color: var(--text-3); font-variant-numeric: tabular-nums; font-size: var(--fs-sm); min-width: 38px; text-align: end; }

/* ---------- Popover menu ---------- */
.menu {
  position: fixed; z-index: 70; min-width: 200px; max-width: min(320px, calc(100vw - 16px));
  max-height: calc(100dvh - 16px); overflow-y: auto;
  background: var(--raised); border: 1px solid var(--border-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-pop);
  padding: 4px; opacity: 0; transform: translateY(-4px) scale(0.98); transform-origin: top; pointer-events: none;
  transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.menu.is-open { opacity: 1; transform: none; pointer-events: auto; }
.menu-item { display: flex; align-items: center; gap: 8px; width: 100%; height: 30px; padding-inline: 8px; border-radius: var(--r-sm); color: var(--text-2); font-size: var(--fs-base); white-space: nowrap; transition: background var(--t-fast), color var(--t-fast); }
.menu-item:hover, .menu-item.is-hover, .menu-item:focus-visible { background: var(--hover); color: var(--text); box-shadow: none; }
.menu-item .icon { color: var(--text-3); }
.menu-item.danger { color: var(--red-text); }
.menu-item.danger .icon { color: var(--red-text); }
.menu-item.is-active { color: var(--text); }
.menu-item .end { margin-inline-start: auto; color: var(--text-3); display: inline-flex; align-items: center; gap: 4px; }
.menu-sep { height: 1px; background: var(--border-strong); margin: 4px -4px; }
.menu-label { padding: 6px 8px 4px; font-size: var(--fs-xs); color: var(--text-3); font-weight: 500; }
.menu-search { padding: 4px 4px 6px; }
.menu-scroll { max-height: 280px; overflow-y: auto; }
.menu-empty { padding: 10px 8px; color: var(--text-3); font-size: var(--fs-sm); }

/* ---------- Tooltips (rail) ---------- */
[data-tip] { position: relative; }
.has-tips [data-tip]:hover::after, .has-tips [data-tip]:focus-visible::after {
  content: attr(data-tip); position: absolute; inset-inline-start: calc(100% + 10px); top: 50%; transform: translateY(-50%);
  background: var(--raised); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--r);
  padding: 4px 8px; font-size: var(--fs-sm); white-space: nowrap; box-shadow: var(--shadow-pop); z-index: 80; pointer-events: none;
}

/* ---------- Modal / drawer ---------- */
.modal-root { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-start; justify-content: center; padding: 10vh 16px 16px; }
.modal-backdrop { position: absolute; inset: 0; background: var(--overlay); opacity: 0; transition: opacity var(--t) var(--ease); }
.modal-root.is-open .modal-backdrop { opacity: 1; }
.modal {
  position: relative; width: 100%; max-width: 480px; max-height: calc(100vh - 12vh - 16px); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-dialog);
  opacity: 0; transform: scale(0.98); transition: opacity var(--t) var(--ease), transform var(--t) var(--ease);
}
.modal-root.is-open .modal { opacity: 1; transform: none; }
.modal.size-sm { max-width: 400px; }
.modal.size-lg { max-width: 640px; }
.modal.size-xl { max-width: 860px; }
.modal-header { display: flex; align-items: flex-start; gap: 12px; padding: 16px 16px 0; }
.modal-title { font-size: var(--fs-md); font-weight: 600; color: var(--text); }
.modal-sub { font-size: var(--fs-base); color: var(--text-3); margin-top: 2px; overflow-wrap: anywhere; }
.modal-body { padding: 16px; overflow-y: auto; flex: 1; min-height: 0; }
.modal-footer { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.modal-footer .start { margin-inline-end: auto; }
.modal-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: var(--r); border: 1px solid var(--border-strong); background: var(--raised); color: var(--text-2); flex-shrink: 0; }
.modal-icon.danger { color: var(--red-text); border-color: var(--red-line); background: var(--red-soft); }
.modal-icon.warn { color: var(--amber-text); border-color: var(--amber-line); background: var(--amber-soft); }
.modal-root.is-drawer { padding: 0; justify-content: flex-end; align-items: stretch; }
.drawer {
  position: relative; width: min(560px, 100vw); height: 100%; display: flex; flex-direction: column;
  background: var(--surface); border-inline-start: 1px solid var(--border-strong); box-shadow: var(--shadow-dialog);
  transform: translateX(100%); transition: transform var(--t-slow) var(--ease);
}
[dir="rtl"] .drawer { transform: translateX(-100%); }
.modal-root.is-open .drawer { transform: none; }
.drawer.size-lg { width: min(720px, 100vw); }
.drawer .modal-header { padding: 14px 16px; border-bottom: 1px solid var(--border); align-items: center; }
@media (max-width: 560px) { .modal-root { padding: 8px; align-items: flex-end; } .modal { max-height: calc(100vh - 16px); } }

/* ---------- Toasts ---------- */
.toast-stack { position: fixed; inset-inline-end: 16px; bottom: 16px; z-index: 90; display: flex; flex-direction: column; gap: 8px; width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; pointer-events: auto;
  background: var(--raised); border: 1px solid var(--border-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-pop);
  opacity: 0; transform: translateY(6px); transition: opacity var(--t) var(--ease), transform var(--t) var(--ease);
}
.toast.is-in { opacity: 1; transform: none; }
.toast > .icon { margin-top: 1px; }
.toast.success > .icon { color: var(--green-text); }
.toast.error > .icon { color: var(--red-text); }
.toast.warning > .icon { color: var(--amber-text); }
.toast.info > .icon { color: var(--blue-text); }
.toast-body { flex: 1; min-width: 0; }
.toast-title { color: var(--text); font-weight: 500; }
.toast-msg { color: var(--text-2); overflow-wrap: anywhere; }
.toast-title + .toast-msg { margin-top: 1px; font-size: var(--fs-sm); }

/* ---------- Loading bar ---------- */
.loading-bar { position: fixed; top: 0; inset-inline: 0; height: 2px; z-index: 100; pointer-events: none; overflow: hidden; opacity: 0; transition: opacity var(--t) var(--ease); }
.loading-bar.is-active { opacity: 1; }
.loading-bar > span { position: absolute; top: 0; bottom: 0; width: 40%; background: var(--accent); animation: lbar 1.1s var(--ease) infinite; }
@keyframes lbar { 0% { inset-inline-start: -40%; } 100% { inset-inline-start: 100%; } }

/* ---------- Command palette ---------- */
.palette { width: 100%; max-width: 600px; }
.palette .modal-body { padding: 0; }
.palette-input { display: flex; align-items: center; gap: 10px; padding: 0 14px; height: 48px; border-bottom: 1px solid var(--border); }
.palette-input .icon { color: var(--text-3); }
.palette-input input { flex: 1; height: 100%; background: transparent; border: 0; font-size: var(--fs-md); color: var(--text); min-width: 0; }
.palette-input input:focus { outline: none; box-shadow: none; }
.palette-list { max-height: 380px; overflow-y: auto; padding: 6px; }
.palette-group { padding: 8px 8px 4px; font-size: var(--fs-xs); color: var(--text-3); font-weight: 500; }
.palette-item { display: flex; align-items: center; gap: 10px; width: 100%; height: 36px; padding-inline: 10px; border-radius: var(--r); color: var(--text-2); }
.palette-item .icon { color: var(--text-3); }
.palette-item .hint { margin-inline-start: auto; color: var(--text-3); font-size: var(--fs-sm); }
.palette-item.is-active { background: var(--hover); color: var(--text); }
.palette-item.is-active .icon { color: var(--text); }
.palette-foot { display: flex; align-items: center; gap: 14px; padding: 8px 14px; border-top: 1px solid var(--border); color: var(--text-3); font-size: var(--fs-xs); }
.palette-foot span { display: inline-flex; align-items: center; gap: 5px; }

/* ---------- Copy button feedback ---------- */
.copy-btn.is-copied { color: var(--green-text) !important; }

/* ---------- Dropzone / QR ---------- */
.dropzone { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 24px; border: 1px dashed var(--border-focus); border-radius: var(--r-lg); color: var(--text-3); text-align: center; cursor: pointer; transition: border-color var(--t-fast), background var(--t-fast), color var(--t-fast); }
.dropzone:hover, .dropzone.is-over { border-color: var(--text-3); background: var(--surface); color: var(--text-2); }
.qr { display: inline-block; padding: 10px; background: #fff; border-radius: var(--r-lg); }
.qr img { width: 168px; height: 168px; image-rendering: pixelated; }

/* ---------- Misc ---------- */
.divider { height: 1px; background: var(--border); margin-block: var(--s4); }
.section-title { font-size: var(--fs-sm); font-weight: 500; color: var(--text-3); margin-bottom: 8px; }
.fade-in { animation: fadeIn var(--t) var(--ease); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
.health { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--text-4); }
.health.ok { background: var(--green); }
.health.bad { background: var(--red); }
.health.off { background: var(--active); box-shadow: inset 0 0 0 1px var(--border-focus); }
.quota-card { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.quota-card .q-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; min-width: 0; }
.quota-card .q-app { font-size: var(--fs-sm); color: var(--text-3); }
.quota-card .q-plan { color: var(--text); font-weight: 500; }
.quota-card .q-num { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; color: var(--text); }
.quota-card .q-num small { font-size: var(--fs-base); color: var(--text-3); font-weight: 400; letter-spacing: 0; }
.quota-card .q-foot { display: flex; justify-content: space-between; font-size: var(--fs-sm); color: var(--text-3); }
