:root {
  --bg: #f9fafb;
  --card: #ffffff;
  --fg: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --input: #d1d5db;
  --primary: #030213;
  --primary-fg: #ffffff;
  --accent: #f3f4f6;
  --danger: #d4183d;
  --star: #f59e0b;
  --ring: rgba(3, 2, 19, 0.18);
  --radius: 10px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
[hidden] { display: none !important; }

.wrap { max-width: 56rem; margin: 0 auto; padding: 2rem 16px; }
.wrap.wide { max-width: 80rem; }
.topright { text-align: right; margin-bottom: 1rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  padding: 1.5rem;
}
.card + .card { margin-top: 1.5rem; }
.card-title { font-size: 1.25rem; font-weight: 600; margin: 0 0 1.5rem; }
.card-title.center { text-align: center; }

h3 { font-size: 1.1rem; font-weight: 600; margin: 0 0 1rem; }
h4 { font-size: 1.05rem; font-weight: 600; margin: 0 0 .75rem; }
section { border-top: 1px solid var(--border); padding-top: 1.5rem; margin-top: 1.5rem; }
.muted { color: var(--muted); font-size: .9rem; }
.muted ul { padding-left: 1.5rem; }

.grid2 { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 768px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.field { margin-bottom: 1rem; }
.grid2 .field { margin-bottom: 0; }
.grid2 + .field, .field + .grid2 { margin-top: 1rem; }

label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: .375rem; }
input, textarea, select {
  width: 100%;
  font: inherit;
  color: inherit;
  background: #f3f3f5;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: .5rem .75rem;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 5rem; }
input:focus, textarea:focus, select:focus { border-color: var(--input); box-shadow: 0 0 0 3px var(--ring); background: #fff; }
.invalid { border-color: var(--danger) !important; box-shadow: 0 0 0 3px rgba(212, 24, 61, .15) !important; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-size: .875rem; font-weight: 500;
  padding: .5rem 1rem; border-radius: 8px;
  border: 1px solid var(--border); background: #fff; color: var(--fg);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, opacity .15s;
}
.btn:hover { background: var(--accent); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.btn.primary:hover { background: #22212e; }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.danger:hover { background: #b3122f; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--fg); background: var(--accent); }
.btn.lg { padding: .7rem 1.25rem; font-size: 1rem; }
.btn.sm { padding: .3rem .6rem; font-size: .8rem; }
.btn.block { width: 100%; }
.btn svg { width: 16px; height: 16px; }

/* Star rating */
.rating label { margin-bottom: .25rem; }
.stars { display: inline-flex; gap: 2px; }
.stars button {
  background: none; border: 0; padding: 2px; cursor: pointer; line-height: 0; border-radius: 4px;
}
.stars button:focus-visible { outline: 2px solid var(--primary); }
.stars svg { width: 28px; height: 28px; fill: none; stroke: #d1d5db; stroke-width: 1.5; transition: transform .1s; }
.stars button:hover svg { transform: scale(1.1); }
.stars .on svg { fill: var(--star); stroke: var(--star); }
.stars-caption { font-size: .8rem; color: var(--muted); margin-left: .5rem; vertical-align: middle; }

/* Signature pad */
.sigbox { border: 2px solid var(--input); border-radius: 8px; padding: .5rem; background: #fff; }
.sigbox canvas {
  display: block; width: 100%; height: 150px;
  border: 1px solid var(--border); border-radius: 6px;
  touch-action: none; cursor: crosshair; background: #fff;
}
.sigbox .sig-row { display: flex; justify-content: space-between; align-items: center; margin-top: .5rem; }
.sigbox.invalid { box-shadow: none !important; }

/* Toasts */
#toasts { position: fixed; top: 16px; right: 16px; left: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; z-index: 100; pointer-events: none; }
.toast {
  pointer-events: auto; max-width: 420px; width: 100%;
  background: #fff; border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: 8px; padding: .75rem 1rem; font-size: .9rem;
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
  animation: toast-in .2s ease-out;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: #16a34a; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

/* Success panel */
.done { text-align: center; padding: 1rem 0; }
.done .check { width: 56px; height: 56px; border-radius: 50%; background: #dcfce7; color: #16a34a; display: inline-flex; align-items: center; justify-content: center; margin-bottom: 1rem; }
.done .check svg { width: 28px; height: 28px; }
.done .actions { display: flex; gap: .75rem; justify-content: center; flex-wrap: wrap; margin-top: 1.25rem; }

/* Admin */
.adminbar { background: #fff; border-bottom: 1px solid var(--border); }
.adminbar .wrap { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; padding-top: 1rem; padding-bottom: 1rem; }
.adminbar h1 { margin: 0; font-size: 1.5rem; font-weight: 600; }
.adminbar .actions { display: flex; gap: .5rem; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
@media (min-width: 768px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 1.25rem; }
.stat b { display: block; font-size: 1.6rem; }
.stat span { color: var(--muted); font-size: .85rem; }

.filters { display: flex; gap: .75rem; flex-wrap: wrap; }
.filters input { flex: 1 1 240px; }
.filters select { width: auto; flex: 0 0 auto; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-weight: 500; color: var(--muted); padding: .6rem .5rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: .7rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td .sub { color: var(--muted); font-size: .8rem; }
td.trunc { max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.actions { white-space: nowrap; }
td.actions .btn { padding: .3rem .45rem; }
.badge { display: inline-block; border: 1px solid var(--border); border-radius: 6px; padding: .05rem .45rem; font-size: .8rem; font-weight: 500; }
.badge.warn { background: #fef3c7; border-color: #fde68a; color: #92400e; }
.badge.ok { background: #dcfce7; border-color: #bbf7d0; color: #166534; }
.badge.bad { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.badge.muted { color: var(--muted); }
.cw-line { display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap; font-size: .9rem; }
.empty { text-align: center; color: var(--muted); padding: 2rem 0; }

.login { max-width: 400px; margin: 10vh auto 0; }
.error-box { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; border-radius: 8px; padding: .6rem .8rem; font-size: .875rem; margin-bottom: 1rem; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 56rem; max-height: 90vh; overflow-y: auto; padding: 1.5rem; }
.modal.small { max-width: 28rem; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.modal-head h2 { margin: 0; font-size: 1.2rem; }
.kv div { margin-bottom: .35rem; font-size: .9rem; }
.kv b { font-weight: 500; }
.ratings-list div { display: flex; justify-content: space-between; font-size: .9rem; padding: .15rem 0; }
.ratings-list .avg { border-top: 1px solid var(--border); margin-top: .35rem; padding-top: .5rem; font-weight: 600; }
.comment { background: var(--bg); border-radius: 8px; padding: .75rem; font-size: .9rem; white-space: pre-wrap; }
.sigs img { max-width: 100%; height: 90px; object-fit: contain; border: 1px solid var(--border); border-radius: 6px; background: #fff; display: block; }
.modal-foot { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 1rem; margin-top: 1.5rem; }
.modal-foot .right { display: flex; gap: .5rem; flex-wrap: wrap; }

.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--fg); border-radius: 50%; animation: spin .7s linear infinite; margin: 3rem auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.mt { margin-top: 1rem; }
.mt-lg { margin-top: 1.5rem; }
.hint { margin: .25rem 0 .5rem; }
.card-title.tight { margin-bottom: .5rem; }
.center-link { text-align: center; margin: 1rem 0 0; }
