/* Apex · Вершина — базовые стили оболочки */
:root {
    --bg: #f4f6f9;
    --panel: #ffffff;
    --ink: #1f2733;
    --muted: #6b7787;
    --line: #e4e8ee;
    --brand: #14385f;
    --brand-2: #1f6feb;
    --accent: #1f6feb;
    --red: #d64545;
    --red-bg: #fdeaea;
    --yellow: #c98a16;
    --yellow-bg: #fdf4e3;
    --green: #2f9e57;
    --green-bg: #e9f6ee;
    --grey: #9aa4b1;
    --grey-bg: #eef1f5;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(20, 40, 80, .08), 0 1px 2px rgba(20, 40, 80, .06);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--ink);
    font-family: "Segoe UI", Roboto, system-ui, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

.layout { display: flex; min-height: 100vh; }

/* ---- Боковая панель ---- */
.sidebar {
    width: 248px;
    flex-shrink: 0;
    background: var(--brand);
    color: #cdd9e8;
    display: flex;
    flex-direction: column;
    padding: 18px 14px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px 18px;
    color: #fff;
}
.brand-mark { font-size: 22px; color: #5aa2ff; }
.brand-text { font-size: 20px; font-weight: 700; letter-spacing: .5px; display: flex; flex-direction: column; line-height: 1; }
.brand-text small { font-size: 11px; font-weight: 400; color: #8fb3df; letter-spacing: 2px; margin-top: 3px; }
.brand-logo { display: block; width: 100%; max-width: 200px; border-radius: 10px; }

.nav { display: flex; flex-direction: column; gap: 3px; margin-top: 6px; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    color: #cdd9e8;
    text-decoration: none;
    font-size: 14.5px;
    transition: background .12s, color .12s;
}
.nav-item:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav-item.active { background: var(--brand-2); color: #fff; }
.nav-ico { width: 18px; text-align: center; opacity: .9; }
.ico { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item .ico { opacity: .85; }
.nav-item.active .ico { opacity: 1; }
.brand-mark .ico { width: 26px; height: 26px; color: #5aa2ff; }

.nav-row { display: flex; align-items: center; }
.nav-row .nav-item, .nav-parent { flex: 1; }
.nav-parent { font-weight: 600; }
.nav-caret {
    background: none; border: 0; color: #6f93bf; cursor: pointer; padding: 6px;
    display: inline-flex; align-items: center; border-radius: 6px;
}
.nav-caret:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.ico-caret { width: 16px; height: 16px; transition: transform .15s; }
.nav-group.closed .ico-caret { transform: rotate(-90deg); }
.nav-group.closed .nav-sub { display: none; }

.nav-sub {
    display: flex; flex-direction: column; gap: 3px;
    margin: 2px 0 8px 14px; padding-left: 8px;
    border-left: 1px solid rgba(255, 255, 255, .14);
}
.nav-sub .nav-item { font-size: 13.5px; }
.nav-section {
    flex: 1; padding: 6px 12px; font-size: 11px; text-transform: uppercase;
    letter-spacing: .6px; color: #6f93bf;
}

.sb-collapse {
    margin-left: auto; background: none; border: 0; color: #8fb3df; cursor: pointer;
    padding: 4px; border-radius: 6px; display: inline-flex;
}
.sb-collapse:hover { color: #fff; background: rgba(255, 255, 255, .08); }

/* свёрнутый сайдбар (иконочный режим) — только на десктопе */
@media (min-width: 861px) {
    .sidebar-collapsed .sidebar { width: 64px; padding: 18px 8px; }
    .sidebar-collapsed .brand-text,
    .sidebar-collapsed .nav-label,
    .sidebar-collapsed .nav-section,
    .sidebar-collapsed .nav-caret,
    .sidebar-collapsed .user-box,
    .sidebar-collapsed .ver { display: none; }
    .sidebar-collapsed .brand { justify-content: center; padding: 6px 0 18px; }
    .sidebar-collapsed .brand-logo { max-width: 46px; }
    .sidebar-collapsed .nav-row { justify-content: center; }
    .sidebar-collapsed .nav-sub { margin: 0; padding: 0; border-left: 0; }
    .sidebar-collapsed .nav-group.closed .nav-sub { display: flex; }
    .sidebar-collapsed .nav-item { justify-content: center; padding: 10px 0; gap: 0; }
    .sidebar-collapsed .logout-btn { justify-content: center; }
    .sidebar-collapsed .sb-collapse { transform: rotate(180deg); margin: 0 auto; }
}

.sidebar-foot { margin-top: auto; padding: 10px 12px; font-size: 12px; color: #6f93bf; }
.user-box { padding: 8px 0; border-top: 1px solid rgba(255,255,255,.12); }
.user-name { color: #fff; font-size: 13.5px; font-weight: 600; }
.user-role { color: #8fb3df; font-size: 12px; }
.logout-btn { width: 100%; margin: 8px 0; padding: 7px; background: rgba(255,255,255,.08); color: #cdd9e8; border: 1px solid rgba(255,255,255,.15); border-radius: 8px; cursor: pointer; font-size: 13px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.logout-btn .ico { width: 16px; height: 16px; }
.logout-btn:hover { background: rgba(255,255,255,.16); color: #fff; }
.ver { font-size: 11px; }

/* ---- Страницы входа / настройки ---- */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--brand); }
.auth-card { background: #fff; border-radius: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.25); padding: 32px; width: 360px; max-width: 92vw; }
.auth-brand { text-align: center; font-size: 20px; font-weight: 700; color: var(--brand); margin-bottom: 6px; }
.auth-brand img { max-width: 160px; max-height: 110px; border-radius: 10px; }
.auth-title { font-size: 18px; margin: 8px 0 18px; text-align: center; }
.form input[type=password] { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; font-family: inherit; }
.form input[type=password]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31,111,235,.12); }

/* ---- Контент ---- */
.content { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    padding: 16px 28px;
}
.page-title { margin: 0; font-size: 20px; font-weight: 650; }

.page-body { padding: 24px 28px; }

/* ---- Карточки ---- */
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    margin-bottom: 18px;
}
.card-title { margin: 0 0 8px; font-size: 16px; font-weight: 600; }
.muted { color: var(--muted); margin: 0; }

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}
.stat { text-align: center; padding: 22px 16px; }
.stat-num { font-size: 34px; font-weight: 700; line-height: 1; }
.stat-label { margin-top: 8px; font-size: 13px; color: var(--muted); }
.stat--red    { border-top: 3px solid var(--red); }
.stat--red    .stat-num { color: var(--red); }
.stat--yellow { border-top: 3px solid var(--yellow); }
.stat--yellow .stat-num { color: var(--yellow); }
.stat--green  { border-top: 3px solid var(--green); }
.stat--green  .stat-num { color: var(--green); }
.stat--grey   { border-top: 3px solid var(--grey); }
.stat--grey   .stat-num { color: var(--grey); }

/* ---- Заглушка раздела ---- */
.placeholder-badge {
    display: inline-block;
    background: var(--grey-bg);
    color: var(--muted);
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 20px;
    margin-bottom: 10px;
}

/* ---- Панель действий / хлебные крошки ---- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; }
.crumb { color: var(--muted); text-decoration: none; font-size: 14px; }
.crumb:hover { color: var(--accent); }

/* ---- Кнопки ---- */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    text-decoration: none;
    font-size: 14px;
    cursor: pointer;
    line-height: 1.2;
}
.btn:hover { background: #f3f5f8; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #195fce; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }

/* ---- Хаб справочников ---- */
.ref-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.ref-card { display: block; text-decoration: none; color: inherit; transition: box-shadow .12s, border-color .12s; }
.ref-card:hover { border-color: var(--accent); box-shadow: 0 3px 10px rgba(20,40,80,.12); }
.ref-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.ref-count {
    background: var(--grey-bg); color: var(--muted);
    font-size: 13px; font-weight: 600; min-width: 28px; text-align: center;
    padding: 2px 8px; border-radius: 14px;
}

/* ---- Таблица ---- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--line); }
.table thead th { background: #f7f9fc; color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .4px; }
.table tbody tr:hover { background: #fafbfd; }
.table tbody tr:last-child td { border-bottom: none; }
.col-actions { width: 1%; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; }

.badge { display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 12px; font-weight: 500; }
.badge--on { background: var(--green-bg); color: var(--green); }
.badge--off { background: var(--grey-bg); color: var(--muted); }

.link { color: var(--accent); text-decoration: none; font-size: 14px; }
.link:hover { text-decoration: underline; }
.link-danger { color: var(--red); background: none; border: none; padding: 0; cursor: pointer; font-size: 14px; margin-left: 14px; }
.link-danger:hover { text-decoration: underline; }
form.inline { display: inline; }

/* ---- Формы ---- */
.form-card { max-width: 640px; }
.field { margin-bottom: 16px; }
.field-label { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 6px; }
.req { color: var(--red); }
.form input[type=text], .form input[type=number], .form select, .form textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
    color: var(--ink);
}
.form input:focus, .form select:focus, .form textarea:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31,111,235,.12);
}
.field-check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.field-check input { width: 16px; height: 16px; }
.field-help { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.field-err { font-size: 12.5px; color: var(--red); margin-top: 5px; }
.field--error input, .field--error select { border-color: var(--red); }
.form-actions { display: flex; gap: 10px; margin-top: 22px; }

/* ---- Картотека: фильтры ---- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters select, .filters input[type=text], .filters input[type=search] {
    padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
    font-size: 13.5px; font-family: inherit; background: #fff; color: var(--ink);
}
.filters input[type=text], .filters input[type=search] { min-width: 230px; }
.toolbar-actions { display: flex; gap: 10px; align-items: center; }

/* ---- Карточка пилота ---- */
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 24px; }
.info-grid > div { display: flex; flex-direction: column; gap: 2px; }
.info-k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.info-v { font-size: 14.5px; }
.section-title { margin: 0; font-size: 17px; font-weight: 650; }
.group-head {
    padding: 10px 16px; background: #eef2f8; border-bottom: 1px solid var(--line);
    font-size: 13px; font-weight: 600; color: var(--brand); text-transform: uppercase; letter-spacing: .4px;
}

/* ---- Аватары и фото сотрудника ---- */
.avatar {
    display: inline-flex; align-items: center; justify-content: center;
    object-fit: cover; background: var(--grey-bg); color: var(--muted);
    font-weight: 600; overflow: hidden; flex-shrink: 0;
}
.avatar-lg { width: 140px; height: 140px; border-radius: 12px; font-size: 42px; }
.avatar-sm { width: 30px; height: 30px; border-radius: 50%; font-size: 12px; margin-right: 9px; }
.photo-ph { background: linear-gradient(135deg, #dbe6f5, #c0d4ee); color: var(--brand); text-transform: uppercase; }
img.avatar { object-fit: cover; }

.profile { display: flex; gap: 24px; align-items: flex-start; }
.profile-photo { display: flex; flex-direction: column; align-items: center; gap: 8px; flex-shrink: 0; }
.profile-info { flex: 1; min-width: 0; }
.photo-form { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.photo-input { width: 150px; font-size: 12px; }
.btn-small { padding: 5px 10px; font-size: 12.5px; }
.crew-namecell { display: inline-flex; align-items: center; }
.sort-link { color: inherit; text-decoration: none; }
.sort-link:hover { color: var(--accent); }
.sort-ar { color: var(--accent); font-size: 11px; }

/* ---- Уведомления ---- */
.alert { padding: 11px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert-error { background: var(--red-bg); color: var(--red); border: 1px solid #f3c4c4; }

/* ---- Статусы годности ---- */
.st { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 12px; white-space: nowrap; }
.st--expired  { background: var(--red-bg);    color: var(--red); }
.st--expiring { background: var(--yellow-bg); color: var(--yellow); }
.st--valid    { background: var(--green-bg);  color: var(--green); }
.st--none     { background: var(--grey-bg);   color: var(--muted); }
.st-lg { font-size: 13px; padding: 4px 12px; }

.card-title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.readiness-counts { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 16px; }

/* мягкая подсветка строк проверок по статусу */
.row--expired td  { background: rgba(214, 69, 69, .06); }
.row--expiring td { background: rgba(201, 138, 22, .07); }

/* история проверок */
.hist-row > td { background: #fafbfd; padding: 0; }
.hist-row details { padding: 2px 16px 8px; }
.hist-row summary { cursor: pointer; color: var(--muted); font-size: 12.5px; padding: 6px 0; }
.hist-table { font-size: 12.5px; margin-top: 4px; }
.hist-table td { border-bottom: 1px dashed var(--line); color: var(--muted); padding: 6px 10px; }
.hist-table tr:last-child td { border-bottom: none; }

/* единые ширины столбцов в таблицах проверок (выравнивание между категориями) */
.checks-table { table-layout: fixed; }
.checks-table th:nth-child(1), .checks-table td:nth-child(1) { width: 23%; }
.checks-table th:nth-child(2), .checks-table td:nth-child(2) { width: 10%; }
.checks-table th:nth-child(3), .checks-table td:nth-child(3) { width: 11%; }
.checks-table th:nth-child(4), .checks-table td:nth-child(4) { width: 13%; }
.checks-table th:nth-child(5), .checks-table td:nth-child(5) { width: 13%; }
.checks-table th:nth-child(6), .checks-table td:nth-child(6) { width: 18%; }
.checks-table th:nth-child(7), .checks-table td:nth-child(7) { width: 12%; }
.checks-table td { overflow-wrap: anywhere; }

/* ---- Печать карточки ---- */
.print-body { background: #f4f6f9; padding: 20px; }
.print-actions { max-width: 820px; margin: 0 auto 14px; display: flex; gap: 10px; }
.print-sheet { max-width: 820px; margin: 0 auto; background: #fff; padding: 30px 36px; box-shadow: var(--shadow); }
.print-head { display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid var(--brand); padding-bottom: 10px; margin-bottom: 18px; }
.print-app { font-weight: 700; color: var(--brand); }
.print-app img { max-height: 46px; }
.print-doc { color: var(--muted); font-size: 13px; }
.print-name { font-size: 22px; margin: 0 0 16px; display: flex; align-items: center; gap: 12px; }
.print-info { width: 100%; border-collapse: collapse; margin-bottom: 12px; font-size: 14px; }
.print-info td { padding: 6px 10px; border: 1px solid var(--line); }
.print-info td:nth-child(odd) { color: var(--muted); width: 18%; background: #f7f9fc; }
.print-cat { font-size: 13px; color: var(--brand); margin: 16px 0 6px; text-transform: uppercase; letter-spacing: .4px; }
.print-foot { margin-top: 22px; padding-top: 10px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; text-align: right; }
@media print {
    .print-actions { display: none; }
    .print-body { background: #fff; padding: 0; }
    .print-sheet { box-shadow: none; max-width: none; padding: 0; }
    .st { border: 1px solid #bbb; }
    .table th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---- Дашборд ---- */
.dash-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 1100px) { .dash-row { grid-template-columns: 1fr; } }
.bar { display: inline-block; width: 90px; height: 8px; background: var(--grey-bg); border-radius: 5px; overflow: hidden; vertical-align: middle; }
.bar-fill { height: 100%; background: var(--green); border-radius: 5px; }
.bar-label { font-size: 12.5px; color: var(--muted); margin-left: 8px; }

/* ---- Матрица годности ---- */
.matrix-wrap { padding: 0; overflow-x: auto; }
.matrix { font-size: 12.5px; }
.matrix th, .matrix td { padding: 7px 10px; border: 1px solid var(--line); white-space: nowrap; }
.matrix .mx-col { font-size: 12px; font-weight: 600; color: var(--brand); text-align: center; white-space: nowrap; }
.mx-sticky { position: sticky; left: 0; background: #fff; z-index: 1; min-width: 200px; }
.matrix thead .mx-sticky { background: #f7f9fc; }
.mx-cell { text-align: center; }
.mx--expired  { background: var(--red-bg);    color: var(--red); }
.mx--expiring { background: var(--yellow-bg); color: var(--yellow); }
.mx--valid    { background: var(--green-bg);  color: var(--green); }
.mx--none, .mx--empty { background: #fafbfd; color: var(--muted); }
.legend { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }

/* ---- Аналитика ---- */
.brow { display: grid; grid-template-columns: 160px 1fr 46px; align-items: center; gap: 12px; margin: 9px 0; }
.brow-label { font-size: 13px; }
.brow-val { font-size: 13px; font-weight: 600; text-align: right; color: var(--brand); }
.sbar { display: flex; height: 16px; background: var(--grey-bg); border-radius: 8px; overflow: hidden; }
.seg { height: 100%; }
.seg--valid { background: var(--green); }
.seg--expiring { background: var(--yellow); }
.seg--expired { background: var(--red); }
.seg--none { background: #cdd5e0; }

.forecast { display: flex; align-items: flex-end; gap: 6px; padding-top: 8px; overflow-x: auto; }
.fcol { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; flex: 1 0 40px; }
.fbar { width: 26px; height: 110px; background: var(--grey-bg); border-radius: 6px 6px 0 0; display: flex; align-items: flex-end; overflow: hidden; }
.fbar-fill { width: 100%; background: var(--brand-2); border-radius: 6px 6px 0 0; min-height: 2px; }
.fbar--expired { background: var(--red); }
.fcount { font-size: 12px; font-weight: 600; margin-top: 4px; }
.flabel { font-size: 10.5px; color: var(--muted); white-space: nowrap; }

/* печать матрицы (со страницы с боковой панелью) */
@media print {
    .sidebar, .topbar, .toolbar { display: none !important; }
    .page-body { padding: 0; }
    .matrix-wrap { overflow: visible; box-shadow: none; border: none; }
    .matrix { font-size: 9.5px; }
    .matrix th, .matrix td { padding: 3px 4px; }
    .st { border: 1px solid #bbb; }
}

/* ======== Адаптивность: телефоны и планшеты ======== */
.nav-toggle { display: none; background: none; border: 0; font-size: 22px; line-height: 1;
    color: var(--ink); cursor: pointer; padding: 2px 4px; }
.nav-backdrop { display: none; }

@media (max-width: 860px) {
    .nav-toggle { display: inline-flex; align-items: center; }
    .sb-collapse { display: none; }
    .topbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px;
        position: sticky; top: 0; z-index: 30; }
    .page-title { font-size: 17px; }
    .page-body { padding: 14px; }

    .sidebar {
        position: fixed; top: 0; left: 0; height: 100%; width: 240px;
        transform: translateX(-100%); transition: transform .2s ease;
        z-index: 50; box-shadow: 2px 0 18px rgba(0, 0, 0, .35);
    }
    body.nav-open .sidebar { transform: translateX(0); }
    body.nav-open .nav-backdrop {
        display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 40;
    }

    /* широкие таблицы и матрица — горизонтальная прокрутка внутри карточки */
    .card { overflow-x: auto; }

    /* карточка пилота — фото над данными */
    .profile { flex-direction: column; }
    .profile-info { width: 100%; }

    /* фильтры — на всю ширину строки */
    .filters { width: 100%; }
    .filters select, .filters input[type=text], .filters input[type=search] { flex: 1 1 140px; min-width: 0; }

    /* аналитика и инфо-сетка — компактнее */
    .brow { grid-template-columns: 96px 1fr 38px; gap: 8px; }
    .info-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
    .info-grid { grid-template-columns: 1fr; }
    .avatar-lg { width: 110px; height: 110px; font-size: 34px; }
    .cards { grid-template-columns: 1fr 1fr; }
}
