* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1420;
  --panel: #161d2e;
  --panel2: #1c2438;
  --border: #2a3450;
  --text: #e7ecf5;
  --muted: #8a94aa;
  --accent: #4f7cff;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex; align-items: baseline; gap: 14px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.brand { font-size: 20px; font-weight: 700; letter-spacing: .5px; }
.topbar-sub { color: var(--muted); font-size: 12px; }

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 260px;
  gap: 16px;
  padding: 16px 22px;
  align-items: start;
}
@media (max-width: 1100px) { .layout { grid-template-columns: 1fr 1fr; } .history { grid-column: 1 / -1; } }
@media (max-width: 760px)  { .layout { grid-template-columns: 1fr; } }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.section-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px; gap: 8px; flex-wrap: wrap;
}
h2 { font-size: 15px; margin-bottom: 12px; }
.section-head h2 { margin-bottom: 0; }
small { color: var(--muted); font-weight: 400; }

.field { display: block; margin-bottom: 10px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input[type="text"], .field input[type="number"], .field select, .field textarea {
  width: 100%;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  font-family: ui-monospace, Consolas, monospace;
}
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 1px solid var(--accent); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.check { display: flex; gap: 8px; align-items: center; font-size: 13px; margin: 10px 0 14px; color: var(--muted); }
.check input { accent-color: var(--accent); }

.btn {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; width: 100%; }
.btn.small { padding: 4px 8px; font-size: 12px; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.empty { color: var(--muted); font-size: 13px; padding: 24px 0; text-align: center; }

.badge { background: var(--panel2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; font-size: 12px; color: var(--muted); }

.labels {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}
.cell {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.cell-head { width: 100%; display: flex; justify-content: space-between; align-items: center; }
.cell-num { font-size: 11px; color: #556; font-weight: 600; }
.cell-value {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px; color: #222; font-weight: 600;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cell canvas { max-width: 100%; }
.cell.invalid { outline: 2px solid #ff5f5f; }
.cell-err { color: #c0392b; font-size: 11px; text-align: center; }

.icon-btn {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 13px; padding: 2px 6px; border-radius: 6px;
}
.icon-btn:hover { color: #ff8080; background: rgba(255,255,255,.06); }

.cell .btn.small { background: #14192a; color: var(--text); border-color: #2a3450; }

.history { max-height: 70vh; overflow: auto; }
.history ul { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.history li {
  display: flex; justify-content: space-between; align-items: center; gap: 6px;
  background: var(--panel2); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 8px; font-size: 12px;
}
.hist-use {
  flex: 1; text-align: left; background: none; border: none; color: var(--text);
  font-family: ui-monospace, Consolas, monospace; font-size: 11px; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hist-use:hover { color: var(--accent); }
.hist-empty { color: var(--muted); background: none; border: none; justify-content: center; }

/* ---- Print ---- */
#printArea { display: none; }
@media print {
  body > *:not(#printArea), .topbar, main, #work { display: none !important; }
  #printArea { display: block !important; }
  .print-box {
    display: inline-block;
    page-break-inside: avoid;
    break-inside: avoid;
    margin: 6px;
    padding: 6px;
    border: 1px dashed #999;
    vertical-align: top;
    text-align: center;
  }
  .print-box canvas { max-width: 180px; }
  .print-label { font-size: 12px; font-weight: 700; margin-bottom: 2px; color: #000; }
}
