/* Project styles on top of the MatDash theme (static/matdash). Keep theme files unmodified. */

/* Text logo (partials/_brand.html). */
/* Brand green: dark enough for white text on it (contrast 5:1); lighter in dark mode. */
:root {
  --brand-green: #2e7d32;
}
[data-bs-theme="dark"] {
  --brand-green: #4caf50;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--brand-green) !important;
  text-decoration: none;
}
.brand .brand-main {
  letter-spacing: 0.06em;
}
.brand .brand-icon {
  font-size: 1.6rem;
  color: var(--brand-green);
}
.brand.brand-lg {
  font-size: 1.6rem;
}
.brand.brand-lg .brand-icon {
  font-size: 2.2rem;
}

/* Large decorative leaf on the sign-in pages' dark panel. */
.auth-leaf {
  position: absolute;
  right: -60px;
  bottom: -60px;
  font-size: 420px;
  color: var(--bs-primary);
  opacity: 0.35;
}

/* Initials avatar for the signed-in user. Set the size with style="--size: 35px". */
.user-avatar {
  --size: 40px;
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: var(--size);
  height: var(--size);
  background-color: var(--bs-primary-bg-subtle);
  color: var(--bs-primary);
  font-weight: 600;
}

/*
 * Small screens (< 1300px, the theme's breakpoint). The MatDash horizontal pages
 * switch to a second, vertical header and sidebar below this width; this project
 * only renders the horizontal ones, so keep them visible and turn the menu into
 * an off-canvas drawer. The hamburger toggles #main-wrapper.show-sidebar, which
 * the theme already uses to slide the drawer in and dim the page behind it.
 */
@media (max-width: 1299.98px) {
  html[data-layout="horizontal"] .with-horizontal {
    display: block;
  }

  /* The drawer lives inside the top bar, so the top bar must sit above the dimmed overlay
     (.dark-transparent, z-index 10); otherwise taps on the menu land on the overlay. */
  html[data-layout="horizontal"] .topbar {
    z-index: 1050;
  }

  html[data-layout="horizontal"] .left-sidebar.with-horizontal {
    position: fixed;
    top: 0;
    left: -280px;
    z-index: 11; /* above the .dark-transparent overlay (10) */
    width: 270px;
    height: 100%;
    padding-top: 1rem;
    overflow-y: auto;
    background-color: var(--bs-body-bg);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.08);
    transition: left 0.2s ease-in;
  }

  html[data-layout="horizontal"] #main-wrapper.show-sidebar .left-sidebar.with-horizontal {
    left: 0;
  }

  /* Touch-sized rows: at least 44px tall, so the menu is easy to tap on a phone. */
  html[data-layout="horizontal"] .left-sidebar.with-horizontal .sidebar-link {
    min-height: 44px;
    align-items: center;
    font-size: 15px;
  }
  html[data-layout="horizontal"] .left-sidebar.with-horizontal .first-level .sidebar-link {
    min-height: 42px;
  }
  html[data-layout="horizontal"] .left-sidebar.with-horizontal {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  html[data-layout="horizontal"] .left-sidebar.with-horizontal .drawer-head .brand {
    font-size: 1.05rem;
  }
}

@media (min-width: 1300px) {
  .nav-drawer-toggle {
    display: none !important;
  }
}

/* Dense forms for working pages (add class="form-compact" to a <form>): smaller
   labels and inputs, tighter spacing, help texts hidden (labels say enough). */
.form-compact .form-label {
  margin-bottom: 0.25rem;
  font-size: 0.8125rem;
  color: var(--bs-secondary-color);
}
.form-compact .form-control,
.form-compact .form-select {
  padding-top: 0.375rem;
  padding-bottom: 0.375rem;
  font-size: 0.875rem;
}
.form-compact .mb-3 {
  margin-bottom: 0.5rem !important;
}
.form-compact .form-text {
  display: none;
}
/* Cash desk toolbar buttons: icon and label side by side. */
.ledger-toolbar .btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

/* Searchable selects (Select2) as tall as the compact inputs beside them, the chosen
   text centred in the box and cut with "…" rather than overflowing. */
.form-compact .select2-container .select2-selection--single {
  height: 35px;
  display: flex;
  align-items: center;
}
/* (as specific as the theme's "body .select2-container--default ... __rendered" line-height: 40px) */
.form-compact .select2-container--default .select2-selection--single .select2-selection__rendered {
  line-height: 33px;
  font-size: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.form-compact .select2-container--default .select2-selection--single .select2-selection__arrow {
  height: 33px;
  top: 1px;
}
/* A block, not inline: the arrow is placed against the box itself, also under a label. */
.form-compact .select2-container {
  display: block;
}

/* Select2 lists: denser rows, so more of a long list (materials, companies) fits. */
.select2-container--open .select2-results__option {
  padding: 0.3rem 0.625rem;
  font-size: 0.875rem;
  line-height: 1.35;
}
.select2-container--open .select2-results > .select2-results__options {
  max-height: 280px;
}
.select2-container--open .select2-search--dropdown .select2-search__field {
  padding: 0.3rem 0.5rem;
  font-size: 0.875rem;
}

/* Action log: the changes column wide enough to read "field: before → after". */
.audit-log .audit-changes { min-width: 280px; font-size: 0.78rem; }

/* Material receipt: a working width, and line columns sized to their content. */
.receipt-form {
  max-width: 1080px;
}
.receipt-lines .receipt-col-number { width: 44px; }
.receipt-lines .receipt-col-quantity { width: 170px; }
.receipt-lines .receipt-col-unit { width: 70px; }
.receipt-lines .receipt-col-remove { width: 48px; }
/* Supplier order: the full width, so its seven line columns fit without scrolling. */
.order-form { max-width: 1400px; }
.order-lines .order-col-quantity { width: 120px; }
.order-lines .order-col-unit { width: 56px; }
.order-lines .order-col-amount { width: 130px; }
.order-lines .order-col-status { width: 135px; }
.order-lines .order-col-date { width: 150px; }
.receipt-lines input[data-number] {
  text-align: end;
  font-variant-numeric: tabular-nums;
}

/* Buttons in a field row line up with the inputs beside them. */
.form-compact .row .btn {
  min-height: 35px;
}

/* Cash desk ledger: Приход / Расход / Остаток column groups, like the workbook sheet.
   Compact enough to fit the screen without sideways scrolling: text wraps, numbers don't. */
.ledger-table { font-size: 0.8125rem; }
.ledger-table th { white-space: nowrap; vertical-align: middle; }
.ledger-table td, .ledger-table th { padding: 0.4rem 0.45rem; }
.ledger-table .num { text-align: end; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ledger-table .ledger-note { min-width: 160px; }
.ledger-table .ledger-counterparty { min-width: 170px; }
/* Long bank payment purposes wrap instead of widening the table; the full text is in the tooltip. */
.ledger-table .ledger-clamp { max-width: 280px; }
.ledger-table th.ledger-income { background-color: var(--bs-success-bg-subtle); }
.ledger-table th.ledger-expense { background-color: var(--bs-danger-bg-subtle); }
.ledger-table th.ledger-balance { background-color: var(--bs-primary-bg-subtle); }
.ledger-table th.ledger-article { background-color: var(--bs-tertiary-bg); }
.ledger-table td.ledger-balance-cell { background-color: rgba(var(--bs-primary-rgb), 0.04); }
/* Opening / carried-over balance row: theme-aware (Bootstrap's table-light stays light in dark mode). */
.ledger-table tr.ledger-opening {
  --bs-table-bg: var(--bs-tertiary-bg);
  --bs-table-color: var(--bs-emphasis-color);
}
/* !important: the theme's dark mode dims every table cell with an !important colour. */
.ledger-table tr.ledger-opening > td {
  color: var(--bs-emphasis-color) !important;
}
.ledger-table .ledger-action { padding: 0.15rem 0.35rem; line-height: 1; }
.ledger-table tr.ledger-cancelled td:not(:last-child):not(.ledger-status) {
  color: var(--bs-secondary-color);
  text-decoration: line-through;
}

/* Collapsible column groups, like Excel's outline buttons. A group's cells have class
   g-<group>; when the table has collapse-<group>, they hide and the narrow gp-<group>
   cells show instead. */
.ledger-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-inline-start: 0.25rem;
  padding: 0;
  border: 1px solid currentColor;
  border-radius: 3px;
  background: transparent;
  color: var(--bs-secondary-color);
  font-size: 0.75rem;
  line-height: 1;
  vertical-align: middle;
}
.ledger-toggle:hover { color: var(--bs-primary); }
.ledger-table [class*="gp-"] { display: none; width: 30px; text-align: center; }
.ledger-collapsed-label {
  display: block;
  margin: 0.4rem auto 0;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-weight: 600;
}
.ledger-table.collapse-article .g-article,
.ledger-table.collapse-income .g-income,
.ledger-table.collapse-expense .g-expense,
.ledger-table.collapse-balance .g-balance { display: none; }
.ledger-table.collapse-article .gp-article,
.ledger-table.collapse-income .gp-income,
.ledger-table.collapse-expense .gp-expense,
.ledger-table.collapse-balance .gp-balance { display: table-cell; }

/* The Sign Out button sits in a form inside the profile dropdown; make it full width like the links. */
.profile-dropdown form .dropdown-item {
  width: 100%;
  text-align: start;
}

/* Production journal: a month of days side by side, the product column stays put while scrolling. */
.journal-grid th,
.journal-grid td {
  padding: 0.3rem 0.35rem;
  font-size: 0.78rem;
}
.journal-grid .journal-product {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 200px;
  background: var(--bs-card-bg, var(--bs-body-bg));
}

/* Sales plan: twelve months side by side; inputs in edit mode stay readable. */
.plan-grid td { min-width: 76px; }
.plan-grid input { min-width: 70px; }

/* Dashboard headline cards: an icon and label, one big figure, then the cash / card / bank split as bars. */
.kpi-card .kpi-icon {
  width: 1.75rem;
  height: 1.75rem;
  font-size: 0.95rem;
  background: var(--kpi-tint, rgba(93, 135, 255, 0.12));
  color: var(--kpi-color, var(--bs-primary));
}
.kpi-card .kpi-value {
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}
.kpi-card .kpi-progress,
.kpi-card .kpi-bar {
  background: var(--bs-tertiary-bg, rgba(0, 0, 0, 0.06));
}
.kpi-card .kpi-usd {
  font-size: 0.68rem;
}
.kpi-card .kpi-label {
  font-size: 0.8rem;
}
.kpi-card .kpi-note {
  font-size: 0.72rem;
}
.kpi-card .kpi-row {
  font-size: 0.74rem;
}
.kpi-card .py-half {
  padding-top: 0.2rem !important;
  padding-bottom: 0.2rem !important;
}
.kpi-card .mt-half {
  margin-top: 0.15rem !important;
}
.kpi-card .kpi-progress,
.kpi-card .kpi-bar {
  height: 0.3rem;
}
.kpi-channels .kpi-channel-label {
  font-size: 0.66rem;
  line-height: 1.2;
}
.kpi-channels .kpi-channel-amount {
  font-size: 0.78rem;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi-primary { --kpi-tint: rgba(93, 135, 255, 0.14); --kpi-color: #5d87ff; }
.kpi-success { --kpi-tint: rgba(19, 222, 185, 0.16); --kpi-color: #0d9c80; }
.kpi-danger { --kpi-tint: rgba(250, 137, 107, 0.16); --kpi-color: #e0624a; }
.kpi-info { --kpi-tint: rgba(73, 190, 255, 0.16); --kpi-color: #1a8fd1; }
.kpi-warning { --kpi-tint: rgba(255, 174, 31, 0.18); --kpi-color: #c97d00; }
.kpi-card .progress-bar {
  background-color: var(--kpi-color, var(--bs-primary));
}
.kpi-bar-cash { background-color: #5d87ff !important; }
.kpi-bar-card { background-color: #ffae1f !important; }
.kpi-bar-bank { background-color: #49beff !important; }

/* Full screen: the menu hides, the page takes the whole window. Toggled from the top bar. */
.fullscreen-mode .left-sidebar,
.fullscreen-mode .nav-drawer-toggle,
.fullscreen-mode .dark-transparent {
  display: none !important;
}
.fullscreen-mode .body-wrapper,
.fullscreen-mode .page-wrapper {
  margin-left: 0 !important;
  margin-top: 0 !important; /* the theme reserves room for the menu row here */
  padding-top: 0 !important;
}
.fullscreen-toggle[aria-pressed="true"] {
  color: var(--bs-primary);
}


/*
 * One row from 1300px up: the brand, the main menu and the controls share the top bar,
 * so there is no second menu bar below it. Below 1300px the menu stays a drawer.
 */
@media (min-width: 1300px) {
  html[data-layout="horizontal"] .app-header .navbar {
    min-height: 60px;
  }
  html[data-layout="horizontal"] .app-header .navbar .navbar-nav .nav-item .nav-link {
    line-height: 60px;
  }
  html[data-layout="horizontal"] .app-header .main-menu .left-sidebar.with-horizontal {
    position: static;
    top: auto;
    width: auto;
    height: auto;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    transition: none;
  }
  html[data-layout="horizontal"] .app-header .main-menu #sidebarnavh.scroll-sidebar {
    height: auto;
    padding: 0;
    overflow: visible;
  }
  html[data-layout="horizontal"] .app-header .main-menu #sidebarnav {
    flex-wrap: nowrap;
    align-items: stretch;
    height: 60px;
  }
  html[data-layout="horizontal"] .app-header .main-menu #sidebarnav > .sidebar-item {
    min-height: 60px;
    display: flex;
    align-items: stretch;
  }
  html[data-layout="horizontal"] .app-header .main-menu #sidebarnav > .sidebar-item > .sidebar-link {
    align-items: center;
    font-size: 13px;
    white-space: nowrap;
    gap: 6px;
  }
  html[data-layout="horizontal"] .app-header .main-menu #sidebarnav > .sidebar-item > .sidebar-link {
    padding: 6px 10px;
  }
  html[data-layout="horizontal"] .app-header .main-menu #sidebarnav > .sidebar-item ul {
    top: calc(60px - 8px);
  }
  html[data-layout="horizontal"] .topbar {
    padding-top: 0;
    padding-bottom: 0;
  }
  html[data-layout="horizontal"] .app-header .navbar,
  html[data-layout="horizontal"] .app-header .navbar-nav,
  html[data-layout="horizontal"] .app-header .navbar-nav .nav-item {
    height: 60px;
  }
  html[data-layout="horizontal"] .app-header .navbar-nav .nav-item {
    display: flex;
    align-items: center;
  }
  html[data-layout="horizontal"] .app-header .navbar-nav .nav-link {
    padding-top: 0;
    padding-bottom: 0;
  }
  html[data-layout="horizontal"] .body-wrapper {
    margin-top: 60px;
  }
}

.app-header .main-menu {
  min-width: 0;
}

/* New pages in the menu (core/navigation.py NEW_PAGES): a small «Новое» badge on the page,
   a dot on its section's icon; js/app.js hides them once the person has opened the page. */
.nav-new {
  padding: 2px 6px;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.2;
  color: #fff;
  background-color: var(--bs-success);
  border-radius: 10px;
}
.sidebar-link .nav-new { flex-shrink: 0; }
.nav-new-dot {
  position: absolute;
  top: -2px;
  right: -4px;
  width: 8px;
  height: 8px;
  background-color: var(--bs-success);
  border: 2px solid var(--bs-body-bg);
  border-radius: 50%;
}
.nav-new[hidden], .nav-new-dot[hidden] { display: none !important; }
/* In the narrow drawer a long name wraps rather than push the badge out of the menu. */
@media (max-width: 1299.98px) {
  .sidebar-link:has(.nav-new) .hide-menu { min-width: 0; white-space: normal; }
}

/* A menu section split into groups (core/navigation.py): headed blocks in the drawer,
   side-by-side columns in the desktop dropdown. */
.nav-groups .nav-group-title {
  padding: 10px 16px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--bs-secondary-color);
}
.nav-groups .nav-group + .nav-group {
  margin-top: 4px;
  border-top: 1px solid var(--bs-border-color);
}
@media (min-width: 1300px) {
  html[data-layout="horizontal"] .sidebar-nav #sidebarnav > .sidebar-item > ul.first-level.nav-groups {
    width: auto;
    padding: 8px;
    /* Open from the menu item's left edge: the theme right-aligns dropdowns, which pushed the
       first column off the left of the screen when the item sits near it (Производство). */
    left: 0;
    right: auto;
  }
  html[data-layout="horizontal"] .sidebar-nav #sidebarnav > .sidebar-item:hover > ul.first-level.collapse.nav-groups {
    display: grid;
    grid-template-columns: repeat(4, minmax(185px, auto));
  }
  .nav-groups .nav-group + .nav-group {
    margin-top: 0;
    border-top: 0;
    border-left: 1px solid var(--bs-border-color);
  }
  .nav-groups .nav-group-title {
    padding-top: 6px;
  }
  html[data-layout="horizontal"] .sidebar-nav .nav-groups .sidebar-link {
    white-space: nowrap;
  }
}

/* Production overview: compact headline tiles, six in a row (production/_tile.html). */
.prod-tile { --tile-color: var(--bs-primary); --tile-tint: rgba(93, 135, 255, 0.12); transition: box-shadow .15s, transform .15s; }
.prod-tile:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08); }
.prod-tile-info { --tile-color: var(--bs-info); --tile-tint: rgba(83, 155, 255, 0.12); }
.prod-tile-success { --tile-color: var(--bs-success); --tile-tint: rgba(19, 222, 185, 0.12); }
.prod-tile-warning { --tile-color: var(--bs-warning); --tile-tint: rgba(255, 174, 31, 0.14); }
.prod-tile-danger { --tile-color: var(--bs-danger); --tile-tint: rgba(250, 137, 107, 0.14); }
.prod-tile-icon { width: 2rem; height: 2rem; font-size: 1.05rem; color: var(--tile-color); background: var(--tile-tint); }
.prod-tile-value { font-size: 1.05rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.prod-tile-unit { font-size: 0.72rem; font-weight: 400; color: var(--bs-secondary-color); }
.prod-tile-label { font-size: 0.76rem; font-weight: 600; color: var(--bs-secondary-color); }
.prod-tile-note { font-size: 0.68rem; color: var(--bs-secondary-color); }
.prod-tile-danger .prod-tile-value, .prod-tile-warning .prod-tile-value { color: var(--tile-color); }
.prod-tile-progress { height: 0.25rem; background: var(--bs-tertiary-bg, rgba(0, 0, 0, 0.06)); }
.min-w-0 { min-width: 0; }
/* Six tiles in a row from 1200px (the theme's own xl breakpoint is wider). */
@media (min-width: 1200px) {
  .prod-tile-col { flex: 0 0 auto; width: 16.6667%; }
}
