:root {
  color-scheme: light;
  font-family: Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #f3f5f9;
  color: #1f2937;
}

.container {
  width: min(1200px, calc(100% - 2rem));
  margin: 0 auto;
}

header {
  padding: 1.5rem 0 0.5rem;
}

h1,
h2 {
  margin: 0 0 0.5rem;
}

.subtitle {
  margin: 0;
  color: #6b7280;
}

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  padding: 1rem 0 2rem;
}

.app-layout {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 1rem;
  padding: 1rem 0 2rem;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 1rem;
}

.sidebar h2 {
  font-size: 1rem;
  margin-bottom: 0.65rem;
}

.menu-list {
  display: grid;
  gap: 0.35rem;
  width: 100%;
}

.menu-list button {
  width: 100%;
  text-align: left;
  background: #f9fafb;
  border-color: #e5e7eb;
  color: #1f2937;
  padding: 0.45rem 0.5rem;
  font-size: 0.8rem;
  line-height: 1.25;
}

.menu-list button:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
  color: #111827;
  filter: none;
}

.menu-list button.active {
  background: #e8f0fe;
  border-color: #93c5fd;
  color: #1d4ed8;
  font-weight: 600;
}

.content-area {
  min-height: calc(100vh - 120px);
}

.fullscreen-section {
  min-height: calc(100vh - 120px);
}

.fullscreen-section.hidden {
  display: none;
}

.hidden {
  display: none !important;
}

.card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 1rem;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
}

hr {
  border: none;
  border-top: 1px solid #e5e7eb;
  margin: 0.7rem 0;
}

.form-grid {
  display: grid;
  gap: 0.5rem;
}

input,
select,
textarea,
button {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  font: inherit;
}

textarea {
  resize: vertical;
}

button {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
  cursor: pointer;
  transition: 0.2s ease;
}

button:hover {
  filter: brightness(0.95);
}

.hint {
  margin: 0 0 0.8rem;
  font-size: 0.9rem;
  color: #6b7280;
}

.collapsible-block {
  margin-bottom: 1.2rem;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}

.collapsible-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: #f9fafb;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.collapsible-content {
  padding: 0.75rem 1rem 1rem;
}

.collapsible-toggle[aria-expanded="true"] .collapsible-icon {
  transform: rotate(90deg);
}

.collapsible-icon {
  display: inline-block;
  font-size: 0.85rem;
  color: #6b7280;
  transition: transform 0.2s ease;
}

.stats {
  margin: 0.7rem 0;
  font-size: 0.95rem;
  color: #374151;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 0.5rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid #e5e7eb;
  text-align: left;
  padding: 0.45rem 0.35rem;
  font-size: 0.92rem;
}

th {
  color: #4b5563;
  font-weight: 600;
}

.danger {
  background: #dc2626;
  border-color: #dc2626;
}

.inline-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.inline-actions input,
.inline-actions select {
  margin-top: 0;
}

#product-search,
#counterparty-search,
#deal-search,
#task-search {
  margin-top: 0.5rem;
}

#export-products,
#export-counterparties,
#export-deals,
#export-tasks,
#export-audit {
  margin-top: 0.5rem;
  background: #0f766e;
  border-color: #0f766e;
}

#logout-btn {
  margin-top: 0.5rem;
}

.kpi-grid {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.kpi-item {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 0.6rem;
  background: #f8fafc;
}

.kpi-item span {
  display: block;
  color: #6b7280;
  font-size: 0.86rem;
}

.kpi-item strong {
  display: block;
  margin-top: 0.25rem;
  font-size: 1rem;
}

.chart-bars {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.4rem;
  align-items: end;
  min-height: 160px;
  margin-top: 0.7rem;
}

.line-chart-wrap {
  width: 100%;
  overflow-x: auto;
  margin-top: 0.7rem;
  padding-bottom: 0.25rem;
}

.line-chart-svg {
  display: block;
  min-width: 640px;
  width: 100%;
  height: auto;
}

.line-chart-grid {
  stroke: #e5e7eb;
  stroke-width: 1;
}

.line-chart-axis-label {
  fill: #6b7280;
  font-size: 11px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1.2rem;
  margin-top: 0.75rem;
}

.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.88rem;
  color: #374151;
}

.chart-legend-color {
  width: 14px;
  height: 3px;
  border-radius: 2px;
  flex-shrink: 0;
}

.dashboard-chart-controls label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
}

.chart-status-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  margin: 0.5rem 0 0.8rem;
}

.chart-status-option {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.chart-bar-value {
  position: absolute;
  top: 0.25rem;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.62rem;
  color: #1e3a8a;
  line-height: 1.1;
  padding: 0 0.15rem;
  word-break: break-word;
}

.chart-bar {
  background: #93c5fd;
  border: 1px solid #60a5fa;
  border-radius: 8px 8px 0 0;
  min-height: 8px;
  position: relative;
}

.chart-bar.is-count {
  background: #86efac;
  border-color: #4ade80;
}

#warehouse-tabs button.active {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

.deals-board {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.6rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

.deal-column {
  position: relative;
  flex: 0 0 200px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #f8fafc;
  min-height: 420px;
  padding: 0.45rem;
  z-index: 1;
}

.deal-column.deal-column-dragover {
  z-index: 2;
  outline: 2px dashed #1d4ed8;
  background: #eff6ff;
}

.deal-column h3 {
  margin: 0.1rem 0 0.45rem;
  font-size: 0.92rem;
}

.deal-dropzone {
  min-height: 360px;
  display: grid;
  gap: 0.4rem;
  align-content: start;
}

.deal-card {
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
  padding: 0.45rem;
  cursor: grab;
}

.deal-title-link {
  background: transparent;
  color: #1d4ed8;
  border: none;
  padding: 0;
  text-align: left;
  font-weight: 700;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
}

.modal-card {
  width: min(900px, calc(100% - 2rem));
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 1rem;
}

.chart-bar-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1.3rem;
  text-align: center;
  font-size: 0.74rem;
  color: #6b7280;
}

/* Блок админки только для роли admin; видимость вкладки задаётся классом .hidden */
#admin-panel-card:not(.admin-panel-available) {
  display: none !important;
}

.menu-list button.menu-item-hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .app-layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
  }
}

.deal-items-block {
  display: grid;
  gap: 0.5rem;
  grid-column: 1 / -1;
}

.deal-items-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: #374151;
}

.deal-item-row {
  display: grid;
  grid-template-columns: 1fr 110px 40px;
  gap: 0.5rem;
  align-items: center;
}

.deal-service-row {
  display: grid;
  grid-template-columns: 1fr 120px 120px 40px;
  gap: 0.5rem;
  align-items: center;
}

.deal-add-item-btn {
  width: auto;
  justify-self: start;
  background: #f3f4f6;
  border-color: #d1d5db;
  color: #1f2937;
}

.deal-add-item-btn:hover {
  background: #e5e7eb;
  filter: none;
}

.deal-item-remove {
  padding: 0.5rem;
  background: #fef2f2;
  border-color: #fecaca;
  color: #b91c1c;
}

.deal-item-remove:hover {
  background: #fee2e2;
  filter: none;
}

.billing-settings-form {
  max-width: 720px;
}

.admin-create-user-form {
  max-width: 720px;
  margin-bottom: 1rem;
}

.muted {
  color: #6b7280;
  font-size: 0.9rem;
}

.invoice-cell {
  white-space: normal;
  min-width: 140px;
}

.invoice-number {
  display: inline-block;
  margin-right: 6px;
  font-size: 0.9rem;
}

.small-btn {
  font-size: 0.85rem;
  padding: 4px 8px;
  margin: 2px 0;
}

.tag-muted {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 0.75rem;
  color: #555;
  background: #eee;
  border-radius: 4px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  grid-column: 1 / -1;
}
