/* ==========================================================================
   Shared components: surfaces, buttons, forms, modal, toast, badges
   ========================================================================== */

/* ── Surfaces ─────────────────────────────────────────────────────────── */
.glass {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.035));
    border: 1px solid var(--line);
    box-shadow: var(--shadow-md);
}

.glass-strong {
    background: #0d1226;
    border: 1px solid var(--line-strong);
    box-shadow: var(--shadow-lg);
}

/* ── Buttons ──────────────────────────────────────────────────────────── */
.button {
    min-height: 44px;
    padding: 0 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: var(--radius-md);
    color: #fff;
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    transition: transform 0.18s var(--ease), filter 0.18s, background 0.18s, border-color 0.18s, opacity 0.18s;
}
.button:hover:not(:disabled) { filter: brightness(1.1); transform: translateY(-1px); }
.button:active:not(:disabled) { transform: translateY(1px); }
.button:disabled { opacity: 0.55; cursor: not-allowed; }

.button-primary {
    background: var(--brand-gradient);
    box-shadow: 0 10px 26px rgba(124, 58, 237, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.button-secondary {
    color: var(--text-soft);
    background: var(--surface-hover);
    border: 1px solid var(--line);
}
.button-secondary:hover:not(:disabled) { border-color: var(--line-strong); }
.button-danger {
    background: linear-gradient(115deg, #e11d48, #ef4444);
    box-shadow: 0 10px 26px rgba(239, 68, 68, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.16);
}
.button-block { width: 100%; }

.button .spinner { width: 16px; height: 16px; }

.icon-button {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: var(--radius-sm);
    color: var(--muted);
    background: var(--surface-hover);
    border: 1px solid transparent;
    transition: color 0.18s, background 0.18s, border-color 0.18s;
}
.icon-button:hover { color: #fff; background: rgba(139, 92, 246, 0.55); }
.icon-button.is-danger:hover { background: rgba(239, 68, 68, 0.75); }
.icon-button .icon { width: 17px; height: 17px; }

.spinner {
    display: inline-block;
    border: 2px solid rgba(255, 255, 255, 0.28);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* ── Forms ────────────────────────────────────────────────────────────── */
.form-field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.form-field.full-width { grid-column: 1 / -1; }

.form-field > label,
.form-label {
    color: var(--text-soft);
    font-size: 0.82rem;
    font-weight: 500;
}
.form-field .optional { color: var(--faint); font-weight: 400; margin-inline-start: 4px; }

.form-field input:not([type="radio"]),
.form-field textarea {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-md);
    outline: 0;
    background: rgba(7, 10, 20, 0.6);
    transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
}
.form-field input:disabled { color: var(--muted); background: var(--surface); cursor: not-allowed; }
.form-field select {
    width: 100%;
    padding: 11px 14px;
    padding-left: 38px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-md);
    outline: 0;
    color: var(--text);
    background: rgba(7, 10, 20, 0.6) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat 12px center / 16px;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    transition: border-color 0.18s, box-shadow 0.18s;
}
.form-field select:focus { border-color: var(--brand); box-shadow: var(--focus-ring); }
.form-field select option { color: #fff; background: #0d1226; }
.form-field input::placeholder,
.form-field textarea::placeholder { color: var(--faint); }
.form-field textarea { resize: vertical; min-height: 84px; line-height: 1.7; }

.form-field input:not([type="radio"]):focus,
.form-field textarea:focus {
    border-color: var(--brand);
    box-shadow: var(--focus-ring);
    background: rgba(7, 10, 20, 0.85);
}
.form-field.has-error input:not([type="radio"]),
.form-field.has-error textarea { border-color: var(--danger); }
.form-field.has-error input:not([type="radio"]):focus,
.form-field.has-error textarea:focus { box-shadow: 0 0 0 3px rgba(251, 113, 133, 0.25); }

.field-hint { color: var(--faint); font-size: 0.74rem; line-height: 1.6; }
.field-error { display: none; color: var(--danger); font-size: 0.76rem; line-height: 1.6; }
.form-field.has-error .field-error { display: block; }

.password-input { position: relative; display: flex; align-items: center; }
/* the input is always dir="ltr", so the toggle sits on its physical right edge */
.password-input input { padding-right: 46px !important; }
.password-toggle {
    position: absolute;
    right: 6px;
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    color: var(--faint);
    transition: color 0.18s, background 0.18s;
}
.password-toggle:hover { color: var(--brand-soft); background: var(--surface-hover); }

/* ── Badges ───────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 9px;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 500;
    line-height: 1.7;
    white-space: nowrap;
}
.badge .icon { width: 12px; height: 12px; }
.badge-resalat { color: var(--ok); background: var(--ok-bg); border-color: rgba(16, 185, 129, 0.28); }
.badge-redbank { color: var(--warn); background: var(--warn-bg); border-color: rgba(245, 158, 11, 0.28); }
.badge-live    { color: var(--ok); background: var(--ok-bg); border-color: rgba(16, 185, 129, 0.28); }
.badge-none    { color: var(--danger); background: var(--danger-bg); border-color: rgba(251, 113, 133, 0.28); }
.badge-idle    { color: var(--muted); background: var(--surface-hover); border-color: var(--line); }

.dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: currentColor;
}

/* ── Modal ────────────────────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    justify-content: center;
    overflow-y: auto;
    padding: 40px 16px;
    opacity: 0;
    visibility: hidden;
    background: rgba(3, 5, 12, 0.78);
    transition: opacity 0.22s, visibility 0.22s;
}
.modal-backdrop.is-open { opacity: 1; visibility: visible; }

.modal {
    width: min(100%, 720px);
    margin: auto;
    border-radius: var(--radius-xl);
    transform: translateY(16px) scale(0.98);
    transition: transform 0.28s var(--ease);
}
.modal-backdrop.is-open .modal { transform: none; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 20px 24px;
    border-bottom: 1px solid var(--line);
}
.modal-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.modal-title h2 { margin: 0; font-size: 1.15rem; font-weight: 700; }
.modal-title small { display: block; color: var(--muted); font-size: 0.76rem; font-weight: 400; }
.modal-title-icon {
    width: 40px; height: 40px;
    display: grid; place-items: center;
    flex: 0 0 auto;
    border-radius: 12px;
    color: var(--brand-soft);
    background: rgba(139, 92, 246, 0.16);
}

.modal-actions { display: flex; gap: 10px; }
.modal-actions .button { flex: 1; }

/* ── Toasts ───────────────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    inset-block-start: 18px;
    inset-inline-start: 18px;
    z-index: 80;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}
.toast {
    min-width: 280px;
    max-width: min(400px, calc(100vw - 36px));
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-md);
    background: rgba(13, 18, 38, 0.95);
    box-shadow: var(--shadow-md);
    pointer-events: auto;
    animation: toast-in 0.3s var(--ease) both;
}
.toast.is-leaving { animation: toast-out 0.22s ease both; }
.toast-icon {
    width: 28px; height: 28px;
    display: grid; place-items: center;
    flex: 0 0 auto;
    border-radius: 50%;
}
.toast-icon .icon { width: 15px; height: 15px; }
.toast.success .toast-icon { color: var(--ok); background: var(--ok-bg); }
.toast.error .toast-icon { color: var(--danger); background: var(--danger-bg); }
.toast.info .toast-icon { color: var(--info); background: var(--info-bg); }
.toast-message { color: var(--text); font-size: 0.84rem; line-height: 1.6; }

/* ── Animations ───────────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-6px) scale(0.97); } }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 620px) {
    .toast-container { inset-inline: 12px; }
    .toast { min-width: 0; max-width: none; }
    /* bottom sheet: auto top margin pushes short modals down, tall ones just scroll from the top */
    .modal-backdrop { padding: 0; flex-direction: column; justify-content: flex-start; align-items: stretch; }
    .modal { width: 100%; margin: auto 0 0; border-radius: var(--radius-xl) var(--radius-xl) 0 0; }
}
