:root {
  --primary: #2f5496;
  --primary-dark: #1e3a6f;
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #232733;
  --muted: #6b7280;
  --border: #e2e5ec;
  --success: #1a7f4c;
  --warning: #b5710a;
  --error: #c0392b;
  --info: #2f5496;
  --critical: #a11d1d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.topbar {
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { color: white; font-weight: bold; text-decoration: none; font-size: 1.1rem; flex: 1; }

.nav-toggle {
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}

.topbar-user { font-size: 0.85rem; opacity: 0.9; white-space: nowrap; }

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 99;
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }

.side-drawer {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 260px;
  max-width: 82vw;
  background: var(--primary-dark);
  color: white;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  z-index: 100;
  display: flex;
  flex-direction: column;
  padding: 10px 0 20px;
  overflow-y: auto;
}
.side-drawer.open { transform: translateX(0); }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px 16px;
  font-weight: bold;
  font-size: 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.15);
  margin-bottom: 8px;
}
.drawer-close { background: none; border: none; color: white; font-size: 1.2rem; cursor: pointer; }

.drawer-link {
  display: block;
  width: 100%;
  color: white;
  text-decoration: none;
  text-align: left;
  background: none;
  border: none;
  font-family: inherit;
  padding: 13px 18px;
  font-size: 0.95rem;
  opacity: 0.92;
  cursor: pointer;
}
.drawer-link:hover, .drawer-link.active { opacity: 1; background: rgba(255,255,255,0.1); }
.drawer-link.primary { font-weight: 700; background: rgba(255,255,255,0.08); }
.drawer-divider { height: 1px; background: rgba(255,255,255,0.15); margin: 8px 0; }
.drawer-logout { color: #ffd6d1; }

.container { max-width: 1000px; margin: 0 auto; padding: 20px 16px 60px; }

.banner { padding: 10px 16px; text-align: center; font-size: 0.9rem; }
.banner-info { background: #fff3cd; color: #7a5c00; }

.flash-wrap { margin-bottom: 16px; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; font-size: 0.92rem; }
.flash-success { background: #e6f4ea; color: var(--success); border: 1px solid #b7dfc4; }
.flash-error { background: #fdecea; color: var(--error); border: 1px solid #f3c1bb; }
.flash-warning { background: #fff6e5; color: var(--warning); border: 1px solid #f3d8a3; }
.flash-info { background: #e8f0fe; color: var(--info); border: 1px solid #c3d6f7; }

h1 { font-size: 1.5rem; margin-bottom: 4px; }
h2 { font-size: 1.2rem; margin-top: 28px; }
.subtitle { color: var(--muted); margin-top: 0; margin-bottom: 20px; font-size: 0.92rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}
.badge-in { background: #e6f4ea; color: var(--success); }
.badge-out { background: #eceff3; color: var(--muted); }
.badge-warning { background: #fff6e5; color: var(--warning); }
.badge-critical { background: #fdecea; color: var(--critical); }

.table-scroll { overflow-x: auto; }
.table-scroll table { white-space: nowrap; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 0.82rem; }
tr:hover td { background: #fafbfd; }

.receipt-list { display: flex; flex-direction: column; gap: 10px; }
.receipt-item {
  display: block;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  color: inherit;
  text-decoration: none;
  background: var(--card);
}
.receipt-item:hover { border-color: var(--primary); background: #fafbfd; }
.receipt-item-main { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.receipt-item-vendor { font-weight: 700; font-size: 1rem; }
.receipt-item-amount { font-weight: 700; font-size: 1.1rem; color: var(--primary); white-space: nowrap; }
.receipt-item-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; font-size: 0.82rem; color: var(--muted); align-items: center; }

form.inline { display: inline; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=number], input[type=date],
input[type=time], input[type=password],
input[type=datetime-local], textarea, select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: white;
  color: var(--text);
}
textarea { resize: vertical; min-height: 100px; }

/* PINは type=password にすると、iOSのSafariがログインパスワードとみなし
   iCloudキーチェーン確認のためのFace ID認証を毎回リクエストしてしまうため、
   type=text のまま -webkit-text-security で見た目だけマスクする */
input.pin-input {
  -webkit-text-security: disc;
  text-security: disc;
}

.btn {
  display: inline-block;
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.92rem;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--primary-dark); }

input[type=file] {
  width: 100%;
  font-size: 0.95rem;
  padding: 6px 0;
}
input[type=file]::file-selector-button,
input[type=file]::-webkit-file-upload-button {
  display: inline-block;
  background: var(--primary);
  color: white;
  border: none;
  padding: 14px 22px;
  margin-right: 14px;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
}
input[type=file]::file-selector-button:hover,
input[type=file]::-webkit-file-upload-button:hover { background: var(--primary-dark); }
.btn-secondary { background: #eceff3; color: var(--text); }
.btn-secondary:hover { background: #dde1e8; }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }

.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 18px; }
.filter-bar .form-group { margin-bottom: 0; min-width: 160px; }

.ai-box { background: #f7f9ff; border: 1px solid #d6e0fa; border-radius: 10px; padding: 14px; margin-top: 10px; }
.ai-box .label { font-size: 0.78rem; color: var(--primary); font-weight: 700; margin-bottom: 6px; }

.camera-wrap { text-align: center; }
#video, #canvas { width: 100%; max-width: 420px; border-radius: 12px; background: #000; }
#canvas { display: none; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
}
.modal-box { max-width: 380px; width: 100%; margin: 0; }

.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.status-dot.in { background: var(--success); }
.status-dot.out { background: var(--muted); }

.empty-state { color: var(--muted); font-size: 0.9rem; padding: 20px 0; text-align: center; }

.footer { text-align: center; color: var(--muted); font-size: 0.78rem; padding: 24px 0; }

.thumb { width: 100%; max-width: 220px; border-radius: 10px; border: 1px solid var(--border); }

