* {
  box-sizing: border-box;
}

:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --warning: #ef4444;
  --qr-scale: 1;
  --map-scale: 1;
}

body {
  margin: 0;
  font-family: "Segoe UI", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  user-select: none;
  overscroll-behavior: none;
}

#app,
.page-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#app {
}

.hidden {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 20% 20%, rgba(37, 99, 235, 0.12), transparent 30%),
              radial-gradient(circle at 80% 0%, rgba(29, 78, 216, 0.18), transparent 32%),
              var(--bg);
}

.login-card {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.12);
}

.login-logo {
  height: 64px;
  display: block;
  margin: 0 auto 12px auto;
}

.login-card h1 {
  margin: 0 0 16px 0;
  font-size: 20px;
  line-height: 1.3;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
  color: var(--text);
}

.login-form input {
  padding: 12px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
}

.login-form button {
  margin-top: 6px;
  padding: 12px 14px;
  border-radius: 10px;
  border: none;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.login-form button:hover {
  background: var(--accent-strong);
}

.login-form button:active {
  transform: translateY(1px);
}

.login-error {
  min-height: 20px;
  color: var(--warning);
  font-weight: 600;
  font-size: 14px;
}

.title-main {
  font-size: 22px;
  font-weight: 700;
}

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

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: var(--panel);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.08);
}

.admin-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

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

.app-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
  letter-spacing: 0.01em;
}

.search-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

.qr-size-control {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #eef2ff;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-top: 10px;
}

.qr-size-control input[type="range"] {
  accent-color: var(--accent);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.ghost-btn,
.primary-btn {
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  transition: background 120ms ease, transform 120ms ease;
}

.primary-btn:hover {
  background: var(--accent-strong);
}

.ghost-btn {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}

.ghost-btn:hover {
  background: #f3f4f6;
}

.admin-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.admin-toggle input {
  accent-color: var(--accent);
}

.danger-btn {
  border-color: #fecdd3;
  color: #b91c1c;
  background: #fff1f2;
}

.danger-btn:hover {
  background: #ffe4e6;
}

.search-container input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  min-width: 160px;
  font-size: 14px;
}

.search-container button {
  padding: 10px 14px;
  border-radius: 10px;
  border: none;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.search-container button:hover {
  background: var(--accent-strong);
}

.search-container button:active {
  transform: translateY(1px);
}

.search-result {
  min-width: 160px;
  font-size: 14px;
  color: var(--muted);
}

.app-main {
  flex: 1;
  display: flex;
  gap: 16px;
  padding: 16px;
}

.map-section {
  flex: 1.6;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.left-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.unassigned-tray {
  width: 230px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tray-title {
  font-weight: 700;
  margin-bottom: 8px;
}

.unassigned-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-content: flex-start;
  min-height: 320px;
}

.map {
  position: relative;
  flex: 1;
  min-height: 520px;
  background: #e5e7eb url("default-layout.png") center/contain no-repeat;
  border-radius: 16px;
  box-shadow: inset 0 0 0 1px var(--border), 0 16px 45px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  aspect-ratio: 2508 / 2546;
  touch-action: none;
  transform: scale(var(--map-scale));
  transform-origin: top left;
}

.map.dragging {
  cursor: grabbing;
}

.table {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translate(-50%, -50%);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.88);
  border: 2px solid var(--accent);
  color: var(--text);
  font-weight: 700;
  text-align: center;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
  user-select: none;
  touch-action: none;
}

.table:hover,
.table.table-hover {
  transform: translate(-50%, -50%) scale(1.05);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.16);
}

.table.table-highlight {
  border-color: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.25), 0 14px 36px rgba(0, 0, 0, 0.22);
}

.table.ghost {
  opacity: 0;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.table.editing {
  cursor: grab;
  border-style: dashed;
}

.table.selected {
  border-color: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.3);
}

.resize-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: var(--accent);
  border: 1px solid #0f172a;
  bottom: 4px;
  right: 4px;
  cursor: se-resize;
  touch-action: none;
  user-select: none;
}

.qr-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: calc(6px * var(--qr-scale));
  padding: calc(10px * var(--qr-scale)) calc(14px * var(--qr-scale));
  border-radius: calc(12px * var(--qr-scale));
  font-size: calc(14px * var(--qr-scale));
  font-weight: 700;
  border: 1px solid var(--border);
  background: linear-gradient(135deg, #f9fafb 0%, #eef2ff 100%);
  color: #0f172a;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  cursor: grab;
  touch-action: none;
  user-select: none;
  user-select: none;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.qr-chip:active {
  cursor: grabbing;
}

.qr-chip.dragging {
  z-index: 50;
  pointer-events: none;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.2);
  transform: translate(-50%, -50%) scale(calc(1.03 * var(--qr-scale)));
}

.qr-chip.on-table {
  position: absolute;
  transform: translate(-50%, -50%);
}

.qr-chip.highlight {
  border-color: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.22), 0 16px 40px rgba(0, 0, 0, 0.25);
}

.qr-list {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.qr-list .row {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.side-panel {
  flex: 0.85;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.08);
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
}

.side-panel h2 {
  margin: 0 0 10px 0;
}

.side-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.info {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
}

.admin-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.08);
}

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

.locations-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.location-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: #f9fafb;
}

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

.loc-name {
  font-weight: 700;
}

.loc-id {
  color: var(--muted);
  font-size: 13px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  width: min(360px, 90%);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.modal-row input {
  width: 120px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.admin-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
}

.admin-form input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.muted {
  color: var(--muted);
}

.collapsed-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 230px;
}

.collapsed-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  width: min(360px, 90%);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.modal-row input {
  width: 120px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 980px) {
  .app-main {
    flex-direction: column;
  }

  .map-section {
    width: 100%;
  }

  .unassigned-tray {
    width: 100%;
    order: 2;
  }
}
