/* ============================================================================
   COMPONENTS — Buttons, Cards, Badges, Tables, Forms, Modals, Toasts
   ============================================================================ */

/* === BUTTONS === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 0 var(--space-4);
    height: 36px;
    font-family: var(--font-sans);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background-color var(--duration-fast), border-color var(--duration-fast),
                color var(--duration-fast), box-shadow var(--duration-fast),
                transform var(--duration-fast);
    white-space: nowrap;
    text-decoration: none;
    outline: none;
    user-select: none;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-sm { height: 30px; padding: 0 var(--space-3); font-size: var(--font-size-xs); border-radius: var(--radius-sm); }
.btn-lg { height: 44px; padding: 0 var(--space-6); font-size: var(--font-size-md); }
.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 30px; }

.btn-primary {
    background-color: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
    box-shadow: 0 1px 2px rgba(79,70,229,0.2);
}
.btn-primary:hover {
    background-color: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
    box-shadow: 0 2px 6px rgba(79,70,229,0.35);
}

.btn-secondary {
    background-color: var(--bg-surface);
    color: var(--text-primary);
    border-color: var(--border-default);
    box-shadow: var(--shadow-xs);
}
.btn-secondary:hover {
    background-color: var(--bg-sunken);
    border-color: var(--border-strong);
}

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

.btn-danger {
    background-color: var(--color-danger);
    color: white;
    border-color: var(--color-danger);
}
.btn-danger:hover { background-color: #dc2626; border-color: #dc2626; }

.btn-success {
    background-color: var(--color-success);
    color: white;
    border-color: var(--color-success);
}
.btn-success:hover { background-color: #059669; }

.btn-outline {
    background-color: transparent;
    color: var(--color-primary);
    border-color: var(--color-primary);
}
.btn-outline:hover { background-color: var(--color-primary-light); }

.btn-warning {
    background-color: var(--color-warning);
    color: white;
    border-color: var(--color-warning);
}
.btn-warning:hover { background-color: var(--color-warning-hover, #d97706); border-color: var(--color-warning-hover, #d97706); }

/* Extra small button */
.btn-xs {
    height: 26px;
    padding: 0 var(--space-2);
    font-size: var(--font-size-xs);
    border-radius: var(--radius-sm);
    gap: var(--space-1);
}

/* Text color modifiers on buttons */
.btn.text-danger  { color: var(--color-danger) !important; }
.btn.text-success { color: var(--color-success) !important; }

/* Lock / Unlock semantic */
.btn-lock   { background-color: #f97316; color: white; border-color: #ea580c; }
.btn-lock:hover   { background-color: #ea580c; border-color: #c2410c; }
.btn-unlock { background-color: var(--color-success); color: white; border-color: var(--color-success); }
.btn-unlock:hover { background-color: #059669; }

/* === CARDS === */
.card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    box-shadow: var(--shadow-card);
    transition: box-shadow var(--duration-base), border-color var(--duration-base);
}

.card:hover { box-shadow: var(--shadow-md); }

.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: var(--space-5);
    gap: var(--space-4);
}

.card-header-left { flex: 1; min-width: 0; }
.card-title { font-size: var(--font-size-md); font-weight: var(--font-weight-semibold); color: var(--text-primary); line-height: 1.3; }
.card-subtitle { font-size: var(--font-size-sm); color: var(--text-secondary); margin-top: 3px; }
.card-divider { height: 1px; background-color: var(--border-subtle); margin: var(--space-5) 0; }

/* === KPI CARDS === */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--space-4);
}

.kpi-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: var(--space-5);
    box-shadow: var(--shadow-card);
    transition: box-shadow var(--duration-base), border-color var(--duration-base), transform var(--duration-base);
    position: relative;
    overflow: hidden;
    cursor: default;
}

.kpi-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px);
    border-color: var(--border-default);
}

.kpi-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: var(--space-4);
}

.kpi-icon-wrap {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.kpi-icon-wrap.indigo  { background-color: var(--brand-50); color: var(--brand-600); }
.kpi-icon-wrap.green   { background-color: var(--color-success-bg); color: var(--color-success); }
.kpi-icon-wrap.amber   { background-color: var(--color-warning-bg); color: var(--color-warning); }
.kpi-icon-wrap.red     { background-color: var(--color-danger-bg); color: var(--color-danger); }
.kpi-icon-wrap.purple  { background-color: var(--color-purple-bg); color: var(--color-purple); }
.kpi-icon-wrap.blue    { background-color: var(--color-info-bg); color: var(--color-info); }
.kpi-icon-wrap.gray    { background-color: var(--bg-sunken); color: var(--text-secondary); }
.kpi-icon-wrap.orange  { background-color: rgba(249,115,22,0.12); color: #f97316; }
.kpi-icon-wrap.teal    { background-color: rgba(20,184,166,0.12); color: #14b8a6; }

:root.dark-mode .kpi-icon-wrap.indigo  { background-color: rgba(99,102,241,0.12);   color: var(--brand-400); }
:root.dark-mode .kpi-icon-wrap.green   { background-color: var(--color-success-bg); color: var(--color-success); }
:root.dark-mode .kpi-icon-wrap.amber   { background-color: var(--color-warning-bg); color: var(--color-warning); }
:root.dark-mode .kpi-icon-wrap.red     { background-color: var(--color-danger-bg);  color: var(--color-danger); }
:root.dark-mode .kpi-icon-wrap.purple  { background-color: var(--color-purple-bg);  color: var(--color-purple); }
:root.dark-mode .kpi-icon-wrap.blue    { background-color: var(--color-info-bg);    color: var(--color-info); }
:root.dark-mode .kpi-icon-wrap.gray    { background-color: rgba(255,255,255,0.06);  color: var(--text-tertiary); }
:root.dark-mode .kpi-icon-wrap.orange  { background-color: rgba(249,115,22,0.15);   color: #fb923c; }
:root.dark-mode .kpi-icon-wrap.teal    { background-color: rgba(20,184,166,0.15);   color: #2dd4bf; }

.kpi-trend-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 11px;
    font-weight: var(--font-weight-semibold);
    padding: 3px 7px;
    border-radius: var(--radius-full);
}

.kpi-trend-badge.up   { background-color: var(--color-success-bg); color: var(--color-success-text); }
.kpi-trend-badge.down { background-color: var(--color-danger-bg);  color: var(--color-danger-text); }
.kpi-trend-badge.flat { background-color: var(--bg-sunken);        color: var(--text-secondary); }

.kpi-label { font-size: var(--font-size-xs); font-weight: var(--font-weight-semibold); color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: var(--space-1); }
.kpi-value { font-size: 1.75rem; font-weight: var(--font-weight-bold); color: var(--text-primary); letter-spacing: -0.03em; line-height: 1.1; }
.kpi-footer { font-size: var(--font-size-xs); color: var(--text-tertiary); margin-top: var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--border-subtle); }

/* Stats grid (analytics/monitoring) */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: var(--space-4);
}

.stat-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: var(--space-5);
    box-shadow: var(--shadow-card);
    transition: box-shadow var(--duration-base), transform var(--duration-base);
    text-align: center;
}

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

.stat-icon {
    width: 48px; height: 48px;
    border-radius: var(--radius-xl);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem;
    margin: 0 auto var(--space-3);
}

.stat-icon.purple { background-color: var(--color-purple-bg); }
.stat-icon.green  { background-color: var(--color-success-bg); }
.stat-icon.blue   { background-color: var(--color-info-bg); }
.stat-icon.amber  { background-color: var(--color-warning-bg); }
.stat-icon.red    { background-color: var(--color-danger-bg); }

.stat-value { font-size: var(--font-size-2xl); font-weight: var(--font-weight-bold); color: var(--text-primary); letter-spacing: -0.03em; }
.stat-label { font-size: var(--font-size-xs); color: var(--text-secondary); margin-top: var(--space-1); font-weight: var(--font-weight-medium); }

/* === BADGES === */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    white-space: nowrap;
    line-height: 1.5;
}

.badge-dot {
    width: 6px; height: 6px;
    border-radius: var(--radius-full);
    background-color: currentColor;
    flex-shrink: 0;
}

.badge.success, .badge.active, .badge.healthy {
    background-color: var(--color-success-bg);
    color: var(--color-success-text);
}
.badge.warning, .badge.pending, .badge.trialing, .badge.past_due, .badge.degraded {
    background-color: var(--color-warning-bg);
    color: var(--color-warning-text);
}
.badge.danger, .badge.failed, .badge.down, .badge.cancelled {
    background-color: var(--color-danger-bg);
    color: var(--color-danger-text);
}
.badge.info, .badge.user {
    background-color: var(--color-info-bg);
    color: var(--color-info-text);
}
.badge.purple, .badge.admin, .badge.pro_yearly {
    background-color: var(--color-purple-bg);
    color: var(--color-purple-text);
}
.badge.gray, .badge.inactive, .badge.free {
    background-color: var(--bg-sunken);
    color: var(--text-secondary);
}
.badge.pro_monthly { background-color: var(--color-success-bg); color: var(--color-success-text); }

/* === TABLES === */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
}

table {
    width: 100%;
    border-collapse: collapse;
    background-color: var(--bg-surface);
    font-size: var(--font-size-sm);
}

thead {
    background-color: var(--bg-sunken);
    border-bottom: 1px solid var(--border-default);
}

th {
    padding: var(--space-3) var(--space-4);
    text-align: left;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
    user-select: none;
}

th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--text-primary); }

td {
    padding: var(--space-3) var(--space-4);
    color: var(--text-secondary);
    border-top: 1px solid var(--border-subtle);
    font-size: var(--font-size-sm);
    vertical-align: middle;
}

td.primary { color: var(--text-primary); font-weight: var(--font-weight-medium); }
td.mono { font-family: var(--font-mono); font-size: var(--font-size-xs); color: var(--text-tertiary); }

tbody tr { transition: background-color var(--duration-fast); }
tbody tr:hover { background-color: var(--bg-sunken); }

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    margin-top: var(--space-4);
}

.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 var(--space-2);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background-color: var(--bg-surface);
    color: var(--text-secondary);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: all var(--duration-fast);
    font-family: inherit;
}

.page-btn:hover:not(:disabled) {
    background-color: var(--bg-sunken);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.page-btn.active {
    background-color: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* === FORMS === */
.form-group { margin-bottom: var(--space-5); }

.form-label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.form-required { color: var(--color-danger); margin-left: 2px; }

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 0 var(--space-3);
    height: 38px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background-color: var(--bg-surface);
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    font-family: var(--font-sans);
    outline: none;
    transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}

.form-textarea { height: auto; padding: var(--space-3); resize: vertical; line-height: var(--line-height-normal); }
.form-select { appearance: none; 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='%239898aa' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 36px; }

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-brand);
}

.form-input::placeholder, .form-textarea::placeholder { color: var(--text-tertiary); }
.form-error { font-size: var(--font-size-xs); color: var(--color-danger); margin-top: var(--space-1); }
.form-help  { font-size: var(--font-size-xs); color: var(--text-tertiary); margin-top: var(--space-1); }

/* Also target inline-styled inputs/selects (legacy support) */
input[class~="search-input"],
select[class~="select-filter"] {
    height: 36px;
    padding: 0 var(--space-3);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background-color: var(--bg-surface);
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    font-family: var(--font-sans);
    outline: none;
    transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}

.search-input:focus, .select-filter:focus {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-brand);
}

/* === MODALS === */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
}

.modal.open,
.modal:not(.hidden) {
    display: flex;
    animation: modalFadeIn 200ms ease forwards;
}

.modal-content {
    background-color: var(--bg-elevated);
    border-radius: 20px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04), 0 30px 60px -15px rgba(0, 0, 0, 0.3);
    max-width: 540px;
    width: 100%;
    max-height: min(90vh, 720px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border-subtle);
}

.modal.open .modal-content,
.modal:not(.hidden) .modal-content {
    animation: modalScaleUp 200ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.modal-header {
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.modal-title { font-size: var(--font-size-lg); font-weight: var(--font-weight-semibold); color: var(--text-primary); }

.modal-close {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    width: 32px; height: 32px;
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    transition: background-color var(--duration-fast), color var(--duration-fast);
}

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

.modal-body {
    padding: var(--space-6);
    overflow-y: auto;
    flex-grow: 1;
}

.modal-footer {
    padding: var(--space-5) var(--space-6);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    flex-shrink: 0;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        backdrop-filter: blur(0px);
        -webkit-backdrop-filter: blur(0px);
    }
    to {
        opacity: 1;
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
    }
}

@keyframes modalScaleUp {
    from {
        transform: scale(0.96);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* === ENTERPRISE MODAL (centered, full-viewport overlay) === */
.enterprise-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 24px;
    pointer-events: none;
}

.enterprise-modal.open,
.enterprise-modal:not(.hidden) {
    display: flex;
    pointer-events: auto;
}

.enterprise-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    opacity: 0;
    transition: opacity 200ms ease-out;
}

.enterprise-modal.open .enterprise-modal-backdrop {
    opacity: 1;
}

.enterprise-modal.closing .enterprise-modal-backdrop {
    opacity: 0;
}

.enterprise-modal-panel {
    position: relative;
    z-index: 1;
    width: min(88vw, 1500px);
    height: 90vh;
    max-height: 90vh;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.04) inset,
        0 24px 48px -12px rgba(15, 23, 42, 0.25),
        0 48px 96px -24px rgba(15, 23, 42, 0.35);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: scale(0.95) translateY(12px);
    transition:
        opacity 200ms ease-out,
        transform 200ms ease-out;
}

.enterprise-modal.open .enterprise-modal-panel {
    opacity: 1;
    transform: scale(1) translateY(0);
}

.enterprise-modal.closing .enterprise-modal-panel {
    opacity: 0;
    transform: scale(0.95) translateY(12px);
}

.enterprise-modal-header {
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 12;
    background: #fff;
    border-bottom: 1px solid var(--border-subtle);
    padding: 20px 24px 16px;
}

.enterprise-modal-tabs {
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 11;
    display: flex;
    gap: 0;
    padding: 0 24px;
    background: var(--bg-sunken);
    border-bottom: 1px solid var(--border-subtle);
    overflow-x: auto;
    scrollbar-width: none;
}

.enterprise-modal-tabs::-webkit-scrollbar { display: none; }

.enterprise-modal-tab,
.enterprise-modal-tabs .drawer-tab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-tertiary);
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s ease, border-color 0.15s ease;
    margin-bottom: -1px;
}

.enterprise-modal-tab:hover,
.enterprise-modal-tabs .drawer-tab:hover {
    color: var(--text-primary);
}

.enterprise-modal-tab.active,
.enterprise-modal-tabs .drawer-tab.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.enterprise-modal-body {
    flex: 1;
    min-height: 0;
    display: flex;
    overflow: hidden;
}

.enterprise-modal-main {
    flex: 1 1 70%;
    min-width: 0;
    overflow-y: auto;
    padding: 24px;
}

.enterprise-modal-properties {
    flex: 0 0 30%;
    max-width: 380px;
    min-width: 280px;
    overflow-y: auto;
    padding: 24px;
    background: var(--bg-sunken);
    border-left: 1px solid var(--border-subtle);
    align-self: stretch;
}

.enterprise-modal-footer {
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    z-index: 12;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 24px;
    background: #fff;
    border-top: 1px solid var(--border-subtle);
    box-shadow: 0 -4px 24px rgba(15, 23, 42, 0.04);
}

.enterprise-modal-footer-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.enterprise-modal-close {
    background: none;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-lg);
    font-size: 1.5rem;
    line-height: 1;
    color: var(--text-tertiary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease, color 0.15s ease;
    flex-shrink: 0;
}

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

html.enterprise-modal-open {
    overflow: hidden;
}

@media (max-width: 1024px) {
    .enterprise-modal-panel {
        width: 95vw;
    }

    .enterprise-modal-body {
        flex-direction: column;
    }

    .enterprise-modal-properties {
        flex: none;
        max-width: none;
        min-width: 0;
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border-subtle);
        position: relative;
        max-height: 40vh;
    }
}

@media (max-width: 768px) {
    .enterprise-modal {
        padding: 0;
        align-items: stretch;
    }

    .enterprise-modal-panel {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }

    .enterprise-modal-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .enterprise-modal-footer-actions {
        justify-content: stretch;
    }

    .enterprise-modal-footer-actions .btn {
        flex: 1;
        justify-content: center;
    }
}

/* === TOAST === */
.toast-container {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    max-width: 380px;
    pointer-events: auto;
    animation: slideLeft var(--duration-base) var(--easing-out);
    border: 1px solid transparent;
}

.toast.success { background-color: var(--color-success); color: white; }
.toast.info    { background-color: var(--color-primary); color: white; }
.toast.warning { background-color: var(--color-warning); color: white; }
.toast.danger  { background-color: var(--color-danger); color: white; }
.toast.hide    { animation: fadeOut var(--duration-base) var(--easing-in) forwards; }

/* === ALERTS === */
.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    border: 1px solid transparent;
    font-size: var(--font-size-sm);
    margin-bottom: var(--space-4);
}

.alert.success, .alert.alert-success { background-color: var(--color-success-bg); color: var(--color-success-text); border-color: var(--color-success-light); }
.alert.warning, .alert.alert-warning { background-color: var(--color-warning-bg); color: var(--color-warning-text); border-color: var(--color-warning-light); }
.alert.danger,  .alert.alert-danger  { background-color: var(--color-danger-bg);  color: var(--color-danger-text);  border-color: var(--color-danger-light); }
.alert.info,    .alert.alert-info    { background-color: var(--color-info-bg);    color: var(--color-info-text);    border-color: var(--color-info-light); }

/* === TABS === */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border-subtle);
    gap: 0;
    margin-bottom: var(--space-6);
}

.tab {
    padding: var(--space-3) var(--space-4);
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color var(--duration-fast), border-color var(--duration-fast);
    font-family: inherit;
    white-space: nowrap;
}

.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: var(--font-weight-semibold); }
.tab-content { display: none; animation: fadeIn var(--duration-base); }
.tab-content.active { display: block; }

/* === SPINNERS & LOADING === */
.spinner {
    display: inline-block;
    width: 24px; height: 24px;
    border: 2px solid var(--border-default);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.spinner-lg { width: 40px; height: 40px; border-width: 3px; }
.spinner-sm { width: 16px; height: 16px; border-width: 2px; }

.chart-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--text-tertiary);
}

/* Skeleton */
.skeleton {
    background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--border-subtle) 50%, var(--bg-sunken) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: var(--radius-md);
}

.skeleton-header { height: 28px; width: 40%; margin-bottom: var(--space-4); }
.skeleton-card { height: 100px; }
.skeleton-text  { height: 14px; margin-bottom: var(--space-2); }

.loading-skeleton {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    padding: var(--space-4);
}

.skeleton-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-4);
}

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

.dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: none;
    flex-direction: column;
    min-width: 160px;
    z-index: 1000;
    overflow: hidden;
    animation: slideDown var(--duration-fast) var(--easing-out);
}

.dropdown-menu.open { display: flex; }
.dropdown-menu.right { left: auto; right: 0; }

.dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-4);
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color var(--duration-fast);
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
    text-decoration: none;
}

.dropdown-item:hover { background-color: var(--bg-sunken); }
.dropdown-item.danger { color: var(--color-danger); }
.dropdown-item.success { color: var(--color-success); }
.dropdown-divider { height: 1px; background-color: var(--border-subtle); margin: var(--space-1) 0; }

/* === EMPTY STATE === */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-16) var(--space-8);
    text-align: center;
    color: var(--text-tertiary);
}

.empty-icon { font-size: 2.5rem; margin-bottom: var(--space-4); opacity: 0.5; }
.empty-title { font-size: var(--font-size-lg); font-weight: var(--font-weight-semibold); color: var(--text-secondary); margin-bottom: var(--space-2); }
.empty-desc { font-size: var(--font-size-sm); color: var(--text-tertiary); max-width: 300px; line-height: 1.6; }

/* === MISC === */
.divider { height: 1px; background-color: var(--border-subtle); margin: var(--space-6) 0; }
.section-title { font-size: var(--font-size-md); font-weight: var(--font-weight-semibold); color: var(--text-primary); margin-bottom: var(--space-4); }

/* Tooltip */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--gray-800);
    color: white;
    font-size: var(--font-size-xs);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--duration-fast);
}

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

/* ── Drawer: sibling panel pattern (User Management, Plans) ── */
.drawer-overlay {
    position: fixed;
    top: 0;
    bottom: 0;
    left: var(--sidebar-width);
    right: 0;
    background-color: rgba(15, 23, 42, 0.35);
    z-index: 1200;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--duration-base) ease, left var(--duration-base) var(--easing-in-out);
}

.drawer-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.app-container.sidebar-is-collapsed .drawer-overlay,
html.sidebar-is-collapsed-init .drawer-overlay {
    left: var(--sidebar-width-collapsed);
}

@media (max-width: 767px) {
    .drawer-overlay {
        left: 0 !important;
    }
}

.drawer.um-drawer,
.drawer.plan-drawer,
.drawer.sub-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 520px;
    max-width: 100%;
    height: 100vh;
    background-color: var(--bg-surface);
    box-shadow: var(--shadow-2xl);
    z-index: 1201;
    transform: translateX(100%);
    transition: transform var(--duration-base) var(--easing-out), visibility var(--duration-base);
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border-subtle);
    visibility: hidden;
    pointer-events: none;
}

.drawer.um-drawer.open,
.drawer.plan-drawer.open,
.drawer.sub-drawer.open {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
}

/* ── Drawer: host wrapper pattern (Subscriptions) ── */
.drawer.drawer-host {
    position: fixed;
    inset: 0;
    z-index: 1200;
    visibility: hidden;
    transition: visibility var(--duration-base);
    pointer-events: none;
}

.drawer.drawer-host.open {
    visibility: visible;
    pointer-events: auto;
}

.drawer.drawer-host .drawer-overlay {
    position: absolute;
    inset: 0;
    background-color: rgba(15, 23, 42, 0.35);
    opacity: 0;
    transition: opacity var(--duration-base) ease;
    pointer-events: none;
}

.drawer.drawer-host.open .drawer-overlay {
    opacity: 1;
    pointer-events: auto;
}

.drawer.drawer-host .drawer-content {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 520px;
    max-width: 100%;
    background-color: var(--bg-surface);
    box-shadow: var(--shadow-xl);
    transform: translateX(100%);
    transition: transform var(--duration-base) var(--easing-out);
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border-subtle);
    pointer-events: auto;
}

.drawer.drawer-host.open .drawer-content {
    transform: translateX(0);
}

.drawer-header {
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.drawer-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
}

.drawer-subtitle {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-family: var(--font-mono);
    margin-top: 2px;
}

.drawer-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: var(--space-1);
    border-radius: var(--radius-sm);
    line-height: 1;
    transition: color var(--duration-fast), background-color var(--duration-fast);
}

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

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-6);
    min-height: 0;
}

.drawer-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--border-subtle);
    background-color: var(--bg-sunken);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    flex-shrink: 0;
}

/* Tabs inside Drawer */
.drawer-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-subtle);
    background-color: var(--bg-sunken);
    padding: 0 var(--space-4);
    flex-shrink: 0;
    overflow-x: auto;
}

.drawer-tab,
.drawer-tab-btn {
    background: none;
    border: none;
    padding: var(--space-3) var(--space-4);
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: color var(--duration-fast), border-color var(--duration-fast);
}

.drawer-tab:hover,
.drawer-tab-btn:hover {
    color: var(--text-primary);
}

.drawer-tab.active,
.drawer-tab-btn.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.drawer-tab-content {
    display: none;
}

.drawer-tab-content.active {
    display: block;
}

.drawer-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-tertiary);
    letter-spacing: 0.05em;
    margin-bottom: var(--space-2);
    display: block;
}

.drawer-val {
    color: var(--text-primary);
    font-size: 0.875rem;
    line-height: 1.5;
}

.drawer-section {
    margin-bottom: var(--space-5);
}

.drawer-section-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
    margin-bottom: var(--space-5);
}

.drawer-section-grid.border-top,
.drawer-section.border-top {
    border-top: 1px solid var(--border-subtle);
    padding-top: var(--space-4);
}

.drawer-list {
    padding-left: var(--space-4);
    margin: var(--space-2) 0;
}

.drawer-list li {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.drawer-list-timeline-item {
    position: relative;
    padding-left: 20px;
    font-size: 13px;
    line-height: 1.4;
}

.drawer-list-timeline-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 4px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--color-primary);
}

.table-compact {
    width: 100%;
    border-collapse: collapse;
}

.table-compact th,
.table-compact td {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--border-subtle);
    text-align: left;
}

.table-compact th {
    background-color: var(--bg-sunken);
    color: var(--text-tertiary);
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
}

/* Timeline Components */
.timeline {
    position: relative;
    padding-left: var(--space-6);
    margin-top: var(--space-4);
}

.timeline::before {
    content: '';
    position: absolute;
    left: 7px;
    top: 0;
    bottom: 0;
    width: 2px;
    background-color: var(--border-subtle);
}

.timeline-item {
    position: relative;
    margin-bottom: var(--space-5);
}

.timeline-dot {
    position: absolute;
    left: -24px;
    top: 4px;
    width: 16px;
    height: 16px;
    border-radius: var(--radius-full);
    background-color: var(--bg-surface);
    border: 3px solid var(--border-strong);
    display: flex;
    align-items: center;
    justify-content: center;
}

.timeline-dot.registration { border-color: var(--color-success); }
.timeline-dot.payment { border-color: var(--color-primary); }
.timeline-dot.scan { border-color: var(--color-purple); }
.timeline-dot.activity { border-color: var(--text-tertiary); }
.timeline-dot.admin { border-color: var(--color-danger); }

.timeline-content {
    background-color: var(--bg-sunken);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border-subtle);
}

.timeline-time {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-bottom: 2px;
}

.timeline-title {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    margin-bottom: 2px;
}

.timeline-desc {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

/* User Avatar circle */
.avatar-circle {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--brand-500), var(--color-purple));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-sm);
}

.avatar-circle.lg {
    width: 64px;
    height: 64px;
    font-size: var(--font-size-xl);
}

/* ─── Detail Info List (Admin Drawer, User Drawer) ─── */
.detail-info-list {
    display: flex;
    flex-direction: column;
}

.detail-info-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    font-size: var(--font-size-sm);
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--border-subtle);
    line-height: 1.4;
}

.detail-info-item:last-child { border-bottom: none; }

.detail-info-label {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
    min-width: 120px;
    padding-top: 1px;
}

.detail-info-value {
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    font-weight: var(--font-weight-medium);
    text-align: right;
    word-break: break-word;
}

/* ─── Activity Timeline (Drawer / Audit) ─── */
.activity-timeline-wrap {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.timeline-event {
    display: flex;
    flex-direction: column;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    background: var(--bg-sunken);
    transition: background-color var(--duration-fast);
}

.timeline-event:hover { background: var(--bg-sunken); border-color: var(--border-default); }

.timeline-event-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.timeline-event-title {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
}

.timeline-event-time {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    white-space: nowrap;
}

.timeline-event-desc {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    margin-top: var(--space-1);
    line-height: 1.5;
}

/* ─── Responsive Modals ─── */
@media (max-width: 640px) {
    .modal { padding: var(--space-3); align-items: flex-end; }
    .modal-content {
        max-width: 100%;
        max-height: 92vh;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    }
    .modal-footer { flex-direction: column; }
    .modal-footer .btn { width: 100%; justify-content: center; }
}

/* ─── Responsive Drawer ─── */
@media (max-width: 768px) {
    .drawer {
        width: 100% !important;
        min-width: 0 !important;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        top: auto;
        bottom: 0;
        height: 90vh;
    }
}

/* ─── Page Header Responsive ─── */
@media (max-width: 640px) {
    .page-header { flex-direction: column; align-items: flex-start; }
    .page-header-actions {
        width: 100%;
        flex-wrap: wrap;
        justify-content: flex-start;
    }
}

/* ─── KPI Card Gray Icon (compat) ─── */
.kpi-icon-wrap.gray {
    background-color: var(--bg-sunken);
    color: var(--text-secondary);
}

/* ─── Usage Tile (User Drawer) ─── */
.um-usage-tile {
    background: var(--bg-sunken);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    text-align: center;
}

.um-usage-tile .usage-label {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
}

.um-usage-tile .usage-value {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    margin-top: var(--space-1);
    letter-spacing: -0.02em;
}

/* ─── Inline Action Buttons in Tables ─── */
.row-actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-1);
    flex-wrap: nowrap;
}

/* ─── Filter Badge ─── */
.filter-badge {
    display: none;
    align-items: center;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    background: var(--color-primary-light);
    color: var(--color-primary);
    border: 1px solid var(--border-brand);
}

.filter-badge.visible { display: inline-flex; }

/* ─── Drawer Tabs ─── */
.drawer-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-subtle);
    padding: 0 var(--space-5);
    overflow-x: auto;
    flex-shrink: 0;
}

.drawer-tab-btn {
    padding: var(--space-3) var(--space-3);
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color var(--duration-fast), border-color var(--duration-fast);
    font-family: inherit;
    white-space: nowrap;
}

.drawer-tab-btn:hover { color: var(--text-primary); }
.drawer-tab-btn.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
    font-weight: var(--font-weight-semibold);
}

.drawer-tab-content { display: none; padding: var(--space-5); }
.drawer-tab-content.active { display: block; animation: fadeIn var(--duration-base); }

/* ─── Drawer section title ─── */
.drawer-section-title {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    margin-bottom: var(--space-3);
    margin-top: var(--space-5);
}

.drawer-section-title:first-child { margin-top: 0; }

/* ─── Skeleton Loaders ─── */
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.skeleton {
    background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--border-default) 50%, var(--bg-sunken) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite linear;
    border-radius: var(--radius-md);
    display: inline-block;
    width: 100%;
    height: 1.2em;
    vertical-align: middle;
}

.skeleton-text { height: 1em; margin-bottom: 0.5rem; }
.skeleton-title { height: 1.5em; width: 60%; margin-bottom: 1rem; }
.skeleton-circle { border-radius: var(--radius-full); width: 40px; height: 40px; }
.skeleton-rect { height: 100px; }

/* Table Skeleton */
.table-skeleton-row {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-subtle);
}
.table-skeleton-cell {
    flex: 1;
    height: 16px;
    background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--border-default) 50%, var(--bg-sunken) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite linear;
    border-radius: var(--radius-sm);
}

/* Card Skeleton */
.card-skeleton {
    padding: var(--space-5);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    box-shadow: var(--shadow-card);
}

/* Chart Skeleton */
.chart-skeleton-placeholder {
    height: 280px;
    background: var(--bg-sunken);
    border-radius: var(--radius-xl);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border-subtle);
    gap: 12px;
    color: var(--text-tertiary);
}

/* Button Loading State */
.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}
.btn-loading::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    top: calc(50% - 8px);
    left: calc(50% - 8px);
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: var(--radius-full);
    animation: spin 0.75s linear infinite;
}

/* Inline Form Validation styling */
.form-input.is-invalid,
.form-select.is-invalid,
.form-textarea.is-invalid {
    border-color: var(--color-danger) !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15) !important;
}
.invalid-feedback {
    display: block;
    font-size: var(--font-size-xs);
    color: var(--color-danger);
    margin-top: 4px;
    animation: fadeIn var(--duration-fast) ease-out;
}
.form-required-indicator {
    color: var(--color-danger);
    margin-left: 2px;
}


