:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #14181f;
  --ink-soft: #525a68;
  --border: #dde1e8;
  --gold: #a8791f;
  --gold-fill: #c9a227;
  --teal: #0f6e6e;
  --danger: #a13a2f;
  --danger-bg: #fbeae7;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Segoe UI', -apple-system, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--ink-soft); font-size: 13.5px; }

.app-body { margin: 0; display: flex; min-height: 100vh; }

.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: #10161f;
  color: #e7eaf0;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  padding: 22px 20px;
  font-weight: 700;
  font-size: 15px;
  border-bottom: 1px solid #232c3a;
}
.sidebar-brand span { display: block; font-size: 12px; font-weight: 400; color: #8991a0; margin-top: 2px; }
.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 14px 10px; }
.sidebar-nav a {
  padding: 10px 12px;
  border-radius: 6px;
  color: #a3acba;
  font-size: 14px;
  font-weight: 500;
}
.sidebar-nav a:hover { background: #161d29; text-decoration: none; color: #e7eaf0; }
.sidebar-nav a.active { background: #1c2532; color: #d4a94a; }
.sidebar-footer { padding: 14px 20px; border-top: 1px solid #232c3a; }
.sidebar-footer a { color: #a3acba; font-size: 13px; }

.app-main { flex: 1; min-width: 0; }
.page { max-width: 980px; padding: 32px 24px 80px; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.page-head h1 { font-size: 22px; margin: 0; }
.page-head-actions { display: flex; align-items: center; gap: 12px; }

.btn {
  display: inline-block;
  background: var(--gold-fill);
  color: #1a1400;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: none;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.btn:hover { text-decoration: none; opacity: .92; }
.btn-secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--border); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-top: 20px;
}

.form { display: flex; flex-direction: column; gap: 16px; max-width: 480px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.form input, .form select {
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-weight: normal;
}
.form button { align-self: flex-start; }

.col-row { display: flex; gap: 16px; flex-wrap: wrap; }
.col-row label { flex: none; }

fieldset.link-mode {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
fieldset.link-mode legend { font-size: 13px; font-weight: 600; padding: 0 6px; }
.radio-row {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  font-weight: normal !important;
  font-size: 14px !important;
}
.radio-row input[type="radio"] { width: auto; }
.sub-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0 0 4px 24px;
  padding: 10px 14px;
  background: var(--bg);
  border-radius: 6px;
}

.alert {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 16px 0;
  font-size: 14px;
}
.alert ul { margin: 8px 0 0; padding-left: 20px; }

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 20px;
}
.tpl-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--ink);
}
.tpl-card:hover { border-color: var(--gold-fill); text-decoration: none; }
.tpl-card img { width: 100%; height: 140px; object-fit: cover; display: block; background: #eee; }
.tpl-card-body { padding: 10px 12px; }
.tpl-name { font-weight: 600; font-size: 14px; }

.tbl-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  margin-top: 16px;
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left;
  padding: 10px 14px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--border);
}
td { padding: 10px 14px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
.clickable-row { cursor: pointer; }
.clickable-row:hover { background: #f8f4e8; }

.status {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}
.status-done { background: #e4f3f1; color: var(--teal); }
.status-pending { background: #fbf2dd; color: var(--gold); }
.status-error { background: var(--danger-bg); color: var(--danger); }

.actions-row { display: flex; gap: 12px; margin: 16px 0; }

.progress-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; font-size: 14px; }
.progress-row b { font-variant-numeric: tabular-nums; }
.progress-bar { height: 10px; background: var(--surface-2, #eceef2); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--gold-fill); border-radius: 999px; transition: width .4s ease; }

.editor-canvas {
  position: relative;
  display: inline-block;
  max-width: 800px;
  width: 100%;
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #111;
}
.editor-canvas img { display: block; width: 100%; height: auto; user-select: none; }

.qr-box {
  position: absolute;
  border: 2px dashed var(--gold-fill);
  background: rgba(201, 162, 39, 0.22);
  cursor: move;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qr-box-label {
  color: var(--gold-fill);
  font-weight: 700;
  font-size: 13px;
  pointer-events: none;
}
.resize-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  background: var(--gold-fill);
  border-radius: 3px;
  cursor: nwse-resize;
}

.login-body {
  margin: 0;
  min-height: 100vh;
  position: relative;
  background: #0a0e14 url('/static/img/login-bg.png') top center / cover no-repeat;
  font-family: 'Segoe UI', -apple-system, 'Helvetica Neue', Arial, sans-serif;
}
.login-card {
  position: absolute;
  left: 60%;
  top: 60%;
  transform: translate(-50%, -50%);
  background: rgba(16, 22, 31, 0.88);
  backdrop-filter: blur(3px);
  border: 1px solid #232c3a;
  border-radius: 10px;
  padding: 36px 32px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  color: #e7eaf0;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
.login-card h1 { margin: 0; font-size: 20px; }
.login-card .muted { margin: -8px 0 6px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; font-weight: 600; }
.login-card input {
  background: #161d29;
  border: 1px solid #232c3a;
  border-radius: 6px;
  padding: 9px 10px;
  color: #e7eaf0;
  font-size: 14px;
}
.login-card button {
  margin-top: 6px;
  background: #d4a94a;
  color: #1a1400;
  border: none;
  border-radius: 6px;
  padding: 10px;
  font-weight: 700;
  cursor: pointer;
}
