:root {
    --brand: #1a5276;
    --brand-dark: #113a52;
    --bg: #f4f6f8;
    --card-bg: #ffffff;
    --border: #dde3e8;
    --text: #24313d;
    --muted: #647380;
    --danger: #b3261e;
    --danger-bg: #fdecea;
    --ok: #1e7e34;
    --ok-bg: #e9f7ef;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}
a { color: var(--brand); }
header.topbar {
    background: var(--brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 56px;
}
header.topbar .brand { font-weight: 600; font-size: 16px; }
header.topbar a { color: #fff; text-decoration: none; }
header.topbar nav { display: flex; gap: 18px; align-items: center; }
header.topbar nav a.active { text-decoration: underline; }
.user-pill { background: rgba(255,255,255,.15); padding: 4px 10px; border-radius: 14px; font-size: 13px; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 22px 18px 60px; }
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 18px 20px;
    margin-bottom: 18px;
}
h1 { font-size: 21px; margin: 0 0 14px; }
h2 { font-size: 17px; margin: 0 0 12px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
table th, table td { padding: 7px 9px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table th { background: #eef2f5; font-weight: 600; position: sticky; top: 0; }
table tbody tr:hover { background: #f8fafb; }
.table-scroll { overflow-x: auto; }
.btn {
    display: inline-block;
    background: var(--brand);
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    text-decoration: none;
}
.btn:hover { background: var(--brand-dark); }
.btn.secondary { background: #6b7a86; }
.btn.danger { background: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 12px; }
form.inline { display: inline; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 18px; }
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=number], input[type=date], input[type=password], select {
    width: 100%; padding: 8px 9px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px;
}
.field { margin-bottom: 12px; }
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13.5px; }
.alert.error { background: var(--danger-bg); color: var(--danger); border: 1px solid #f3c8c4; }
.alert.ok { background: var(--ok-bg); color: var(--ok); border: 1px solid #bfe6cb; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.tile {
    background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 22px;
    text-decoration: none; color: var(--text); display: block;
}
.tile:hover { border-color: var(--brand); box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.tile h3 { margin: 0 0 6px; color: var(--brand); font-size: 16px; }
.tile p { margin: 0; color: var(--muted); font-size: 13px; }
.tag { display: inline-block; background: #eef2f5; border-radius: 10px; padding: 2px 9px; font-size: 12px; color: var(--muted); }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-box { background: #fff; padding: 34px 32px; border-radius: 12px; width: 340px; box-shadow: 0 4px 24px rgba(0,0,0,.08); }
.login-box h1 { text-align: center; color: var(--brand); }
.subnav { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.subnav a { padding: 7px 13px; border-radius: 7px; background: #eef2f5; text-decoration: none; color: var(--text); font-size: 13.5px; }
.subnav a.active { background: var(--brand); color: #fff; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.checkbox-row input { width: auto; }
.right { text-align: right; }
.muted { color: var(--muted); }

/* --- Справки: бутони за генериране и печат --- */
.report-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 0 0 12px; }
.report-actions .btn.excel { background: #1e7e34; }
.report-actions .btn.excel:hover { background: #166228; }
.report-bar { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.report-bar form { margin: 0; }
.print-head { display: none; }
@media print {
    @page { size: A4 landscape; margin: 12mm; }
    body { background: #fff; font-size: 11px; }
    header.topbar, .subnav, .no-print, .report-actions, .report-bar form, .btn { display: none !important; }
    .wrap { max-width: none; padding: 0; }
    .card { border: none; padding: 0; margin: 0 0 14px; break-inside: avoid; }
    body.printing-one .card:not(.print-target), body.printing-one h1 { display: none !important; }
    .print-head { display: block; margin-bottom: 8px; font-size: 11px; color: #444; }
    .table-scroll { overflow: visible; }
    table { font-size: 10px; }
    table th, table td { padding: 4px 5px; white-space: normal; }
    table th { position: static; }
}

/* --- Справки като в Excel (седмична справка, справка за партида) --- */
table.report th.num, table.report td.num { text-align: right; }
table.report th.c, table.report td.c { text-align: center; }
table.report thead th { background: #2f5496; color: #fff; }
table.report tr.subtotal td { background: #ddebf7; font-weight: 600; }
table.report tr.grandtotal th { background: #1f4e78; color: #fff; }
table.report tr.section td { background: #ddebf7; color: #1f4e78; font-weight: 700; }
table.report tr.strong td { background: #f2f2f2; font-weight: 600; }
.week-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.week-chips a.tag { text-decoration: none; color: var(--brand); }
.week-chips a.tag:hover { background: var(--brand); color: #fff; }
.pricing-report { max-width: 760px; }
.signatures { display: flex; justify-content: space-between; margin-top: 48px; }
@page portrait { size: A4 portrait; margin: 15mm; }
@media print {
    .pricing-report { page: portrait; max-width: none; }
    table.report thead th, table.report tr.subtotal td, table.report tr.grandtotal th,
    table.report tr.section td, table.report tr.strong td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    table.report thead { display: table-header-group; }
}
.btn.excel-btn { background: #1e7e34; }

/* --- Storage to Storage v2: справки за период, контроли, редакция --- */
.period-form { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: flex-end; }
.period-form label { margin: 0; }
.period-form input[type=date] { width: auto; }
.quick-periods { display: inline-flex; flex-wrap: wrap; gap: 6px; font-size: 12.5px; }
.quick-periods a { background: #eef2f5; padding: 4px 9px; border-radius: 12px; text-decoration: none; }
.quick-periods a:hover { background: var(--brand); color: #fff; }
.warn { color: var(--danger); font-weight: 600; }
.okc { color: var(--ok); }
td.actions { white-space: nowrap; vertical-align: middle; }
td.actions > * { margin-right: 3px; }
table.report tr.dim td { color: #9aa5ae; }
select.yn { width: auto; padding: 3px 6px; font-size: 13px; }
.print-only { display: none; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; margin-top: 16px; align-items: start; }
@media print {
  .no-print-select { display: none !important; }
  .print-only { display: inline; }
  td.actions, th.no-print, td.no-print, .no-print { display: none !important; }
  .two-col { display: block; }
  .two-col table { margin-bottom: 10px; }
}

/* --- Заявки / Заявка за печат --- */
h3.form-sec { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--brand); margin: 14px 0 8px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.field small { display: block; margin-top: 3px; font-size: 12px; }
.request-sheet { background: #fff; border: 1px solid var(--border); border-radius: 10px; max-width: 820px; margin: 0 auto 18px; padding: 34px 40px; font-family: "Times New Roman", Georgia, serif; font-size: 15px; color: #000; }
.rq-to { font-weight: 700; margin: 0 0 22px; }
.rq-title { text-align: center; font-size: 22px; margin: 0; letter-spacing: .12em; }
.rq-subtitle { text-align: center; font-size: 15px; margin: 4px 0 22px; }
table.rq-table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.rq-table th, table.rq-table td { border: 1px solid #555; padding: 5px 8px; white-space: normal; vertical-align: top; background: #fff; position: static; }
table.rq-table th { width: 34%; font-weight: 700; text-align: left; }
table.rq-table th small { font-weight: 400; }
table.rq-table tr.gap td { border-left: none; border-right: none; padding: 4px; }
.rq-sign { margin-top: 46px; }
.doc-link { white-space: nowrap; }
@media print {
  .request-sheet { page: portrait; border: none; padding: 0; max-width: none; margin: 0; font-size: 13px; }
  table.rq-table { font-size: 12.5px; }
  table.rq-table th, table.rq-table td { padding: 4px 6px; }
}

/* --- Форматиране v5: по-широк изглед, пренасяне на заглавия и текст, без излизане извън картите --- */
.wrap { max-width: 1640px; }
.card { min-width: 0; overflow-wrap: anywhere; }
.table-scroll { max-width: 100%; max-height: 72vh; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.table-scroll > table { margin: 0; }
.table-scroll table th { position: sticky; top: 0; z-index: 2; }
table.report th { white-space: normal; vertical-align: bottom; line-height: 1.25; min-width: 72px; max-width: 160px; overflow-wrap: normal; word-break: keep-all; hyphens: manual; }
table.report td { padding: 6px 8px; }
table.report td.txt { white-space: normal; min-width: 120px; max-width: 230px; overflow-wrap: break-word; }
table.report td.txt.wide { min-width: 220px; max-width: 360px; }
table.report td.actions { white-space: nowrap; }
table.report tfoot th { position: static; max-width: none; white-space: nowrap; }
table.report td.num { white-space: nowrap; }
.two-col > .table-scroll { max-height: none; }
.two-col table.report td:not(.num) { white-space: normal; }
.two-col table.report th { max-width: none; }
.report-bar { align-items: center; }
.report-bar > .muted { flex: 1 1 360px; min-width: 0; }
.period-form label { white-space: nowrap; }
.subnav a { white-space: nowrap; }
.grid { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.grid .field label { min-height: 2.6em; display: flex; align-items: flex-end; }
.field input[type=file] { width: 100%; font-size: 13px; }
td .btn.small, td form.inline .btn.small { margin: 1px 0; }
@media (max-width: 760px) {
  .wrap { padding: 14px 10px 40px; }
  .card { padding: 14px 12px; }
  header.topbar { height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 6px; }
  header.topbar nav { flex-wrap: wrap; gap: 10px; }
  .grid { grid-template-columns: 1fr; }
  .grid .field label { min-height: 0; }
  .two-col { grid-template-columns: 1fr; }
}
@media print {
  .table-scroll { max-height: none; overflow: visible; border: none; }
  .table-scroll table th { position: static; }
  table.report th { max-width: none; }
  table.report td.txt { max-width: none; }
}

/* --- Печат / PDF на справките: завършен вид --- */
.print-sign { display: none; }
@media print {
  @page {
    size: A4 landscape; margin: 14mm 10mm 16mm;
    @bottom-left { content: "Storage to Storage · Traguardogroup Import/LPG"; font-size: 8px; color: #777; }
    @bottom-right { content: "Страница " counter(page) " от " counter(pages); font-size: 8px; color: #777; }
  }
  body { font-family: Calibri, "Segoe UI", Arial, sans-serif; color: #000; }
  .print-head {
    display: block; font-size: 10px; color: #444; margin: 0 0 10px; padding: 0 0 6px;
    border-bottom: 2px solid #1f3864;
  }
  .card.print-target > h2, body:not(.printing-one) .card > h2 {
    font-size: 17px; color: #1f3864; margin: 0 0 4px;
  }
  .card > h2 + .print-head { margin-top: 0; }
  .card h2 { color: #1f3864; break-after: avoid; }
  table.report { border: 1px solid #9fb3c8; }
  table.report th, table.report td { border: 1px solid #c5d3e2; }
  table.report thead th { background: #2f5496 !important; color: #fff !important; }
  table.report tbody tr:nth-child(even) td { background: #f5f8fc; }
  table.report tfoot th, table.report tr.grandtotal th { background: #d6e4f5 !important; color: #1f3864 !important; border-top: 2px solid #1f3864; }
  table.report tr.dim td { color: #8a949c; }
  table.report tr { break-inside: avoid; }
  table.report, table.report * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .warn { color: #b3261e !important; }
  .print-sign {
    display: flex; justify-content: space-between; gap: 20px; margin-top: 34px; font-size: 11px; break-inside: avoid;
  }
  .card .muted { color: #555; }
}
@media print {
  .report-bar { display: none !important; }
  table.report td { white-space: nowrap; padding: 3px 5px; }
  table.report td.txt { white-space: normal; }
}
@media print {
  .two-col { display: grid !important; grid-template-columns: 1fr 1.3fr; gap: 12px; break-inside: avoid; }
  .two-col table { margin-bottom: 0; }
}
.quick-periods a.on { background: var(--brand); color: #fff; }

/* --- Лек фон на страниците --- */
body {
  background-color: #eef3f8;
  background-image:
    radial-gradient(circle at 12% 0%, rgba(47, 84, 150, .10) 0, rgba(47, 84, 150, 0) 38%),
    radial-gradient(circle at 92% 18%, rgba(30, 126, 52, .06) 0, rgba(30, 126, 52, 0) 32%),
    radial-gradient(circle at 50% 100%, rgba(26, 82, 118, .08) 0, rgba(26, 82, 118, 0) 45%),
    linear-gradient(180deg, #f6f9fc 0%, #e9eff6 100%);
  background-attachment: fixed;
}
.card { box-shadow: 0 1px 3px rgba(17, 58, 82, .06), 0 6px 18px rgba(17, 58, 82, .05); border-color: #dbe4ee; }
@media print { body { background: #fff !important; } .card { box-shadow: none; } }

/* --- Фонова снимка (пристанище с контейнери) --- */
body {
  background-color: #e9eff6;
  background-image:
    linear-gradient(180deg, rgba(240, 245, 250, .80) 0%, rgba(236, 242, 248, .86) 45%, rgba(233, 239, 246, .92) 100%),
    url("bg-port.jpg");
  background-size: cover, cover;
  background-position: center, center top;
  background-repeat: no-repeat, no-repeat;
  background-attachment: fixed, fixed;
}
header.topbar { background: rgba(17, 58, 82, .94); backdrop-filter: blur(4px); box-shadow: 0 2px 10px rgba(0,0,0,.18); }
.wrap > h1 { text-shadow: 0 1px 0 rgba(255,255,255,.7); }
.wrap > p.muted { color: #3f4f5c; }
.subnav a { background: rgba(255,255,255,.85); box-shadow: 0 1px 2px rgba(17,58,82,.08); }
.subnav a.active { background: var(--brand); }
.card { background: rgba(255, 255, 255, .96); }
@media print { body { background: #fff !important; } header.topbar { box-shadow: none; } }
.alert.readonly-note { background: #fff8e1; color: #7a5b00; border: 1px solid #f1dd9b; }
/* --- Състояние на заявките --- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.st-active { background: #fff4d6; color: #8a5a00; }
.badge.st-done { background: #e3f4e8; color: #1e7e34; }
.status-filter { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 10px; font-size: 13px; }
.status-filter a { background: rgba(255,255,255,.9); border: 1px solid var(--border); padding: 4px 10px; border-radius: 14px; text-decoration: none; color: var(--text); }
.status-filter a.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.status-filter a.on .badge { background: transparent; color: #fff; padding: 0; }
.btn.ok-btn { background: var(--ok); }
.btn.ok-btn:hover { background: #166228; }
table.perm-table { width: auto; min-width: 460px; }
table.perm-table input[type=checkbox] { width: 18px; height: 18px; }
