:root {
  --bg: #f4f7f8;
  --surface: #ffffff;
  --primary: #0f4c5c;
  --primary-light: #1b6b7f;
  --accent: #e36414;
  --text: #1a1a1a;
  --text-muted: #5c6b73;
  --border: #d8e0e4;
  --danger: #c1121f;
  --success: #2a9d8f;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(15, 76, 92, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  padding-bottom: calc(16px + var(--safe-bottom));
}

.app-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  padding: calc(16px + var(--safe-top)) 20px 20px;
  text-align: center;
}

.app-title {
  font-size: 1.25rem;
  font-weight: 700;
}

.app-subtitle {
  font-size: 0.85rem;
  opacity: 0.9;
  margin-top: 4px;
}

.tab-nav {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.tab-btn {
  border: none;
  background: transparent;
  padding: 10px 4px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: 8px;
  cursor: pointer;
}

.tab-btn.active {
  background: rgba(15, 76, 92, 0.1);
  color: var(--primary);
}

.app-main {
  padding: 12px;
  max-width: 560px;
  margin: 0 auto;
}

.tab-panel[hidden] {
  display: none !important;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.card h2,
.card h3 {
  font-size: 1rem;
  margin-bottom: 12px;
  color: var(--primary);
}

.field-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  margin-top: 12px;
}

.field-label:first-child {
  margin-top: 0;
}

.required {
  color: var(--danger);
  font-size: 0.75rem;
}

.field-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: #fff;
  -webkit-appearance: none;
  appearance: none;
}

.field-input:focus {
  outline: 2px solid rgba(15, 76, 92, 0.25);
  border-color: var(--primary);
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.input-row .field-input {
  flex: 1;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn:active {
  opacity: 0.85;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-secondary {
  background: #e8eef0;
  color: var(--primary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 8px 12px;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-large {
  width: 100%;
  margin-top: 8px;
  padding: 16px;
  font-size: 1rem;
}

.hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 8px;
}

.scanner-card .scanner-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.scanner-card h2 {
  margin-bottom: 0;
}

.scanner-container {
  position: relative;
  margin-top: 12px;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  aspect-ratio: 4 / 3;
}

.scanner-container.hidden {
  display: none;
}

#scanner-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner-overlay {
  position: absolute;
  inset: 15% 10%;
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 8px;
  pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35);
}

.entry-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.entry-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
}

.entry-item-main {
  min-width: 0;
}

.entry-item-code {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: ui-monospace, monospace;
}

.entry-item-name {
  font-weight: 600;
  margin: 2px 0;
  word-break: break-all;
}

.entry-item-detail {
  font-size: 0.9rem;
  color: var(--primary);
}

.sync-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: middle;
}

.sync-badge.synced {
  background: rgba(42, 157, 143, 0.15);
  color: var(--success);
}

.sync-badge.unsynced {
  background: rgba(227, 100, 20, 0.12);
  color: var(--accent);
}

.sync-card .summary {
  margin: 12px 0;
  font-weight: 700;
  color: var(--primary);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.entry-item-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.entry-item-actions .btn {
  padding: 8px 10px;
  font-size: 0.8rem;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
}

.empty-state.hidden {
  display: none;
}

.list-header .summary {
  margin-top: 8px;
  font-weight: 700;
  color: var(--primary);
}

.export-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.export-preview {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 12px;
  border-radius: 8px;
  font-size: 0.7rem;
  line-height: 1.4;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 320px;
  overflow-y: auto;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%) translateY(120%);
  background: rgba(26, 26, 26, 0.92);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 100;
  transition: transform 0.25s ease;
  max-width: calc(100% - 32px);
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.hidden {
  display: none !important;
}

.text-danger { color: var(--danger); }

.product-info { margin-top: 12px; }

.suggestions { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.suggestion-btn {
  text-align: left; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 8px; background: #f8fafb; font-size: 0.85rem; cursor: pointer;
}

.calc-amount { margin-top: 12px; font-size: 1.1rem; color: var(--primary); }
.tax-details { margin-top: 12px; font-size: 0.9rem; }
.tax-details summary { cursor: pointer; color: var(--text-muted); padding: 8px 0; }

.dash-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.dash-card {
  background: var(--surface); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); text-align: center;
}
.dash-label { font-size: 0.8rem; color: var(--text-muted); }
.dash-value { font-size: 1.3rem; font-weight: 700; color: var(--primary); margin: 4px 0; }
.dash-sub { font-size: 0.85rem; color: var(--text-muted); }

.brand-list { display: flex; flex-direction: column; gap: 8px; }
.brand-item {
  background: var(--surface); border-radius: 10px; padding: 12px 16px;
  box-shadow: var(--shadow); display: grid; grid-template-columns: 1fr auto; gap: 4px;
}
.brand-name { font-weight: 600; }
.brand-amount { font-weight: 700; color: var(--primary); text-align: right; }
.brand-yoy { grid-column: 1 / -1; font-size: 0.8rem; color: var(--text-muted); }

.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: flex-end; justify-content: center; }
.modal.hidden { display: none !important; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.modal-content {
  position: relative; background: var(--surface); border-radius: 16px 16px 0 0;
  padding: 24px 20px calc(20px + var(--safe-bottom)); width: 100%; max-width: 560px;
  max-height: 80dvh; overflow-y: auto;
}
.modal-content h2 { margin-bottom: 16px; color: var(--primary); }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }

.confirm-list { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 0.95rem; }
.confirm-list dt { color: var(--text-muted); font-weight: 600; }
.confirm-list dd { margin: 0; }
.confirm-amount { font-size: 1.2rem; font-weight: 700; color: var(--accent); }

.demo-barcodes-panel { margin-top: 12px; display: flex; flex-direction: column; gap: 12px; }
.demo-bc-card {
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; text-align: center;
}
.demo-bc-name { font-size: 0.85rem; font-weight: 600; margin-bottom: 8px; color: var(--text); }
.demo-bc-svg { width: 100%; max-width: 280px; height: 80px; display: block; margin: 0 auto; }
.demo-bc-jan {
  font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, monospace;
  font-size: 0.9rem; letter-spacing: 0.05em; margin: 8px 0;
}
.demo-use-jan { width: 100%; }

@media (min-width: 480px) {
  .app-title { font-size: 1.4rem; }
  .modal { align-items: center; }
  .modal-content { border-radius: 16px; margin: 20px; }
}
