/* === Base === */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #f4f5f7;
  color: #1f2328;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0 0 .5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: .95rem; margin-top: 1.25rem; color: #4b5563; text-transform: uppercase; letter-spacing: .03em; }
.muted { color: #6b7280; font-size: .9rem; margin: 0 0 1rem; }
.hidden { display: none !important; }

/* === Login === */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.login-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.login-card h1 { font-size: 1.25rem; }
.login-card form { display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; }
.login-card label { font-size: .85rem; color: #4b5563; }

/* === Topbar === */
.topbar {
  background: #111827;
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .8rem 1.25rem;
}
.topbar .brand { font-weight: 600; }
.topbar .link { color: #d1d5db; text-decoration: none; font-size: .9rem; }
.topbar .link:hover { color: #fff; }

/* === App layout === */
.app { max-width: 880px; margin: 1.5rem auto; padding: 0 1rem; display: flex; flex-direction: column; gap: 1.25rem; }
.card { background: #fff; border: 1px solid #e5e7eb; border-radius: 12px; padding: 1.25rem; box-shadow: 0 1px 2px rgba(0,0,0,.04); }

/* === Inputs === */
input, textarea, select {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: .55rem .75rem;
  font: inherit;
  background: #fff;
  color: inherit;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
label { display: block; font-size: .85rem; color: #374151; margin-bottom: .25rem; }
label > input, label > textarea { margin-top: .25rem; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: .75rem; }
.span-2 { grid-column: span 2; }
@media (max-width: 600px) {
  .grid-2 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
}

.row { display: flex; gap: .5rem; align-items: center; margin-top: 1rem; flex-wrap: wrap; }
.row.right { justify-content: flex-end; }
.check { display: inline-flex; align-items: center; gap: .4rem; }
.check input { width: auto; margin: 0; }

/* === Buttons === */
.btn {
  display: inline-block;
  text-decoration: none;
  background: #fff;
  border: 1px solid #d1d5db;
  color: #1f2328;
  padding: .55rem 1rem;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #f3f4f6; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn.primary:hover { background: #1d4ed8; }
.btn.small { padding: .35rem .7rem; font-size: .85rem; }
.btn.danger { color: #b91c1c; border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }

/* === Dropzone === */
.dropzone {
  border: 2px dashed #d1d5db;
  border-radius: 10px;
  padding: 1.5rem;
  text-align: center;
  position: relative;
  background: #fafafa;
  cursor: pointer;
}
.dropzone.drag { border-color: #2563eb; background: #eff6ff; }
.dropzone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone .link { color: #2563eb; text-decoration: underline; }

/* === Thumbnails === */
.thumbs { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .75rem; }
.thumb {
  position: relative;
  width: 110px; height: 110px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .remove {
  position: absolute; top: 2px; right: 2px;
  background: rgba(17,24,39,.85); color: #fff;
  border: 0; border-radius: 999px;
  width: 22px; height: 22px;
  cursor: pointer; font-size: 14px; line-height: 1;
}

/* === Items table === */
.items { width: 100%; border-collapse: collapse; margin-top: .5rem; font-size: .9rem; }
.items th, .items td { border: 1px solid #e5e7eb; padding: .4rem .5rem; text-align: left; }
.items th { background: #f9fafb; font-weight: 600; }
.items .right { text-align: right; }
.items input { padding: .3rem .4rem; border-radius: 6px; }
.items input[type="number"] { text-align: right; }
.items tfoot td { border: 0; padding-top: .75rem; }

/* === Alerts === */
.alert { padding: .6rem .8rem; border-radius: 8px; margin-bottom: .75rem; }
.alert.error { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.alert.success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }

/* === Loading overlay === */
.loading {
  position: fixed; inset: 0;
  background: rgba(255,255,255,.85);
  display: grid; place-items: center;
  z-index: 50;
}
.spinner {
  width: 42px; height: 42px;
  border: 4px solid #e5e7eb;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading p { font-weight: 500; color: #374151; }
