* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --bg: #f5f5f5;
  --card-bg: #ffffff;
  --text: #333333;
  --text-light: #888888;
  --border: #e0e0e0;
  --danger: #e53935;
  --success: #43a047;
  --header-h: 56px;
  --nav-h: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

/* === Header === */
.app-header {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--primary);
  color: white;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  box-shadow: 0 2px 4px rgba(0,0,0,.15);
}
.app-header h1 { font-size: 18px; font-weight: 600; }
.header-btn {
  background: none; border: none; color: white;
  font-size: 14px; cursor: pointer; padding: 8px;
  display: flex; align-items: center; gap: 4px;
}
.header-back { font-size: 24px; }

/* === Bottom Nav === */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: white;
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-decoration: none; color: var(--text-light);
  font-size: 10px; gap: 2px; cursor: pointer;
  border: none; background: none;
}
.nav-item.active { color: var(--primary); }
.nav-item .nav-icon { font-size: 24px; }

/* === Views === */
.view {
  display: none;
  padding-top: var(--header-h);
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  min-height: 100vh;
}
.view.active { display: block; }

/* === Login === */
.login-view {
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  display: none;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary) 0%, #4a90d9 100%);
  justify-content: center; align-items: center;
}
.login-view.active { display: flex !important; }
.login-box {
  background: white; border-radius: 16px; padding: 40px 24px;
  width: 90%; max-width: 360px;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.login-box h2 { text-align: center; margin-bottom: 8px; font-size: 22px; }
.login-box .subtitle { text-align: center; color: var(--text-light); margin-bottom: 24px; font-size: 13px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; color: var(--text-light); margin-bottom: 4px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 16px; outline: none;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--primary);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 12px 24px; border: none; border-radius: 8px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  width: 100%; transition: background .2s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: white; }
.btn-outline {
  background: white; color: var(--primary); border: 1px solid var(--primary);
}
.btn-sm { padding: 8px 16px; font-size: 13px; width: auto; }
.error-msg { color: var(--danger); font-size: 13px; margin-top: 8px; text-align: center; }

/* === Card List === */
.search-bar {
  padding: 12px 16px;
  position: sticky; top: var(--header-h); background: var(--bg); z-index: 10;
}
.search-input {
  width: 100%; padding: 10px 16px 10px 40px;
  border: 1px solid var(--border); border-radius: 24px;
  font-size: 15px; background: white; outline: none;
}
.search-wrap { position: relative; }
.search-wrap::before {
  content: '🔍'; position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  font-size: 16px;
}
.tab-bar {
  display: flex; padding: 0 16px; gap: 0;
  background: white; border-bottom: 1px solid var(--border);
}
.tab-btn {
  flex: 1; padding: 12px; text-align: center;
  border: none; background: none; font-size: 14px; font-weight: 600;
  color: var(--text-light); cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.card-list { padding: 8px 16px; }
.card-item {
  display: flex; align-items: center; gap: 12px;
  background: white; border-radius: 12px; padding: 12px;
  margin-bottom: 8px; cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  transition: box-shadow .2s;
}
.card-item:active { box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.card-thumb {
  width: 72px; height: 44px; border-radius: 6px;
  object-fit: cover; background: #eee; flex-shrink: 0;
}
.card-thumb-placeholder {
  width: 72px; height: 44px; border-radius: 6px;
  background: #e8eaf6; display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.card-info { flex: 1; min-width: 0; }
.card-info .name { font-size: 15px; font-weight: 600; }
.card-info .company { font-size: 12px; color: var(--text-light); margin-top: 2px; }
.card-info .dept { font-size: 11px; color: var(--text-light); }
.card-badge {
  font-size: 10px; padding: 2px 8px; border-radius: 10px;
  background: #e3f2fd; color: var(--primary); white-space: nowrap;
}
.card-badge.private { background: #fff3e0; color: #e65100; }

.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-light);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }

/* === Card Detail === */
.detail-view { background: white; }
.detail-card-image {
  width: calc(100% - 32px); margin: 16px auto; border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.12); display: block;
  max-height: 200px; object-fit: contain; background: #f9f9f9;
}
.detail-person {
  padding: 16px; border-bottom: 1px solid var(--border);
}
.detail-person .name { font-size: 22px; font-weight: 700; }
.detail-person .dept { font-size: 14px; color: var(--text-light); margin-top: 4px; }
.detail-person .company { font-size: 13px; color: var(--text-light); }

.detail-section {
  padding: 16px;
}
.detail-section-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}
.detail-section-header h3 { font-size: 15px; font-weight: 700; }
.detail-section-header button {
  border: none; background: none; color: var(--primary);
  font-size: 14px; cursor: pointer;
}

.detail-field {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0; border-bottom: 1px solid #f0f0f0;
}
.detail-field:last-child { border-bottom: none; }
.detail-field-info { flex: 1; }
.detail-field-label { font-size: 12px; color: var(--text-light); }
.detail-field-value { font-size: 15px; margin-top: 2px; word-break: break-all; }
.detail-field-actions { display: flex; gap: 8px; }
.detail-action-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: none; background: #f0f0f0; font-size: 18px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}

.detail-meta {
  padding: 16px; border-top: 8px solid var(--bg);
}
.detail-meta-item {
  padding: 14px 0; border-bottom: 1px solid #f0f0f0;
  display: flex; justify-content: space-between; align-items: center;
}
.detail-meta-label { font-size: 15px; font-weight: 600; }
.detail-meta-value { font-size: 14px; color: var(--text-light); }

/* === Camera === */
.camera-view {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: black; z-index: 200; display: none;
}
.camera-view.active { display: flex; flex-direction: column; }
.camera-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; z-index: 1;
}
.camera-close {
  width: 36px; height: 36px; background: rgba(255,255,255,.2);
  border: none; border-radius: 50%; color: white; font-size: 20px;
  cursor: pointer;
}
.camera-orientation {
  display: flex; background: rgba(255,255,255,.2); border-radius: 20px; overflow: hidden;
}
.camera-orientation button {
  padding: 8px 16px; border: none; background: none;
  color: rgba(255,255,255,.7); font-size: 13px; cursor: pointer;
}
.camera-orientation button.active {
  background: rgba(255,255,255,.3); color: white;
}

.camera-body {
  flex: 1; position: relative; display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
#cameraVideo {
  width: 100%; height: 100%; object-fit: cover;
}
.camera-guide {
  position: absolute; pointer-events: none;
}
.camera-guide.horizontal { width: 85%; aspect-ratio: 91/55; }
.camera-guide.vertical { width: 60%; aspect-ratio: 55/91; }
.camera-guide .corner {
  position: absolute; width: 24px; height: 24px;
}
.corner { border-color: #00e676; border-style: solid; border-width: 0; }
.corner.tl { top: 0; left: 0; border-top-width: 3px; border-left-width: 3px; }
.corner.tr { top: 0; right: 0; border-top-width: 3px; border-right-width: 3px; }
.corner.bl { bottom: 0; left: 0; border-bottom-width: 3px; border-left-width: 3px; }
.corner.br { bottom: 0; right: 0; border-bottom-width: 3px; border-right-width: 3px; }

.camera-footer {
  padding: 16px; display: flex; align-items: center; justify-content: center;
  gap: 32px; z-index: 1;
}
.camera-footer .label { color: rgba(255,255,255,.6); font-size: 13px; text-align: center; margin-bottom: 8px; }
.gallery-btn {
  width: 48px; height: 48px; border-radius: 8px;
  border: 2px solid rgba(255,255,255,.4); background: rgba(255,255,255,.1);
  color: white; font-size: 20px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.gallery-btn span { font-size: 9px; margin-top: 2px; }
.capture-btn {
  width: 72px; height: 72px; border-radius: 50%;
  border: 4px solid white; background: transparent;
  cursor: pointer; position: relative;
}
.capture-btn::after {
  content: ''; position: absolute;
  top: 4px; left: 4px; right: 4px; bottom: 4px;
  border-radius: 50%; background: #00e676;
}
.capture-btn:active::after { background: #00c853; }
#galleryInput { display: none; }

/* === Edit Form === */
.edit-view { background: white; }
.edit-form { padding: 16px; }
.edit-form .form-group { margin-bottom: 12px; }
.edit-form textarea { min-height: 60px; resize: vertical; }
.visibility-toggle {
  display: flex; gap: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
  margin-top: 4px;
}
.visibility-toggle button {
  flex: 1; padding: 10px; border: none; background: white;
  font-size: 14px; cursor: pointer;
}
.visibility-toggle button.active {
  background: var(--primary); color: white;
}
.ocr-status {
  padding: 12px 16px; background: #e8f5e9; margin: 16px;
  border-radius: 8px; font-size: 13px; color: #2e7d32;
  display: flex; align-items: center; gap: 8px;
}
.ocr-status.loading { background: #fff3e0; color: #e65100; }
.spinner {
  width: 18px; height: 18px; border: 2px solid #ccc;
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Admin === */
.admin-section {
  padding: 16px;
}
.admin-section h3 {
  font-size: 16px; font-weight: 700; margin-bottom: 12px;
  padding-bottom: 8px; border-bottom: 2px solid var(--primary);
}
.admin-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px; background: white; border-radius: 8px;
  margin-bottom: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.admin-item-info { flex: 1; }
.admin-item-info .main { font-weight: 600; }
.admin-item-info .sub { font-size: 12px; color: var(--text-light); }
.admin-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: none; font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn.edit { background: #e3f2fd; }
.icon-btn.delete { background: #ffebee; }

/* === Modal === */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.5); z-index: 300;
  display: none; justify-content: center; align-items: flex-end;
}
.modal-overlay.active { display: flex; }
.modal {
  background: white; width: 100%; max-width: 480px;
  border-radius: 16px 16px 0 0; padding: 24px;
  max-height: 80vh; overflow-y: auto;
  animation: slideUp .3s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal h3 { margin-bottom: 16px; }

/* === FAB === */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 20px);
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--primary); color: white;
  border: none; font-size: 28px;
  box-shadow: 0 4px 12px rgba(26,115,232,.4);
  cursor: pointer; z-index: 50;
  display: flex; align-items: center; justify-content: center;
}
.fab:active { transform: scale(.95); }

/* === Responsive === */
@media (min-width: 600px) {
  .card-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
}
@media (min-width: 900px) {
  .card-list { grid-template-columns: 1fr 1fr 1fr; }
}
