/* ============================================================
   Монитор Заказов — стиль в духе 11mn (компактно, зелёные рамки)
   ============================================================ */

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: Tahoma, Verdana, Arial, sans-serif;
    font-size: 12px;
    color: #1a1a1a;
    background: #fff;
}

a { color: #1a4fb3; }
a:hover { color: #d3380a; }

h1 { font-size: 18px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 8px; }
h3 { font-size: 14px; margin: 0; }

/* ---------- Кнопки ---------- */
.btn {
    font: 12px Tahoma, sans-serif;
    padding: 4px 10px;
    border: 1px solid #9ab89a;
    background: #eef5ee;
    color: #1a1a1a;
    cursor: pointer;
    border-radius: 2px;
    white-space: nowrap;
}
.btn:hover  { background: #dbe9db; }
.btn:active { background: #c8dcc8; }
.btn:disabled { opacity: .55; cursor: default; }

.btn-primary { background: #d6e6d6; border-color: #6f9c6f; }
.btn-success { background: #cfe8cf; border-color: #4e8b4e; font-weight: bold; }
.btn-default { background: #f0f0f0; border-color: #c4c4c4; }
.btn-danger  { background: #f7dede; border-color: #cf8f8f; }
.btn-small   { padding: 2px 8px; font-size: 11px; }

/* ---------- Верхняя панель ---------- */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 4px 12px;
    background: #d6e6d6;
    border-bottom: 2px solid #6f9c6f;
    height: 30px;
}
.top-bar-left { display: flex; align-items: baseline; gap: 10px; }
.top-bar-left h1 { font-size: 14px; margin: 0; }
.top-bar-right { display: flex; align-items: center; gap: 4px; flex-wrap: nowrap; }
.last-sync { color: #555; font-size: 11px; margin: 0 4px; }

/* ---------- Фильтры ---------- */
.filters-panel {
    padding: 4px 8px;
    background: #d6e6d6;
    border-bottom: 2px solid #6f9c6f;
}
.filter-row {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: nowrap;
}
.filter-label {
    font-size: 11px;
    font-weight: bold;
    white-space: nowrap;
    color: #24512a;
}
.filter-input {
    font: 11px Tahoma, sans-serif;
    padding: 2px 4px;
    border: 1px solid #4e8b4e;
    background: #fff;
    height: 22px;
}
.filter-date { width: 130px; }
.filter-select { width: 140px; }
.filter-search { width: 180px; }
.filter-sep {
    width: 1px;
    height: 18px;
    background: #9ab89a;
    margin: 0 2px;
}

/* ---------- Групповые действия ---------- */
.bulk-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f4f8f4;
    border-bottom: 1px solid #b7cdb7;
    flex-wrap: wrap;
}
.bulk-count {
    font-weight: bold;
    color: #24512a;
    min-width: 110px;
}

/* ---------- Таблица заказов ---------- */
.orders-table-wrapper { padding: 0; overflow-x: auto; }

.orders-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    font-size: 11px;
}
.orders-table th,
.orders-table td {
    border: 1px solid #4e8b4e;   /* зелёные рамки как на 11mn */
    padding: 2px 4px;
    text-align: left;
    vertical-align: middle;
}
.orders-table th {
    background: #c8dcc8;
    font-weight: bold;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 2;
    cursor: default;
    font-size: 11px;
    padding: 3px 5px;
}
/* Сортировать можно только те колонки, на которых висит onclick в index.html */
.orders-table th[onclick] { cursor: pointer; user-select: none; }
.orders-table th[onclick]:hover { background: #b7cdb7; }
.orders-table tbody tr { background: #fff; }
.orders-table tbody tr:nth-child(even) { background: #f0f8f0; }
.orders-table tbody tr:hover { background: #d6e6d6; }
.orders-table tbody tr.selected { background: #cfe8cf !important; }

.orders-table .num { text-align: right; white-space: nowrap; }
.orders-table .center { text-align: center; }
.orders-table .nowrap { white-space: nowrap; }

.col-check { width: 22px; text-align: center; }
.col-num, .col-date, .col-qty, .col-sum, .col-delivery, .col-status, .col-input, .col-output,
.col-pavilion, .col-courier, .col-supplier { white-space: nowrap; }
.col-name { min-width: 150px; }
.col-address { min-width: 120px; }
.col-pavilion, .col-status, .col-courier { min-width: 110px; }

.loading-row { text-align: center; color: #777; padding: 20px !important; }
.empty-row td { text-align: center; color: #777; }

/* Номер заказа - оранжевый фон */
.cell-order {
    background: #ffe0b0 !important;
    font-weight: bold;
}
.cell-order a {
    font-weight: bold;
    color: #1a1a1a;
    text-decoration: none;
}
.cell-order a:hover { color: #d3380a; }

/* Inline select в ячейке */
.cell-inline-select {
    font: 11px Tahoma, sans-serif;
    padding: 1px 2px;
    border: 1px solid #4e8b4e;
    background: #fff;
    height: 22px;
    width: 100%;
    min-width: 80px;
}

.row-actions { white-space: nowrap; }
.row-actions .btn { padding: 1px 6px; font-size: 10px; }

/* ---------- Пагинация ---------- */
.pagination {
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 0 12px 12px;
    flex-wrap: wrap;
}
.pagination .btn.current { background: #cfe8cf; font-weight: bold; }
.pagination .muted { color: #888; }

/* ---------- Модальные окна ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(20, 40, 20, .45);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 20px 10px;
    overflow-y: auto;
    z-index: 100;
}
.modal-content {
    background: #fff;
    border: 2px solid #6f9c6f;
    border-radius: 3px;
    width: 100%;
    max-width: 980px;
    box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: #d6e6d6;
    border-bottom: 1px solid #9ab89a;
}
.modal-close {
    border: none;
    background: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: #4e6b4e;
}
.modal-body { padding: 12px; }
.modal-footer {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #cfe0cf;
    background: #f4f8f4;
}

/* ---------- Форма ---------- */
.form-row { display: grid; gap: 10px; margin-bottom: 10px; }
.form-row-3 { grid-template-columns: repeat(3, 1fr); }
.form-group { display: flex; flex-direction: column; gap: 3px; }
.form-group label { font-weight: bold; }

input, select, textarea {
    font: 12px Tahoma, sans-serif;
    padding: 4px 5px;
    border: 1px solid #a8bfa8;
    border-radius: 2px;
    background: #fff;
    width: 100%;
}
input[readonly] { background: #f0f0f0; color: #555; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #4e8b4e;
    box-shadow: 0 0 0 2px rgba(78,139,78,.18);
}
textarea { resize: vertical; }

.address-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    padding: 8px;
    margin-bottom: 10px;
    border: 1px dashed #b7cdb7;
    background: #fbfdfb;
}

/* ---------- Форма заказа в духе 11mn ---------- */
.order-form { background: #fff; padding: 10px 12px; }
.of-back { margin-bottom: 6px; font-size: 11px; }
.of-add-row { display: flex; justify-content: flex-end; margin: 4px 0 10px; }

.of-columns {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 24px;
    align-items: start;
}
.of-col { display: flex; flex-direction: column; gap: 6px; }
.of-col .form-group label { font-weight: normal; font-size: 11px; }
.of-col input, .of-col select, .of-col textarea {
    font-size: 11px;
    padding: 2px 3px;
    border: 1px solid #808080;
    border-radius: 0;
    background: #fff;
}
.of-col textarea { resize: vertical; }

/* Оранжевая рамка на ключевых полях (как на 11mn) */
.of-accent { border: 3px solid #e8720c !important; }

/* Адрес: метка слева, поле справа */
.of-addr-label { font-size: 11px; margin-top: 2px; }
.of-addr-row {
    display: grid;
    grid-template-columns: 92px 1fr;
    align-items: center;
    gap: 6px;
}
.of-addr-row label { font-size: 11px; font-weight: normal; }
.of-addr-row.of-addr-area { align-items: start; }
.of-addr-row.of-addr-area label { padding-top: 3px; }

.items-table-old { margin-bottom: 0; }
.items-table-old th { background: #e8f0e8; font-size: 11px; padding: 2px 4px; }
.items-table-old td { padding: 1px 3px; }

@media (max-width: 1000px) {
    .of-columns { grid-template-columns: 1fr; }
}

/* ---------- Позиции ---------- */
.order-section { margin-bottom: 12px; }
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
    font-weight: bold;
}
.section-actions { display: flex; gap: 6px; }

.items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}
.items-table th, .items-table td {
    border: 1px solid #4e8b4e;
    padding: 2px 4px;
}
.items-table th { background: #d6e6d6; text-align: left; }
.items-table input, .items-table select { padding: 2px 3px; font-size: 11px; }
.items-table .col-i-name input { width: 100%; min-width: 180px; }
.items-table .col-i-price { width: 80px; }
.items-table .col-i-qty   { width: 56px; }
.items-table .col-i-sup   { width: 110px; }
.items-table .col-i-stat  { width: 140px; }
.items-table .col-i-del   { width: 26px; text-align: center; }
.items-table .del-btn {
    border: none;
    background: none;
    color: #b33;
    font-size: 15px;
    cursor: pointer;
    line-height: 1;
}
.items-total {
    text-align: right;
    padding: 6px 4px;
    font-weight: bold;
    color: #24512a;
}

/* ---------- Экран входа ---------- */
.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #eef5ee;
}
.login-box {
    width: 300px;
    padding: 20px;
    background: #fff;
    border: 2px solid #6f9c6f;
    border-radius: 3px;
    box-shadow: 0 4px 18px rgba(0,0,0,.12);
    text-align: center;
}
.login-box p { color: #666; margin: 0 0 12px; }
.login-box input { margin-bottom: 10px; }
.error-msg { color: #b32020; margin-top: 8px; min-height: 16px; }

/* ---------- Уведомления ---------- */
#toast {
    position: fixed;
    right: 16px;
    bottom: 16px;
    padding: 10px 14px;
    border-radius: 3px;
    background: #24512a;
    color: #fff;
    box-shadow: 0 4px 14px rgba(0,0,0,.3);
    z-index: 300;
    max-width: 340px;
}
#toast.err { background: #8e1f1f; }

/* ---------- Чек для печати (копия образца, 1 страница A4) ---------- */
.print-modal { max-width: 860px; }
#print-content { background: #fff; }

.receipt {
    font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
    font-size: 10pt;
    line-height: 1.25;
    color: #000;
    padding: 8px 14px;
    width: 100%;
}

.receipt-title {
    font-size: 14pt;
    font-weight: bold;
    text-align: center;
    margin: 0 0 8px;
}

.rec-supplier {
    margin-bottom: 6px;
    font-size: 10pt;
}

.receipt-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    border: 1.5px solid #808080;
    margin: 0 0 6px;
    font-size: 10pt;
}
.receipt-table th, .receipt-table td {
    border: 1px solid #808080;
    padding: 4px 6px;
    text-align: left;
    vertical-align: top;
    word-wrap: break-word;
    line-height: 1.3;
}
.receipt-table th {
    font-weight: bold;
}
/* Пропорции колонок замерены по образцу 11mn */
.receipt-table .th-num  { width: 3%;  text-align: center; }
.receipt-table .th-name { width: 33%; }
.receipt-table .th-price { width: 23%; }
.receipt-table .th-qty  { width: 14%; text-align: center; }
.receipt-table .th-sum  { width: 27%; }
.receipt-table .tc-num {
    text-align: left;
    white-space: nowrap;
}

/* Таблица в листе доставки — 4 колонки без номера */
.delivery-sheet .receipt-table .th-name { width: 59%; }
.delivery-sheet .receipt-table .th-price { width: 14%; }
.delivery-sheet .receipt-table .th-qty  { width: 10%; text-align: center; }
.delivery-sheet .receipt-table .th-sum  { width: 17%; }
.receipt-table .tc-right { text-align: right; }
.receipt-table tr.row-delivery td { font-style: italic; }
.receipt-table tr.row-total td { border-top: 1px solid #000; }

.wordsum-total { margin: 4px 0 8px; line-height: 1.35; }

.legal-text {
    font-size: 8.5pt;
    line-height: 1.3;
    text-align: justify;
    margin: 10px 0 14px;
    white-space: pre-line;
}

.signs-block { margin: 10px 0 6px; }
.sign-line {
    text-decoration: underline;
    margin-bottom: 16px;
    font-size: 10pt;
}
.sign-row {
    display: flex;
    justify-content: flex-start;
    gap: 100px;
    margin-top: 10px;
}

.cut-mark { margin: 12px 0 8px; font-size: 10pt; }

.thanks-text { font-size: 9pt; line-height: 1.3; margin: 4px 0 14px; }

/* ---------- Лист доставки ---------- */
.delivery-sheet { margin-top: 6px; }
.delivery-title {
    font-size: 14pt;
    font-weight: bold;
    text-align: center;
    margin: 6px 0 8px;
    position: relative;
}
.delivery-title .delivery-site {
    position: absolute;
    right: 0;
    font-size: 14pt;
    font-weight: bold;
}

.delivery-info {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    border: 1.5px solid #808080;
    margin-bottom: 6px;
    font-size: 10pt;
}
.delivery-info td {
    border: 1px solid #808080;
    padding: 4px 6px;
    vertical-align: top;
    line-height: 1.3;
}
.delivery-info td:nth-child(1) { width: 18%; white-space: nowrap; }
.delivery-info td:nth-child(2) { width: 40%; }
.delivery-info td:nth-child(3) { width: 17%; white-space: nowrap; }
.delivery-info .di-notes { vertical-align: top; }
.delivery-info .di-label strong { font-weight: bold; }
.delivery-info .di-value { font-weight: normal; }

.courier-block { margin: 0 0 12px; }
.courier-block .row-delivery {
    border: 1px solid #808080;
    border-top: none;
    padding: 4px 6px;
    font-style: italic;
    font-size: 10pt;
}

.delivery-sign {
    margin-top: 14px;
    font-size: 10pt;
    line-height: 1.5;
}

/* ---------- Печать ---------- */
@page { size: A4; margin: 8mm 10mm; }
@media print {
    body > *:not(#print-modal) { display: none !important; }
    #print-modal {
        position: static;
        display: block !important;
        background: none;
        padding: 0;
        overflow: visible;
    }
    .print-modal {
        max-width: none;
        border: none;
        box-shadow: none;
    }
    .modal-header, .modal-footer { display: none !important; }
    .modal-body { padding: 0; }
}

/* ---------- Узкие экраны ---------- */
@media (max-width: 900px) {
    .form-row-3 { grid-template-columns: 1fr 1fr; }
    .address-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 620px) {
    .form-row-3 { grid-template-columns: 1fr; }
    .address-grid { grid-template-columns: repeat(2, 1fr); }
}
