* { box-sizing: border-box; }
body {
  margin: 0; font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: #222; background: #f4f5f7;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- left sidebar layout ---- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 208px; flex-shrink: 0; background: #1f2937; color: #e5e7eb;
  display: flex; flex-direction: column; padding: 16px 0;
}
.sidebar .brand {
  display: flex; align-items: flex-start; gap: 6px;
  font-weight: 700; font-size: 18px; letter-spacing: .5px;
  padding: 2px 14px 16px; border-bottom: 1px solid #374151; margin-bottom: 8px;
}
.sidebar .brand-name { flex: 1; min-width: 0; }
.sidebar .brand-name span { display: block; font-size: 11px; font-weight: 400; opacity: .6; margin-top: 4px; }
.sidebar-toggle {
  background: none; border: none; color: #94a3b8; cursor: pointer; flex-shrink: 0;
  font-size: 18px; line-height: 1; padding: 2px 6px; border-radius: 6px;
}
.sidebar-toggle:hover { background: #374151; color: #fff; }
.sidebar nav { flex: 1; display: flex; flex-direction: column; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px; white-space: nowrap;
  color: #cbd5e1; padding: 11px 16px; font-size: 14px; border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: #374151; color: #fff; text-decoration: none; }
.sidebar nav a.active { background: #111827; color: #fff; border-left-color: #3b82f6; font-weight: 600; }
.nav-ico { width: 20px; flex-shrink: 0; text-align: center; font-size: 15px; }
.nav-txt { overflow: hidden; text-overflow: ellipsis; }
.sidebar-foot { padding: 14px 16px 0; border-top: 1px solid #374151; }
.sidebar-foot .user { font-size: 13px; opacity: .85; margin-bottom: 8px; }
.btn-link { display: flex; align-items: center; gap: 10px; color: #93c5fd; font-size: 13px; }

/* ---- desktop: collapsible icon rail ---- */
@media (min-width: 769px) {
  .sidebar { transition: width .18s ease; }
  body.sidebar-collapsed .sidebar { width: 60px; }
  body.sidebar-collapsed .sidebar .brand { justify-content: center; padding: 2px 0 16px; }
  body.sidebar-collapsed .brand-name,
  body.sidebar-collapsed .nav-txt,
  body.sidebar-collapsed .sidebar-foot .user { display: none; }
  body.sidebar-collapsed .sidebar nav a,
  body.sidebar-collapsed .sidebar-foot .btn-link {
    justify-content: center; gap: 0; padding-left: 0; padding-right: 0;
  }
  body.sidebar-collapsed .sidebar nav a { border-left-width: 0; }
  body.sidebar-collapsed .sidebar-foot { padding: 14px 0 0; text-align: center; }
  body.sidebar-collapsed .sidebar-toggle { transform: rotate(180deg); }
}

main { flex: 1; padding: 24px; min-width: 0; }
.auth-main { padding: 24px; }

/* mobile-only chrome (hidden on desktop) */
.mobile-topbar, .nav-backdrop { display: none; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; }
.flash.ok { background: #dcfce7; color: #166534; }
.flash.error { background: #fee2e2; color: #991b1b; }

.btn {
  display: inline-block; padding: 8px 16px; border-radius: 6px;
  border: 1px solid #cbd5e1; background: #fff; cursor: pointer; font-size: 14px;
}
.btn.primary { background: #3b82f6; color: #fff; border-color: #3b82f6; }
.btn:hover { filter: brightness(.97); }
.toolbar { margin-bottom: 16px; }
.status-bar { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.status-bar .vision-status { flex: 1; min-width: 240px; margin-bottom: 0; }
.vision-status { padding: 8px 14px; border-radius: 6px; font-size: 13px; margin-bottom: 14px; }
.vision-status.ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.vision-status.bad { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* table */
.grid { width: 100%; border-collapse: collapse; background: #fff; font-size: 14px; }
.grid th, .grid td { padding: 10px 12px; border-bottom: 1px solid #eef0f3; text-align: left; }
.grid thead th { background: #fafbfc; border-bottom: 2px solid #e5e7eb; font-weight: 600; }
.grid tbody tr:hover { background: #f9fafb; }
.pdf { display: inline-block; padding: 3px 8px; border-radius: 4px; color: #fff; font-size: 12px; font-weight: 700; }
.pdf.jp { background: #16a34a; }
.pdf.en { background: #dc2626; }
.edit { font-size: 16px; }
.link-danger { border: none; background: none; color: #dc2626; cursor: pointer; font-size: 14px; }
.muted { color: #9ca3af; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

/* auth */
.auth-card {
  max-width: 360px; margin: 60px auto; background: #fff; padding: 28px;
  border-radius: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.1);
}
.auth-card h1 { margin-top: 0; }
.auth-card label, .record-form label { display: block; margin-bottom: 14px; font-size: 13px; font-weight: 600; color: #374151; }
.auth-card input, .record-form input, .record-form select, .record-form textarea {
  width: 100%; padding: 8px 10px; margin-top: 4px; border: 1px solid #d1d5db;
  border-radius: 6px; font-size: 14px; font-weight: 400;
}

/* modal */
.modal { border: none; border-radius: 10px; padding: 24px; width: 460px; }
.modal::backdrop { background: rgba(0,0,0,.4); }
.modal h2 { margin-top: 0; }
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; border: 2px dashed #cbd5e1; border-radius: 10px; padding: 34px 28px;
  min-height: 120px; text-align: center; color: #6b7280; margin-bottom: 16px;
  cursor: pointer; transition: border-color .15s, background .15s, color .15s;
}
.drop:hover { border-color: #94a3b8; background: #f8fafc; }
/* ネイティブの小さいファイル選択ウィジェットは隠す（枠全体をクリック/ドロップ対象に） */
.drop input[type="file"] { display: none; }
.drop .drop-ico { font-size: 26px; line-height: 1; pointer-events: none; }
.drop .drop-text { pointer-events: none; word-break: break-all; }
/* ドラッグ中のハイライト（枠内どこでも反応） */
.drop.dragover { border-color: #3b82f6; background: #eff6ff; color: #2563eb; }
.modal menu { display: flex; justify-content: flex-end; gap: 10px; padding: 0; margin: 18px 0 0; }
.req { color: #dc2626; }

/* edit form */
.record-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.record-head h1 { font-size: 20px; margin: 6px 0; }
.head-actions { margin-left: auto; display: flex; gap: 8px; }
.status { font-size: 12px; padding: 2px 8px; border-radius: 10px; background: #e5e7eb; color: #374151; text-transform: uppercase; }
.status.generated { background: #dcfce7; color: #166534; }

.record-form { background: #fff; padding: 20px; border-radius: 10px; margin-top: 12px; }

/* 3-column review layout */
.form-cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; align-items: start; }
.form-col { min-width: 0; }

.field { margin-bottom: 12px; }
.field-label { display: block; font-size: 12px; font-weight: 700; color: #374151; margin-bottom: 4px; }
.record-form .field input,
.record-form .field textarea,
.record-form .field select {
  width: 100%; margin: 0; padding: 7px 9px; border: 1px solid #d1d5db;
  border-radius: 6px; font-size: 14px; font-weight: 400; background: #fff;
}
.record-form .field textarea { resize: vertical; min-height: 62px; line-height: 1.4; font-family: inherit; }
.record-form .field textarea.big { min-height: 150px; }

/* side-by-side fields (Weight/Gross, L/W/H, FF/FR, RF/RR, Mileage) */
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; min-width: 0; }

/* year / month / day */
.date-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }

.ocr-warnings { margin: 14px 0; padding: 10px 14px; background: #fff7ed; border: 1px solid #fdba74; border-left: 4px solid #f97316; border-radius: 8px; color: #9a3412; font-size: 13px; }
.ocr-warnings strong { display: block; margin-bottom: 4px; }
.ocr-warnings ul { margin: 0; padding-left: 18px; }
.ocr-warnings li { margin: 2px 0; }

.ocr-ref { margin-top: 18px; border-top: 1px solid #eef0f3; padding-top: 12px; }
.ocr-ref summary { cursor: pointer; font-size: 13px; font-weight: 600; color: #6b7280; }
textarea.ocr { width: 100%; margin-top: 10px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; white-space: pre; border: 1px solid #d1d5db; border-radius: 6px; padding: 8px; }
.form-actions { margin-top: 20px; display: flex; gap: 12px; justify-content: flex-end; }

@media (max-width: 1000px) { .form-cols { grid-template-columns: 1fr; } }

/* horizontal scroll wrapper for wide tables on small screens */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ============ mobile / small-screen layout ============ */
@media (max-width: 768px) {
  /* fixed top bar with hamburger */
  .mobile-topbar {
    display: flex; align-items: center; gap: 12px;
    position: fixed; top: 0; left: 0; right: 0; height: 52px; z-index: 50;
    background: #1f2937; color: #fff; padding: 0 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,.25);
  }
  .hamburger {
    background: none; border: none; color: #fff; font-size: 24px;
    line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 6px;
  }
  .hamburger:active { background: rgba(255,255,255,.12); }
  .mobile-brand { font-weight: 700; font-size: 16px; letter-spacing: .5px; }

  /* sidebar becomes an off-canvas drawer */
  .layout { display: block; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 250px; z-index: 60;
    transform: translateX(-100%); transition: transform .25s ease;
    overflow-y: auto;
  }
  body.nav-open .sidebar { transform: translateX(0); box-shadow: 2px 0 16px rgba(0,0,0,.4); }
  .sidebar-toggle { display: none; }   /* desktop-only control */

  .nav-backdrop {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(0,0,0,.45); opacity: 0; pointer-events: none;
    transition: opacity .25s ease;
  }
  body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }

  /* main content clears the fixed top bar */
  main { padding: 68px 14px 28px; }

  /* tighter headers / wrap action buttons */
  .record-head { gap: 10px; }
  .record-head h1 { font-size: 17px; }
  .head-actions { margin-left: 0; }

  /* upload modal fits the screen */
  .modal { width: auto; max-width: calc(100vw - 28px); margin: 0; }

  /* apply form: plate inputs stack 2-per-row */
  .plate-row { grid-template-columns: 1fr 1fr !important; }
  .apply-form { padding: 14px; }

  /* form action buttons go full width & stack */
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; }
}

@media (max-width: 420px) {
  .plate-row { grid-template-columns: 1fr !important; }
}
