:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #6b7584;
  --border: #dde1e7;
  --primary: #1f6feb;
  --primary-dark: #1858c2;
  --success: #1a7f37;
  --danger: #c62828;
  --warning: #9a6700;
  --new: #1f6feb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.45; min-height: 100vh; }
.optional { color: var(--muted); font-weight: 400; }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.2rem; margin: 1.5rem 0 .75rem; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* --- cabinet layout -------------------------------------------------- */
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  padding: .6rem 1.25rem; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center; width: 32px; height: 32px;
  border-radius: 8px; background: var(--primary); color: #fff; font-weight: 800;
}
.topbar nav { display: flex; gap: .25rem; flex: 1; }
.topbar nav a { padding: .45rem .8rem; border-radius: 8px; color: var(--text); text-decoration: none; }
.topbar nav a:hover { background: var(--bg); }
.topbar nav a.active { background: #e8f0fe; color: var(--primary-dark); font-weight: 600; }
.account { display: flex; align-items: center; gap: .75rem; }
.account span { display: flex; flex-direction: column; line-height: 1.15; text-align: right; }
.account small { color: var(--muted); }
.account form { margin: 0; }

.page { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; }
.card + .card { margin-top: 1rem; }
.narrow { max-width: 420px; margin: 3rem auto; }

/* --- forms & buttons ------------------------------------------------- */
.form { display: grid; gap: .9rem; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .9rem; align-items: end; }
label { display: grid; gap: .3rem; font-weight: 600; font-size: .92rem; }
label.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
input, select, textarea {
  font: inherit; padding: .6rem .7rem; border: 1px solid var(--border);
  border-radius: 8px; background: #fff; color: var(--text); width: 100%;
}
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid #b6d0fb; border-color: var(--primary); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; padding: .55rem 1rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--bg); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(.92); background: var(--success); }
.btn-danger { color: var(--danger); border-color: #f1c4c4; }
.btn-danger:hover { background: #fdecec; }
.btn-ghost { border-color: transparent; }
.btn-sm { padding: .3rem .65rem; font-size: .88rem; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.btn-row form { margin: 0; }

.alert { padding: .75rem 1rem; border-radius: 8px; margin: 0 0 1rem; }
.alert-error { background: #fdecec; color: var(--danger); border: 1px solid #f5c2c2; }
.alert-success { background: #e9f6ec; color: var(--success); border: 1px solid #bfe3c8; }
.alert-info { background: #e8f0fe; color: var(--primary-dark); border: 1px solid #c7d9fb; }

/* --- tables ---------------------------------------------------------- */
.table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table th, .table td { padding: .65rem .75rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.table tr[data-href] { cursor: pointer; }
.table tr[data-href]:hover td { background: #f8fafc; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.table-wrap .table tr:last-child td { border-bottom: 0; }

.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--bg); color: var(--muted); }
.badge-new { background: #e8f0fe; color: var(--new); }
.badge-printed { background: #e9f6ec; color: var(--success); }
.badge-rejected { background: #fdecec; color: var(--danger); }
.badge-warn { background: #fff4d6; color: var(--warning); }

/* --- orders ---------------------------------------------------------- */
.order-code { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.35rem; letter-spacing: .04em; }
.order-code-xl { font-size: 3rem; line-height: 1; }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.toolbar form { display: flex; gap: .5rem; margin: 0; }
.toolbar input[type=search] { width: 160px; }
.filters { display: flex; gap: .25rem; flex-wrap: wrap; }
.filters a { padding: .35rem .75rem; border-radius: 999px; text-decoration: none; color: var(--text); border: 1px solid var(--border); background: var(--surface); font-size: .92rem; }
.filters a.active { background: var(--text); border-color: var(--text); color: #fff; }
tr.is-new td { background: #f3f8ff; }
tr.flash td { animation: flash 2.5s ease-out; }
@keyframes flash { from { background: #fff1b8; } to { background: #f3f8ff; } }
.live-indicator { display: inline-flex; align-items: center; gap: .4rem; font-size: .85rem; color: var(--muted); }
.live-indicator::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #aab2bd; }
.live-indicator.online::before { background: var(--success); }

.order-meta { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1.25rem; margin: 0; }
.order-meta dt { color: var(--muted); }
.order-meta dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.comment-box { background: #fffbea; border: 1px solid #f3e3a1; border-radius: 8px; padding: .75rem 1rem; white-space: pre-wrap; word-break: break-word; font-size: 1.05rem; }

.files-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.file-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.file-thumb { aspect-ratio: 210 / 297; background: #eef0f3; display: grid; place-items: center; overflow: hidden; }
.file-thumb img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.file-thumb .placeholder { color: var(--muted); font-weight: 700; font-size: 1.4rem; text-transform: uppercase; }
.file-body { padding: .75rem; display: grid; gap: .5rem; }
.file-name { font-weight: 600; word-break: break-all; font-size: .92rem; }
.file-info { color: var(--muted); font-size: .85rem; }

/* --- print page ------------------------------------------------------ */
body.print-page { background: #525659; }
.print-bar { position: fixed; top: 0; left: 0; right: 0; display: flex; gap: .5rem; align-items: center; padding: .5rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 2; }
.print-frame { position: fixed; top: 54px; left: 0; right: 0; bottom: 0; width: 100%; height: calc(100% - 54px); border: 0; background: #525659; }

/* --- client (phone) -------------------------------------------------- */
body.client { background: #fff; }
body.client .page { max-width: 560px; padding: 1rem 1rem 2.5rem; }
.client-head { text-align: center; padding: .75rem 0 1.25rem; }
.client-head small { display: block; color: var(--muted); font-size: .95rem; }
.client-head h1 { font-size: 1.9rem; margin: .1rem 0 0; }
.pick-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.pick-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .35rem;
  min-height: 96px; border-radius: 16px; border: 2px solid var(--border); background: var(--bg);
  font: inherit; font-weight: 700; font-size: 1rem; color: var(--text); cursor: pointer; text-align: center;
}
.pick-btn svg { width: 34px; height: 34px; }
.pick-btn { position: relative; }
.sr-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }
.pick-btn:focus-within { outline: 3px solid #b6d0fb; }
.pick-btn:active { background: #e8f0fe; border-color: var(--primary); }
.file-list { list-style: none; padding: 0; margin: 1rem 0; display: grid; gap: .5rem; }
.file-list li { display: flex; align-items: center; gap: .6rem; padding: .6rem .7rem; border: 1px solid var(--border); border-radius: 12px; }
.file-list .fl-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.file-list .fl-size { color: var(--muted); font-size: .85rem; }
.file-list .fl-error { color: var(--danger); font-size: .85rem; }
.file-list button { border: 0; background: transparent; font-size: 1.6rem; line-height: 1; color: var(--muted); padding: .1rem .4rem; cursor: pointer; }
body.client label { font-size: 1rem; }
body.client input, body.client textarea { font-size: 1.1rem; padding: .8rem; border-radius: 12px; }
.submit-btn { width: 100%; min-height: 64px; font-size: 1.25rem; border-radius: 16px; margin-top: .5rem; }
.progress { height: 10px; border-radius: 999px; background: var(--bg); overflow: hidden; margin-top: .75rem; }
.progress span { display: block; height: 100%; width: 0; background: var(--primary); transition: width .2s; }
.hint { color: var(--muted); font-size: .9rem; text-align: center; margin: .75rem 0 0; }
.done { text-align: center; padding: 2rem 0; }
.done .order-code { font-size: 6rem; line-height: 1; letter-spacing: .08em; color: var(--primary); margin: 1rem 0; }
.done .say { font-size: 1.6rem; font-weight: 700; }

/* --- admin ----------------------------------------------------------- */
.copy-field { display: flex; gap: .4rem; }
.copy-field input { font-family: ui-monospace, monospace; font-size: .9rem; }
.qr-preview { width: 96px; height: 96px; image-rendering: pixelated; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.password-box { font-family: ui-monospace, monospace; font-size: 1.4rem; font-weight: 700; letter-spacing: .05em; padding: .5rem .75rem; background: var(--bg); border-radius: 8px; display: inline-block; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: .5rem; padding: .5rem .75rem; }
  .topbar nav { order: 3; width: 100%; overflow-x: auto; }
  .account { margin-left: auto; }
  .page { padding: 1rem .75rem 2rem; }
  .order-meta { grid-template-columns: 1fr; gap: .1rem; }
  .order-meta dd { margin-bottom: .5rem; }
}
.print-bar .spacer { margin-left: auto; }
.print-bar .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-wrap + .card { margin-top: 1.5rem; }
.copy-field input { min-width: 300px; }
