:root{
  --bg: #0b0f14;
  --panel: #0f1722;
  --card: #121c29;
  --text: #e8eef7;
  --muted: #9fb0c6;
  --border: rgba(255,255,255,.10);
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --radius: 14px;

  --primary: #4da3ff;
  --danger: #ff5d5d;
  --ghost: rgba(255,255,255,.10);

  --gap: 12px;
  --gap-lg: 16px;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  background: linear-gradient(180deg, var(--bg), #08101a 60%, #07101a);
  color:var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans JP", "Hiragino Kaku Gothic ProN", Meiryo, Arial;
  line-height:1.45;
}

a{ color:inherit; }
hr.sep{
  border:0;
  border-top:1px solid var(--border);
  margin:16px 0;
}

.container{
  width:min(1100px, 100%);
  margin:0 auto;
  padding:12px;
  padding-bottom:28px;
}

/* ===== Top bar (mobile-first) ===== */
.topbar{
  position: sticky;
  top: 0;
  z-index: 50;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:10px 12px;
  background: rgba(11,15,20,.82);
  backdrop-filter: blur(10px);
  border-bottom:1px solid var(--border);
}

.brand{
  display:flex;
  align-items:center;
  gap:10px;
  min-width: 0;
}
.logo{
  width:40px;
  height:40px;
  border-radius:12px;
  display:grid;
  place-items:center;
  background: rgba(77,163,255,.18);
  border:1px solid rgba(77,163,255,.35);
  font-weight:800;
  letter-spacing:.5px;
  flex: 0 0 auto;
}
.title{ min-width:0; }
.title h1{
  font-size:16px;
  margin:0;
  line-height:1.15;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.subtitle{
  font-size:12px;
  color:var(--muted);
  margin-top:4px;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
#version-tag{ opacity:.75; margin-left:6px; }

/* ===== action menu (collapsible on mobile) ===== */
.action-menu{ position:relative; }
.action-menu > summary{
  list-style:none;
  cursor:pointer;
}
.action-menu > summary::-webkit-details-marker{ display:none; }
.action-menu .actions{
  display:none;
  flex-direction:column;
  gap:8px;
  position:absolute;
  right:0;
  top:46px;
  min-width: 220px;
  padding:10px;
  background: rgba(18,28,41,.98);
  border:1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.action-menu[open] .actions{ display:flex; }

/* ===== tabs (sticky, scrollable on mobile) ===== */
.tabs{
  position: sticky;
  top: 62px; /* depends on topbar height */
  z-index: 40;
  display:flex;
  gap:8px;
  padding:10px 12px;
  border-bottom:1px solid var(--border);
  background: rgba(11,15,20,.70);
  backdrop-filter: blur(10px);
  overflow-x:auto;
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar{ height:0; }
.tab{
  flex: 0 0 auto;
  border:1px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text);
  padding:8px 10px;
  border-radius: 999px;
  font-size: 13px;
}
.tab.active{
  background: rgba(77,163,255,.18);
  border-color: rgba(77,163,255,.35);
}

/* ===== panels/cards ===== */
.panel{ display:none; }
.panel.active{ display:block; }

.card{
  background: rgba(18,28,41,.92);
  border:1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding:14px;
  margin-bottom: 12px;
}
.card h2{
  font-size:16px;
  margin:0 0 8px;
}
.card h3{
  font-size:14px;
  margin:0 0 8px;
}
.hint{
  color: var(--muted);
  font-size:12.5px;
}
.hint.code{
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Noto Sans Mono", monospace;
  font-size: 12px;
}

/* ===== layout grids ===== */
.grid-2, .grid-3{
  display:grid;
  gap:12px;
}
.grid-2{ grid-template-columns: 1fr; }
.grid-3{ grid-template-columns: 1fr; }

/* ===== forms ===== */
.form-grid{
  display:grid;
  gap:10px;
}
.form-row{
  display:flex;
  flex-direction:column;
  gap:6px;
}
.form-row label{
  font-size:12.5px;
  color: var(--muted);
}
.row{
  display:flex;
  gap:8px;
  align-items:center;
}
.row.space{ justify-content:space-between; align-items:flex-start; gap:10px; flex-wrap:wrap; }
.actions-row{ align-items:flex-end; flex-wrap:wrap; }

input, select, textarea{
  width:100%;
  border:1px solid var(--border);
  background: rgba(255,255,255,.03);
  color: var(--text);
  padding:12px 12px;
  border-radius: 12px;
  outline:none;
  font-size:16px; /* iOS: avoid zoom */
}
textarea{ resize:vertical; }
select.select{ appearance:auto; }

.form-row.compact input{ padding:10px 12px; }

/* ===== buttons ===== */
.btn{
  border:1px solid var(--border);
  background: rgba(255,255,255,.06);
  color: var(--text);
  padding:10px 12px;
  border-radius: 12px;
  font-size: 14px;
  cursor:pointer;
  white-space:nowrap;
}
.btn:hover{ background: rgba(255,255,255,.10); }
.btn:disabled{ opacity:.55; cursor:not-allowed; }
.btn-primary{
  background: rgba(77,163,255,.22);
  border-color: rgba(77,163,255,.40);
}
.btn-danger{
  background: rgba(255,93,93,.18);
  border-color: rgba(255,93,93,.35);
}
.btn-ghost{
  background: rgba(255,255,255,.04);
}
label.file{ position:relative; overflow:hidden; }
label.file input[type="file"]{
  position:absolute;
  inset:0;
  opacity:0;
  cursor:pointer;
}

/* ===== scan area ===== */
.scanbox{
  margin-top:10px;
  border:1px solid var(--border);
  border-radius: 14px;
  padding:10px;
  background: rgba(0,0,0,.16);
}
.reader{
  width:100%;
  border-radius: 12px;
  overflow:hidden;
  background: rgba(0,0,0,.22);
  border:1px solid rgba(255,255,255,.06);
  /* Make it feel right on mobile */
  aspect-ratio: 4 / 3;
  min-height: 220px;
}
.reader-small{
  aspect-ratio: 16 / 9;
  min-height: 160px;
}
.scan-controls{
  display:grid;
  grid-template-columns: 1fr;
  gap:8px;
  margin-top:10px;
}

/* ===== tables ===== */
.table-wrap{
  width:100%;
  overflow-x:auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 12px;
  border:1px solid rgba(255,255,255,.06);
}
.table{
  width:100%;
  border-collapse: collapse;
  min-width: 720px; /* allow scroll on mobile */
}
.table th, .table td{
  padding:10px 10px;
  border-bottom:1px solid rgba(255,255,255,.06);
  font-size: 13px;
  vertical-align: top;
}
.table th{
  color: var(--muted);
  font-weight: 600;
  background: rgba(255,255,255,.03);
}

/* ===== messages ===== */
.msg{
  margin-top:10px;
  padding:10px 12px;
  border-radius: 12px;
  background: rgba(255,255,255,.04);
  border:1px solid rgba(255,255,255,.06);
  color: var(--muted);
  min-height: 20px;
}

/* ===== modal ===== */
.modal{
  position: fixed;
  inset: 0;
  display:none;
  z-index: 100;
  background: rgba(0,0,0,.55);
}
.modal.show{ display:block; }
.modal-card{
  position:absolute;
  left:50%;
  top:50%;
  transform: translate(-50%,-50%);
  width: min(920px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  overflow:auto;
  background: rgba(18,28,41,.98);
  border:1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.modal-head, .modal-foot{
  position: sticky;
  top: 0;
  background: rgba(18,28,41,.98);
  backdrop-filter: blur(10px);
  border-bottom:1px solid rgba(255,255,255,.06);
  padding:12px;
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
}
.modal-foot{
  top:auto;
  bottom:0;
  border-top:1px solid rgba(255,255,255,.06);
  border-bottom:0;
}
.modal-title{ font-weight:700; }
.modal-body{ padding:12px; }

.detail-grid{
  display:grid;
  grid-template-columns: 1fr;
  gap:10px;
}

/* ===== QR grid ===== */
.qr-grid{
  display:grid;
  grid-template-columns: repeat(2, 1fr);
  gap:12px;
  margin-top:12px;
}

/* ===== Desktop enhancements ===== */
@media (min-width: 900px){
  .container{ padding:16px; }
  .title h1{ font-size:18px; }
  .subtitle{ font-size:12.5px; }

  /* action menu always visible on desktop */
  .action-menu > summary{ display:none; }
  .action-menu .actions{
    display:flex !important;
    position:static;
    flex-direction:row;
    min-width: auto;
    padding:0;
    background: transparent;
    border:0;
    box-shadow:none;
    gap:10px;
  }

  .tabs{ top: 64px; }
  .grid-2{ grid-template-columns: 1fr 1fr; }
  .grid-3{ grid-template-columns: 1fr 1fr 1fr; }

  .scan-controls{
    grid-template-columns: 1fr auto auto;
    align-items:center;
  }

  .detail-grid{ grid-template-columns: 1fr 1fr; }
  .qr-grid{ grid-template-columns: repeat(4, 1fr); }
}

/* ===== Small phones: tighten ===== */
@media (max-width: 380px){
  .title h1{ font-size: 15px; }
  .tab{ padding:7px 9px; font-size:12.5px; }
  .btn{ padding:10px 10px; font-size:13.5px; }
}
