/* ==========================================================================
   style.css — единая тема системы учёта ТС и оборудования
   Фиолетово-синяя гамма, карточки, адаптивная вёрстка
   ========================================================================== */

:root {
    --c-primary: #6a5cf0;
    --c-primary-dark: #4b3fb8;
    --c-secondary: #3a8bf5;
    --c-bg: #f4f3fc;
    --c-surface: #ffffff;
    --c-text: #2c2560;
    --c-text-muted: #6b6690;
    --c-border: #e4e1f7;

    --c-success: #1c9e5b;
    --c-success-bg: #e6f8ef;
    --c-warning: #b98900;
    --c-warning-bg: #fff6e0;
    --c-danger: #d43b3b;
    --c-danger-bg: #fdecec;
    --c-info: #7b3ff2;
    --c-info-bg: #f1eafe;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 8px 24px rgba(60, 40, 140, .08);
    --shadow-lg: 0 20px 60px rgba(30, 20, 90, .25);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
    background: var(--c-bg);
    color: var(--c-text);
    font-size: 14px;
}

a { color: var(--c-primary-dark); }

/* ---------------------------------------------------------------- Layout */

.app-header {
    background: linear-gradient(120deg, var(--c-primary-dark), var(--c-primary) 55%, var(--c-secondary));
    color: #fff;
    padding: 14px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
    flex-wrap: wrap;
    gap: 12px;
}

.app-header .brand {
    font-weight: 700;
    font-size: 17px;
    letter-spacing: .2px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-nav {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.app-nav a {
    color: rgba(255,255,255,.85);
    text-decoration: none;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    transition: background .15s;
}

.app-nav a:hover, .app-nav a.active {
    background: rgba(255,255,255,.18);
    color: #fff;
}

.app-user {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}

.app-user .role-badge {
    background: rgba(255,255,255,.2);
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.app-user a.logout {
    color: #fff;
    text-decoration: none;
    opacity: .85;
}
.app-user a.logout:hover { opacity: 1; }

.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 24px 28px 60px;
}

.page-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}

.page-title h1 {
    font-size: 21px;
    margin: 0;
    color: var(--c-text);
}

.page-title p.subtitle {
    margin: 4px 0 0;
    color: var(--c-text-muted);
    font-size: 13px;
}

/* ---------------------------------------------------------------- Cards */

.card {
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    border-left: 5px solid var(--c-primary);
    position: relative;
    overflow: hidden;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--c-text);
    line-height: 1;
}

.stat-card .stat-label {
    margin-top: 6px;
    color: var(--c-text-muted);
    font-size: 12.5px;
    font-weight: 600;
}

.stat-card.status-active  { border-color: var(--c-success); }
.stat-card.status-reserve { border-color: var(--c-warning); }
.stat-card.status-repair  { border-color: var(--c-danger); }
.stat-card.status-requests{ border-color: var(--c-info); }

/* ---------------------------------------------------------------- Table */

.table-wrap {
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

thead th {
    text-align: left;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--c-text-muted);
    padding: 12px 14px;
    border-bottom: 2px solid var(--c-border);
    white-space: nowrap;
}

tbody td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--c-border);
    vertical-align: middle;
}

tbody tr:hover { background: #faf9ff; }
tbody tr:last-child td { border-bottom: none; }

.thumb {
    width: 42px;
    height: 42px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--c-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--c-text-muted);
}

/* ---------------------------------------------------------------- Badges */

.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 700;
}

.badge-active, .badge-open      { background: var(--c-success-bg); color: var(--c-success); }
.badge-reserve, .badge-in_progress { background: var(--c-warning-bg); color: var(--c-warning); }
.badge-repair, .badge-closed    { background: var(--c-danger-bg); color: var(--c-danger); }
.badge-archive                  { background: #eee; color: #777; }
.badge-info                     { background: var(--c-info-bg); color: var(--c-info); }

/* -------------------------------------------------------------- Buttons */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    transition: opacity .15s, transform .1s;
    line-height: 1.2;
}
.btn:active { transform: scale(.97); }

.btn-primary { background: linear-gradient(120deg, var(--c-primary), var(--c-secondary)); color: #fff; }
.btn-outline { background: #fff; color: var(--c-primary-dark); border: 1px solid var(--c-border); }
.btn-danger  { background: var(--c-danger-bg); color: var(--c-danger); }
.btn-ghost   { background: transparent; color: var(--c-text-muted); }
.btn-sm      { padding: 6px 10px; font-size: 12px; }
.btn:hover   { opacity: .9; }
.btn:disabled{ opacity: .4; cursor: not-allowed; }

.icon-btn {
    border: none;
    background: var(--c-bg);
    border-radius: var(--radius-sm);
    width: 30px;
    height: 30px;
    cursor: pointer;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.icon-btn:hover { background: var(--c-border); }

/* --------------------------------------------------------------- Forms */

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}

label {
    display: block;
    font-size: 12.5px;
    font-weight: 700;
    color: var(--c-text);
    margin-bottom: 6px;
}

input[type=text], input[type=password], input[type=number],
input[type=date], input[type=email], input[type=file],
select, textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    background: #fff;
    font-family: inherit;
    color: var(--c-text);
    outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--c-primary); }
textarea { resize: vertical; min-height: 72px; }

.field { margin-bottom: 14px; }

.filters-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
    align-items: flex-end;
}
.filters-bar .field { margin-bottom: 0; min-width: 160px; }
.filters-bar .field.search { flex: 1; min-width: 220px; }

/* -------------------------------------------------------------- Modals */

.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(30, 20, 70, .45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}
.modal-backdrop.open { display: flex; }

.modal {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px 26px;
}
.modal.modal-wide { max-width: 760px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-close {
    background: none; border: none; font-size: 20px; cursor: pointer; color: var(--c-text-muted);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}

/* -------------------------------------------------------------- Alerts */

.alert { padding: 12px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 14px; }
.alert-error   { background: var(--c-danger-bg); color: var(--c-danger); }
.alert-success { background: var(--c-success-bg); color: var(--c-success); }
.alert-warning { background: var(--c-warning-bg); color: var(--c-warning); }
.alert-info    { background: var(--c-info-bg); color: var(--c-info); }

.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    min-width: 220px;
    animation: toast-in .2s ease;
}
.toast-success { background: var(--c-success); }
.toast-error   { background: var(--c-danger); }
@keyframes toast-in { from { transform: translateY(-8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ------------------------------------------------------------- Helpers */

.flex { display: flex; align-items: center; gap: 8px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.muted { color: var(--c-text-muted); }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.empty-state {
    text-align: center;
    padding: 50px 20px;
    color: var(--c-text-muted);
}
.empty-state .emoji { font-size: 36px; margin-bottom: 10px; }

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--c-border); margin-bottom: 18px; }
.tabs button {
    background: none; border: none; padding: 10px 16px; font-size: 13.5px; font-weight: 700;
    color: var(--c-text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.tabs button.active { color: var(--c-primary-dark); border-color: var(--c-primary); }

.doc-list, .equip-list, .req-list { display: flex; flex-direction: column; gap: 10px; }
.list-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px; border: 1px solid var(--c-border); border-radius: var(--radius-sm); gap: 12px; flex-wrap: wrap;
}
.list-item .li-main { display: flex; align-items: center; gap: 10px; }
.list-item .li-title { font-weight: 700; }
.list-item .li-sub { font-size: 12px; color: var(--c-text-muted); }

/* ------------------------------------------------------------ Auth page */

.auth-wrap {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--c-primary-dark), var(--c-primary) 45%, var(--c-secondary));
    padding: 20px;
}
.auth-card {
    background: #fff; border-radius: 16px; max-width: 400px; width: 100%;
    padding: 36px 34px; box-shadow: var(--shadow-lg);
}
.auth-card h1 { font-size: 21px; margin: 0 0 4px; }
.auth-card p.subtitle { margin: 0 0 24px; color: var(--c-text-muted); font-size: 13px; }
.auth-card button { width: 100%; justify-content: center; padding: 11px; margin-top: 8px; }
.demo-creds { margin-top: 20px; font-size: 11.5px; color: var(--c-text-muted); line-height: 1.6; }
.demo-creds code { background: var(--c-bg); padding: 1px 5px; border-radius: 4px; }

/* ------------------------------------------------------------ Responsive */

@media print {
    @page { size: landscape; margin: 10mm; }

    .app-header, .app-nav, .filters-bar, .no-print, .app-user { display: none !important; }
    body { background: #fff; font-size: 11px; }
    .container { padding: 0; max-width: none; }
    .card, .table-wrap { box-shadow: none; border: 1px solid #ccc; overflow: visible; }

    table { min-width: 0 !important; width: 100% !important; table-layout: fixed; font-size: 10px; }
    thead { display: table-header-group; } /* заголовок повторяется на каждой печатной странице */
    tr { page-break-inside: avoid; }

    th, td {
        padding: 4px 6px !important;
        white-space: normal !important;
        overflow-wrap: break-word;
        word-break: break-word;
    }

    .stats-grid { grid-template-columns: repeat(6, 1fr); gap: 6px; margin-bottom: 12px; }
    .stat-card { padding: 8px; box-shadow: none; border: 1px solid #ddd; }
    .stat-card .stat-value { font-size: 16px; }
    .stat-card .stat-label { font-size: 10px; }

    .badge { border: 1px solid currentColor; background: none !important; }
}

@media (max-width: 720px) {
    .app-header { padding: 12px 16px; }
    .app-nav { width: 100%; order: 3; }
    .container { padding: 16px; }
    .page-title h1 { font-size: 18px; }
    table { min-width: 620px; }
}
