/* ══════════════════════════════════════════════════
   Proposal (КП) — Stylesheet
   ══════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --c-bg:        #f6f0e7;
  --c-surface:   #fffaf3;
  --c-primary:   #201c1a;
  --c-accent:    #d3112e;
  --c-accent2:   #8f131a;
  --c-text:      #201c1a;
  --c-muted:     #6c625c;
  --c-border:    #dacbb7;
  --c-hover:     #fff3e0;
  --c-success:   #2d9b6f;
  --shadow-sm:   0 6px 16px rgba(47, 27, 8, 0.10);
  --shadow-md:   0 14px 34px rgba(47, 27, 8, 0.16);
  --radius:      10px;
  --radius-sm:   6px;
  --transition:  .18s ease;
}

body {
  font-family: "Arial", "Helvetica", sans-serif;
  font-size: 14px;
  background: radial-gradient(circle at 80% -10%, #ffe6bf, transparent 45%),
    radial-gradient(circle at 10% 30%, #fff4de, transparent 35%), var(--c-bg);
  color: var(--c-text);
  min-height: 100vh;
}

/* ── Buttons ───────────────────────────────────── */
button, .btn-primary, .btn-secondary, .btn-ghost {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 9px 18px;
  transition: background var(--transition), transform var(--transition), opacity var(--transition);
}
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--c-primary);
  color: #fff;
  width: 100%;
}
.btn-primary:hover:not(:disabled) { background: #3a312c; }

.btn-secondary {
  background: var(--c-accent);
  color: #fff;
}
.btn-secondary:hover:not(:disabled) { background: var(--c-accent2); }

.btn-ghost {
  background: transparent;
  color: var(--c-primary);
  border: 1.5px solid var(--c-border);
}
.btn-ghost:hover:not(:disabled) { background: var(--c-hover); }

.btn-sm { padding: 6px 13px; font-size: 0.8rem; }
.btn-danger { color: var(--c-accent); border-color: #fce4e6; }
.btn-danger:hover { background: #fff0f1 !important; }

/* ── App layout ────────────────────────────────── */
.app { display: flex; flex-direction: column; min-height: 100vh; }

/* ── Profile Panel ─────────────────────────────── */
.profile-panel {
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  overflow: hidden;
  max-height: 400px;
  transition: max-height .3s ease, padding .3s ease;
  padding: 20px 24px;
}
.profile-panel.is-hidden { max-height: 0; padding: 0 24px; }

.profile-panel .panel-inner { max-width: 560px; margin: 0 auto; }
.profile-panel h2 { font-size: 1rem; margin-bottom: 14px; }
.profile-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: end;
}
.profile-form label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 0.76rem; font-weight: 600; color: var(--c-muted);
  text-transform: uppercase; letter-spacing: .04em;
}
.profile-form input, .profile-form select {
  padding: 8px 10px;
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
}
.profile-form input:focus, .profile-form select:focus {
  outline: none; border-color: var(--c-accent2);
}
.profile-actions { display: flex; align-items: center; gap: 10px; grid-column: span 2; }
.status-ok { font-size: 0.8rem; color: var(--c-success); }

/* ── Main KP layout ────────────────────────────── */
.kp-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 16px;
  padding: 20px 24px;
  flex: 1;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.kp-panel {
  background: var(--c-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 20px;
}

/* ── KP Meta ───────────────────────────────────── */
.kp-meta h2 { font-size: 1.05rem; margin-bottom: 12px; }
.kp-meta-fields {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.kp-meta-fields label, .catalog-search-box label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 0.75rem; font-weight: 600; color: var(--c-muted);
  text-transform: uppercase; letter-spacing: .04em;
}
.optional { font-weight: 400; text-transform: none; font-size: 0.7rem; color: #aaa; }

.kp-meta-fields input {
  padding: 8px 10px;
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
}
.kp-meta-fields input:focus { outline: none; border-color: var(--c-accent2); }

/* ── Catalog search ────────────────────────────── */
.catalog-search-box h3 { font-size: 0.92rem; margin-bottom: 10px; }
.search-row { display: flex; gap: 8px; }
.search-row input {
  flex: 1;
  padding: 9px 12px;
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
}
.search-row input:focus { outline: none; border-color: var(--c-accent2); }
.search-row .btn-primary { width: auto; }
.search-row .btn-ghost { width: auto; white-space: nowrap; }
.search-row .btn-ghost.is-active {
  background: #ffe7dd;
  border-color: #d17173;
  color: #6e171b;
}

.catalog-filters {
  margin-top: 10px;
  padding: 10px;
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: #fff6ea;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  align-items: end;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.catalog-filters label {
  display: grid;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.catalog-filters input,
.catalog-filters select {
  padding: 8px 10px;
  border: 1.5px solid var(--c-border);
  border-radius: 8px;
  font-size: 0.86rem;
  font-family: inherit;
  background: #fff;
}

.catalog-filters input:focus,
.catalog-filters select:focus {
  outline: none;
  border-color: var(--c-accent2);
}

.catalog-filters .btn-secondary,
.catalog-filters .btn-ghost {
  width: auto;
  white-space: nowrap;
  justify-self: start;
}

.catalog-filters .filter-attr,
.catalog-filters label {
  min-width: 0;
}

/* Catalog results grid */
.catalog-results {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  max-height: 340px;
  overflow-y: auto;
  padding-right: 2px;
}
.catalog-results:empty { display: none; }

.catalog-card {
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 10px;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  display: flex; flex-direction: column; gap: 6px;
}
.catalog-card:hover { border-color: var(--c-accent2); box-shadow: 0 2px 10px rgba(143, 19, 26, 0.16); background: var(--c-hover); }
.catalog-card img {
  width: 100%; aspect-ratio: 1/1; object-fit: contain;
  border-radius: 4px;
  background: #f9f9f9;
}
.catalog-card .cc-name { font-size: 0.78rem; font-weight: 600; line-height: 1.3; }
.catalog-card .cc-sku { font-size: 0.72rem; color: var(--c-muted); }
.catalog-card .cc-price { font-size: 0.85rem; font-weight: 700; color: var(--c-accent2); }
.catalog-card .cc-add-btn {
  width: 100%; background: var(--c-accent); color: #fff;
  border: none; border-radius: 4px; padding: 5px;
  font-size: 0.75rem; font-weight: 600; cursor: pointer;
  transition: background var(--transition);
  margin-top: auto;
}
.catalog-card .cc-add-btn:hover { background: var(--c-accent2); }

/* search state cards */
.catalog-loading, .catalog-empty {
  grid-column: 1 / -1;
  padding: 20px;
  text-align: center;
  color: var(--c-muted);
  font-size: 0.85rem;
}

/* ── Items table ───────────────────────────────── */
.selected-items-wrap { flex: 1; }
.selected-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.selected-head h3 { font-size: 0.92rem; }

.badge {
  background: var(--c-accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 20px;
  padding: 2px 8px;
}

.empty-state {
  padding: 32px;
  text-align: center;
  color: var(--c-muted);
  border: 1.5px dashed var(--c-border);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}
.empty-state-sm { color: var(--c-muted); font-size: 0.82rem; padding: 12px 0; }

.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}
.items-table thead tr {
  background: var(--c-primary);
  color: #fff;
}
.items-table th {
  padding: 9px 10px;
  font-weight: 600;
  font-size: 0.76rem;
  text-align: left;
  white-space: nowrap;
}
.items-table tbody tr { transition: background var(--transition); }
.items-table tbody tr:nth-child(even) { background: #fff6ea; }
.items-table tbody tr:hover { background: var(--c-hover); }
.items-table td { padding: 8px 10px; vertical-align: middle; }

.col-img { width: 58px; }
.col-sku { width: 90px; }
.col-price { width: 100px; }
.col-disc { width: 130px; }
.col-final { width: 110px; }
.col-del { width: 36px; }

.td-img img {
  width: 50px; height: 50px; object-fit: contain;
  border-radius: 4px; background: #f5f5f5;
  display: block;
}
.td-img .no-img {
  width: 50px; height: 50px; background: #f0f0f0;
  border-radius: 4px; display: flex; align-items: center; justify-content: center;
  color: #bbb; font-size: 18px;
}

.td-name { font-weight: 600; line-height: 1.3; }
.td-sku { color: var(--c-muted); font-size: 0.78rem; }
.td-price { font-weight: 500; }
.td-final { font-weight: 700; color: var(--c-primary); }

/* Discount input */
.disc-wrap { display: flex; gap: 4px; align-items: center; }
.disc-type-select {
  padding: 5px 4px;
  border: 1.5px solid var(--c-border);
  border-radius: 4px;
  font-size: 0.76rem;
  font-family: inherit;
  background: #fff;
  width: 46px;
}
.disc-value-input {
  width: 60px;
  padding: 5px 6px;
  border: 1.5px solid var(--c-border);
  border-radius: 4px;
  font-size: 0.84rem;
  font-family: inherit;
  text-align: right;
}
.disc-value-input:focus, .disc-type-select:focus { outline: none; border-color: var(--c-accent2); }

.btn-del {
  background: none; border: none; color: #d9534f;
  cursor: pointer; padding: 4px 6px; border-radius: 4px;
  font-size: 1rem; line-height: 1;
  transition: background var(--transition);
}
.btn-del:hover { background: #fce8e8; }

tfoot .total-row td, tfoot .savings-row td {
  padding: 10px 10px;
  border-top: 2px solid var(--c-border);
}
.total-label, .savings-label { text-align: right; font-weight: 600; color: var(--c-muted); padding-right: 10px; }
.total-value { font-size: 1.05rem; font-weight: 700; color: var(--c-primary); }
.savings-value { color: var(--c-accent); font-weight: 700; }

/* ── Actions ───────────────────────────────────── */
.kp-actions {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding-top: 8px; border-top: 1px solid var(--c-border);
}
.kp-actions .btn-primary { width: auto; }
.kp-status { font-size: 0.82rem; color: var(--c-muted); margin-left: auto; }
.kp-status.ok { color: var(--c-success); }
.kp-status.err { color: var(--c-accent); }

/* ── Sidebar ───────────────────────────────────── */
.kp-sidebar {
  background: var(--c-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--c-border);
  padding: 16px;
  align-self: start;
  position: sticky; top: 68px;
  max-height: calc(100vh - 88px);
  overflow-y: auto;
}
.kp-sidebar h3 { font-size: 0.88rem; margin-bottom: 12px; color: var(--c-muted); text-transform: uppercase; letter-spacing: .05em; }

.proposal-history { display: flex; flex-direction: column; gap: 8px; }

.history-card {
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 10px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.history-card:hover { border-color: var(--c-accent2); background: var(--c-hover); }
.history-card.active { border-color: var(--c-accent); background: #fff1e8; }
.history-card-title { font-weight: 600; font-size: 0.82rem; line-height: 1.3; margin-bottom: 3px; }
.history-card-meta { font-size: 0.72rem; color: var(--c-muted); }
.history-card-actions { display: flex; gap: 6px; margin-top: 8px; }
.btn-hist {
  flex: 1; padding: 5px 8px; font-size: 0.72rem; font-weight: 600;
  border-radius: 4px; border: 1.5px solid var(--c-border);
  cursor: pointer; background: #fff; font-family: inherit;
  transition: background var(--transition);
}
.btn-hist:hover { background: var(--c-hover); }
.btn-hist-del { color: var(--c-accent); border-color: #fce4e6; }
.btn-hist-del:hover { background: #fff0f1 !important; }

.cc-img-placeholder {
  width: 100%;
  aspect-ratio: 1;
  background: #f0f0f0;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #bbb;
}

/* ── Scrollbar ─────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d0d3e0; border-radius: 4px; }

/* ── Responsive ────────────────────────────────── */
@media (max-width: 960px) {
  .kp-layout { grid-template-columns: 1fr; }
  .kp-sidebar { position: static; max-height: none; }
  .kp-meta-fields { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .kp-meta-fields { grid-template-columns: 1fr; }
  .profile-form { grid-template-columns: 1fr; }
  .kp-actions { flex-direction: column; }
  .search-row { flex-direction: column; }
  .catalog-filters {
    grid-template-columns: 1fr;
  }
}
