*, *::before, *::after {
    box-sizing: border-box;
}

:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #eff6ff;
    --success: #059669;
    --success-soft: #ecfdf5;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --warning: #d97706;
    --warning-soft: #fffbeb;
    --dark: #1e293b;
    --radius: 14px;
    --shadow: 0 4px 20px rgba(15, 23, 42, 0.06);
}

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

.container {
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 16px;
}

/* Topbar */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 40;
}
.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-top: 12px;
    padding-bottom: 12px;
}
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.brand-logo {
    font-size: 28px;
    line-height: 1;
    flex-shrink: 0;
}
.brand-title {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.brand-sub {
    font-size: 0.85rem;
    color: var(--muted);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.role-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}
.role-student { background: var(--primary-soft); color: var(--primary-dark); }
.role-profesor { background: #f3e8ff; color: #7e22ce; }
.role-admin { background: #1e293b; color: #ffffff; }
.role-module { background: #fef3c7; color: #92400e; }

.main-content {
    padding-top: 20px;
    padding-bottom: 48px;
}

/* Auth Page */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px 14px;
    background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 55%, #e0f2fe 100%);
}
.auth-card {
    width: 100%;
    max-width: 450px;
    background: var(--surface);
    border-radius: 18px;
    box-shadow: 0 12px 36px rgba(15, 23, 42, 0.1);
    padding: 28px 24px;
    border: 1px solid rgba(226, 232, 240, 0.8);
}
.auth-header {
    text-align: center;
    margin-bottom: 20px;
}
.auth-icon { font-size: 42px; margin-bottom: 6px; }
.auth-header h1 { margin: 0 0 6px; font-size: 1.35rem; }
.auth-header p { margin: 0; font-size: 0.9rem; color: var(--muted); }

.tab-bar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    background: #f1f5f9;
    padding: 5px;
    border-radius: 12px;
    margin-bottom: 20px;
}
.tab-btn {
    border: none;
    background: transparent;
    padding: 10px 8px;
    border-radius: 9px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--muted);
    cursor: pointer;
    transition: all 0.15s ease;
    min-height: 42px;
}
.tab-btn.active {
    background: var(--surface);
    color: var(--primary-dark);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.auth-switch {
    margin-top: 16px;
    text-align: center;
    font-size: 0.9rem;
    color: var(--muted);
}
.link-btn {
    background: none;
    border: none;
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    padding: 4px;
    font-size: inherit;
}
.link-btn:hover { text-decoration: underline; }

/* Flash Alerts */
.flash-stack {
    width: 100%;
    max-width: 1180px;
    margin: 0 auto 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.auth-wrapper .flash-stack { max-width: 450px; }

.alert {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 0.92rem;
    border: 1px solid transparent;
    margin-bottom: 12px;
}
.alert-success { background: var(--success-soft); color: #065f46; border-color: #a7f3d0; }
.alert-error { background: var(--danger-soft); color: #991b1b; border-color: #fecaca; }
.alert-warning { background: var(--warning-soft); color: #92400e; border-color: #fde68a; }
.alert-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
}

/* Subnav */
.subnav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    margin-bottom: 20px;
    -webkit-overflow-scrolling: touch;
}
.subnav-link {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    padding: 10px 16px;
    border-radius: 11px;
    background: var(--surface);
    color: var(--muted);
    font-weight: 600;
    font-size: 0.92rem;
    border: 1px solid var(--border);
    min-height: 44px;
    transition: all 0.15s ease;
}
.subnav-link:hover { text-decoration: none; border-color: #cbd5e1; color: var(--text); }
.subnav-link.active {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}

/* Cards & Typography */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 20px;
}
.card-narrow { max-width: 560px; }
.card h2 { margin: 0 0 10px; font-size: 1.15rem; }
.sub-heading { margin: 0 0 14px; font-size: 1.1rem; }

.section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 18px;
}
.section-head h1 { margin: 0 0 4px; font-size: 1.35rem; }
.muted { color: var(--muted); font-size: 0.9rem; margin: 0; }

.section-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

/* Module Grid */
.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 14px;
}
.module-card {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    color: var(--text);
    box-shadow: var(--shadow);
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.module-card:hover {
    text-decoration: none;
    transform: translateY(-2px);
    border-color: var(--primary);
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.12);
}
.module-card-exam {
    background: linear-gradient(135deg, #fffbeb 0%, #ffffff 70%);
    border-color: #f59e0b;
}
.module-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.module-icon { font-size: 28px; }
.count-pill {
    font-size: 0.78rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 999px;
    background: #f1f5f9;
    color: var(--muted);
}
.count-pill.has-files { background: var(--success-soft); color: #047857; }
.module-card-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 4px; }
.module-card-desc { font-size: 0.86rem; color: var(--muted); flex: 1; margin-bottom: 14px; }
.module-card-cta { font-size: 0.88rem; font-weight: 600; color: var(--primary); }

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}
.stat-value { font-size: 1.5rem; font-weight: 800; color: var(--primary-dark); }
.stat-label { font-size: 0.84rem; color: var(--muted); margin-top: 2px; }

/* Two Column Layout */
.grid-two-col {
    display: grid;
    grid-template-columns: minmax(300px, 420px) 1fr;
    gap: 18px;
    align-items: start;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}
.breadcrumb-current { font-size: 1.2rem; font-weight: 700; }

/* Forms & Inputs */
.form-stack {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.form-group label {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text);
}
input[type="text"],
input[type="password"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: 11px 13px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    font-size: 1rem; /* 16px previne zoom automat pe iOS */
    font-family: inherit;
    background: #ffffff;
    color: var(--text);
    min-height: 44px;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.search-input { max-width: 280px; }
.input-sm { padding: 7px 10px !important; min-height: 36px !important; font-size: 0.88rem !important; width: 130px !important; }
.form-hint { font-size: 0.83rem; color: var(--muted); margin: 12px 0 0; }
.checkbox-row { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; font-size: 0.92rem; }
.checkbox-row input { width: 18px; height: 18px; margin-top: 2px; flex-shrink: 0; }

/* Dropzone */
.dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    border: 2px dashed #94a3b8;
    border-radius: 14px;
    padding: 24px 16px;
    background: #f8fafc;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
}
.dropzone:hover, .dropzone.dragover {
    border-color: var(--primary);
    background: var(--primary-soft);
}
.dropzone-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}
.dropzone-icon { font-size: 32px; margin-bottom: 6px; }
.dropzone-title { font-weight: 700; font-size: 0.95rem; }
.dropzone-sub { font-size: 0.82rem; color: var(--muted); margin-top: 2px; }
.dropzone-preview {
    margin-top: 10px;
    font-size: 0.84rem;
    color: var(--primary-dark);
    font-weight: 600;
    word-break: break-word;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.93rem;
    border: 1px solid transparent;
    cursor: pointer;
    min-height: 44px;
    text-decoration: none;
    transition: background 0.15s ease, transform 0.08s ease;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(0.99); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 0.84rem; min-height: 36px; }

.btn-primary { background: var(--primary); color: #ffffff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #ffffff; }
.btn-success:hover { background: #047857; }
.btn-dark { background: var(--dark); color: #ffffff; }
.btn-dark:hover { background: #0f172a; }
.btn-outline { background: #ffffff; border-color: #cbd5e1; color: var(--text); }
.btn-outline:hover { background: #f8fafc; }
.btn-danger-outline { background: #ffffff; border-color: #fca5a5; color: var(--danger); }
.btn-danger-outline:hover { background: var(--danger-soft); }

/* File Lists & Badges */
.file-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fcfdff;
    flex-wrap: wrap;
}
.file-item-main {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    min-width: 0;
    flex: 1;
}
.file-item-info { min-width: 0; flex: 1; }
.file-name { font-weight: 600; word-break: break-word; }
.file-meta { font-size: 0.82rem; color: var(--muted); margin-top: 2px; }
.file-note { font-size: 0.84rem; color: #334155; background: #f1f5f9; padding: 4px 8px; border-radius: 6px; margin-top: 6px; display: inline-block; }
.file-item-actions, .action-row, .user-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.inline-reset-form { display: flex; gap: 6px; align-items: center; }

.file-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 800;
    padding: 4px 7px;
    border-radius: 7px;
    flex-shrink: 0;
    letter-spacing: 0.03em;
}
.badge-pdf { background: #fee2e2; color: #b91c1c; }
.badge-doc { background: #dbeafe; color: #1d4ed8; }
.badge-xls { background: #dcfce7; color: #15803d; }
.badge-ppt { background: #ffedd5; color: #c2410c; }
.badge-zip { background: #fef3c7; color: #92400e; }
.badge-img { background: #f3e8ff; color: #7e22ce; }
.badge-other { background: #e2e8f0; color: #334155; }

.scope-pill, .scope-pill-sm {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 700;
    background: var(--primary-soft);
    color: var(--primary-dark);
}
.scope-pill-sm { padding: 1px 7px; font-size: 0.72rem; margin-right: 4px; }
.scope-exam { background: #fef3c7; color: #92400e; }

/* Materials Grid */
.material-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}
.material-card { display: flex; flex-direction: column; gap: 10px; }
.material-top { display: flex; align-items: center; justify-content: space-between; }
.material-title { margin: 0; font-size: 1.08rem; }
.material-desc { margin: 0; font-size: 0.9rem; color: #334155; }
.material-meta { display: flex; flex-direction: column; gap: 4px; font-size: 0.83rem; color: var(--muted); flex: 1; }
.material-footer { margin-top: 6px; }

/* Data Table (Desktop) -> Stacked Cards (Mobile) */
.table-card { padding: 0; overflow: hidden; }
.table-responsive { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.data-table th {
    text-align: left;
    padding: 13px 16px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}
.data-table td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #fafcff; }
.file-cell { display: flex; align-items: center; gap: 8px; word-break: break-word; }
.cell-sub { font-size: 0.8rem; color: var(--muted); }
.text-right { text-align: right; }

/* Empty State */
.empty-state { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty-icon { font-size: 40px; margin-bottom: 8px; }

/* Upload Overlay */
.upload-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}
.upload-overlay[hidden] { display: none; }
.upload-overlay-card {
    background: #ffffff;
    border-radius: 16px;
    padding: 28px 24px;
    text-align: center;
    max-width: 320px;
    width: 100%;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e2e8f0;
    border-top-color: var(--primary);
    border-radius: 50%;
    margin: 0 auto 14px;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive Breakpoints (Tablet & Mobile) */
@media (max-width: 900px) {
    .grid-two-col { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 720px) {
    .topbar-inner { flex-wrap: wrap; }
    .brand-title { font-size: 0.95rem; }
    .section-head { flex-direction: column; align-items: stretch; }
    .section-actions { flex-direction: column; align-items: stretch; }
    .section-actions .search-input, .filter-inline .search-input, .inline-form select { max-width: 100%; width: 100%; }

    /* Transform table into touch-friendly mobile cards */
    .table-card { background: transparent; border: none; box-shadow: none; }
    .data-table thead { display: none; }
    .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
    .data-table tr {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 12px 14px;
        margin-bottom: 12px;
        box-shadow: var(--shadow);
    }
    .data-table td {
        padding: 6px 0;
        border: none;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 10px;
        text-align: right;
    }
    .data-table td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.8rem;
        color: var(--muted);
        text-align: left;
        flex-shrink: 0;
    }
    .data-table td.text-right { justify-content: flex-end; padding-top: 10px; border-top: 1px solid var(--border); margin-top: 6px; }
    .data-table td.text-right::before { display: none; }

    .file-item { flex-direction: column; align-items: stretch; }
    .file-item-actions, .user-actions { justify-content: flex-end; width: 100%; }
}
