:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --ok: #10b981;
  --ok-soft: #d1fae5;
  --pending: #f43f5e;
  --pending-soft: #ffe4e6;
  --warn: #f59e0b;
  --warn-soft: #fef3c7;
  --accent: #6366f1;
  --accent-soft: #eef2ff;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--ink); padding-bottom: 2rem; overflow-x: hidden; }
#app { transition: transform .32s cubic-bezier(.4, 0, .2, 1); }
body.ai-open #app { transform: translateX(-420px); }
body.ai-lock { position: fixed; left: 0; right: 0; width: 100%; overflow: hidden; }

header {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 60%, #312e81 100%);
  color: #fff;
  padding: .85rem 1.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo { font-weight: 800; font-size: 1.15rem; letter-spacing: .02em; display: flex; align-items: center; gap: .45rem; }
.logo::before { content: ''; width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, #10b981, #6366f1); box-shadow: 0 2px 8px rgba(16,185,129,.4); }
.ai-open-btn {
  background: rgba(255,255,255,.12); color: #fff;
  border: 1px solid rgba(255,255,255,.28); border-radius: 999px;
  padding: .45rem .95rem; font-size: .85rem; font-weight: 700;
  cursor: pointer; display: flex; align-items: center; gap: .4rem;
  transition: background .15s, transform .1s;
}
.ai-open-btn:hover { background: rgba(255,255,255,.22); }
.ai-open-btn:active { transform: scale(.96); }

#ai-drawer {
  position: fixed; top: 0; right: 0;
  height: 100vh; height: 100dvh;
  width: 420px; max-width: 100vw;
  background: var(--bg);
  box-shadow: -10px 0 40px rgba(15,23,42,.28);
  transform: translateX(100%);
  transition: transform .32s cubic-bezier(.4, 0, .2, 1);
  z-index: 50;
  display: flex; flex-direction: column;
  padding: 1rem;
  gap: .6rem;
  visibility: hidden;
}
body.ai-open #ai-drawer { transform: translateX(0); visibility: visible; }
.ai-drawer-header { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; }
.ai-model { font-weight: 800; font-size: .95rem; }
.ai-model span { font-weight: 400; color: var(--muted); font-size: .78rem; margin-left: .35rem; }
.ai-hint { font-size: .78rem; color: var(--muted); margin-top: .25rem; line-height: 1.4; }
.ai-header-btns { display: flex; gap: .4rem; }
.ai-header-btns button {
  border: none; background: var(--card); color: var(--ink);
  width: 34px; height: 34px; border-radius: .55rem;
  font-size: .95rem; cursor: pointer; flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(15,23,42,.1);
  transition: background .15s;
}
#btn-ai-close:hover { background: var(--pending-soft); color: #be123c; }
#btn-ai-clear:hover { background: var(--warn-soft); color: #b45309; }
.ai-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: .6rem; padding: .2rem 0; min-height: 0; }
.ai-msg { max-width: 88%; padding: .65rem .85rem; border-radius: .9rem; font-size: .88rem; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }
.ai-msg.user { align-self: flex-end; background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; border-bottom-right-radius: .3rem; }
.ai-msg.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: .3rem; }
.ai-msg.assistant.thinking { opacity: .6; font-style: italic; }
.ai-input-card {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 1.1rem;
  padding: .65rem .75rem .55rem;
  box-shadow: 0 2px 12px rgba(15,23,42,.08);
}
.ai-input-card:focus-within { border-color: var(--accent); }
.ai-input-card textarea {
  width: 100%; border: none; background: transparent;
  resize: none; font-size: .9rem; outline: none;
  min-height: 40px; max-height: 110px; font-family: inherit;
  padding: 0 .15rem; color: var(--ink);
}
.ai-input-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: .45rem; }
.ai-pill {
  border: 1.5px solid var(--line); background: var(--bg);
  border-radius: 999px; padding: .38rem .8rem;
  font-size: .8rem; font-weight: 700; color: var(--muted);
  cursor: pointer; transition: all .15s;
}
.ai-pill:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.ai-send {
  width: 38px; height: 38px; border-radius: 50%;
  border: none; background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff; font-size: 1.15rem; font-weight: 800;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 10px rgba(99,102,241,.4);
  transition: transform .1s, opacity .15s;
}
.ai-send:hover { opacity: .9; }
.ai-send:active { transform: scale(.9); }

@media (max-width: 768px) {
  #ai-drawer { width: 100vw; padding: .85rem; }
  body.ai-open #app { transform: none; }
  .ai-open-btn { padding: .4rem .75rem; font-size: .8rem; }
}

.tabs {
  position: sticky; top: 0; z-index: 10;
  display: flex;
  background: var(--card);
  box-shadow: 0 1px 0 var(--line);
}
.tab {
  flex: 1;
  padding: .85rem .25rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: color .15s;
  white-space: nowrap;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.panel { display: none; padding: 1rem; max-width: 760px; margin: 0 auto; }
.panel.active { display: block; }
h3 { margin: 1.2rem 0 .5rem; font-size: .95rem; }
.hint { font-size: .82rem; color: var(--muted); margin-bottom: .6rem; line-height: 1.5; }

.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; margin-bottom: .9rem; }
.stat { border-radius: .8rem; padding: .65rem .3rem; text-align: center; background: var(--card); box-shadow: 0 1px 3px rgba(15,23,42,.06); }
.stat b { font-size: 1.35rem; display: block; line-height: 1.2; }
.stat span { font-size: .72rem; color: var(--muted); font-weight: 600; }
.stat-ok { background: var(--ok-soft); } .stat-ok b { color: #047857; } .stat-ok span { color: #059669; }
.stat-pending { background: var(--pending-soft); } .stat-pending b { color: #be123c; } .stat-pending span { color: #e11d48; }
.stat-unknown { background: var(--warn-soft); } .stat-unknown b { color: #b45309; } .stat-unknown span { color: #d97706; }

.filters { display: flex; gap: .4rem; margin-bottom: .75rem; flex-wrap: wrap; }
.filter {
  padding: .38rem .8rem; border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--card); font-size: .82rem; font-weight: 600; color: var(--muted); cursor: pointer;
  transition: all .15s;
}
.filter.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.sort-select {
  width: auto; flex: 1 1 100%; min-width: 0;
  padding: .38rem .6rem; margin: 0;
  border: 1.5px solid var(--line); border-radius: 999px;
  background: var(--card); font-size: .82rem; font-weight: 600; color: var(--muted);
  cursor: pointer; outline: none;
}

.order-card {
  position: relative;
  background: var(--card);
  border-radius: .8rem;
  padding: .75rem .95rem;
  margin-bottom: .55rem;
  display: flex; align-items: center; gap: .75rem;
  box-shadow: 0 1px 3px rgba(15,23,42,.07);
  border-left: 4px solid transparent;
}
.order-card.received { border-left-color: var(--ok); }
.order-card.pending { border-left-color: var(--pending); }
.order-card.unknown { border-left-color: var(--warn); }
.order-card.back-shop { border-left-color: #8b5cf6; background: #faf5ff; }
.order-card.moving { border-left-color: var(--pending); }

button.ghost {
  flex: 1; padding: .65rem; border: 2px dashed #c4b5fd; border-radius: .65rem;
  background: #faf5ff; color: #6d28d9; font-size: .88rem; font-weight: 700; cursor: pointer;
}
.order-card .mark { font-size: 1.35rem; width: 2rem; text-align: center; flex-shrink: 0; }
.mark-check {
  appearance: none; -webkit-appearance: none;
  width: 26px; height: 26px; flex-shrink: 0;
  border: 2px solid #cbd5e1; border-radius: 7px;
  background: #fff; cursor: pointer; position: relative;
  transition: background .15s, border-color .15s;
}
.mark-check:checked { background: var(--ok); border-color: var(--ok); }
.mark-check:checked::after {
  content: '✓'; position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 15px; font-weight: 900;
}
.mark-check:disabled { cursor: not-allowed; opacity: .9; }
.mark-check:disabled { cursor: not-allowed; opacity: .9; }
.order-info { flex: 1; min-width: 0; padding-right: 2.5rem; }
.order-id { font-weight: 700; font-size: .95rem; word-break: break-all; letter-spacing: .01em; }
.order-id2 { font-weight: 600; font-size: .85rem; color: #334155; word-break: break-all; margin-top: .1rem; }
.copy-btn {
  border: none; background: transparent; cursor: pointer;
  font-size: .85rem; color: #94a3b8;
  padding: .1rem .3rem; margin-left: .3rem;
  border-radius: .35rem; vertical-align: middle;
  transition: color .15s, background .15s;
}
.copy-btn:hover { color: var(--accent); background: var(--accent-soft); }
.copy-btn:active { transform: scale(.9); }
.order-meta { font-size: .78rem; color: var(--muted); word-break: break-all; margin-top: .15rem; }
.shop-badge {
  position: absolute; top: .55rem; right: .65rem;
  background: var(--accent-soft); color: #4338ca;
  font-size: .7rem; font-weight: 700;
  padding: .18rem .55rem; border-radius: 999px;
  max-width: 42%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.actions { display: flex; gap: .5rem; margin: 1rem 0; }
.action-bar {
  position: sticky; bottom: .6rem; z-index: 5;
  display: flex; gap: .5rem;
  padding: .5rem;
  margin: .6rem 0 .75rem;
  background: rgba(241, 245, 249, .92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: .9rem;
  box-shadow: 0 6px 20px rgba(15, 23, 42, .14);
}
.action-bar button.primary, .action-bar button.ghost, .action-bar button.danger { margin: 0; }
button.primary, button.danger {
  flex: 1; padding: .72rem; border: none; border-radius: .65rem;
  font-size: .92rem; font-weight: 700; cursor: pointer;
  transition: transform .1s, opacity .15s;
}
button.primary:active, button.danger:active { transform: scale(.98); }
button.primary { background: linear-gradient(135deg, #10b981, #059669); color: #fff; box-shadow: 0 2px 8px rgba(16,185,129,.35); }
button.danger { background: var(--pending-soft); color: #be123c; max-width: 260px; }

#qr-reader { border-radius: .9rem; overflow: hidden; background: #0f172a; min-height: 60px; }
#qr-reader video { border-radius: .9rem; }
.scan-status { margin-top: .75rem; padding: .7rem .85rem; border-radius: .65rem; font-weight: 600; font-size: .9rem; display: none; word-break: break-all; }
.scan-status.ok { display: block; background: var(--ok-soft); color: #047857; }
.scan-status.dup { display: block; background: var(--warn-soft); color: #92400e; }
.scan-status.miss { display: block; background: var(--pending-soft); color: #be123c; }

#scan-list { list-style: none; }
.scan-item { position: relative; border-radius: .65rem; margin-bottom: .4rem; overflow: hidden; }
.scan-del {
  position: absolute; top: 0; right: 0; bottom: 0; width: 84px;
  background: linear-gradient(135deg, #f43f5e, #e11d48); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 1.2rem; cursor: pointer;
}
.scan-content {
  position: relative; background: var(--card); border-radius: .65rem;
  padding: .55rem .8rem; font-size: .86rem;
  display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  word-break: break-all; transition: transform .18s ease; touch-action: pan-y;
  box-shadow: 0 1px 3px rgba(15,23,42,.07);
}
.scan-time { color: var(--muted); white-space: nowrap; font-size: .74rem; flex-shrink: 0; }
.scan-date-row {
  display: flex; gap: .45rem; align-items: center;
  margin: .45rem 0 .6rem;
}
.scan-date-row input[type=date] {
  padding: .4rem .6rem; border: 1.5px solid var(--line); border-radius: .55rem;
  font-size: .88rem; background: var(--card);
}
.scan-date-row button {
  padding: .38rem .7rem; border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--card); font-size: .82rem; font-weight: 600; color: var(--muted); cursor: pointer;
}
.scan-date-row button:hover { border-color: var(--accent); color: var(--accent); }

.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; line-height: 1.8; font-size: .9rem; }
.hidden { display: none; }

input[type=file] { margin-bottom: .5rem; font-size: .85rem; max-width: 100%; }
#shop-name { width: 100%; padding: .58rem .75rem; border-radius: .6rem; border: 1.5px solid var(--line); font-size: .92rem; margin-bottom: .55rem; outline: none; }
#shop-name:focus { border-color: var(--accent); }
select { width: 100%; padding: .55rem .65rem; border-radius: .6rem; border: 1.5px solid var(--line); font-size: .9rem; margin-bottom: .4rem; background: var(--card); outline: none; }
select:focus { border-color: var(--accent); }
label.hint { display: block; margin-top: .4rem; font-weight: 600; }
#file-info { font-size: .85rem; margin: .5rem 0; color: #334155; line-height: 1.5; }

.type-radio { display: flex; gap: .5rem; margin-bottom: .7rem; }
.type-radio label {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: .4rem;
  background: var(--card); border: 1.5px solid var(--line); border-radius: .6rem;
  padding: .55rem; font-size: .88rem; font-weight: 600; cursor: pointer;
}
.type-radio input { accent-color: var(--accent); }
.type-radio label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: #4338ca; }

.check-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
.check-item {
  display: flex; align-items: center; gap: .45rem;
  background: var(--card); border-radius: .6rem; padding: .5rem .7rem;
  font-size: .82rem; cursor: pointer; word-break: break-word;
  box-shadow: 0 1px 2px rgba(15,23,42,.05);
}
.check-item input { width: 16px; height: 16px; flex-shrink: 0; accent-color: var(--accent); }

.sync-row { display: flex; gap: .5rem; }
.sync-row input { flex: 1; padding: .58rem .75rem; border-radius: .6rem; border: 1.5px solid var(--line); font-size: .92rem; min-width: 0; outline: none; }
.sync-row input:focus { border-color: var(--accent); }
.sync-row button { flex-shrink: 0; padding: .58rem 1.2rem; border: none; border-radius: .6rem; font-weight: 700; cursor: pointer; background: linear-gradient(135deg, #10b981, #059669); color: #fff; }
.sync-row button#btn-change-key { background: #e2e8f0; color: var(--ink); padding: .58rem .8rem; }
#sync-status.ok { color: #047857; font-weight: 600; }
#sync-status.err { color: #be123c; font-weight: 600; }

#toast {
  position: fixed; bottom: 5.8rem; left: 50%;
  transform: translateX(-50%) translateY(20px);
  opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff;
  padding: .68rem 1.15rem; border-radius: .7rem;
  font-size: .88rem; font-weight: 600;
  transition: transform .25s ease, opacity .25s ease; z-index: 99;
  white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
  box-shadow: 0 4px 16px rgba(15,23,42,.3);
}
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

@media (max-width: 480px) {
  .summary { grid-template-columns: repeat(2, 1fr); }
  .check-grid { grid-template-columns: 1fr; }
  .tab { font-size: .8rem; padding: .8rem .15rem; }
  .mark-check { width: 21px; height: 21px; border-radius: 6px; }
  .mark-check:checked::after { font-size: 12px; }
  .order-card { gap: .6rem; padding: .65rem .7rem; }
  .order-id { font-size: .88rem; }
  .order-id2 { font-size: .8rem; }
  .order-info { padding-right: 0; }
}
