/**
 * xBot · Component styles
 *
 * All classes prefixed with `x-` to avoid collision with Tailwind utilities
 * and any legacy CSS still on the page during the migration.
 *
 * Order: button, card, field/input, badge, table, empty, modal, toast,
 *        section, utility.
 */

/* ============================================================
 * BUTTON
 * ============================================================ */
.x-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--space-2);
	border: 1px solid transparent;
	border-radius: var(--radius-md);
	font-weight: 500;
	font-size: var(--text-sm);
	line-height: 1;
	cursor: pointer;
	transition:
		background-color var(--dur-fast) var(--ease-out),
		border-color     var(--dur-fast) var(--ease-out),
		color            var(--dur-fast) var(--ease-out),
		box-shadow       var(--dur-fast) var(--ease-out),
		transform        var(--dur-fast) var(--ease-out);
	user-select: none;
	white-space: nowrap;
	text-decoration: none;
	position: relative;
}
.x-btn:focus-visible {
	outline: none;
	box-shadow: var(--shadow-focus);
}
.x-btn:active:not([disabled]) {
	transform: translateY(0.5px);
}
.x-btn[disabled],
.x-btn[aria-disabled="true"] {
	opacity: 0.5;
	cursor: not-allowed;
	pointer-events: none;
}

/* sizes */
.x-btn--sm { height: 28px; padding-inline: var(--space-3); font-size: var(--text-xs); }
.x-btn--md { height: 34px; padding-inline: var(--space-4); }
.x-btn--lg { height: 42px; padding-inline: var(--space-5); font-size: var(--text-base); }

.x-btn--icon-only { padding-inline: 0; aspect-ratio: 1; }

/* variants */
.x-btn--primary {
	background: var(--accent);
	color: var(--accent-fg);
	border-color: var(--accent);
}
.x-btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.x-btn--primary:active { background: var(--accent-pressed); }

.x-btn--secondary {
	background: var(--bg);
	color: var(--text);
	border-color: var(--border-strong);
}
.x-btn--secondary:hover { background: var(--surface); border-color: var(--text-secondary); }

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

.x-btn--danger {
	background: var(--danger);
	color: white;
	border-color: var(--danger);
}
.x-btn--danger:hover { filter: brightness(1.05); }

/* loading state */
.x-btn--loading .x-btn__label { opacity: 0.7; }
.x-btn__spinner {
	animation: x-spin 0.7s linear infinite;
}
@keyframes x-spin { to { transform: rotate(360deg); } }

.x-btn__icon {
	flex-shrink: 0;
	width: 14px;
	height: 14px;
}
.x-btn--lg .x-btn__icon { width: 16px; height: 16px; }


/* ============================================================
 * CARD
 * ============================================================ */
.x-card {
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	padding: var(--space-4);
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
	color: inherit;
	text-decoration: none;
}
.x-card--linkable {
	cursor: pointer;
	transition: border-color var(--dur-fast), transform var(--dur-fast), box-shadow var(--dur-fast);
}
.x-card--linkable:hover {
	border-color: var(--border-strong);
	transform: translateY(-1px);
	box-shadow: var(--shadow-sm);
	text-decoration: none;
}

.x-card__icon {
	width: 32px;
	height: 32px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: var(--radius-sm);
	background: var(--accent-soft);
	color: var(--accent);
	margin-bottom: var(--space-2);
}

.x-card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.x-card__title { font-size: var(--text-md); font-weight: 600; letter-spacing: -0.005em; }
.x-card__actions { display: inline-flex; gap: var(--space-2); }
.x-card__subtitle { color: var(--text-secondary); font-size: var(--text-sm); }
.x-card__body { color: var(--text); }
.x-card__foot { padding-top: var(--space-3); border-top: 1px solid var(--border); margin-top: auto; }

.x-card--subtle {
	background: var(--surface);
	border-color: transparent;
}


/* ============================================================
 * FIELD / INPUT / TEXTAREA
 * ============================================================ */
.x-field { display: flex; flex-direction: column; gap: var(--space-2); }

.x-field__label {
	font-size: var(--text-sm);
	font-weight: 500;
	color: var(--text);
}
.x-field__req { color: var(--danger); margin-inline-start: 2px; }

.x-field__control { position: relative; display: flex; align-items: stretch; }
.x-field__icon {
	position: absolute;
	inset-inline-start: 12px;
	top: 50%;
	transform: translateY(-50%);
	color: var(--text-muted);
	pointer-events: none;
	display: inline-flex;
}
.x-field--icon .x-input { padding-inline-start: 36px; }

.x-input {
	width: 100%;
	height: 36px;
	padding-inline: var(--space-3);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	background: var(--bg);
	color: var(--text);
	font-size: var(--text-sm);
	transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.x-input:hover { border-color: var(--border-strong); }
.x-input:focus {
	outline: none;
	border-color: var(--accent);
	box-shadow: var(--shadow-focus);
}
.x-input::placeholder { color: var(--text-muted); }
.x-input[disabled] { opacity: 0.6; cursor: not-allowed; }

textarea.x-input {
	height: auto;
	min-height: 80px;
	padding-block: var(--space-3);
	resize: vertical;
	line-height: var(--leading-normal);
}

.x-field__help  { font-size: var(--text-xs); color: var(--text-muted); }
.x-field__error { font-size: var(--text-xs); color: var(--danger); }
.x-field--error .x-input { border-color: var(--danger); }
.x-field--error .x-input:focus { box-shadow: 0 0 0 3px var(--danger-soft); }


/* ============================================================
 * BADGE
 * ============================================================ */
.x-badge {
	display: inline-flex;
	align-items: center;
	gap: var(--space-1);
	font-size: var(--text-xs);
	font-weight: 500;
	padding: 2px var(--space-2);
	border-radius: var(--radius-full);
	border: 1px solid transparent;
	line-height: 1.4;
}
.x-badge__dot {
	width: 6px; height: 6px;
	border-radius: 50%;
	background: currentColor;
}
.x-badge--neutral { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }
.x-badge--success { background: var(--success-soft); color: var(--success); }
.x-badge--warning { background: var(--warning-soft); color: var(--warning); }
.x-badge--danger  { background: var(--danger-soft);  color: var(--danger); }
.x-badge--info    { background: var(--info-soft);    color: var(--info); }
.x-badge--accent  { background: var(--accent-soft);  color: var(--accent-hover); }


/* ============================================================
 * TABLE
 * ============================================================ */
.x-table {
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	overflow: hidden;
}
.x-table__head,
.x-table__row {
	display: grid;
	gap: var(--space-3);
	padding: var(--space-3) var(--space-4);
	border-bottom: 1px solid var(--border);
	align-items: center;
	font-size: var(--text-sm);
}
.x-table__row:last-child { border-bottom: 0; }
.x-table__head {
	background: var(--surface-2);
	color: var(--text-muted);
	font-size: var(--text-xs);
	text-transform: uppercase;
	letter-spacing: 0.04em;
	font-weight: 600;
	padding-block: var(--space-2);
}
.x-table__row:hover { background: var(--surface); }
.x-table__cell { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }


/* ============================================================
 * EMPTY STATE
 * ============================================================ */
.x-empty {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: var(--space-12) var(--space-6);
	text-align: center;
	gap: var(--space-2);
	background: var(--bg);
	border: 1px dashed var(--border-strong);
	border-radius: var(--radius-md);
}
.x-empty__icon {
	width: 48px; height: 48px;
	display: inline-flex;
	align-items: center; justify-content: center;
	border-radius: 50%;
	background: var(--surface-2);
	color: var(--text-muted);
	margin-bottom: var(--space-2);
}
.x-empty__title { font-weight: 600; font-size: var(--text-md); }
.x-empty__body  { color: var(--text-secondary); max-width: 340px; }
.x-empty__action { margin-top: var(--space-3); }


/* ============================================================
 * MODAL
 * ============================================================ */
.x-modal[hidden] { display: none; }
.x-modal {
	position: fixed;
	inset: 0;
	z-index: var(--z-modal);
	display: flex;
	align-items: center;
	justify-content: center;
	padding: var(--space-4);
	animation: x-fade-in var(--dur-base) var(--ease-out);
}
.x-modal__backdrop {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.5);
	z-index: var(--z-modal-bg);
}
.x-modal__panel {
	position: relative;
	z-index: var(--z-modal);
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	box-shadow: var(--shadow-xl);
	width: 100%;
	max-height: 90vh;
	display: flex;
	flex-direction: column;
	animation: x-pop-in var(--dur-base) var(--ease-out);
}
.x-modal--sm .x-modal__panel { max-width: 420px; }
.x-modal--md .x-modal__panel { max-width: 600px; }
.x-modal--lg .x-modal__panel { max-width: 880px; }

.x-modal__head {
	display: flex; align-items: center; justify-content: space-between;
	padding: var(--space-4) var(--space-5);
	border-bottom: 1px solid var(--border);
}
.x-modal__title { font-size: var(--text-md); font-weight: 600; }
.x-modal__close {
	background: transparent; border: 0;
	width: 28px; height: 28px;
	border-radius: var(--radius-sm);
	color: var(--text-muted);
	cursor: pointer;
	display: inline-flex; align-items: center; justify-content: center;
}
.x-modal__close:hover { color: var(--text); background: var(--surface); }

.x-modal__body { padding: var(--space-5); overflow: auto; flex: 1; }
.x-modal__foot {
	padding: var(--space-3) var(--space-5);
	border-top: 1px solid var(--border);
	display: flex; gap: var(--space-2); justify-content: flex-end;
}

@keyframes x-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes x-pop-in  {
	from { opacity: 0; transform: translateY(8px) scale(0.98); }
	to   { opacity: 1; transform: translateY(0)    scale(1); }
}


/* ============================================================
 * TOAST
 * ============================================================ */
.x-toast-host {
	position: fixed;
	bottom: var(--space-6);
	inset-inline: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: var(--space-2);
	pointer-events: none;
	z-index: var(--z-toast);
}
.x-toast {
	pointer-events: auto;
	background: var(--text);
	color: var(--bg);
	padding: var(--space-2) var(--space-4);
	border-radius: var(--radius-md);
	font-size: var(--text-sm);
	font-weight: 500;
	box-shadow: var(--shadow-lg);
	display: inline-flex;
	align-items: center;
	gap: var(--space-2);
	animation: x-toast-in var(--dur-base) var(--ease-out);
}
.x-toast--success { background: var(--success); color: white; }
.x-toast--danger  { background: var(--danger);  color: white; }
.x-toast--info    { background: var(--info);    color: white; }
@keyframes x-toast-in {
	from { opacity: 0; transform: translateY(20px); }
	to   { opacity: 1; transform: translateY(0); }
}


/* ============================================================
 * SECTION
 * ============================================================ */
.x-section { display: flex; flex-direction: column; gap: var(--space-4); }
.x-section__head {
	display: flex; align-items: flex-end; justify-content: space-between;
	gap: var(--space-4);
}
.x-section__title { font-size: var(--text-xl); font-weight: 600; letter-spacing: -0.01em; }
.x-section__subtitle { color: var(--text-secondary); font-size: var(--text-sm); margin-top: 2px; }
.x-section__actions { display: inline-flex; gap: var(--space-2); }


/* ============================================================
 * CREDITS WIDGET (bot dashboard)
 * ============================================================ */
.credit-widget {
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	padding: var(--space-5);
	display: flex;
	flex-direction: column;
	gap: var(--space-4);
}
.credit-widget.is-low { border-color: color-mix(in srgb, var(--warning) 50%, var(--border)); }
.credit-widget.is-empty { border-color: var(--danger); }

.credit-widget__head {
	display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4);
}
.credit-widget__balance {
	font-size: var(--text-3xl);
	font-weight: 700;
	letter-spacing: -0.02em;
	line-height: 1;
}
.credit-widget__label {
	font-size: var(--text-sm);
	color: var(--text-muted);
	margin-top: var(--space-1);
}
.credit-widget__label span { color: var(--text-secondary); }
.credit-widget__sub {
	font-size: var(--text-sm);
	color: var(--text-secondary);
}
.credit-widget__sub strong { color: var(--text); font-weight: 600; }

.credit-widget__breakdown {
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
}
.credit-widget__row {
	display: grid;
	grid-template-columns: 130px 1fr 60px;
	gap: var(--space-3);
	align-items: center;
	font-size: var(--text-sm);
}
.credit-widget__row-label {
	color: var(--text-secondary);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
.credit-widget__row-bar {
	height: 6px;
	background: var(--surface-2);
	border-radius: 999px;
	overflow: hidden;
}
.credit-widget__row-fill {
	height: 100%;
	background: var(--accent);
	border-radius: 999px;
	transition: width var(--dur-slow) var(--ease-out);
}
.credit-widget__row-total {
	text-align: end;
	color: var(--text);
	font-variant-numeric: tabular-nums;
	font-weight: 500;
}
.credit-widget__empty {
	color: var(--text-muted);
	font-size: var(--text-sm);
	padding: var(--space-3) 0;
}

/* ============================================================
 * TOGGLE switch
 * ============================================================ */
.x-toggle { position: relative; display: inline-flex; align-items: center; flex-shrink: 0; }
.x-toggle input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.x-toggle__track {
	width: 36px; height: 20px;
	background: var(--surface-3);
	border-radius: 999px;
	position: relative;
	transition: background var(--dur-fast);
}
.x-toggle__thumb {
	position: absolute;
	top: 2px;
	inset-inline-start: 2px;
	width: 16px; height: 16px;
	background: var(--bg);
	border-radius: 50%;
	box-shadow: var(--shadow-sm);
	transition: inset-inline-start var(--dur-fast) var(--ease-out);
}
.x-toggle input:checked ~ .x-toggle__track { background: var(--accent); }
.x-toggle input:checked ~ .x-toggle__track .x-toggle__thumb { inset-inline-start: 18px; }
.x-toggle input:focus-visible ~ .x-toggle__track { box-shadow: var(--shadow-focus); }

/* ============================================================
 * SETTINGS PRESET widget
 * ============================================================ */
.x-preset { display: flex; flex-direction: column; gap: var(--space-5); }
.x-preset__quickpicks { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.x-preset__pick {
	padding: 6px var(--space-3);
	border: 1px solid var(--border);
	border-radius: var(--radius-full);
	background: var(--bg);
	font-size: var(--text-sm);
	cursor: pointer;
	transition: all var(--dur-fast);
}
.x-preset__pick:hover { border-color: var(--border-strong); }
.x-preset__pick.is-active { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

.x-preset__group {
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	overflow: hidden;
}
.x-preset__group-title {
	padding: var(--space-3) var(--space-4);
	background: var(--surface-2);
	font-size: var(--text-xs);
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--text-muted);
	font-weight: 600;
	border-bottom: 1px solid var(--border);
}

.x-preset__row {
	display: flex; align-items: center; justify-content: space-between;
	gap: var(--space-4);
	padding: var(--space-3) var(--space-4);
	border-bottom: 1px solid var(--border);
	cursor: pointer;
	transition: background var(--dur-fast);
}
.x-preset__row:hover { background: var(--surface); }
.x-preset__row:last-child { border-bottom: 0; }
.x-preset__row[data-disabled="true"] { opacity: 0.5; pointer-events: none; }

.x-preset__row-text { flex: 1; min-width: 0; }
.x-preset__row-label {
	font-weight: 500;
	font-size: var(--text-sm);
	display: inline-flex;
	align-items: center;
	gap: var(--space-2);
}
.x-preset__row-help { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }
.x-preset__cost {
	font-family: var(--font-mono);
	font-size: 10.5px;
	background: var(--accent-soft);
	color: var(--accent-hover);
	padding: 1px 6px;
	border-radius: var(--radius-full);
}

.x-preset__savebar {
	position: sticky;
	bottom: 0;
	display: flex;
	align-items: center;
	gap: var(--space-3);
	padding: var(--space-3) 0;
	background: linear-gradient(to top, var(--surface) 80%, transparent);
}
.x-preset__savebar-status { color: var(--text-muted); font-size: var(--text-sm); flex: 1; }

/* ============================================================
 * UTILITY (small helpers — keep this list short)
 * ============================================================ */
.x-stack { display: flex; flex-direction: column; gap: var(--space-3); }
.x-row   { display: flex; gap: var(--space-3); align-items: center; }
.x-grow  { flex: 1; min-width: 0; }
.x-hr    { height: 1px; background: var(--border); margin-block: var(--space-4); border: 0; }

.x-text-muted { color: var(--text-muted); }
.x-text-sm    { font-size: var(--text-sm); }

.x-mono { font-family: var(--font-mono); }
