/* components.css — reusable UI components for the admin dashboard. */

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    height: 38px;
    padding: 0 var(--sp-4);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    background: var(--surface-1);
    color: var(--text);
    font: inherit;
    font-weight: var(--fw-medium);
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn svg { width: 16px; height: 16px; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:active { background: var(--accent-active); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.06); background: var(--danger); }

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

.btn-sm { height: 30px; padding: 0 var(--sp-3); font-size: var(--fs-sm); }
.btn-icon { width: 38px; padding: 0; }
.btn-icon.btn-sm { width: 30px; }
.btn-block { width: 100%; }

/* ── Nav items (sidebar) ─────────────────────────────────── */
.nav-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3);
    border-radius: var(--r-md);
    color: var(--text-muted);
    font-weight: var(--fw-medium);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-size: var(--fs-base);
    transition: background var(--t-fast), color var(--t-fast);
}
.nav-item:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: var(--fw-semibold); }
.nav-item svg { width: 18px; height: 18px; flex: none; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
}
.card__head { padding: var(--sp-5) var(--sp-5) 0; }
.card__title { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.card__desc { color: var(--text-muted); font-size: var(--fs-sm); margin-top: var(--sp-1); }
.card__body { padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-4); }
.card__foot { padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); display: flex; gap: var(--sp-3); justify-content: flex-end; }

/* ── Form fields ─────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: var(--sp-2); }
.field > label { font-weight: var(--fw-medium); font-size: var(--fs-sm); }
.field .hint { color: var(--text-subtle); font-size: var(--fs-xs); }

.input, .select, .textarea {
    width: 100%;
    height: 38px;
    padding: 0 var(--sp-3);
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    color: var(--text);
    font: inherit;
    font-size: var(--fs-base);
    transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
.textarea { height: auto; min-height: 84px; padding: var(--sp-3); resize: vertical; line-height: var(--lh-base); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); background: var(--surface-1); }
.input::placeholder, .textarea::placeholder { color: var(--text-subtle); }
.input:disabled, .select:disabled { opacity: 0.6; cursor: not-allowed; }
.select { appearance: none; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238a94a3' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right var(--sp-3) center; padding-right: var(--sp-7);
}

/* Toggle switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: var(--sp-3); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 42px; height: 24px; border-radius: var(--r-full); background: var(--border-strong); transition: background var(--t-fast); flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform var(--t-fast); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { box-shadow: var(--focus-ring); }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px var(--sp-2);
    border-radius: var(--r-full);
    font-size: var(--fs-xs); font-weight: var(--fw-semibold);
    background: var(--surface-3); color: var(--text-muted);
    line-height: 1.4;
}
.badge--success { background: var(--success-soft); color: var(--success); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--danger  { background: var(--danger-soft);  color: var(--danger); }
.badge--info    { background: var(--info-soft);    color: var(--info); }
.badge--accent  { background: var(--accent-soft);  color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* ── Tables ──────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface-1); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
.table th, .table td { padding: var(--sp-3) var(--sp-4); text-align: left; border-bottom: 1px solid var(--border); }
.table th { font-weight: var(--fw-semibold); font-size: var(--fs-sm); color: var(--text-muted); background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text); }

/* ── Tabs (settings, segmented) ──────────────────────────── */
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--border); margin-bottom: var(--sp-5); overflow-x: auto; }
.tab { padding: var(--sp-3) var(--sp-4); border: none; background: none; color: var(--text-muted); font: inherit; font-weight: var(--fw-medium); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; transition: color var(--t-fast), border-color var(--t-fast); }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: flex; flex-direction: column; gap: var(--sp-5); animation: fade-in var(--t-base); }

/* ── Progress ────────────────────────────────────────────── */
.progress { width: 100%; height: 8px; background: var(--surface-3); border-radius: var(--r-full); overflow: hidden; }
.progress__bar { height: 100%; width: 0; background: var(--accent); border-radius: var(--r-full); transition: width var(--t-base); }
.progress__bar.indeterminate { width: 35% !important; animation: indet 1.2s ease-in-out infinite; }

/* ── Spinner ─────────────────────────────────────────────── */
.spinner { width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; flex: none; }
.loading { display: flex; align-items: center; gap: var(--sp-3); color: var(--text-muted); padding: var(--sp-5); justify-content: center; }
.empty { text-align: center; color: var(--text-subtle); padding: var(--sp-7) var(--sp-4); }

/* ── Inline status message ───────────────────────────────── */
.status-msg { font-size: var(--fs-sm); padding: var(--sp-2) var(--sp-3); border-radius: var(--r-sm); display: none; }
.status-msg.show { display: block; }
.status-msg.info { background: var(--info-soft); color: var(--info); }
.status-msg.success { background: var(--success-soft); color: var(--success); }
.status-msg.error { background: var(--danger-soft); color: var(--danger); }
.status-msg.warn { background: var(--warning-soft); color: var(--warning); }

/* ── Toasts ──────────────────────────────────────────────── */
.toast-host { position: fixed; top: var(--sp-5); right: var(--sp-5); z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--sp-2); max-width: min(380px, calc(100vw - 2rem)); }
.toast {
    display: flex; align-items: flex-start; gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    background: var(--surface-1); border: 1px solid var(--border);
    border-left: 3px solid var(--text-subtle);
    border-radius: var(--r-md); box-shadow: var(--shadow-lg);
    animation: toast-in var(--t-base);
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warning); }
.toast.info { border-left-color: var(--info); }
.toast.leaving { animation: toast-out var(--t-base) forwards; }
.toast__msg { font-size: var(--fs-base); }

/* ── Modal ───────────────────────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; z-index: var(--z-modal); background: rgba(16,24,40,0.55); display: grid; place-items: center; padding: var(--sp-5); animation: fade-in var(--t-fast); }
.modal { width: 100%; max-width: 460px; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); animation: pop-in var(--t-base); }
.modal__head { padding: var(--sp-5) var(--sp-5) 0; font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.modal__body { padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-4); }
.modal__foot { padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); display: flex; gap: var(--sp-3); justify-content: flex-end; }

/* Icon-only theme/menu buttons */
.icon-btn { display: grid; place-items: center; width: 38px; height: 38px; border-radius: var(--r-md); border: 1px solid transparent; background: none; color: var(--text-muted); cursor: pointer; transition: background var(--t-fast), color var(--t-fast); }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

/* ── Animations ──────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }
@keyframes indet { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }
