:root {
  --bg: #e8edf2;
  --ink: #132033;
  --muted: #5b6778;
  --line: #cfd6e0;
  --card: #ffffff;
  --navy: #0f2744;
  --accent: #1f4e79;
  --danger: #8b2e2e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  font: 15px/1.45 "Source Sans 3", sans-serif;
  background:
    radial-gradient(900px 420px at 10% -10%, #d7e6f5 0%, transparent 55%),
    radial-gradient(700px 380px at 100% 0%, #c9d7e8 0%, transparent 50%),
    var(--bg);
  min-height: 100vh;
}

.login-body {
  display: grid;
  place-items: center;
  padding: 24px;
}

.app-body { padding: 20px 24px 48px; }

.card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px 26px 24px;
  box-shadow: 0 1px 2px rgba(15, 39, 68, .06), 0 12px 32px rgba(15, 39, 68, .08);
}

.kicker {
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 6px;
}

h1, .page-title {
  margin: 0 0 8px;
  font-family: "Source Serif 4", serif;
  font-size: 26px;
  color: var(--navy);
}

h2 {
  margin: 0 0 8px;
  font-family: "Source Serif 4", serif;
  font-size: 20px;
  color: var(--navy);
}

.sub { margin: 0 0 16px; color: var(--muted); font-size: 14px; }

label { display: block; font-size: 13px; font-weight: 600; margin: 0 0 6px; }

input[type="text"],
input[type="password"],
input[type="file"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  font: inherit;
  margin-bottom: 14px;
  background: #fff;
}

input:focus { outline: 2px solid #b7d0e8; border-color: var(--accent); }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  margin-bottom: 16px;
}
.check input { width: auto; margin: 0; }

button, .file-btn {
  border: 0;
  border-radius: 8px;
  padding: 11px 14px;
  font: inherit;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--navy), var(--accent));
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Author display:flex must not override HTML hidden */
[hidden] {
  display: none !important;
}

button:hover, .file-btn:hover { filter: brightness(1.05); }
button:disabled { opacity: .5; cursor: not-allowed; filter: none; }

button.secondary, .file-btn {
  background: #fff;
  color: var(--navy);
  border: 1px solid var(--line);
}

button.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--line);
  font-weight: 600;
}

.linkish {
  display: block;
  margin-top: 12px;
  text-align: center;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

.err {
  background: #f8eaea;
  color: var(--danger);
  border: 1px solid #e4c3c3;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 14px;
}

.ok {
  background: #eef6ef;
  color: #1b5e45;
  border: 1px solid #c9e0d0;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 14px;
}

.msg {
  margin-top: 10px;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}
.msg.error {
  color: var(--danger);
  background: #f8eaea;
  border-color: #e4c3c3;
}
.msg.ok {
  color: #1b5e45;
  background: #eef6ef;
  border-color: #c9e0d0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.user-chip {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
}

.layout {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 16px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 2px rgba(15, 39, 68, .04);
}

.panel-wide { grid-column: 1 / -1; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

.preview-wrap {
  min-height: 220px;
  display: grid;
  place-items: center;
  background: #f3f6f9;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}

.preview-wrap img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 8px 24px rgba(15, 39, 68, .12);
}

.empty { color: var(--muted); font-size: 14px; margin: 8px 0; }

.list-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.list-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.list-table th,
.list-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
}

.list-table button {
  padding: 7px 10px;
  font-size: 13px;
}

.panel-vault .vault-shell {
  max-width: 920px;
}

.editing-hint {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
}

.list-table tr.is-selected {
  background: #eef5fb;
}

.list-table tr.list-row {
  cursor: pointer;
}

.list-table tr.list-row:hover {
  background: #f3f6f9;
}

.list-table td.row-actions {
  white-space: nowrap;
}

.panel-vault .vault-toolbar {
  margin: 0 0 14px;
}

.vault-lock {
  max-width: 520px;
  margin-top: 4px;
}

.vault-lock input[type="password"] {
  max-width: 100%;
}

.vault-table-wrap {
  overflow-x: auto;
  max-width: 100%;
}

#vaultListWrap {
  max-width: 720px;
}

.assets-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.asset-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f7f9fb;
}

.drop-zone {
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}

.drop-zone.drop-active {
  border-color: var(--accent);
  background: #eef5fb;
  box-shadow: inset 0 0 0 1px var(--accent);
}

.photo-drop {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f7f9fb;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.drop-hint {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--muted);
}

.photo-drop .drop-hint {
  margin: 0;
}

.drop-file-name {
  margin: 0;
  font-size: 13px;
  color: var(--navy);
  word-break: break-all;
}

.asset-card h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--navy);
}

.asset-preview {
  width: 100%;
  height: 120px;
  object-fit: contain;
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: 6px;
  margin-bottom: 10px;
}

.asset-meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

@media (max-width: 900px) {
  .assets-grid { grid-template-columns: 1fr; }
}

.layout-editor-title {
  margin: 22px 0 6px;
  font-size: 16px;
  color: var(--navy);
}

.layout-stage-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e8eef4;
  padding: 12px;
}

.layout-stage {
  position: relative;
  width: min(100%, 808px);
  aspect-ratio: 1011 / 638;
  margin: 0 auto;
  background: #cfd8e3;
  border-radius: 4px;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

.layout-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
}

.layout-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  z-index: 1;
}

.layout-box {
  position: absolute;
  border: 2px solid var(--accent);
  background: rgba(31, 78, 121, 0.12);
  box-sizing: border-box;
  cursor: move;
  min-width: 24px;
  min-height: 24px;
  z-index: 2;
}

.layout-box[data-key="panel"] {
  border-color: #5b7c99;
  background: rgba(255, 255, 255, 0.28);
}

.layout-box[data-key="photo"] {
  border-color: #1f4e79;
  background: rgba(31, 78, 121, 0.18);
}

.layout-box[data-key="barcode"] {
  border-color: #222;
  background: rgba(0, 0, 0, 0.12);
}

.layout-box[data-key="stamp"],
.layout-box[data-key="signature"] {
  border-color: #2a6f4e;
  background: rgba(42, 111, 78, 0.15);
}

.layout-box.is-active {
  outline: 2px solid #f0a202;
  z-index: 3;
}

.layout-box-label {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--navy);
  background: rgba(255, 255, 255, 0.85);
  padding: 1px 5px;
  border-radius: 3px;
  pointer-events: none;
}

.layout-handle {
  position: absolute;
  right: -5px;
  bottom: -5px;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 2px;
  cursor: nwse-resize;
  box-sizing: border-box;
}

.opacity-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 28px;
  margin-top: 12px;
  align-items: center;
}

.opacity-field {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--navy);
  font-weight: 600;
  margin: 0;
}

.opacity-field input[type="range"] {
  width: 140px;
  margin: 0;
}

.opacity-field span {
  min-width: 2.5em;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-weight: 500;
}

.layout-box[data-key="director"] {
  border-color: #8a5a2b;
  background: rgba(138, 90, 43, 0.16);
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; }
}
