:root {
  --bg: #e8eef2;
  --bg-accent: #d5e0e8;
  --surface: #f7fafc;
  --ink: #1a2332;
  --muted: #5a6a7a;
  --line: #c5d0da;
  --accent: #0f6e56;
  --accent-hover: #0a5542;
  --danger: #9b2c2c;
  --warn: #9a6700;
  --ok: #0f6e56;
  --shadow: 0 1px 2px rgba(26, 35, 50, 0.06);
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #cfe0ea 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #d9ebe3 0%, transparent 50%),
    var(--bg);
  min-height: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1.25rem 3rem;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  padding: 0.85rem 0 1.25rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1.5rem;
}

.brand {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  font-size: 0.95rem;
}

.nav a { color: var(--muted); text-decoration: none; }
.nav a:hover, .nav a.active { color: var(--ink); }

.userbox {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

h1 {
  font-size: 1.55rem;
  margin: 0 0 0.35rem;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--muted);
  margin: 0 0 1.25rem;
  font-size: 0.95rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  font: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; color: #fff; }
.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}
.btn-secondary:hover { background: var(--bg-accent); color: var(--ink); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #7f1d1d; }
.btn-sm { padding: 0.25rem 0.55rem; font-size: 0.85rem; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

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

th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: #eef3f6;
}

tr:last-child td { border-bottom: none; }

.mono { font-family: var(--mono); font-size: 0.88rem; }
.muted { color: var(--muted); }
.right { text-align: right; }
.low { color: var(--warn); font-weight: 600; }
.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.78rem;
  background: var(--bg-accent);
  color: var(--ink);
}
.badge-draft { background: #e8edf2; }
.badge-built { background: #d8eee6; color: var(--ok); }
.badge-sold { background: #f0e4e4; color: var(--danger); }

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-bottom: 1.5rem;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: 0.85rem; }
.stat .value { font-size: 1.6rem; font-weight: 700; margin-top: 0.2rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}

.form {
  display: grid;
  gap: 0.9rem;
  max-width: 560px;
}
.form.wide { max-width: 720px; }
.form.sale-form {
  max-width: 980px;
  width: 100%;
}

.discount-row {
  display: grid;
  grid-template-columns: 1fr 90px;
  gap: 0.5rem;
}
.sale-lines-block {
  border-top: 1px solid var(--line);
  padding-top: 0.85rem;
}
.sale-head {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) 90px 120px 100px;
  gap: 0.5rem;
  padding: 0 0.15rem 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.sale-summary {
  margin-top: 0.65rem;
  text-align: right;
}
.pill {
  display: inline-block;
  font-size: 0.8rem;
  padding: 0.35rem 0.55rem;
  border-radius: 6px;
  background: var(--bg-accent);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.public-topbar {
  justify-content: space-between;
}
.catalog-shell {
  max-width: 1100px;
}
.catalog-contacts {
  font-size: 0.9rem;
}
.catalog-filters {
  margin-bottom: 1.25rem;
}
.catalog-section-title {
  font-size: 1.1rem;
  margin: 1.25rem 0 0.75rem;
  font-weight: 600;
}
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.catalog-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.catalog-photo {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: #eef3f6;
  display: block;
}
.catalog-photo-empty {
  background:
    linear-gradient(145deg, #e8eef2 0%, #d5e0e8 100%);
}
.catalog-photo-assembly {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.06em;
  font-size: 1.25rem;
}
.catalog-card-body {
  padding: 0.75rem 0.85rem 0.95rem;
  display: grid;
  gap: 0.25rem;
}
.catalog-meta {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.catalog-name {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
}
.catalog-type {
  margin: 0;
  font-size: 0.85rem;
}
.catalog-price {
  margin: 0.35rem 0 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
}
.catalog-footer {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  font-size: 0.9rem;
  display: grid;
  gap: 0.25rem;
}


.client-picker {
  position: relative;
  display: grid;
  gap: 0.35rem;
}
.client-picker .hint {
  margin: 0;
  font-size: 0.8rem;
}
.client-picker-list {
  position: absolute;
  z-index: 20;
  top: 2.55rem;
  left: 0;
  right: 0;
  max-height: 240px;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}
.client-picker-item {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.client-picker-item:last-child { border-bottom: 0; }
.client-picker-item:hover,
.client-picker-item:focus {
  background: var(--bg-accent);
  outline: none;
}
.cpi-name { color: var(--ink); }
.cpi-phone { color: var(--muted); font-size: 0.85rem; }
.client-picker-empty {
  padding: 0.65rem 0.7rem;
  color: var(--muted);
  font-size: 0.9rem;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
}

input, select, textarea {
  font: inherit;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

textarea { min-height: 80px; resize: vertical; }

.row-2 {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr 1fr;
}

.alert {
  padding: 0.75rem 0.9rem;
  border-radius: 6px;
  background: #f8e8e8;
  color: var(--danger);
  border: 1px solid #e8c5c5;
  margin-bottom: 1rem;
}
.notice {
  padding: 0.75rem 0.9rem;
  border-radius: 6px;
  background: #e8f5ee;
  color: #1f6b43;
  border: 1px solid #c5e8d2;
  margin-bottom: 1rem;
}

.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: min(100%, 400px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.login-card h1 { margin-bottom: 0.25rem; }
.login-card .subtitle { margin-bottom: 1.25rem; }

.bom-row, .sale-row {
  display: grid;
  gap: 0.5rem;
  grid-template-columns: 2fr 1fr auto;
  align-items: center;
  margin-bottom: 0.5rem;
}
.sale-row {
  grid-template-columns: 120px minmax(0, 1fr) 90px 120px 100px;
  align-items: center;
  padding: 0.45rem 0.15rem;
  border-bottom: 1px solid var(--line);
}
.sale-row .sale-cell {
  min-width: 0;
}
.sale-row .sale-cell input,
.sale-row .sale-cell select {
  width: 100%;
}
.sale-row .actions-cell {
  display: flex;
  justify-content: flex-end;
}
.sale-row > input[type="hidden"] {
  display: none;
}

.search-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.photo-block {
  display: grid;
  gap: 0.65rem;
}
.photo-preview-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 96px;
}
.photo-preview {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}
.checkbox-inline {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.9rem;
}
.thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  display: block;
  background: #fff;
}
.thumb-empty {
  display: inline-block;
  background: var(--bg-accent);
}

.inline-edit {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin: 0;
}
.inline-edit input {
  min-width: 140px;
  flex: 1;
}

@media (max-width: 720px) {
  .row-2, .bom-row, .sale-row { grid-template-columns: 1fr; }
  .sale-head { display: none; }
  .sale-row .actions-cell { justify-content: flex-start; }
  .topbar { align-items: flex-start; }
}
