:root {
  --primary: #5b1a2b;
  --primary-hover: #74263a;
  --dark: #2a0d15;
  --bg: #f7f3f1;
  --panel: #ffffff;
  --ink: #1b1114;
  --muted: #6f6266;
  --line: #e6dcd8;
  --danger: #b3261e;
  --ok: #1f7a4d;
  --font: "Poppins", system-ui, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 14px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { font-weight: 500; letter-spacing: -0.02em; }
img, video { display: block; max-width: 100%; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); font-weight: 500; white-space: nowrap; text-decoration: none; transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.1s; }
.btn:hover { border-color: var(--ink); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.small { height: 32px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: 0.45; pointer-events: none; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--dark); }
.login form { width: min(380px, 100%); background: var(--panel); border-radius: 14px; padding: 36px; }
.login .mark { font-size: 20px; font-weight: 500; letter-spacing: 0.3em; text-transform: uppercase; }
.login h1 { font-size: 22px; margin: 22px 0 6px; }
.login p { color: var(--muted); margin-bottom: 22px; }
.login .btn { width: 100%; margin-top: 16px; height: 44px; }
.login .error { color: var(--danger); margin: 10px 0 0; min-height: 20px; }

/* Layout */
.shell { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--dark); color: #fbf1ee; padding: 24px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.side .mark { padding: 0 10px 20px; font-size: 17px; font-weight: 500; letter-spacing: 0.3em; text-transform: uppercase; }
.side .mark small { display: block; margin-top: 4px; font-size: 11px; letter-spacing: 0.04em; text-transform: none; opacity: 0.6; font-weight: 400; }
.side h3 { font-size: 11px; font-weight: 500; opacity: 0.55; padding: 16px 10px 6px; letter-spacing: 0.04em; }
.side nav button { display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left; padding: 8px 10px; border-radius: 8px; color: rgba(251, 241, 238, 0.82); transition: background 0.15s, color 0.15s; }
.side nav button:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }
.side nav button[aria-current="true"] { background: #fbf1ee; color: var(--dark); font-weight: 500; }
.side nav button span { font-size: 12px; opacity: 0.6; }
.side .out { margin-top: auto; padding: 16px 10px 0; }
.side .out button { opacity: 0.7; text-decoration: underline; text-underline-offset: 3px; }

.main { min-width: 0; }
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 14px 32px; background: rgba(247, 243, 241, 0.92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top h1 { font-size: 20px; margin-right: auto; }
.status { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.status.dirty::before { background: #d08a1c; }
.content { padding: 28px 32px 80px; max-width: 980px; }
.intro { color: var(--muted); margin-bottom: 20px; max-width: 44rem; }

/* Fields */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 22px; margin-bottom: 16px; }
.panel > h2 { font-size: 16px; margin-bottom: 16px; }
.f { margin-bottom: 18px; }
.f:last-child { margin-bottom: 0; }
.f > label, .f > .lab { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.f .hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
input[type="text"], input[type="search"], input[type="password"], textarea, select { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; transition: border-color 0.15s; }
textarea { resize: vertical; min-height: 76px; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: 0; border-color: var(--primary); }
.color { display: flex; align-items: center; gap: 10px; }
.color input[type="color"] { width: 44px; height: 40px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; }
.color input[type="text"] { width: 120px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }

.media { display: flex; align-items: center; gap: 14px; }
.media img, .media video { width: 84px; height: 112px; object-fit: cover; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); }
.media code { display: block; font-size: 12px; color: var(--muted); margin-bottom: 8px; word-break: break-all; }
.media .row { display: flex; gap: 8px; }

.list-item { border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 10px; background: #fcfaf9; }
.list-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; font-size: 12px; color: var(--muted); font-weight: 500; }
.list-head .row, .row { display: flex; gap: 6px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.chip { display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 6px; border: 1px solid var(--line); border-radius: 10px; background: #fcfaf9; }
.chip img { width: 36px; height: 48px; object-fit: cover; border-radius: 6px; }
.chip strong { display: block; font-weight: 500; font-size: 13px; }
.chip span { font-size: 12px; color: var(--muted); }

/* Catalogue */
.bar { display: flex; gap: 10px; margin-bottom: 18px; }
.bar input, .bar select { max-width: 260px; }
.bar .btn { margin-left: auto; }
.pieces { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.piece { display: flex; flex-direction: column; align-items: stretch; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; transition: border-color 0.15s, transform 0.15s; }
.piece:hover { border-color: var(--primary); transform: translateY(-2px); }
.piece .ph { position: relative; aspect-ratio: 3 / 4; background: var(--bg); }
.piece img { width: 100%; height: 100%; object-fit: cover; object-position: center 20%; }
.piece .tag { position: absolute; top: 8px; left: 8px; background: var(--primary); color: #fff; font-size: 11px; font-weight: 500; padding: 3px 8px; border-radius: 6px; }
.piece .tx { padding: 10px 12px 12px; }
.piece strong { display: block; font-weight: 500; }
.piece span { font-size: 12px; color: var(--muted); }
.back { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 16px; font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; margin-bottom: 12px; }
.photo { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fcfaf9; }
.photo .ph { position: relative; aspect-ratio: 3 / 4; }
.photo img, .photo video { width: 100%; height: 100%; object-fit: cover; }
.photo .tag { position: absolute; top: 6px; left: 6px; background: var(--ink); color: #fff; font-size: 11px; padding: 2px 7px; border-radius: 6px; }
.photo .tag.used { background: var(--ok); }
.photo .acts { display: flex; justify-content: space-between; padding: 6px; }
.photo .acts button { width: 30px; height: 30px; border-radius: 6px; display: grid; place-items: center; font-size: 15px; transition: background 0.15s; }
.photo .acts button:hover { background: var(--line); }
.photo .acts button:disabled { opacity: 0.3; pointer-events: none; }
.photo .acts .x { color: var(--danger); }
.photo.pick { cursor: pointer; transition: border-color 0.15s, transform 0.15s; }
.photo.pick:hover { border-color: var(--primary); transform: translateY(-2px); }
.photo.pick[aria-pressed="true"] { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary); }
.photo .name { padding: 6px 8px; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.drop { border: 1.5px dashed #cdbfba; border-radius: 12px; padding: 22px; text-align: center; color: var(--muted); background: #fcfaf9; margin-bottom: 16px; transition: border-color 0.15s, background 0.15s; }
.drop.over { border-color: var(--primary); background: #f8eeee; }
.drop strong { display: block; color: var(--ink); font-weight: 500; margin-bottom: 4px; }
.drop .btn { margin-top: 12px; }

/* Modal and toast */
dialog.modal { border: 0; border-radius: 14px; padding: 0; width: min(900px, 94vw); max-height: 88vh; color: var(--ink); }
dialog.modal::backdrop { background: rgba(42, 13, 21, 0.6); }
.modal-in { display: flex; flex-direction: column; max-height: 88vh; }
.modal-head, .modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-foot { border-bottom: 0; border-top: 1px solid var(--line); }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 20px; overflow-y: auto; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 100; padding: 12px 18px; border-radius: 10px; background: var(--ink); color: #fff; opacity: 0; transform: translateY(12px); transition: opacity 0.25s, transform 0.25s; pointer-events: none; max-width: 360px; }
.toast.show { opacity: 1; transform: none; }
.toast.bad { background: var(--danger); }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .side nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .side nav button { width: auto; }
  .side h3 { width: 100%; }
  .top { padding: 12px 16px; flex-wrap: wrap; }
  .content { padding: 20px 16px 80px; }
  .two { grid-template-columns: 1fr; }
}
