/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    height: 38px;
    padding: 0 var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    font-size: var(--text-sm);
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
    box-shadow: var(--shadow-xs);
}
.btn-primary:hover:not(:disabled) { background: var(--brand-strong); box-shadow: var(--shadow-sm); }

.btn-accent {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: var(--shadow-xs);
}
.btn-accent:hover:not(:disabled) { background: var(--accent-strong); }

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

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

.btn-danger {
    background: var(--bg-surface);
    border-color: var(--color-danger);
    color: var(--color-danger);
}
.btn-danger:hover:not(:disabled) { background: var(--color-danger-bg); }

.btn-sm { height: 32px; padding: 0 var(--space-3); font-size: var(--text-xs); }
.btn-lg { height: 44px; padding: 0 var(--space-6); font-size: var(--text-base); }
.btn-icon { width: 34px; height: 34px; padding: 0; }
.btn-block { width: 100%; }

/* ---------- Forms ---------- */
.field { margin-bottom: var(--space-4); }
.field label {
    display: block;
    margin-bottom: var(--space-2);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-primary);
}
.field .hint { margin-top: var(--space-1); font-size: var(--text-xs); color: var(--text-muted); }
.field .error-text { margin-top: var(--space-1); font-size: var(--text-xs); color: var(--color-danger); }

.input, .select, .textarea {
    width: 100%;
    height: 40px;
    padding: 0 var(--space-3);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-strong);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: var(--text-base);
    font-family: inherit;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.textarea { height: auto; min-height: 96px; padding: var(--space-3); resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--brand-blue-500);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.16);
}
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
.input[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--color-danger); }

.field-row { display: flex; gap: var(--space-3); }
.field-row .field { flex: 1; }

.checkbox-row { display: flex; align-items: center; gap: var(--space-2); }
.checkbox-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--brand); }

/* ---------- Cards ---------- */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card-pad { padding: var(--space-6); }
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--border-subtle);
}
.card-header h2, .card-header h3 { margin: 0; }
.card-body { padding: var(--space-6); }

/* ---------- Stat tiles ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: var(--space-4);
}
.stat-tile {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
}
.stat-tile .stat-label {
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: var(--space-2);
}
.stat-tile .stat-value {
    font-size: var(--text-3xl);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}
.stat-tile .stat-sub { font-size: var(--text-xs); color: var(--text-secondary); margin-top: var(--space-1); }

/* ---------- Tables ---------- */
.table-wrap {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
table.data-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.data-table thead th {
    text-align: left;
    padding: var(--space-3) var(--space-4);
    background: var(--bg-surface-sunken);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border-default);
    white-space: nowrap;
}
.data-table tbody td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
    vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background var(--transition-fast); }
.data-table tbody tr:hover { background: var(--bg-surface-sunken); }
.data-table .cell-muted { color: var(--text-muted); }
.data-table .cell-actions { display: flex; gap: var(--space-2); justify-content: flex-end; }

/* Keeps a long table at a fixed viewport-relative height with its own
   scrollbar and a header that stays pinned while scrolling. */
.table-scroll { max-height: 560px; overflow-y: auto; }
.table-scroll table.data-table thead th { position: sticky; top: 0; z-index: 1; }

.text-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    max-width: 480px;
}

/* ---------- Badges / tags ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 2px var(--space-2);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1.7;
}
.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-danger { background: var(--color-danger-bg); color: var(--color-danger); }
.badge-info { background: var(--color-info-bg); color: var(--color-info); }
.badge-neutral { background: var(--gray-150); color: var(--gray-600); }

.tag-chip {
    display: inline-flex;
    align-items: center;
    padding: 3px var(--space-2);
    border-radius: var(--radius-sm);
    background: var(--bg-surface-sunken);
    border: 1px solid var(--border-default);
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(11, 28, 51, 0.5);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    z-index: 100;
}
.modal-overlay[hidden] { display: none; }
.modal {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 560px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    animation: modal-in 160ms cubic-bezier(0.2, 0.8, 0.3, 1);
}
.modal-wide { max-width: 760px; }
.modal-xl { max-width: 960px; }

/* ---------- Module picker ---------- */
.module-picker-toolbar {
    position: sticky;
    top: 0;
    background: var(--bg-surface);
    z-index: 2;
    padding-bottom: var(--space-3);
    margin-bottom: var(--space-3);
    border-bottom: 1px solid var(--border-subtle);
}
.category-pills { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); }
.category-pill {
    padding: 4px var(--space-3);
    border-radius: var(--radius-full);
    border: 1px solid var(--border-default);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: var(--text-xs);
    font-weight: 600;
    cursor: pointer;
}
.category-pill.is-active { background: var(--brand); border-color: var(--brand); color: #fff; }
.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    align-items: stretch;
    gap: var(--space-4);
    max-height: 52vh;
    overflow-y: auto;
    padding: 2px;
}
.module-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-4);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    height: 100%;
}
.module-card:hover { border-color: var(--brand); box-shadow: var(--shadow-sm); }
.module-card.is-added { background: var(--bg-surface-sunken); }
.module-card-title {
    font-weight: 600;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.6em;
}
.module-card-desc { color: var(--text-muted); font-size: var(--text-sm); min-height: 2.6em; }
.module-card-price { font-size: var(--text-sm); font-weight: 600; color: var(--text-primary); }
.module-card-dep {
    font-size: var(--text-xs);
    color: var(--color-info);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.module-card-inputs { display: flex; flex-direction: column; gap: var(--space-2); border-top: 1px dashed var(--border-subtle); padding-top: var(--space-2); margin-top: var(--space-1); }
.module-card [data-card-action] { margin-top: auto; padding-top: var(--space-2); }

/* ---------- Protection / status notices ---------- */
.viewer-protection-notice {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    background: var(--color-warning-bg);
    color: var(--color-warning);
    font-size: var(--text-xs);
    border-radius: var(--radius-md);
    margin-top: var(--space-4);
}
.viewer-protection-notice svg { width: 16px; height: 16px; flex-shrink: 0; }
@keyframes modal-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--border-subtle);
}
.modal-body { padding: var(--space-6); overflow-y: auto; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--border-subtle);
}

/* ---------- Upload progress ---------- */
.upload-progress {
    margin-top: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}
.upload-progress-label {
    display: flex;
    justify-content: space-between;
    font-size: var(--text-xs);
    color: var(--text-muted);
}
.upload-progress-track {
    position: relative;
    height: 10px;
    border-radius: 999px;
    background: var(--bg-inset, rgba(37, 146, 235, 0.12));
    overflow: hidden;
}
.upload-progress-fill {
    position: absolute;
    inset: 0 auto 0 0;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--brand-blue-600, #2592eb), #60c8ff, var(--brand-blue-600, #2592eb));
    background-size: 200% 100%;
    animation: upload-shimmer 1.2s linear infinite;
    transition: width 150ms ease;
}
.upload-progress-fill.is-indeterminate {
    width: 40% !important;
    animation: upload-shimmer 1.2s linear infinite, upload-indeterminate 1.1s ease-in-out infinite;
}
@keyframes upload-shimmer {
    from { background-position: 200% 0; }
    to { background-position: 0 0; }
}
@keyframes upload-indeterminate {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(250%); }
}
.upload-progress-fill.is-done {
    background: var(--color-success, #22c55e);
    animation: none;
}

/* ---------- Toast ---------- */
.toast-stack {
    position: fixed;
    top: var(--space-5);
    right: var(--space-5);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}
.toast {
    min-width: 260px;
    max-width: 360px;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    background: var(--gray-900);
    color: #fff;
    box-shadow: var(--shadow-lg);
    font-size: var(--text-sm);
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    animation: toast-in 180ms cubic-bezier(0.2, 0.8, 0.3, 1);
}
.toast.toast-success { background: var(--color-success); }
.toast.toast-danger { background: var(--color-danger); }
.toast.toast-info { background: var(--brand-blue-700); }
@keyframes toast-in {
    from { opacity: 0; transform: translateX(16px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ---------- Empty state ---------- */
.empty-state {
    text-align: center;
    padding: var(--space-12) var(--space-6);
    color: var(--text-muted);
}
.empty-state .empty-icon {
    width: 48px; height: 48px;
    margin: 0 auto var(--space-4);
    color: var(--gray-300);
}
.empty-state h3 { color: var(--text-secondary); margin-bottom: var(--space-1); }

/* ---------- Loading ---------- */
.spinner {
    width: 18px; height: 18px;
    border: 2px solid rgba(0,0,0,0.12);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
    background: linear-gradient(90deg, var(--gray-150) 25%, var(--gray-100) 37%, var(--gray-150) 63%);
    background-size: 400% 100%;
    animation: skeleton-loading 1.4s ease infinite;
    border-radius: var(--radius-sm);
}
@keyframes skeleton-loading {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

/* ---------- Tabs ---------- */
.tab-bar {
    display: flex;
    gap: var(--space-1);
    border-bottom: 1px solid var(--border-default);
    margin-bottom: var(--space-5);
}
.tab-btn {
    padding: var(--space-3) var(--space-4);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: var(--text-sm);
    cursor: pointer;
    margin-bottom: -1px;
}
.tab-btn.active { color: var(--brand); border-bottom-color: var(--accent); }
.tab-btn:hover:not(.active) { color: var(--text-primary); }

/* ---------- Content grid / card tiles ---------- */
.content-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: var(--space-5);
}
.content-tile {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-base), transform var(--transition-base);
    cursor: pointer;
    display: flex;
    flex-direction: column;
}
.content-tile:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.content-tile .thumb {
    aspect-ratio: 16/10;
    background: linear-gradient(135deg, var(--ink-900), var(--brand-blue-700));
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,0.85);
    position: relative;
}
.content-tile .thumb svg { width: 32px; height: 32px; }
.content-tile .thumb .type-badge {
    position: absolute;
    top: var(--space-2);
    left: var(--space-2);
    background: rgba(11, 28, 51, 0.65);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: var(--radius-full);
}
.content-tile .thumb .dl-badge {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: var(--radius-full);
}
.content-tile .tile-body { padding: var(--space-4); flex: 1; display: flex; flex-direction: column; gap: var(--space-2); }
.content-tile .tile-title { font-weight: 650; font-size: var(--text-base); color: var(--text-primary); }
.content-tile .tile-tags { display: flex; flex-wrap: wrap; gap: var(--space-1); }

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

/* ---------- Utility ---------- */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-4 { margin-bottom: var(--space-4); }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: var(--text-sm); }
.w-full { width: 100%; }
