:root {
    --green-900: #1f4d2b;
    --green-700: #2e7d40;
    --green-600: #3a9150;
    --green-100: #e7f3ea;
    --gold: #e8a916;
    --gold-dark: #c98a00;
    --ink: #1d2421;
    --muted: #6b7770;
    --line: #e2e7e3;
    --bg: #f4f6f4;
    --card: #ffffff;
    --red: #c0392b;
    --red-bg: #fdecea;
    --blue: #2563eb;
    --blue-bg: #e8f0fe;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.5;
}

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

/* ---------- Шапка ---------- */
.topbar {
    background: linear-gradient(180deg, var(--green-900), var(--green-700));
    color: #fff;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 10px 18px;
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand-logo {
    width: 46px; height: 46px; border-radius: 50%;
    background: #fff; padding: 3px; object-fit: contain;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-org { font-weight: 700; font-size: 15px; }
.brand-sys { font-size: 12px; color: var(--gold); letter-spacing: .3px; }

.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a {
    color: #eaf3ec; padding: 7px 11px; border-radius: 8px; font-size: 14px;
}
.nav a:hover { background: rgba(255,255,255,.14); text-decoration: none; }

.user-area { display: flex; align-items: center; gap: 10px; }
.user-chip {
    display: flex; flex-direction: column; align-items: flex-end;
    color: #fff; font-size: 13px; line-height: 1.2; gap: 5px;
}
.user-chip:hover { text-decoration: none; opacity: .9; }
.user-name { font-weight: 600; }

/* ---------- Контейнер / подвал ---------- */
.container { max-width: 1180px; margin: 24px auto; padding: 0 18px; }
.site-footer {
    max-width: 1180px; margin: 40px auto 24px; padding: 16px 18px;
    border-top: 1px solid var(--line); color: var(--muted); font-size: 13px;
    display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
}

h1.page-title { font-size: 24px; margin: 0 0 6px; }
.page-sub { color: var(--muted); margin: 0 0 20px; }

/* ---------- Карточки / панели ---------- */
.card {
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px;
    margin-bottom: 18px;
}
.panel-title { font-size: 16px; font-weight: 700; margin: 0 0 14px; }
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; align-items: start; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Формы ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 600; color: #2c3530; }
.field .req { color: var(--red); }
input[type=text], input[type=email], input[type=tel], input[type=password],
input[type=search], select, textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--line);
    border-radius: 8px; font-size: 14px; font-family: inherit; background: #fff;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--green-600); box-shadow: 0 0 0 3px var(--green-100);
}
textarea { resize: vertical; min-height: 110px; }
.hint { font-size: 12px; color: var(--muted); }
.form-actions { margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Кнопки ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
    border: 1px solid transparent; border-radius: 8px; padding: 10px 16px;
    font-size: 14px; font-weight: 600; font-family: inherit; background: #eef1ee; color: var(--ink);
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn-primary { background: var(--green-700); color: #fff; }
.btn-gold { background: var(--gold); color: #3a2c00; }
.btn-danger { background: var(--red-bg); color: var(--red); border-color: #f3c9c4; }
.btn-ghost { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.4); }
.btn-ghost:hover { background: rgba(255,255,255,.22); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Бейджи ---------- */
.badge {
    display: inline-block; padding: 3px 10px; border-radius: 999px;
    font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-waiting { background: #fff3d6; color: #8a6100; }
.badge-in_progress { background: var(--blue-bg); color: var(--blue); }
.badge-done { background: var(--green-100); color: var(--green-700); }
.badge-role { background: rgba(255,255,255,.18); color: #fff; }
.badge-type { background: #eef1ee; color: #3a4540; }

/* Уровни критичности (SLA) */
.badge-crit-s1 { background: #fde0df; color: #b3261e; }
.badge-crit-s2 { background: #ffe6cc; color: #b35a00; }
.badge-crit-s3 { background: #fff3d6; color: #8a6100; }
.badge-crit-s4 { background: #e9eef0; color: #4a5a60; }
.crit-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; vertical-align: baseline; }
.crit-dot-s1 { background: #b3261e; }
.crit-dot-s2 { background: #d97706; }
.crit-dot-s3 { background: #d9a406; }
.crit-dot-s4 { background: #8aa0a8; }

/* Соблюдение SLA */
.sla-ok { color: #1e7a34; }
.sla-breach { color: #b3261e; font-weight: 700; }
.sla-pill { padding: 2px 9px; border-radius: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.sla-pill-ok { background: #e7f6ec; color: #1e7a34; }
.sla-pill-breach { background: #fde0df; color: #b3261e; }
.crit-legend { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 18px; margin-top: 10px; }
.crit-legend .ci { font-size: 12.5px; color: #444; }
@media (max-width: 860px) { .crit-legend { grid-template-columns: 1fr; } }

/* ---------- Таблицы ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; }
.table tr:hover td { background: #fafbfa; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* На десктопе широкие таблицы держат ширину; на мобильных (см. медиазапрос ниже)
   превращаются в карточки с подписями колонок — без горизонтального скролла. */
.table-wide { min-width: 720px; }

/* ---------- Карточки пользователей (управление учётками) ---------- */
.user-cards { display: flex; flex-direction: column; gap: 12px; }
.user-card { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; background: #fff; }
.user-card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.user-card-head .uname { font-weight: 700; font-size: 15px; }
.user-card-head .ufull { color: var(--ink); }
.user-card-controls { display: flex; gap: 12px 18px; flex-wrap: wrap; align-items: center; }
.uc-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.uc-form input[type=text], .uc-form input[type=password] { width: auto; min-width: 150px; }
.uc-form select { width: auto; }
.uc-check { display: flex; align-items: center; gap: 5px; font-size: 13px; white-space: nowrap; }
.uc-check input { width: auto; }

/* ---------- Ключ-значение ---------- */
.kv { display: grid; grid-template-columns: 200px 1fr; gap: 8px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }

/* ---------- Канбан ---------- */
.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.board-col { background: #eef1ee; border-radius: var(--radius); padding: 12px; min-height: 200px; }
.board-col.drop-hover { outline: 2px dashed var(--green-600); outline-offset: -4px; }
.board-col-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.board-col-head h3 { margin: 0; font-size: 15px; }
.col-count { background: #fff; border-radius: 999px; padding: 1px 9px; font-size: 12px; color: var(--muted); }
.ticket-card {
    display: block; background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--green-600);
    border-radius: 8px; padding: 12px; margin-bottom: 10px; box-shadow: var(--shadow); color: var(--ink);
}
.ticket-card:hover { text-decoration: none; border-left-color: var(--gold); }
.ticket-card[draggable=true] { cursor: grab; }
.ticket-card.dragging { opacity: .5; }
.tc-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.tc-num { font-weight: 700; }
.tc-desc { font-size: 13px; color: #39443e; margin: 6px 0; }
.tc-meta { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }

/* ---------- Фильтры ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters .field { gap: 4px; }
.filters select, .filters input { min-width: 150px; }

/* ---------- Flash ---------- */
.flash-area { margin-bottom: 18px; display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 11px 14px; border-radius: 8px; font-size: 14px; border: 1px solid transparent; }
.flash-info { background: var(--blue-bg); color: var(--blue); border-color: #cfe0fb; }
.flash-success { background: var(--green-100); color: var(--green-700); border-color: #c7e6cf; }
.flash-error { background: var(--red-bg); color: var(--red); border-color: #f3c9c4; }

/* ---------- Таймлайн / журнал ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before {
    content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px;
    border-radius: 50%; background: var(--green-600);
}
.timeline .ts { font-size: 12px; color: var(--muted); }

.time-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat { background: #fafbfa; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 16px; font-weight: 700; }

.hero {
    background: linear-gradient(120deg, var(--green-100), #fff);
    border: 1px solid var(--line);
}

.notice { padding: 12px 14px; border-radius: 8px; background: var(--green-100); color: var(--green-900); font-size: 14px; }

/* ---------- Адаптив ---------- */
@media (max-width: 860px) {
    .form-grid { grid-template-columns: 1fr; }
    .grid-2 { grid-template-columns: 1fr; gap: 14px; }
    .board { grid-template-columns: 1fr; }
    .kv { grid-template-columns: 1fr; gap: 2px 0; }
    .kv dt { margin-top: 8px; }
    .nav { order: 3; width: 100%; }
    .nav a { padding: 6px 9px; font-size: 13px; }
    .container { margin: 16px auto; padding: 0 14px; }
    .card { padding: 16px; }
    .topbar-inner { padding: 8px 14px; gap: 10px; }
    .page-title { font-size: 21px; }
    .filters { gap: 8px; }
    .filters select, .filters input { min-width: 130px; }
}

/* Широкие таблицы на телефоне → карточки: каждая строка отдельным блоком,
   у каждой ячейки подпись из data-label. Без горизонтального скролла. */
@media (max-width: 720px) {
    .table-wide { min-width: 0; }
    .table-wide thead { display: none; }
    .table-wide tbody, .table-wide tr, .table-wide td { display: block; width: 100%; }
    .table-wide tr { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 12px; padding: 4px 12px; }
    .table-wide tr:hover td { background: transparent; }
    .table-wide td { border: none; padding: 8px 0; display: flex; justify-content: space-between;
                     align-items: baseline; gap: 14px; text-align: right; }
    .table-wide td:not(:last-child) { border-bottom: 1px solid var(--line); }
    .table-wide td::before { content: attr(data-label); color: var(--muted); font-size: 12px;
                             font-weight: 600; text-align: left; white-space: nowrap; }
    .table-wide td:last-child { justify-content: stretch; }
    .table-wide td:last-child .btn { width: 100%; justify-content: center; }
}
