@import url('./variables.css');
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; cursor: default; }

html { font-size: 16px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; scrollbar-gutter: stable; }

body { font-family: var(--font-sans); font-size: 0.875rem; line-height: 1.55; color: var(--text); background: var(--bg); min-height: 100vh; }

::selection { background: var(--primary); color: #1a1a1a; }
::-moz-selection { background: var(--primary); color: #1a1a1a; }

a { color: var(--primary); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }

button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: inherit; }
input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="range"]):not([type="file"]),
textarea { cursor: text; }
img, svg { display: block; max-width: 100%; }

.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.text-center { text-align: center; }
.text-sm { font-size: 0.75rem; }
.text-lg { font-size: 1rem; }
.text-xl { font-size: 1.25rem; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.w-full { width: 100%; }
.p-4 { padding: 1rem; }
.p-6 { padding: 1.5rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.ml-2 { margin-left: 0.5rem; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── BUTTONS ─────────────────────────────────────────────── */

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 0.5rem; padding: 0.5rem 1rem; font-size: 0.875rem; font-weight: 500;
    line-height: 1.5; border: 1px solid transparent; border-radius: var(--radius);
    transition: all var(--transition); white-space: nowrap; user-select: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(0.97); }

.btn-primary {
    color: var(--text); background: var(--primary); border-color: var(--primary);
    font-weight: 600;
}
.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover); border-color: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(237,168,42,0.35); transform: translateY(-1px);
}

.btn-secondary { color: var(--text); background: var(--bg-white); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--border); }

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

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

.btn-sm { padding: 0.3rem 0.625rem; font-size: 0.8125rem; border-radius: var(--radius-sm); }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; border-radius: var(--radius-lg); }
.btn-icon { padding: 0.5rem; width: 2.25rem; height: 2.25rem; }
.btn-icon.btn-sm { width: 1.875rem; height: 1.875rem; padding: 0.3rem; }

.btn-upload {
    color: var(--text); background: var(--primary); border-color: var(--primary);
    font-weight: 600; border-radius: var(--radius-full); padding: 0.625rem 1.5rem;
    font-size: 0.9375rem;
}
.btn-upload:hover:not(:disabled) {
    background: var(--primary-hover); box-shadow: 0 6px 16px rgba(237,168,42,0.3);
    transform: translateY(-1px);
}

.btn-create {
    color: var(--text); background: var(--bg-white); border: 1px solid var(--border);
    border-radius: var(--radius-full); padding: 0.5rem 1.25rem; font-weight: 500;
}
.btn-create:hover:not(:disabled) { background: var(--bg-hover); }

/* ─── FORMS ─────────────────────────────────────────────── */

.form-group { display: flex; flex-direction: column; gap: 0.375rem; }
.form-label { font-size: 0.8125rem; font-weight: 500; color: var(--text-secondary); }

.form-input {
    width: 100%; padding: 0.625rem 0.875rem; font-size: 0.875rem;
    color: var(--text); background: var(--bg-white);
    border: 1.5px solid var(--border); border-radius: var(--radius);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-input:focus {
    outline: none; border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
.form-input::placeholder { color: var(--text-muted); }
.form-input:disabled { background: var(--bg-hover); cursor: not-allowed; }
.form-error { font-size: 0.75rem; color: var(--danger); }

select.form-input {
    appearance: none; -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239C9790' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.25rem;
    cursor: pointer;
}

/* ─── CARDS ─────────────────────────────────────────────── */

.card {
    background: var(--bg-white); border: 1px solid var(--border);
    border-radius: var(--radius-xl); box-shadow: var(--shadow-xs);
    transition: box-shadow var(--transition-slow);
}
.card:hover { box-shadow: var(--shadow); }
.card-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border-light); }
.card-body { padding: 1.25rem; }
.card-footer { padding: 0.875rem 1.25rem; border-top: 1px solid var(--border-light); background: var(--bg); }

/* ─── BADGES ─────────────────────────────────────────────── */

.badge {
    display: inline-flex; align-items: center; padding: 0.125rem 0.625rem;
    font-size: 0.75rem; font-weight: 500; border-radius: var(--radius-full);
}
.badge-primary { color: var(--primary);  background: var(--primary-light); }
.badge-success { color: var(--success);  background: var(--success-light); }
.badge-warning { color: var(--warning);  background: var(--warning-light); }
.badge-danger  { color: var(--danger);   background: var(--danger-light); }
.badge-info    { color: var(--info);     background: var(--info-light); }

/* ─── DROPDOWN ─────────────────────────────────────────────── */

.dropdown { position: relative; }
.dropdown-menu {
    position: absolute; top: calc(100% + 4px); right: 0; z-index: 50;
    min-width: 180px; padding: 0.375rem; background: var(--bg-white);
    border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: dropdownIn 200ms cubic-bezier(0.16,1,0.3,1);
    will-change: transform, opacity;
}
.dropdown-item {
    display: flex; align-items: center; gap: 0.625rem; width: 100%;
    padding: 0.5rem 0.625rem; font-size: 0.8125rem; color: var(--text);
    background: transparent; border: none; text-align: left; cursor: pointer;
    border-radius: var(--radius-sm); transition: background var(--transition);
}
.dropdown-item:hover { background: var(--bg-hover); text-decoration: none; }
.dropdown-item svg { width: 1rem; height: 1rem; color: var(--text-muted); flex-shrink: 0; }
.dropdown-item-danger { color: var(--danger); }
.dropdown-item-danger svg { color: var(--danger); }
.dropdown-divider { height: 1px; margin: 0.25rem 0; background: var(--border-light); }

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

/* ─── MODAL ─────────────────────────────────────────────── */

.modal-overlay {
    position: fixed; inset: 0; z-index: 100;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.3); backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px); animation: fadeIn 200ms ease;
    will-change: opacity;
}
.modal {
    width: 100%; max-width: 480px; max-height: 90vh; margin: 1rem;
    background: var(--bg-white); border-radius: var(--radius-2xl);
    box-shadow: 0 25px 60px rgba(0,0,0,0.15);
    animation: modalPop 300ms cubic-bezier(0.16,1,0.3,1);
    overflow: hidden; display: flex; flex-direction: column;
    will-change: transform, opacity;
    backface-visibility: hidden; -webkit-backface-visibility: hidden;
    transform: translateZ(0);
}
.modal-large { max-width: 860px; }
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border-light);
}
.modal-title { font-size: 1.125rem; font-weight: 600; }
.modal-close {
    padding: 0.25rem; color: var(--text-muted); background: transparent;
    border: none; border-radius: var(--radius); transition: all var(--transition);
}
.modal-close:hover { color: var(--text); background: var(--bg-hover); }
.modal-body { padding: 1.5rem; overflow-y: auto; flex: 1; min-height: 0; }
.modal-footer {
    display: flex; justify-content: flex-end; gap: 0.5rem;
    padding: 1rem 1.5rem; border-top: 1px solid var(--border-light);
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalPop {
    from { opacity: 0; transform: scale(0.94) translate3d(0, 10px, 0); }
    to   { opacity: 1; transform: scale(1)    translate3d(0, 0,    0); }
}

/* ─── TOAST ─────────────────────────────────────────────── */

.toast-container {
    position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 200;
    display: flex; flex-direction: column; gap: 0.5rem;
}
.toast {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.875rem 1rem; min-width: 300px; max-width: 420px;
    background: var(--bg-white); border: 1px solid var(--border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    animation: toastSlide 400ms cubic-bezier(0.16,1,0.3,1);
}
.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-warning { border-left: 3px solid var(--warning); }
.toast-info { border-left: 3px solid var(--info); }
.toast-message { flex: 1; font-size: 0.875rem; }
.toast-close {
    padding: 0.25rem; color: var(--text-muted); background: transparent;
    border: none; cursor: pointer; border-radius: var(--radius-xs);
    transition: color var(--transition);
}
.toast-close:hover { color: var(--text); }

@keyframes toastSlide {
    from { opacity: 0; transform: translateX(100%) scale(0.95); }
    60% { opacity: 1; transform: translateX(-2%); }
    to { transform: translateX(0); }
}

/* ─── SPINNER ─────────────────────────────────────────────── */

.spinner {
    width: 1.25rem; height: 1.25rem; border: 2px solid var(--border);
    border-top-color: var(--primary); border-radius: 50%;
    animation: spin 0.65s linear infinite; will-change: transform;
}
.spinner-sm { width: 1rem; height: 1rem; border-width: 1.5px; }
.spinner-lg { width: 2rem; height: 2rem; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
    background: linear-gradient(90deg, var(--bg-hover) 25%, var(--bg-active) 50%, var(--bg-hover) 75%);
    background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: var(--radius);
    will-change: background-position;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ─── AVATAR ─────────────────────────────────────────────── */

.avatar {
    display: flex; align-items: center; justify-content: center;
    width: 2.25rem; height: 2.25rem; border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--primary-light), var(--primary-glow));
    color: var(--primary); font-weight: 600; font-size: 0.875rem; text-transform: uppercase;
    flex-shrink: 0;
}
.avatar-sm { width: 1.75rem; height: 1.75rem; font-size: 0.75rem; }
.avatar-lg { width: 3rem; height: 3rem; font-size: 1.125rem; }

/* ─── EMPTY STATE ─────────────────────────────────────────────── */

.empty-state {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; padding: 4rem 1.5rem; text-align: center;
    flex: 1; min-height: 300px;
    animation: fadeIn var(--transition-smooth);
}
.empty-state-icon { width: 5rem; height: 5rem; margin-bottom: 1.25rem; color: var(--text-muted); opacity: 0.5; }
.empty-state-title { font-size: 1.125rem; font-weight: 600; margin-bottom: 0.375rem; color: var(--text); }
.empty-state-description { color: var(--text-secondary); max-width: 300px; }

/* ─── PAGINATION ─────────────────────────────────────────────── */

.pagination { display: flex; align-items: center; gap: 0.25rem; }
.pagination-btn {
    min-width: 2rem; height: 2rem; padding: 0 0.375rem;
    font-size: 0.8125rem; font-weight: 500; color: var(--text-secondary);
    background: transparent; border: 1px solid transparent;
    border-radius: var(--radius-sm); cursor: pointer;
    transition: all var(--transition);
}
.pagination-btn:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); }
.pagination-btn.active { background: var(--primary); color: var(--text); border-color: var(--primary); font-weight: 600; }
.pagination-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ─── TABENC FOOTER BADGE ───────────────────────────────────────────── */

.tabenc-footer {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    padding: 0.625rem 1rem;
    font-size: 0.7rem; color: var(--text-muted);
    border-top: 1px solid var(--border);
    user-select: none;
}
.tabenc-footer strong { color: var(--text-secondary); font-weight: 600; }
.tabenc-footer svg { flex-shrink: 0; opacity: 0.6; }

.tabenc-aside-badge {
    display: flex; align-items: center; gap: 5px;
    padding: 0 1.5rem 1rem;
    font-size: 0.7rem; color: rgba(255,255,255,0.45);
}
.tabenc-aside-badge strong { color: rgba(255,255,255,0.65); font-weight: 600; }
.tabenc-aside-badge svg { flex-shrink: 0; }

/* ─── PREVIEW MEDIA (in modal) ──────────────────────────────────────── */

.preview-media {
    display: flex; align-items: center; justify-content: center;
    max-height: calc(90vh - 180px); overflow: hidden;
    border-radius: var(--radius-lg);
}
.preview-media img {
    max-width: 100%; max-height: calc(90vh - 180px);
    object-fit: contain; border-radius: var(--radius);
    display: block;
}
.preview-media video {
    max-width: 100%; max-height: calc(90vh - 180px);
    border-radius: var(--radius);
}
.preview-video-wrap {
    display: flex; flex-direction: column; align-items: center;
    gap: 0.625rem; width: 100%;
}
.preview-video-note {
    font-size: 0.8125rem; color: var(--text-muted);
    text-align: center; padding: 0 1rem;
}
.preview-video-note-link { color: var(--primary); text-decoration: none; }
.preview-video-note-link:hover { text-decoration: underline; }
.preview-audio {
    display: flex; flex-direction: column; align-items: center;
    gap: 1.25rem; padding: 2rem 1rem;
}
.preview-audio-icon {
    width: 4rem; height: 4rem; color: var(--text-muted); opacity: 0.7;
}
.preview-audio-icon svg { width: 100%; height: 100%; }
.preview-audio audio { width: 100%; min-width: 280px; }
.preview-pdf {
    width: 100%; height: calc(90vh - 200px); min-height: 300px;
    border: none; border-radius: var(--radius);
}
.preview-text {
    font-size: 0.8125rem; line-height: 1.6; color: var(--text);
    white-space: pre-wrap; word-break: break-all; font-family: monospace;
    background: var(--bg); padding: 1rem; border-radius: var(--radius);
    max-height: calc(90vh - 200px); overflow-y: auto;
}
.preview-markdown {
    font-size: 0.9rem; line-height: 1.75; color: var(--text);
    max-height: calc(90vh - 200px); overflow-y: auto;
    padding: 0.25rem 0.5rem;
}
.preview-markdown h1, .preview-markdown h2, .preview-markdown h3,
.preview-markdown h4, .preview-markdown h5, .preview-markdown h6 {
    color: var(--text); font-weight: 700; margin: 1.25rem 0 0.5rem;
    letter-spacing: -0.02em; line-height: 1.3;
}
.preview-markdown h1 { font-size: 1.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.4rem; }
.preview-markdown h2 { font-size: 1.25rem; border-bottom: 1px solid var(--border-light); padding-bottom: 0.3rem; }
.preview-markdown h3 { font-size: 1.1rem; }
.preview-markdown p { margin: 0.65rem 0; }
.preview-markdown ul, .preview-markdown ol { padding-left: 1.5rem; margin: 0.5rem 0; }
.preview-markdown li { margin: 0.25rem 0; }
.preview-markdown code {
    font-family: monospace; font-size: 0.82em;
    background: var(--bg); color: var(--primary);
    padding: 0.15em 0.4em; border-radius: var(--radius-xs);
    border: 1px solid var(--border-light);
}
.preview-markdown pre {
    background: var(--bg); border: 1px solid var(--border-light);
    border-radius: var(--radius); padding: 1rem; overflow-x: auto;
    margin: 0.75rem 0;
}
.preview-markdown pre code { background: none; border: none; padding: 0; color: var(--text-secondary); font-size: 0.8125rem; }
.preview-markdown blockquote {
    border-left: 3px solid var(--primary); margin: 0.75rem 0;
    padding: 0.375rem 1rem; color: var(--text-secondary);
    background: var(--primary-light); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.preview-markdown table { border-collapse: collapse; width: 100%; margin: 0.75rem 0; }
.preview-markdown th, .preview-markdown td {
    border: 1px solid var(--border); padding: 0.4rem 0.75rem;
    text-align: left; font-size: 0.875rem;
}
.preview-markdown th { background: var(--bg); font-weight: 600; color: var(--text-secondary); }
.preview-markdown a { color: var(--primary); cursor: pointer; }
.preview-markdown img { max-width: 100%; border-radius: var(--radius); }
.preview-markdown hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.preview-markdown strong { color: var(--text); }
.preview-markdown em { color: var(--text-secondary); }
.preview-unsupported {
    display: flex; flex-direction: column; align-items: center;
    gap: 0.75rem; padding: 2.5rem 1rem; text-align: center;
}
.preview-unsupported-icon {
    width: 3.5rem; height: 3.5rem; color: var(--text-muted); opacity: 0.55;
    flex-shrink: 0;
}
.preview-unsupported-icon svg { width: 100%; height: 100%; }
.preview-unsupported-name {
    font-size: 0.9375rem; font-weight: 600; color: var(--text);
    max-width: 400px; word-break: break-all;
}
.preview-unsupported-size { font-size: 0.8125rem; color: var(--text-muted); }
