/* components.css — Buttons, forms, tables, badges, cards, modals, toasts */

/* ═══════════════════════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════════════════════ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 18px;
    font-size: 0.85rem;
    font-weight: 500;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
    line-height: 1.4;
    white-space: nowrap;
    user-select: none;
}

.btn:focus-visible {
    box-shadow: var(--focus-ring);
}

.btn-primary {
    background: var(--accent-gradient);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 1px 3px rgba(37, 99, 235, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(37, 99, 235, 0.3);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border);
}

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

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}

.btn-ghost:hover {
    background: var(--accent-light);
    color: var(--accent);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    box-shadow: 0 1px 3px rgba(220, 38, 38, 0.25);
}

.btn-danger:hover {
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
    transform: translateY(-1px);
}

.btn-danger:focus-visible {
    box-shadow: var(--focus-ring-danger);
}

.btn-success {
    background: var(--success);
    color: #fff;
    box-shadow: 0 1px 3px rgba(5, 150, 105, 0.25);
}

.btn-success:hover {
    box-shadow: 0 4px 12px rgba(5, 150, 105, 0.3);
    transform: translateY(-1px);
}

.btn-sm {
    padding: 5px 12px;
    font-size: 0.78rem;
    border-radius: var(--radius-sm);
}

.btn-lg {
    padding: 12px 24px;
    font-size: 0.95rem;
}

.btn-icon {
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: var(--radius);
}

.btn:disabled, .btn[aria-disabled="true"] {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

/* Button group */
.btn-group {
    display: inline-flex;
    gap: 0;
}

.btn-group .btn {
    border-radius: 0;
}

.btn-group .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.btn-group .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }

/* ═══════════════════════════════════════════════════════════════
   FORMS
   ═══════════════════════════════════════════════════════════════ */
.form-field {
    margin-bottom: 20px;
}

.form-field label {
    display: block;
    font-size: 0.82rem;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-primary);
    letter-spacing: 0.01em;
}

.form-field .required { color: var(--danger); }

.form-field input,
.form-field select,
.form-field textarea {
    width: 100%;
    padding: 9px 14px;
    font-size: 0.875rem;
    font-family: inherit;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-field input::placeholder,
.form-field textarea::placeholder {
    color: var(--text-muted);
}

.form-field input:hover,
.form-field select:hover,
.form-field textarea:hover {
    border-color: var(--border-strong);
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.form-field input[aria-invalid="true"],
.form-field.has-error input {
    border-color: var(--danger);
}

.form-field input[aria-invalid="true"]:focus,
.form-field.has-error input:focus {
    box-shadow: 0 0 0 3px var(--danger-bg);
}

.field-error {
    font-size: 0.78rem;
    color: var(--danger);
    min-height: 1.3em;
    margin-top: 4px;
}

.field-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ═══════════════════════════════════════════════════════════════
   TABLES
   ═══════════════════════════════════════════════════════════════ */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.data-table th {
    text-align: left;
    padding: 10px 14px;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

.data-table td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--border-light);
    transition: background var(--transition);
}

.data-table tbody tr:hover td {
    background: var(--accent-light);
}

.data-table tbody tr:active td {
    background: var(--accent-medium);
}

.empty-row {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 14px !important;
    font-style: italic;
}

/* Sortable column headers */
.data-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.data-table th.sortable:hover {
    color: var(--text-primary);
}

/* ═══════════════════════════════════════════════════════════════
   BADGES
   ═══════════════════════════════════════════════════════════════ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    font-size: 0.72rem;
    font-weight: 600;
    border-radius: var(--radius-full);
    letter-spacing: 0.02em;
    white-space: nowrap;
    line-height: 1.6;
}

.badge-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid var(--success-border);
}

.badge-warning {
    background: var(--warning-bg);
    color: var(--warning);
    border: 1px solid var(--warning-border);
}

.badge-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid var(--danger-border);
}

.badge-info {
    background: var(--info-bg);
    color: var(--info);
    border: 1px solid var(--info-border);
}

.badge-neutral {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.badge-accent {
    background: var(--accent-light);
    color: var(--accent);
    border: 1px solid var(--accent-glow);
}

/* Pulsing badge for live status */
.badge-live::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    margin-right: 6px;
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ═══════════════════════════════════════════════════════════════
   METRIC CARDS
   ═══════════════════════════════════════════════════════════════ */
.metric-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow-card);
    transition: all var(--transition-slow);
    position: relative;
    overflow: hidden;
}

.metric-card:hover {
    box-shadow: var(--shadow-card-hover);
    transform: translateY(-1px);
}

/* Subtle top accent line */
.metric-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent-gradient);
    opacity: 0;
    transition: opacity var(--transition);
}

.metric-card:hover::before { opacity: 1; }

.metric-title {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 600;
}

.metric-value {
    font-size: 1.85rem;
    font-weight: 700;
    margin: 6px 0 2px;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.metric-subtitle {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.metric-trend {
    font-size: 0.78rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.trend-up { color: var(--success); }
.trend-down { color: var(--danger); }
.trend-stable { color: var(--text-muted); }

/* ═══════════════════════════════════════════════════════════════
   TOAST NOTIFICATIONS
   ═══════════════════════════════════════════════════════════════ */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 420px;
}

.toast {
    padding: 14px 18px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.35s var(--transition-spring);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    align-items: flex-start;
    gap: 10px;
    line-height: 1.45;
}

.toast-info {
    background: var(--info-bg);
    color: var(--info);
    border: 1px solid var(--info-border);
}

.toast-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid var(--success-border);
}

.toast-warning {
    background: var(--warning-bg);
    color: var(--warning);
    border: 1px solid var(--warning-border);
}

.toast-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid var(--danger-border);
}

.toast-close {
    background: none;
    border: none;
    color: inherit;
    opacity: 0.5;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0;
    margin-left: auto;
    flex-shrink: 0;
    transition: opacity var(--transition);
}

.toast-close:hover { opacity: 1; }

@keyframes toastIn {
    from { transform: translateX(120%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.toast-exit {
    animation: toastOut 0.25s ease forwards;
}

@keyframes toastOut {
    to { transform: translateX(120%); opacity: 0; }
}

/* ═══════════════════════════════════════════════════════════════
   MODAL
   ═══════════════════════════════════════════════════════════════ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 900;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    max-width: 520px;
    width: 90%;
    box-shadow: var(--shadow-xl);
    animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}

.modal-wide { max-width: 600px; }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1.05rem;
    font-weight: 600;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    line-height: 1;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ═══════════════════════════════════════════════════════════════
   PAGINATION
   ═══════════════════════════════════════════════════════════════ */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 20px;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.pagination-info {
    font-variant-numeric: tabular-nums;
}

.pagination-buttons {
    display: flex;
    gap: 4px;
}

.pagination-buttons .btn {
    min-width: 34px;
    padding: 6px 10px;
}

.pagination-buttons .btn.active {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
}

/* ═══════════════════════════════════════════════════════════════
   DROPDOWN
   ═══════════════════════════════════════════════════════════════ */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 180px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 4px;
    z-index: 100;
    animation: dropdownIn 0.15s ease;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    font-size: 0.85rem;
    color: var(--text-primary);
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    text-align: left;
    transition: background var(--transition);
}

.dropdown-item:hover {
    background: var(--accent-light);
    color: var(--accent);
}

.dropdown-item-danger:hover {
    background: var(--danger-bg);
    color: var(--danger);
}

.dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

@keyframes dropdownIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════════════════
   TOOLTIP
   ═══════════════════════════════════════════════════════════════ */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    padding: 5px 10px;
    font-size: 0.75rem;
    font-weight: 500;
    color: #fff;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
    z-index: 50;
}

[data-tooltip]:hover::after {
    opacity: 1;
}

/* ═══════════════════════════════════════════════════════════════
   AVATAR
   ═══════════════════════════════════════════════════════════════ */
.avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--accent-gradient);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
    text-transform: uppercase;
}

.avatar-sm { width: 24px; height: 24px; font-size: 0.65rem; }
.avatar-lg { width: 40px; height: 40px; font-size: 0.9rem; }

/* ═══════════════════════════════════════════════════════════════
   SWITCH / TOGGLE
   ═══════════════════════════════════════════════════════════════ */
.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
}

.switch input { opacity: 0; width: 0; height: 0; position: absolute; }

.switch-track {
    position: absolute;
    inset: 0;
    background: var(--bg-tertiary);
    border-radius: 11px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all var(--transition);
}

.switch-track::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition);
}

.switch input:checked + .switch-track {
    background: var(--accent);
    border-color: var(--accent);
}

.switch input:checked + .switch-track::before {
    transform: translateX(18px);
}

.switch input:focus-visible + .switch-track {
    box-shadow: var(--focus-ring);
}

/* ═══════════════════════════════════════════════════════════════
   STANDALONE INPUT/SELECT (outside .form-field context)
   ═══════════════════════════════════════════════════════════════ */
.input-standalone,
.select-standalone {
    padding: 8px 14px;
    font-size: 0.875rem;
    font-family: inherit;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.input-standalone:focus,
.select-standalone:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.input-standalone::placeholder {
    color: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════════════
   QR CODE IMAGE
   ═══════════════════════════════════════════════════════════════ */
.qr-image {
    display: block;
    margin: 0 auto 16px;
    max-width: 250px;
    border-radius: var(--radius);
}

/* ─── Config Management ─── */
.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-3, 1rem);
}
.config-card {
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.config-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg, 0 4px 12px rgba(0,0,0,0.15));
}
.config-category-title {
    font-size: var(--font-lg, 1.125rem);
    font-weight: 600;
    border-bottom: 2px solid var(--border-color, #e2e8f0);
    padding-bottom: var(--space-1, 0.25rem);
    margin-bottom: var(--space-2, 0.5rem);
}
.config-editor {
    width: 100%;
    font-family: var(--font-mono, 'Consolas', 'Monaco', monospace);
    font-size: 13px;
    line-height: 1.5;
    padding: var(--space-3, 1rem);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: var(--radius, 6px);
    background: var(--bg-surface, #fff);
    color: var(--text-primary, #1a1a2e);
    resize: vertical;
    tab-size: 2;
    white-space: pre;
    overflow-x: auto;
}
.config-editor:focus {
    outline: 2px solid var(--color-primary, #3b82f6);
    outline-offset: -1px;
}
.config-status-bar {
    font-size: var(--font-xs, 0.75rem);
    color: var(--text-muted, #64748b);
    padding: var(--space-1, 0.25rem) var(--space-2, 0.5rem);
    background: var(--bg-subtle, #f1f5f9);
    border-radius: 0 0 var(--radius, 6px) var(--radius, 6px);
    border: 1px solid var(--border-color, #e2e8f0);
    border-top: none;
}
