:root {
  color-scheme: light;
  --cream: #fff8ee;
  --cream-2: #fff1dc;
  --paper: #fffdfa;
  --ink: #241513;
  --muted: #7a625e;
  --line: #efd4c4;
  --orange: #ff7a1a;
  --orange-soft: #ffe3c7;
  --red: #c61618;
  --deep-red: #8d1115;
  --gold: #d8952f;
  --green: #1f8a61;
  --blue: #315a92;
  --shadow: 0 18px 42px rgba(141, 17, 21, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 122, 26, 0.08), transparent 360px),
    var(--cream);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 16px;
  letter-spacing: 0;
}

.hidden {
  display: none !important;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
label.file-button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(255, 122, 26, 0.36);
  outline-offset: 2px;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(180deg, rgba(141, 17, 21, 0.84), rgba(141, 17, 21, 0.94)),
    var(--cream);
}

.login-card {
  display: grid;
  gap: 14px;
  width: min(100%, 390px);
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 8px;
  padding: 24px;
  background: var(--paper);
  box-shadow: 0 24px 70px rgba(36, 21, 19, 0.28);
}

.login-card img {
  width: 76px;
  height: 76px;
  object-fit: cover;
  border-radius: 50%;
}

.login-card h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.05;
}

.login-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--deep-red);
  font-weight: 700;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-width: 0;
  height: 100vh;
  padding: 22px 18px;
  background:
    linear-gradient(180deg, rgba(255, 122, 26, 0.24), transparent 220px),
    var(--deep-red);
  color: #fff;
}

.brand {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.brand > div,
.topbar > div {
  min-width: 0;
}

.brand img {
  width: 58px;
  height: 58px;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.75);
  border-radius: 50%;
  background: var(--cream);
}

.brand strong,
.sidebar-status strong,
.compact-list strong,
.action-list strong,
.card-title {
  display: block;
}

.brand strong {
  font-size: 20px;
  line-height: 1.1;
}

.brand span,
.sidebar-status span {
  color: rgba(255, 255, 255, 0.74);
  font-size: 14px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.78);
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.sidebar-status {
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 10px;
  align-items: start;
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.status-dot {
  width: 10px;
  height: 10px;
  margin-top: 6px;
  border-radius: 50%;
  background: #63d690;
  box-shadow: 0 0 0 5px rgba(99, 214, 144, 0.16);
}

.dashboard {
  display: grid;
  gap: 22px;
  align-content: start;
  min-width: 0;
  padding: 26px;
}

.topbar,
.panel-heading {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
}

.topbar h1,
.panel h2 {
  margin: 0;
  line-height: 1.08;
}

.topbar h1 {
  max-width: 820px;
  font-size: 32px;
}

.panel h2 {
  font-size: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--red);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.order-hero {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(0, 1.5fr);
  gap: 14px;
}

.order-hero-main,
.order-hero-plan {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  animation: softIn 0.28s ease both;
}

.order-hero-main {
  display: grid;
  align-content: center;
  gap: 8px;
  min-height: 166px;
  padding: 22px;
  background:
    linear-gradient(135deg, rgba(255, 122, 26, 0.34), rgba(255, 255, 255, 0.08)),
    linear-gradient(180deg, var(--red), var(--deep-red));
  color: #fff;
}

.order-hero-main span,
.order-hero-main small {
  color: rgba(255, 255, 255, 0.82);
  font-weight: 800;
}

.order-hero-main strong {
  overflow-wrap: anywhere;
  font-size: clamp(36px, 5vw, 64px);
  line-height: 0.96;
}

.order-hero-plan {
  display: grid;
  gap: 12px;
  padding: 16px;
  background: rgba(255, 253, 250, 0.96);
}

.order-hero-heading {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
}

.order-hero-heading span,
.global-production-card span,
.global-production-card small {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.order-hero-heading strong {
  color: var(--deep-red);
  font-size: 22px;
  overflow-wrap: anywhere;
  text-align: right;
}

.global-production-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.global-production-card {
  min-width: 0;
  border: 1px solid rgba(255, 122, 26, 0.24);
  border-radius: 8px;
  padding: 12px;
  background: #fffaf4;
}

.global-production-card strong,
.global-production-card b {
  display: block;
  margin-top: 5px;
  overflow-wrap: anywhere;
}

.global-production-card strong {
  color: var(--deep-red);
  font-size: 22px;
}

.global-production-card b {
  color: var(--ink);
}

.role-chip {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff7ec;
  color: var(--deep-red);
  font-weight: 800;
  white-space: nowrap;
}

#import-data {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.primary-button,
.ghost-button,
.danger-button,
.file-button,
.table-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--paper);
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.primary-button {
  border-color: var(--deep-red);
  background: linear-gradient(180deg, var(--red), var(--deep-red));
  color: #fff;
  font-weight: 700;
}

.ghost-button,
.file-button {
  background: #fff;
}

.danger-button {
  border-color: rgba(198, 22, 24, 0.32);
  background: #fff3f1;
  color: var(--deep-red);
}

.table-action {
  min-height: 32px;
  padding: 0 10px;
  font-size: 14px;
}

.table-action.danger {
  border-color: rgba(198, 22, 24, 0.28);
  color: var(--deep-red);
}

.primary-button,
.ghost-button,
.danger-button,
.file-button,
.table-action,
.nav-item,
.work-card,
.lead-card,
.cost-card,
.metric-card {
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    border-color 0.18s ease,
    background 0.18s ease;
}

.primary-button:hover,
.ghost-button:hover,
.danger-button:hover,
.file-button:hover,
.table-action:hover,
.work-card:hover,
.lead-card:hover,
.cost-card:hover,
.metric-card:hover {
  transform: translateY(-1px);
}

@keyframes softIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.metric-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.96);
  box-shadow: var(--shadow);
  animation: softIn 0.28s ease both;
}

.metric-card {
  display: grid;
  gap: 8px;
  min-height: 126px;
  padding: 18px;
}

.metric-card span,
.metric-card small {
  color: var(--muted);
}

.metric-card strong {
  overflow-wrap: anywhere;
  font-size: 30px;
  line-height: 1;
}

.metric-card.attention {
  border-color: rgba(255, 122, 26, 0.42);
  background: #fff3e4;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.work-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.72fr) minmax(0, 1.55fr);
  gap: 14px;
  align-items: start;
}

.stacked-panels {
  display: grid;
  gap: 14px;
}

.span-2 {
  grid-column: span 2;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel-heading.compact {
  margin-bottom: 16px;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.segmented button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
}

.segmented button.selected {
  border-color: var(--deep-red);
  background: var(--deep-red);
  color: #fff;
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0 6px;
}

.stats-strip div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.stats-strip span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.stats-strip strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  font-size: 22px;
}

.wheat-strip {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0;
}

.data-form {
  display: grid;
  gap: 12px;
}

.data-form label,
.shift-toolbar label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
}

input::placeholder {
  color: #aa928e;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.done,
.badge.paid,
.badge.ok,
.badge.income,
.badge.ordered,
.badge.taken {
  background: #e7f6ef;
  color: var(--green);
}

.badge.work,
.badge.shipped,
.badge.samples,
.badge.reserved {
  background: #eaf1fb;
  color: var(--blue);
}

.badge.planned,
.badge.wait,
.badge.expense,
.badge.waiting,
.badge.new {
  background: var(--orange-soft);
  color: #96510a;
}

.badge.low,
.badge.unpaid,
.badge.debt,
.badge.no_answer,
.badge.lost,
.badge.problem,
.badge.blocked,
.badge.danger {
  background: #fff0ee;
  color: var(--deep-red);
}

.badge.accepted,
.badge.in_progress {
  background: #fff3e4;
  color: #96510a;
}

.badge.production,
.badge.ready,
.badge.todo {
  background: #eaf1fb;
  color: var(--blue);
}

.bar-chart {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(34px, 1fr));
  gap: 7px;
  align-items: end;
  min-height: 230px;
  padding-top: 20px;
}

.bar {
  display: grid;
  grid-template-rows: 1fr auto auto;
  gap: 7px;
  min-width: 0;
  height: 210px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.bar-fill {
  align-self: end;
  min-height: 7px;
  border-radius: 8px 8px 3px 3px;
  background: linear-gradient(180deg, var(--orange), var(--red));
}

.bar strong {
  color: var(--ink);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.action-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.action-list li,
.compact-item,
.empty-state,
.goal-card,
.shift-card,
.debt-card,
.lead-card,
.note-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.action-list span,
.compact-list span,
.empty-state,
.muted {
  color: var(--muted);
}

.compact-list {
  display: grid;
  gap: 10px;
}

.compact-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.compact-item strong,
.compact-item span {
  overflow-wrap: anywhere;
}

.empty-cell {
  padding: 24px 10px;
  color: var(--muted);
  text-align: center;
}

.goal-board,
.shift-board,
.debt-board,
.note-board {
  display: grid;
  gap: 12px;
}

.order-board,
.task-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.order-summary,
.production-summary,
.stock-summary,
.raw-material-board {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.order-summary {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.production-summary,
.raw-material-board {
  grid-template-columns: repeat(4, minmax(130px, 1fr));
}

.stock-summary {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.order-total-card,
.production-card,
.stock-total-card,
.raw-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.order-total-card span,
.order-total-card small,
.production-card span,
.stock-total-card span,
.stock-total-card small,
.raw-card span,
.raw-card small {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.order-total-card strong,
.production-card strong,
.production-card b,
.stock-total-card strong,
.raw-card strong,
.raw-card b {
  display: block;
  margin-top: 5px;
  overflow-wrap: anywhere;
}

.order-total-card strong,
.stock-total-card strong {
  color: var(--deep-red);
  font-size: 22px;
}

.production-card {
  border-color: rgba(255, 122, 26, 0.26);
  background: #fffaf4;
}

.production-card b {
  color: var(--deep-red);
  font-size: 18px;
}

.stock-total-card {
  background: #fffdfa;
}

.raw-card {
  display: grid;
  gap: 6px;
  border-color: rgba(216, 149, 47, 0.32);
  background: #fffaf4;
}

.raw-card.low {
  border-color: rgba(198, 22, 24, 0.32);
  background: #fff4f1;
}

.raw-card b {
  color: var(--deep-red);
  font-size: 18px;
}

.raw-card .badge {
  justify-self: start;
}

.orders-compact-table {
  min-width: 0;
  table-layout: fixed;
}

.orders-compact-table th,
.orders-compact-table td {
  padding: 9px 8px;
  overflow-wrap: anywhere;
}

.cell-note {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.work-column {
  display: grid;
  align-content: start;
  gap: 10px;
  min-width: 0;
}

.work-column h3 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0;
  font-size: 15px;
}

.work-column h3 strong {
  color: var(--muted);
  font-size: 13px;
}

.work-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.work-card header {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  justify-content: space-between;
}

.work-card p {
  margin: 0;
  color: var(--muted);
}

.staff-note {
  border-left: 3px solid var(--orange);
  padding-left: 9px;
  color: var(--ink) !important;
}

.hot-note {
  color: var(--deep-red) !important;
  font-weight: 800;
}

.task-card.urgent,
.work-card.stale,
.stale-row {
  border-color: rgba(198, 22, 24, 0.5);
  background: #fff8f6;
}

.work-card.stale {
  animation: stalePulse 1.35s ease-in-out infinite;
}

@keyframes stalePulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(198, 22, 24, 0.08);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(198, 22, 24, 0.14);
  }
}

.goal-card,
.shift-card,
.debt-card,
.note-card {
  display: grid;
  gap: 10px;
}

.goal-card header,
.shift-card header,
.debt-card header,
.lead-card header,
.note-card header {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  justify-content: space-between;
}

.progress {
  overflow: hidden;
  height: 10px;
  border-radius: 999px;
  background: var(--cream-2);
}

.progress span {
  display: block;
  width: var(--progress, 0%);
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--orange), var(--red));
}

.shift-toolbar {
  max-width: 360px;
  margin-bottom: 14px;
}

.shift-card.taken {
  border-color: rgba(31, 138, 97, 0.28);
}

.debt-card {
  border-color: rgba(198, 22, 24, 0.28);
}

.debt-card.ready {
  border-color: rgba(31, 138, 97, 0.32);
  background: #fffef8;
}

.lead-columns {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 12px;
}

.crm-stats,
.cost-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.crm-stats div,
.cost-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.crm-stats span,
.cost-card span,
.cost-card small {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.crm-stats strong,
.cost-card strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  font-size: 20px;
}

.cost-card.attention {
  border-color: rgba(255, 122, 26, 0.42);
  background: #fff7ec;
}

.crm-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 0.35fr);
  gap: 10px;
  margin-bottom: 12px;
}

.crm-toolbar label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.duplicate-board {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.duplicate-card {
  display: grid;
  gap: 4px;
  border: 1px solid rgba(198, 22, 24, 0.28);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff3f1;
  color: var(--deep-red);
}

.duplicate-card span {
  color: var(--muted);
}

.lead-column {
  display: grid;
  align-content: start;
  gap: 10px;
  min-width: 0;
}

.lead-column h3 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0;
  font-size: 15px;
}

.lead-column h3 strong {
  color: var(--muted);
  font-size: 13px;
}

.lead-card {
  display: grid;
  gap: 8px;
}

.lead-card.stale {
  border-color: rgba(198, 22, 24, 0.42);
  background: #fff8f6;
}

.tag-row,
.timeline-mini {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-row span {
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--orange-soft);
  color: #96510a;
  font-size: 12px;
  font-weight: 800;
}

.timeline-mini {
  display: grid;
}

.timeline-mini span {
  color: var(--muted);
  font-size: 13px;
}

.selected-row {
  background: #fff7ec;
}

.lead-card p,
.note-card p,
.debt-card p,
.shift-card p,
.goal-card p {
  margin: 0;
  color: var(--muted);
}

@media (max-width: 1180px) {
  .kpi-grid,
  .overview-grid,
  .order-hero {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .span-2 {
    grid-column: span 2;
  }

  .lead-columns,
  .crm-stats,
  .cost-summary,
  .stock-summary,
  .raw-material-board {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }

  .global-production-grid {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .order-board,
  .task-board,
  .order-summary,
  .production-summary {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    z-index: 10;
    height: auto;
    max-height: none;
    padding: 12px;
  }

  .brand {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .brand img {
    width: 44px;
    height: 44px;
  }

  .brand strong {
    font-size: 18px;
  }

  .nav-list {
    display: flex;
    gap: 8px;
    margin: 0 -12px;
    padding: 0 12px 2px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .nav-item {
    flex: 0 0 auto;
    width: auto;
    min-height: 38px;
    padding: 0 12px;
    white-space: nowrap;
  }

  .sidebar-status {
    display: none;
  }

  .dashboard {
    padding: 18px;
  }

  .topbar,
  .panel-heading,
  .goal-card header,
  .shift-card header,
  .debt-card header,
  .lead-card header,
  .note-card header {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar h1 {
    font-size: 26px;
  }

  .topbar-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .kpi-grid,
  .order-hero,
  .overview-grid,
  .stats-strip,
  .wheat-strip,
  .lead-columns,
  .crm-stats,
  .cost-summary,
  .global-production-grid,
  .stock-summary,
  .raw-material-board,
  .crm-toolbar,
  .order-summary,
  .production-summary,
  .order-board,
  .task-board {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .order-hero-heading {
    flex-direction: column;
  }

  .order-hero-heading strong {
    text-align: left;
  }

  .bar-chart {
    overflow-x: auto;
    grid-template-columns: repeat(var(--bar-count, 7), minmax(48px, 1fr));
    padding-bottom: 6px;
  }

  .bar {
    height: 180px;
  }
}

@media (max-width: 430px) {
  .dashboard {
    padding: 14px;
  }

  .topbar-actions > * {
    flex: 1 1 auto;
  }

  .metric-card strong {
    font-size: 26px;
  }

  .compact-item {
    grid-template-columns: 1fr;
  }

  .primary-button,
  .ghost-button,
  .danger-button,
  .file-button {
    width: 100%;
  }

}

/* Прозвон пивточек */
.crm-description { margin: 8px 0 0; color: var(--muted); line-height: 1.5; font-size: 14px; }
.crm-heading { align-items: flex-start; flex-wrap: wrap; }
.crm-heading h2 { font-size: clamp(24px, 3vw, 34px); }
.crm-panel .crm-stats { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.crm-panel .crm-stats div:nth-child(3), .crm-panel .crm-stats div:nth-child(4) { background: var(--cream-2); }
.crm-quick-filters { display: flex; gap: 8px; flex-wrap: wrap; margin: 20px 0; }
.crm-quick-filters button { border: 1px solid var(--line); border-radius: 20px; padding: 9px 14px; color: var(--muted); background: var(--paper); font-size: 13px; font-weight: 700; }
.crm-quick-filters button.selected { background: var(--deep-red); border-color: var(--deep-red); color: white; }
.crm-filters { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.crm-filters .crm-search { grid-column: 1 / -1; }
.crm-results-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 16px 0; color: var(--muted); font-size: 13px; }
.crm-lead-list { display: grid; gap: 12px; }
.crm-record { grid-template-columns: 1.2fr 1fr 1.2fr 1fr; gap: 18px; padding: 20px; box-shadow: none; }
.crm-record > div { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.crm-record p { font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; white-space: pre-line; }
.crm-record .crm-record-actions { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 12px; gap: 8px; }
.crm-name-button { padding: 0; border: 0; background: none; color: var(--ink); font-size: 17px; font-weight: 800; text-align: left; overflow-wrap: anywhere; }
.crm-name-button:hover { color: var(--red); text-decoration: underline; }
.crm-caption { font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.crm-phone { color: var(--deep-red); font-size: 16px; font-weight: 800; text-decoration: none; overflow-wrap: anywhere; }
.crm-secondary-phone { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.crm-record-note { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.crm-sample-badge { display: inline-block; padding: 5px 8px; border-radius: 6px; font-size: 12px; color: var(--muted); background: #f4eeea; }
.crm-sample-badge.attention { color: #8b420d; background: var(--orange-soft); font-weight: 700; }
.crm-due { color: var(--red); font-size: 13px; font-weight: 800; }
.crm-priority { color: var(--red); font-size: 12px; font-weight: 800; }
.badge.interested, .badge.testing { background: #e4f3ec; color: #176744; }
.badge.later, .badge.supplier { background: #eaf0fa; color: #315a92; }
.badge.irrelevant { background: #eee9e6; color: var(--muted); }
.crm-empty { padding: 42px 20px; text-align: center; }
.crm-empty strong { color: var(--ink); font-size: 20px; }
.crm-empty p { line-height: 1.6; }
.crm-dialog { width: min(850px, calc(100% - 32px)); max-height: calc(100dvh - 40px); padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); color: var(--ink); box-shadow: 0 30px 100px #24151355; }
.crm-dialog::backdrop { background: #24151399; backdrop-filter: blur(3px); }
.crm-dialog-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 22px 24px; border-bottom: 1px solid var(--line); background: var(--cream); }
.crm-dialog-heading h2 { margin: 4px 0 0; font-size: 24px; overflow-wrap: anywhere; }
.crm-dialog .data-form { padding: 22px 24px; gap: 22px; }
.crm-fieldset { display: grid; gap: 14px; min-width: 0; padding: 16px; margin: 0; border: 1px solid var(--line); border-radius: 8px; }
.crm-fieldset legend { padding: 0 6px; font-size: 15px; font-weight: 800; color: var(--ink); }
textarea { width: 100%; min-height: 76px; resize: vertical; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; color: var(--ink); background: white; line-height: 1.5; }
textarea:focus-visible { outline: 3px solid #ff7a1a5c; outline-offset: 2px; }
textarea::placeholder { color: #aa928e; }
.crm-phone-check { font-size: 12px; line-height: 1.5; color: var(--green); }
.crm-phone-check.has-error { color: var(--red); }
.crm-more { border: 1px solid var(--line); border-radius: 8px; }
.crm-more summary { padding: 16px; cursor: pointer; font-size: 14px; font-weight: 700; }
.crm-dialog .crm-more .data-form { padding: 0 16px 16px; gap: 14px; }
.crm-history h3 { margin: 0 0 12px; font-size: 15px; }
.crm-history-event { padding: 12px 0 12px 14px; border-left: 2px solid var(--line); }
.crm-history-event small { color: var(--muted); font-size: 12px; }
.crm-history-event p { margin: 4px 0; font-size: 14px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.crm-dialog-footer { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; padding-top: 16px; border-top: 1px solid var(--line); }
.crm-dialog button:disabled { opacity: .6; cursor: wait; }
@media (max-width: 1400px) {
  .crm-panel .crm-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .crm-record { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .crm-panel .crm-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .crm-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .crm-record { grid-template-columns: minmax(0, 1fr); padding: 16px; gap: 16px; }
  .crm-dialog { width: calc(100% - 16px); max-height: calc(100dvh - 16px); border-radius: 10px; }
  .crm-dialog-heading, .crm-dialog .data-form { padding: 16px; }
  .crm-fieldset { padding: 12px; }
  .crm-dialog .form-row { grid-template-columns: minmax(0, 1fr); }
  .crm-heading > .row-actions { width: 100%; }
}
.crm-focused .order-hero, .crm-focused .kpi-grid { display: none; }
.crm-dialog-heading { position: sticky; top: 0; z-index: 2; }
.crm-dialog-footer { position: sticky; bottom: -22px; z-index: 1; margin: 0 -24px -22px; padding: 16px 24px; background: var(--paper); box-shadow: 0 -6px 16px #24151308; }
@media (max-width: 680px) { .crm-dialog-footer { bottom: -16px; margin: 0 -16px -16px; padding: 14px 16px; } }
