/* Atlant Armour KP — styles */
:root {
    --bg: #f4f4f5; --surface: #fff; --text: #222; --text-muted: #6b6f76;
    --primary: #a3241c; --primary-light: #c22e22; --primary-bg: #fbebe9;
    --border: #e0e0e2; --danger: #c0392b; --warning: #c9711c; --success: #3f8a4a;
    --radius: 8px; --shadow: 0 1px 3px rgba(0,0,0,.08);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; font-size: 14px; }

/* Header */
.header { display: flex; align-items: center; gap: 20px; padding: 10px 20px; background: var(--primary); color: #fff; position: sticky; top: 0; z-index: 100; }
.header__logo { font-size: 18px; font-weight: 700; white-space: nowrap; }
.header__sub { font-weight: 300; opacity: .7; }
.header__nav { display: flex; gap: 4px; flex: 1; }
.header__nav a { color: rgba(255,255,255,.8); text-decoration: none; padding: 6px 12px; border-radius: var(--radius); font-size: 13px; }
.header__nav a:hover, .header__nav a.active { background: rgba(255,255,255,.15); color: #fff; }
.header__user { font-size: 13px; white-space: nowrap; }
.header__user a { color: rgba(255,255,255,.7); margin-left: 10px; cursor: pointer; }

/* Layout */
.main { max-width: 1100px; margin: 20px auto; padding: 0 20px; }

/* Cards */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.card__title { font-size: 16px; font-weight: 600; margin-bottom: 12px; }

/* Tables */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; padding: 8px 10px; border-bottom: 2px solid var(--border); font-weight: 600; color: var(--text-muted); font-size: 12px; text-transform: uppercase; }
.table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:hover td { background: var(--primary-bg); }
.table .num { text-align: center; width: 40px; }
.table .price { text-align: right; white-space: nowrap; }

/* Log table: fixed narrow columns, the message takes what is left */
.table--logs { table-layout: fixed; }
.table--logs .col-when { width: 150px; }
.table--logs .col-level { width: 90px; }
.table--logs .col-source { width: 200px; }
.table--logs td { word-break: break-word; }
.table--logs .log__when { white-space: nowrap; }
.table--logs .log__source { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.table--logs .log__msg { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border: none; border-radius: var(--radius); font-size: 13px; cursor: pointer; font-weight: 500; transition: .15s; }
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-light); }
.btn--outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn--outline:hover { border-color: var(--primary); color: var(--primary); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--sm { padding: 4px 10px; font-size: 12px; }
.btn--block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; text-transform: uppercase; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
textarea, select {
    width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius);
    font-size: 14px; font-family: inherit; background: var(--surface); color: var(--text);
}
textarea { resize: vertical; min-height: 80px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-bg); }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge--new { background: #ececed; color: #4b4f56; }
.badge--draft { background: #fff3e0; color: #e65100; }
.badge--sent { background: var(--primary-bg); color: var(--primary); }
.badge--confirmed { background: #e8f5e9; color: var(--success); }
.badge--warning { background: #fff3e0; color: var(--warning); }

/* Notification dot */
.notif-dot { display: inline-block; width: 8px; height: 8px; background: var(--danger); border-radius: 50%; margin-left: 4px; vertical-align: super; }

/* PDF preview */
.pdf-frame { width: 100%; height: 600px; border: 1px solid var(--border); border-radius: var(--radius); }

/* Grid */
.grid { display: grid; gap: 16px; }
.grid--2 { grid-template-columns: 1fr 1fr; }
.grid--3 { grid-template-columns: 1fr 1fr 1fr; }

/* Flex */
.flex { display: flex; gap: 10px; align-items: center; }
.flex--between { justify-content: space-between; }
.flex--end { justify-content: flex-end; }
.flex--wrap { flex-wrap: wrap; }

/* Toast */
.toast-container { position: fixed; top: 60px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 10px 16px; border-radius: var(--radius); color: #fff; font-size: 13px; animation: slideIn .3s; max-width: 350px; }
.toast--success { background: var(--success); }
.toast--error { background: var(--danger); }
.toast--info { background: #4b4f56; }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* Login */
.login-wrap { display: flex; justify-content: center; align-items: center; min-height: 80vh; }
.login-box { width: 340px; }

/* Loading */
.loading { text-align: center; padding: 40px; color: var(--text-muted); }

/* Responsive */
@media (max-width: 768px) {
    .grid--2, .grid--3 { grid-template-columns: 1fr; }
    .header { flex-wrap: wrap; gap: 8px; }
    .header__nav { order: 3; width: 100%; overflow-x: auto; }
    .pdf-frame { height: 400px; }
}

/* ==== Module 002: orders, invoices, company chat ==== */

/* Utility text */
.muted { color: var(--text-muted); font-size: 12px; }
.ok { color: var(--success); font-weight: 600; }
.no { color: var(--danger); font-weight: 600; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; word-break: break-all; }

/* Request type + unanswered badges */
.badge--order { background: #fdecea; color: #b3261e; }
.badge--kp { background: #ececed; color: #4b4f56; }
/* Triage categories that never become a request — muted, they need no attention */
.badge--muted { background: var(--bg); color: var(--text-muted); }
.badge--unanswered { margin-left: 6px; }
.badge--warn { background: #fff3e0; color: var(--warning); }
.badge--critical { background: #fdecea; color: var(--danger); }

/* Unanswered rows (FR-038) */
.row--unanswered td { background: #fffaf0; }
.row--unanswered.row--critical td { background: #fdf1f0; box-shadow: inset 3px 0 0 var(--danger); }
.row--unanswered.row--warn td { box-shadow: inset 3px 0 0 var(--warning); }
.table tr.row--unanswered:hover td { background: var(--primary-bg); }

/* Inline settings strip on the request card */
.card--inline { display: flex; align-items: center; gap: 10px; padding: 12px 20px; flex-wrap: wrap; }
.card--inline select { width: auto; min-width: 150px; }

/* Company card layout */
.grid--chat { grid-template-columns: 1.4fr 1fr; align-items: start; }

/* Chat feed (FR-033) */
.chat { max-height: 60vh; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 4px; }
.msg { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; font-size: 13px; }
.msg__head { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.msg__subject { font-weight: 600; margin-bottom: 4px; }
.msg__body { white-space: pre-wrap; word-break: break-word; max-height: 260px; overflow-y: auto; }
.msg__files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.msg--in { background: #fff; border-left: 3px solid #9aa0a6; }
.msg--out { background: var(--primary-bg); border-left: 3px solid var(--primary); margin-left: 24px; }
.msg--note { background: #fffdf3; border-left: 3px solid var(--warning); }
.msg--system { font-style: italic; }
.chat__composer { display: flex; gap: 8px; align-items: flex-end; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.chat__composer textarea { min-height: 44px; }
.chat__composer .btn { white-space: nowrap; }

/* Attachment chips */
.chip { display: inline-block; padding: 2px 8px; border: 1px solid var(--border); border-radius: 12px; font-size: 12px; text-decoration: none; color: var(--text); background: #fff; }
.chip:hover { border-color: var(--primary); color: var(--primary); }

/* Invoice block */
.invoice { padding: 10px 0; border-bottom: 1px solid var(--border); }
.invoice:last-child { border-bottom: none; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; z-index: 300; padding: 20px; }
.modal__box { width: 100%; max-width: 460px; margin: 0; max-height: 85vh; overflow-y: auto; }

@media (max-width: 768px) {
    .grid--chat { grid-template-columns: 1fr; }
    .msg--out { margin-left: 0; }
    .chat { max-height: none; }
}

/* ==== Module 004: admin console, logs, mail ==== */

/* Tab strip of the admin console */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tab { padding: 8px 14px; font-size: 13px; text-decoration: none; color: var(--text-muted); border-bottom: 2px solid transparent; }
.tab:hover { color: var(--primary); }
.tab--active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* One setting row: label + source, the field, the reset button */
.setting { display: grid; grid-template-columns: 1fr 320px auto; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.setting:last-child { border-bottom: none; }
.setting__label label { font-weight: 600; display: block; }
.setting__label .muted { margin-top: 2px; }
.setting__actions { min-width: 90px; text-align: right; }

/* Counter next to a nav item */
.pill { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: rgba(255,255,255,.25); font-size: 11px; text-align: center; }
.pill--danger { background: var(--danger); color: #fff; }

/* A card that reports a problem */
.card--alert { border-left: 3px solid var(--danger); }

/* Mail list */
.row--unread td { font-weight: 600; background: #f7f5f4; }
.row--off td { opacity: .55; }

@media (max-width: 768px) {
    .setting { grid-template-columns: 1fr; }
    .setting__actions { text-align: left; }
}

/* «Подходящие позиции» on a request card: two lines per position — the name over
   the full width of the card (it is the long field), the numbers under it */
.match-row { display: grid; grid-template-columns: 76px 66px 90px minmax(0,130px) minmax(0,1fr) auto auto;
             gap: 6px; align-items: center; padding-bottom: 10px; margin-bottom: 10px;
             border-bottom: 1px solid var(--border); }
.match-row input[type="text"], .match-row input[type="number"] { width: 100%; }
.match-row__name { grid-column: 1 / -1; position: relative; min-width: 0; }
.match-row__name .muted { font-size: 12px; margin-bottom: 2px; }
.match-row label { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.price-opts-slot:empty { display: none; }
.price-opts { font-size: 12px; padding: 6px 8px; }

/* Catalog autocomplete under the position name */
.suggest { position: absolute; z-index: 30; left: 0; right: 0; top: 100%;
           background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
           box-shadow: 0 4px 12px rgba(0,0,0,.15); max-height: 260px; overflow-y: auto; }
.suggest__item { padding: 6px 10px; cursor: pointer; font-size: 13px; border-bottom: 1px solid var(--border); }
.suggest__item:last-child { border-bottom: none; }
.suggest__item:hover { background: var(--primary-bg); }

/* Photo picker of a KP position */
.item-card__photos { margin-top: 10px; }
.photos { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.photo { position: relative; width: 84px; height: 84px; border: 2px solid var(--border);
         border-radius: var(--radius); overflow: hidden; cursor: pointer; opacity: .45; }
.photo--on { border-color: var(--primary); opacity: 1; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo input { position: absolute; top: 4px; left: 4px; z-index: 2; }

/* ==== Mail client: threads (module 010) ====
   A mail program's list is small type: the subject leads, everything else —
   who wrote, from which mailbox, the first line — is grey and half a size down. */
.card--flush { padding: 0; overflow: hidden; }
.mlist { display: flex; flex-direction: column; }
.mlist__empty { padding: 30px; text-align: center; color: var(--text-muted); }
.mrow { display: grid; grid-template-columns: 38px minmax(0,1fr) auto; gap: 8px;
        padding: 8px 16px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 12px; }
.mrow:hover { background: var(--primary-bg); }
.mrow--unread { background: #fbfbf5; }
.mrow--unread .mrow__subject { font-weight: 700; }
.mrow__dir { font-size: 14px; white-space: nowrap; }
.mrow__clip { margin-left: 2px; }
.mrow__main { min-width: 0; }
.mrow__subject { font-size: 13px; color: var(--text); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
/* «Тема · 4» — how many letters the conversation already holds */
.mrow__count { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px;
               background: var(--border); color: var(--text-muted); font-size: 11px; text-align: center; font-weight: 600; }
.mrow__meta { color: var(--text-muted); margin-top: 1px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mrow__meta a { color: var(--primary); }
.mrow__preview { color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.mrow__date { color: var(--text-muted); white-space: nowrap; }
.chip--box { padding: 0 6px; font-size: 11px; background: var(--primary-bg); border-color: var(--primary-bg); color: var(--primary); }

/* One conversation, every mailbox, oldest first */
.thread { display: flex; flex-direction: column; gap: 8px; }
.tmsg { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.tmsg--in { border-left: 3px solid var(--primary); }
.tmsg--out { border-left: 3px solid var(--border); }
.tmsg__head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
              padding: 8px 14px; cursor: pointer; font-size: 12px; }
.tmsg__head:hover { background: var(--primary-bg); }
.tmsg__who { font-weight: 600; font-size: 13px; }
.tmsg__folder { font-size: 11px; }
.tmsg__date { margin-left: auto; }
.tmsg__body { display: none; padding: 0 14px 14px; font-size: 13px; }
.tmsg--open .tmsg__body { display: block; }

/* ==== Matched positions: the «равнозначные» question (module 009) ==== */
.note--choice { background: #fff8e6; border: 1px solid #f0d79a; border-radius: var(--radius);
                padding: 8px 12px; font-size: 12px; margin-bottom: 10px; }
.match-row--choice { background: #fffdf5; border-left: 3px solid var(--warning); padding-left: 8px; }
.choice { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.choice__title { font-size: 12px; font-weight: 600; color: var(--warning); }
.choice__opt { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%;
               text-align: left; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius);
               background: #fff; cursor: pointer; font: inherit; }
.choice__opt:hover { border-color: var(--primary); background: var(--primary-bg); }
.choice__name { font-size: 13px; }

/* Vector index progress */
.progress { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin: 6px 0; }
.progress__bar { height: 100%; background: var(--primary); transition: width .2s; }

/* ==== Kanban boards (module 010) ==== */
.board-tile { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
              padding: 16px; cursor: pointer; border-top: 3px solid var(--primary); }
.board-tile:hover { box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.board-tile__name { font-weight: 600; margin-bottom: 4px; }
.board { display: flex; gap: 12px; align-items: flex-start; overflow-x: auto; padding-bottom: 12px; }
.bcol { flex: 0 0 270px; background: #ebecf0; border-radius: 8px; padding: 8px; border-top: 3px solid var(--col); }
.bcol__head { display: flex; align-items: center; gap: 6px; padding: 2px 4px 8px; }
.bcol__title { font-weight: 600; font-size: 13px; cursor: pointer; flex: 1; }
.bcol__count { font-size: 11px; color: var(--text-muted); }
.bcol__x { border: none; background: none; cursor: pointer; color: var(--text-muted); font-size: 15px; line-height: 1; }
.bcol__x:hover { color: var(--danger); }
.bcol__cards { display: flex; flex-direction: column; gap: 6px; min-height: 24px; border-radius: 6px; }
.bcol__cards--over { background: #dfe1e6; outline: 2px dashed var(--primary); outline-offset: 2px; }
.bcol__add { width: 100%; margin-top: 6px; padding: 6px; border: none; background: none; cursor: pointer;
             color: var(--text-muted); font-size: 12px; text-align: left; border-radius: 6px; }
.bcol__add:hover { background: #dfe1e6; color: var(--text); }
.bcard { background: #fff; border-radius: 6px; box-shadow: 0 1px 2px rgba(9,30,66,.25); padding: 8px 10px; cursor: grab; }
.bcard:hover { background: #f7f8f9; }
.bcard--dragging { opacity: .5; cursor: grabbing; }
.bcard__title { font-size: 13px; font-weight: 500; margin-bottom: 4px; word-break: break-word; }
.bcard__note { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.bcard__meta { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 11px; }
.bcard__actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; font-size: 11px; }
.bcard__actions a { color: var(--text-muted); cursor: pointer; text-decoration: none; }
.bcard__actions a:hover { color: var(--primary); }
.board-pick__board { padding: 8px 0; border-bottom: 1px solid var(--border); }
.board-pick__name { font-weight: 600; font-size: 13px; margin-bottom: 6px; }

/* Cross-board / requests search result rows */
.search-hit { padding: 8px 4px; border-bottom: 1px solid var(--border); cursor: pointer; }
.search-hit:last-child { border-bottom: none; }
.search-hit:hover { background: var(--primary-bg); }

/* ==== Mobile: large touch targets, nothing wider than the screen ====
   Every `.table` scrolls inside itself (the page never does), buttons and
   form fields grow to a comfortable tap size, and the multi-column strips
   that work fine on a desktop (match-row, board columns) stack or narrow
   instead of pushing the page sideways. */
@media (max-width: 640px) {
    html, body { overflow-x: hidden; }
    .main { padding: 0 12px; margin: 12px auto; }
    .card { padding: 14px; }

    .btn { padding: 12px 16px; font-size: 15px; min-height: 44px; }
    .btn--sm { padding: 9px 12px; font-size: 13px; min-height: 40px; }

    input[type="text"], input[type="email"], input[type="password"], input[type="number"],
    textarea, select {
        font-size: 16px; /* keeps iOS Safari from zooming in on focus */
        padding: 11px 12px;
    }

    .header { padding: 10px 12px; }
    .header__nav { overflow-x: visible; flex-wrap: wrap; }
    .header__nav a { padding: 9px 12px; }

    /* A table never forces the page to scroll — it scrolls inside its own box */
    .table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table thead, .table tbody { display: table; width: 100%; min-width: 100%; }

    /* «Подходящие позиции»: one wide row of six fields becomes two columns
       that stack, instead of a row wider than the phone */
    .match-row { grid-template-columns: 1fr 1fr; }
    .match-row__name, .price-opts-slot, .match-row label, .match-row > button:last-child {
        grid-column: 1 / -1;
    }

    /* Kanban: one column at a time, swiped between, rather than a strip of
       narrow ones that only a horizontal scroll can reach */
    .bcol { flex: 0 0 84vw; }

    .grid--3 { grid-template-columns: 1fr; }
}
