:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e2e5ea;
  --primary: #1f6feb;
  --primary-dark: #185ac2;
  --danger: #c62828;
  --ok: #2e7d32;
  --warn: #b26a00;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 1.25rem 0 .5rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
h2:first-child { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pre { white-space: pre-wrap; }
.inline { display: inline; }
.wide { width: 100%; }

/* ----- top bar ----- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .7rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); }
.topnav { display: flex; gap: 1.1rem; align-items: center; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 2rem 0 1rem; }

/* ----- layout ----- */
.container { max-width: 1200px; margin: 0 auto; padding: 1.25rem; }
.container.narrow { max-width: 820px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.head-meta { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin-top: .25rem; }
.actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.detail-layout { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 1.25rem; }
@media (max-width: 900px) { .detail-layout { grid-template-columns: 1fr; } }

/* ----- buttons ----- */
button, .btn, .btn-primary, .btn-danger {
  font: inherit; cursor: pointer; border-radius: 8px; padding: .5rem .9rem; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); display: inline-block; line-height: 1.2;
}
.btn:hover { background: #eef1f5; text-decoration: none; }
.btn.small { padding: .3rem .6rem; font-size: .85rem; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-link { background: none; border: none; padding: 0; color: var(--primary); }
.btn-link.danger { color: var(--danger); }
.btn-link:hover { text-decoration: underline; }
.btn-ghost { background: none; border: 1px solid var(--border); }

/* ----- forms ----- */
input[type=text], input[type=search], input[type=number], input[type=password], select, textarea {
  font: inherit; padding: .5rem .65rem; border: 1px solid var(--border); border-radius: 8px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31,111,235,.35); border-color: var(--primary); }
label, legend { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
.field { margin-bottom: 1rem; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; }
.form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.error { display: block; color: var(--danger); font-size: .85rem; margin-top: .25rem; }
.error:empty { display: none; }
.help { color: var(--muted); font-size: .85rem; margin: .3rem 0 0; }
.row { display: flex; gap: .5rem; align-items: center; }
.row select { width: auto; min-width: 180px; }
.input-row { display: flex; gap: .4rem; }
.compat-row { display: grid; grid-template-columns: 1.2fr 1.4fr .8fr auto; gap: .5rem; align-items: center; margin-bottom: .5rem; }
@media (max-width: 640px) { .compat-row { grid-template-columns: 1fr; } }

/* ----- filters ----- */
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto auto; gap: .5rem; align-items: center; margin-bottom: 1.25rem; }
@media (max-width: 900px) { .filters { grid-template-columns: 1fr 1fr; } }

/* ----- cards ----- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; color: inherit; transition: box-shadow .15s; }
.card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.08); text-decoration: none; }
.thumb { aspect-ratio: 4 / 3; background: #eceff3; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.placeholder { color: #aab0bb; font-size: 2rem; }
.placeholder.large { height: 240px; display: flex; align-items: center; justify-content: center; background: #eceff3; border-radius: 8px; font-size: 1rem; }
.card-body { padding: .75rem .9rem; }
.card-title { font-weight: 600; margin-bottom: .15rem; }
.card-row { display: flex; gap: .6rem; align-items: center; margin-top: .35rem; flex-wrap: wrap; }
.price { font-weight: 600; }
.price.big { font-size: 1.3rem; }
.empty { text-align: center; color: var(--muted); padding: 3rem 0; }

/* ----- badges ----- */
.badge { font-size: .75rem; padding: .15rem .5rem; border-radius: 999px; font-weight: 600; }
.badge.in_stock { background: #e3f3e5; color: var(--ok); }
.badge.reserved { background: #fff3df; color: var(--warn); }
.badge.sold { background: #ebedf0; color: var(--muted); }

/* ----- gallery ----- */
.main-photo { width: 100%; max-height: 70vh; object-fit: contain; background: #111; border-radius: 8px; }
.thumbs { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .75rem; }
.thumb-item { width: 120px; }
.thumb-img { width: 120px; height: 90px; object-fit: cover; border-radius: 6px; border: 2px solid transparent; cursor: pointer; display: block; }
.thumb-item.is-cover .thumb-img { border-color: var(--primary); }
.thumb-actions { display: flex; gap: .5rem; font-size: .78rem; margin-top: .25rem; flex-wrap: wrap; }
.upload-form { display: flex; gap: .5rem; align-items: center; margin-top: 1rem; flex-wrap: wrap; }
.upload-form input[type=file] { width: auto; }

/* ----- detail ----- */
.props { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0; }
.props dt { color: var(--muted); }
.props dd { margin: 0; }
.json { background: #f6f8fa; padding: .75rem; border-radius: 8px; font-size: .8rem; overflow: auto; }
#adText { font-family: inherit; width: 100%; margin-bottom: .5rem; }
.footer-dates { margin-top: 1.5rem; }

/* ----- pagination ----- */
.pagination { display: flex; gap: 1rem; align-items: center; justify-content: center; margin: 1.5rem 0; }

/* ----- flash ----- */
.flash { padding: .6rem .9rem; border-radius: 8px; margin-bottom: 1rem; }
.flash.info { background: #e3f3e5; color: var(--ok); }
.flash.warning { background: #fff3df; color: var(--warn); }
.flash.error { background: #fdecea; color: var(--danger); }

/* ----- login ----- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; width: min(400px, 92vw); }
.login-card h1 { text-align: center; margin-bottom: 1.25rem; }
.login-card .btn-primary { margin-top: 1rem; }
