/* portal/static/portal/css/app.css
   Современная дизайн-система для EDU Portal.
   Использует CSS-переменные, легко темизируется.
*/

:root {
    --app-primary: #07294d;
    --app-primary-light: #1a4a7a;
    --app-primary-dark: #051d35;
    --app-accent: #00a86b;
    --app-accent-light: #2dd4a8;
    --app-bg: #f5f7fa;
    --app-surface: #ffffff;
    --app-border: #e2e8f0;
    --app-text: #1e293b;
    --app-text-muted: #64748b;
    --app-sidebar-bg: #0a1f3a;
    --app-sidebar-width: 260px;
    --app-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --app-shadow: 0 1px 3px rgba(15, 23, 42, 0.1), 0 1px 2px rgba(15, 23, 42, 0.06);
    --app-shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.1), 0 2px 4px -2px rgba(15, 23, 42, 0.06);
    --app-shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.1), 0 4px 6px -4px rgba(15, 23, 42, 0.05);
    --app-radius: 0.625rem;
    --app-radius-lg: 0.875rem;
}

* { box-sizing: border-box; }

body {
    background-color: var(--app-bg);
    color: var(--app-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 0.9rem;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ===== Navbar ===== */
.app-navbar {
    background: linear-gradient(135deg, var(--app-primary) 0%, var(--app-primary-dark) 100%);
    box-shadow: var(--app-shadow-md);
    height: 56px;
    z-index: 1030;
}
.app-navbar .navbar-brand { font-size: 1rem; letter-spacing: 0.5px; }

.avatar-circle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-weight: 600;
    font-size: 0.85rem;
}

.flag-btn {
    opacity: 0.5;
    transition: opacity 0.15s, transform 0.15s;
    border-radius: 3px;
    overflow: hidden;
    display: inline-block;
}
.flag-btn:hover { opacity: 0.8; transform: scale(1.1); }
.flag-btn.active { opacity: 1; box-shadow: 0 0 0 2px var(--app-accent); }

/* ===== Layout ===== */
.app-layout {
    display: flex;
    flex: 1 0 auto;
    margin-top: 56px;
    min-height: calc(100vh - 56px - 48px);
}

.app-content {
    flex: 1 1 auto;
    min-width: 0;
    padding: 1.5rem;
}
@media (min-width: 992px) {
    .app-content { padding: 2rem 2.5rem; }
}

/* ===== Sidebar ===== */
.app-sidebar {
    width: var(--app-sidebar-width);
    background: var(--app-sidebar-bg);
    color: rgba(255, 255, 255, 0.7);
    flex-shrink: 0;
    position: sticky;
    top: 56px;
    height: calc(100vh - 56px);
    overflow-y: auto;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
}
.app-sidebar .sidebar-header {
    padding: 1.25rem 1.25rem 0.75rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255, 255, 255, 0.4);
}
.app-sidebar .nav-link {
    color: rgba(255, 255, 255, 0.7);
    padding: 0.625rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    font-size: 0.875rem;
    border-left: 3px solid transparent;
    transition: all 0.15s;
}
.app-sidebar .nav-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.05);
}
.app-sidebar .nav-link.active {
    color: #fff;
    background: rgba(0, 168, 107, 0.1);
    border-left-color: var(--app-accent);
}
.app-sidebar .nav-link i { font-size: 1.05rem; opacity: 0.8; }

/* ===== Footer ===== */
.app-footer {
    background: var(--app-primary-dark);
    color: rgba(255, 255, 255, 0.6);
    padding: 0.875rem 1.5rem;
    font-size: 0.8rem;
    flex-shrink: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

/* ===== Cards ===== */
.card {
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius-lg);
    box-shadow: var(--app-shadow-sm);
    background: var(--app-surface);
}
.card-header {
    background: var(--app-surface);
    border-bottom: 1px solid var(--app-border);
    padding: 1rem 1.25rem;
    font-weight: 600;
}
.card-header.bg-rt {
    background: linear-gradient(135deg, var(--app-primary) 0%, var(--app-primary-dark) 100%) !important;
    color: #fff;
    border-bottom: none;
}
.card-body { padding: 1.25rem; }

/* ===== Page header ===== */
.page-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--app-border);
}
.page-header h1, .page-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--app-text);
}
.page-header .text-muted { font-size: 0.85rem; }

/* ===== Forms (compact) ===== */
.form-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--app-text-muted);
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.form-label .req { color: #dc3545; margin-left: 2px; }
.form-control, .form-select {
    border-radius: 0.5rem;
    border: 1px solid var(--app-border);
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus, .form-select:focus {
    border-color: var(--app-accent);
    box-shadow: 0 0 0 3px rgba(0, 168, 107, 0.12);
}
.form-control.is-invalid, .form-select.is-invalid {
    border-color: #dc3545;
}
.invalid-feedback { font-size: 0.78rem; }

/* Language field group */
.lang-field-group {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
}
.lang-field {
    position: relative;
}
.lang-field .lang-flag {
    position: absolute;
    top: 50%;
    left: 0.625rem;
    transform: translateY(-50%);
    width: 18px;
    height: 13px;
    pointer-events: none;
}
.lang-field .form-control { padding-left: 2.25rem; }

/* ===== Buttons ===== */
.btn { border-radius: 0.5rem; font-weight: 500; padding: 0.5rem 1rem; font-size: 0.875rem; transition: all 0.15s; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn-primary { background: var(--app-primary); border-color: var(--app-primary); }
.btn-primary:hover { background: var(--app-primary-light); border-color: var(--app-primary-light); }
.btn-success { background: var(--app-accent); border-color: var(--app-accent); }
.btn-success:hover { background: #009762; border-color: #009762; }

/* ===== Tables ===== */
.table {
    margin-bottom: 0;
    font-size: 0.875rem;
}
.table thead th {
    background: var(--app-bg);
    border-bottom: 2px solid var(--app-border);
    color: var(--app-text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.75rem 1rem;
}
.table tbody td { padding: 0.75rem 1rem; vertical-align: middle; }
.table-hover tbody tr:hover { background: rgba(0, 168, 107, 0.04); }

/* ===== Badges ===== */
.badge { font-weight: 600; padding: 0.4em 0.65em; border-radius: 0.375rem; }
.badge.bg-success { background: var(--app-accent) !important; }
.badge.bg-secondary { background: var(--app-text-muted) !important; }

/* ===== Period tree ===== */
.period-tree { list-style: none; padding: 0; margin: 0; }
.period-tree ul { list-style: none; padding-left: 1.5rem; margin: 0; border-left: 2px dashed var(--app-border); }
.period-node {
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: box-shadow 0.15s, border-color 0.15s;
}
.period-node:hover {
    box-shadow: var(--app-shadow-md);
    border-color: var(--app-accent);
}
.period-node.is-year {
    border-left: 4px solid var(--app-accent);
    background: linear-gradient(90deg, rgba(0, 168, 107, 0.04) 0%, var(--app-surface) 100%);
}
.period-node.is-semester {
    border-left: 4px solid #f59e0b;
}
.period-node .toggle {
    background: none;
    border: none;
    color: var(--app-text-muted);
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.period-node .toggle:hover { color: var(--app-accent); }
.period-node .period-icon {
    width: 36px;
    height: 36px;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}
.period-node.is-year .period-icon { background: rgba(0, 168, 107, 0.12); color: var(--app-accent); }
.period-node.is-semester .period-icon { background: rgba(245, 158, 11, 0.12); color: #f59e0b; }
.period-node .period-title { font-weight: 600; font-size: 0.95rem; }
.period-node .period-dates { font-size: 0.8rem; color: var(--app-text-muted); font-variant-numeric: tabular-nums; }
.period-node .actions { margin-left: auto; opacity: 0; transition: opacity 0.15s; }
.period-node:hover .actions { opacity: 1; }
@media (max-width: 768px) {
    .period-node .actions { opacity: 1; }
}

/* Type badge */
.type-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2em 0.55em;
    border-radius: 0.3rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.type-badge.year { background: rgba(0, 168, 107, 0.12); color: var(--app-accent); }
.type-badge.semester { background: rgba(245, 158, 11, 0.12); color: #f59e0b; }
.type-badge.module { background: rgba(139, 92, 246, 0.12); color: #8b5cf6; }
.type-badge.session { background: rgba(239, 68, 68, 0.12); color: #ef4444; }

/* ===== Stat tiles (home) ===== */
.stat-tile {
    display: block;
    text-decoration: none;
    color: inherit;
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius-lg);
    padding: 1.5rem;
    height: 100%;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}
.stat-tile::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--tile-color, var(--app-accent));
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.2s;
}
.stat-tile:hover {
    transform: translateY(-2px);
    box-shadow: var(--app-shadow-lg);
    border-color: var(--tile-color, var(--app-accent));
}
.stat-tile:hover::before { transform: scaleX(1); }
.stat-tile .tile-icon {
    width: 48px;
    height: 48px;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 1rem;
    background: var(--tile-bg, rgba(0, 168, 107, 0.1));
    color: var(--tile-color, var(--app-accent));
}
.stat-tile .tile-title { font-weight: 600; font-size: 1rem; margin-bottom: 0.25rem; }
.stat-tile .tile-desc { font-size: 0.8rem; color: var(--app-text-muted); }

/* ===== Empty state ===== */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--app-text-muted);
}
.empty-state i { font-size: 3rem; opacity: 0.3; margin-bottom: 1rem; }

/* ===== Utilities ===== */
.text-muted { color: var(--app-text-muted) !important; }
.cursor-pointer { cursor: pointer; }

/* === Дополнения к app.css (ПУНКТ 4, 5, 6) === */

/* Sidebar footer — кнопка Back to Dashboard внизу */
.app-sidebar {
    display: flex;
    flex-direction: column;
}
.app-sidebar .sidebar-header { flex-shrink: 0; }
.app-sidebar > .nav,
.app-sidebar .offcanvas-body > .nav { flex-grow: 1; }
.sidebar-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding: 0.5rem 0;
    flex-shrink: 0;
}
.sidebar-footer .nav-link {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.85rem;
}
.sidebar-footer .nav-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.05);
}

/* === ПУНКТ 5: упрощённое дерево периодов (2 уровня) === */
.period-node.is-year {
    border-left: 4px solid var(--app-accent);
    background: linear-gradient(90deg, rgba(0, 168, 107, 0.05) 0%, var(--app-surface) 100%);
    font-weight: 600;
}
.period-node.is-semester {
    border-left: 4px solid #94a3b8;
    background: var(--app-surface);
}
.period-node .period-title { font-size: 0.95rem; }
.period-node.is-year .period-title { font-size: 1rem; }

/* === ПУНКТ 6: цвет плитки модуля на дашборде === */
.module-color-swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    vertical-align: middle;
    margin-right: 6px;
    border: 1px solid rgba(0,0,0,0.1);
}

/* === ПУНКТ 3: унифицированный confirm-delete === */
.confirm-delete-card {
    border: 1px solid #fca5a5;
    border-radius: var(--app-radius-lg);
    background: var(--app-surface);
    box-shadow: var(--app-shadow-md);
    overflow: hidden;
    max-width: 540px;
    margin: 2rem auto;
}
.confirm-delete-card .confirm-icon-wrap {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    padding: 2rem 1rem;
    text-align: center;
}
.confirm-delete-card .confirm-icon {
    font-size: 3rem;
    color: #dc2626;
}
.confirm-delete-card .confirm-body {
    padding: 1.5rem;
    text-align: center;
}
.confirm-delete-card .confirm-body h4 {
    margin-bottom: 0.5rem;
    font-weight: 600;
}
.confirm-delete-card .confirm-body .confirm-target {
    display: inline-block;
    background: var(--app-bg);
    padding: 0.25rem 0.6rem;
    border-radius: 0.375rem;
    font-weight: 600;
    margin: 0 0.25rem;
}
.confirm-delete-card .confirm-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    padding: 0 1.5rem 1.5rem;
}
.confirm-delete-card .confirm-meta {
    background: var(--app-bg);
    padding: 0.75rem 1.5rem;
    font-size: 0.8rem;
    color: var(--app-text-muted);
    border-top: 1px solid var(--app-border);
    text-align: center;
}

/* === ПУНКТ 5: подсказка валидации дат === */
.date-validation-hint {
    font-size: 0.78rem;
    color: var(--app-text-muted);
    margin-top: 0.35rem;
}
.date-validation-hint.error {
    color: #dc2626;
    font-weight: 500;
}


/* === Дополнения к app.css для Structure === */

.structure-node {
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    padding: 0.625rem 0.875rem;
    margin-bottom: 0.4rem;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    transition: box-shadow 0.15s, border-color 0.15s;
}
.structure-node:hover {
    box-shadow: var(--app-shadow-md);
}
.structure-node.is-unit {
    border-left: 4px solid #07294d;
    background: linear-gradient(90deg, rgba(7, 41, 77, 0.04) 0%, var(--app-surface) 100%);
    font-weight: 500;
}
.structure-node.is-speciality {
    border-left: 4px solid var(--app-accent);
    background: linear-gradient(90deg, rgba(0, 168, 107, 0.05) 0%, var(--app-surface) 100%);
}
.structure-node.is-group {
    border-left: 4px solid #f59e0b;
}
.structure-node .structure-icon {
    width: 32px;
    height: 32px;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}
.structure-node.is-unit .structure-icon { background: rgba(7, 41, 77, 0.1); color: #07294d; }
.structure-node.is-speciality .structure-icon { background: rgba(0, 168, 107, 0.12); color: var(--app-accent); }
.structure-node.is-group .structure-icon { background: rgba(245, 158, 11, 0.12); color: #f59e0b; }

.structure-node .structure-title { font-weight: 600; font-size: 0.92rem; }
.structure-node.is-unit .structure-title { font-size: 0.98rem; }
.structure-node .structure-meta { margin-top: 0.15rem; }
.structure-node .actions { margin-left: auto; opacity: 0; transition: opacity 0.15s; }
.structure-node:hover .actions { opacity: 1; }
@media (max-width: 768px) { .structure-node .actions { opacity: 1; } }

.structure-node .toggle {
    background: none; border: none; color: var(--app-text-muted);
    cursor: pointer; padding: 0; width: 20px; height: 20px;
    display: flex; align-items: center; justify-content: center;
}
.structure-node .toggle:hover { color: var(--app-accent); }

.structure-children { margin-left: 0.5rem; }

/* Type badges */
.type-badge.unit { background: rgba(7, 41, 77, 0.12); color: #07294d; }
.type-badge.speciality { background: rgba(0, 168, 107, 0.12); color: var(--app-accent); }
.type-badge.group { background: rgba(245, 158, 11, 0.12); color: #f59e0b; }
