/* ============================================
   保険証券リーダー — シック・落ち着きデザイン
   カラーパレット：チャコール × ウォームベージュ × ゴールド
   ============================================ */

:root {
  --bg:         #1a1917;
  --bg-2:       #201f1d;
  --bg-3:       #252321;
  --surface:    #2c2a27;
  --surface-2:  #333129;
  --border:     rgba(210, 195, 170, 0.12);
  --border-2:   rgba(210, 195, 170, 0.22);

  --text-1:     #e8e0d4;
  --text-2:     #a89f92;
  --text-3:     #6b6358;

  --gold:       #c9a96e;
  --gold-light: #e0c896;
  --gold-dim:   rgba(201, 169, 110, 0.18);
  --gold-glow:  rgba(201, 169, 110, 0.08);

  --danger:     #c87070;
  --danger-bg:  rgba(200, 112, 112, 0.12);
  --success:    #7baa7e;
  --success-bg: rgba(123, 170, 126, 0.12);
  --muted:      rgba(168, 159, 146, 0.12);

  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --sidebar-w:  220px;
  --transition: 0.18s ease;

  font-family: 'DM Sans', 'Noto Sans JP', sans-serif;
  font-size: 14px;
  color: var(--text-1);
  line-height: 1.6;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); min-height: 100vh; }
button { cursor: pointer; font-family: inherit; }
input { font-family: inherit; }
svg { display: block; flex-shrink: 0; }

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 10px; }

/* ============ LAYOUT ============ */
.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ============ SIDEBAR ============ */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: #0f0e0c;
  border-right: 1px solid rgba(210, 195, 170, 0.18);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 0;
}

.sidebar-top { flex: 1; padding: 0 1rem; }
.sidebar-bottom { padding: 1rem; border-top: 1px solid var(--border); }

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 0.5rem 1.5rem;
  color: var(--gold-light);
  font-family: 'Cormorant Garamond', serif;
  font-size: 17px;
  font-weight: 400;
  letter-spacing: 0.04em;
}
.logo svg { color: var(--gold); }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 11px;
  border: none;
  background: transparent;
  color: #ede8e1;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 400;
  text-align: left;
  letter-spacing: 0.01em;
  line-height: 1;
  cursor: pointer;
}
.nav-item svg { color: #c8bfb0; flex-shrink: 0; }
.nav-item.active {
  background: var(--gold-dim);
  color: var(--gold-light);
}
.nav-item.active svg { color: var(--gold); }

.api-status {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-3);
  margin-top: 4px;
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
  flex-shrink: 0;
  transition: background 0.3s;
}
.status-dot.ok { background: var(--success); }
.status-dot.error { background: var(--danger); }

/* ============ MAIN ============ */
.main {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
}

.view { display: none; padding: 2.5rem 2.5rem 4rem; max-width: 1100px; }
.view.active { display: block; }

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.page-header h1 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 28px;
  font-weight: 400;
  color: var(--text-1);
  letter-spacing: 0.02em;
  margin-bottom: 4px;
}
.page-header p { font-size: 13px; color: var(--text-3); }

/* ============ READER GRID ============ */
.reader-grid {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 900px) {
  .reader-grid { grid-template-columns: 1fr; }
  .view { padding: 1.5rem; }
  .sidebar { width: 180px; }
  .page-header h1 { font-size: 22px; }
}

/* ============ MOBILE ============ */
@media (max-width: 600px) {
  .layout {
    flex-direction: column;
    height: 100vh;
  }

  /* サイドバー → ボトムナビ */
  .sidebar {
    width: 100%;
    flex-shrink: 0;
    order: 2;
    flex-direction: row;
    padding: 0;
    border-right: none;
    border-top: 1px solid rgba(210, 195, 170, 0.18);
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 50;
  }
  .sidebar-top {
    flex: 1;
    padding: 0;
    display: flex;
    align-items: stretch;
  }
  .logo { display: none; }
  .nav {
    flex-direction: row;
    flex: 1;
    gap: 0;
  }
  .nav-item[data-view] {
    flex: 1;
    justify-content: center;
    padding: 12px 8px;
    border-radius: 0;
    font-size: 11px;
    flex-direction: column;
    gap: 4px;
  }
  .sidebar-bottom { display: none; }

  /* メインエリア */
  .main {
    order: 1;
    padding-bottom: 56px; /* ボトムナビ分 */
  }
  .view {
    padding: 1rem 1rem 2rem;
  }

  /* ページヘッダー */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
  }
  .page-header h1 {
    font-size: 20px;
  }
  .page-header p {
    font-size: 12px;
  }

  /* アップロード */
  .upload-zone {
    min-height: 220px;
  }
  .upload-icon-wrap {
    width: 52px;
    height: 52px;
  }
  .upload-icon-wrap svg {
    width: 22px;
    height: 22px;
  }
  .upload-hint-title {
    font-size: 13px;
  }
  .upload-btns {
    flex-direction: column;
    width: 100%;
  }
  .btn-upload-cam,
  .btn-upload-file {
    justify-content: center;
    padding: 12px 14px;
  }

  /* 解析ボタン */
  .btn-analyze {
    padding: 14px;
    font-size: 15px;
  }

  /* 結果パネル */
  .results-panel {
    min-height: 250px;
  }
  #results-content {
    padding: 1rem;
  }
  .r-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .r-field.full {
    grid-column: 1;
  }
  .r-card {
    padding: 0.875rem 1rem;
  }
  .results-empty {
    padding: 2rem 1rem;
  }

  /* エクスポート */
  .export-row {
    flex-direction: column;
  }
  .btn-export {
    justify-content: center;
    padding: 10px 14px;
  }

  /* 履歴 */
  .history-card {
    grid-template-columns: 48px 1fr;
    padding: 0.875rem;
  }
  .history-thumb {
    width: 48px;
    height: 48px;
  }
  .history-meta {
    grid-column: 1 / -1;
    text-align: left;
    display: flex;
    gap: 12px;
  }
  .history-info h3 {
    font-size: 13px;
  }
}

/* ============ UPLOAD PANEL ============ */
.upload-panel { display: flex; flex-direction: column; gap: 12px; }

.upload-zone {
  border: 1px dashed var(--border-2);
  border-radius: var(--radius-lg);
  min-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--transition), background var(--transition);
  cursor: default;
  overflow: hidden;
  background: var(--bg-2);
}
.upload-zone.drag-over {
  border-color: var(--gold);
  background: var(--gold-glow);
}

#upload-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 2rem;
  text-align: center;
}

.upload-icon-wrap {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gold);
  margin-bottom: 4px;
}

.upload-hint-title { font-size: 14px; font-weight: 500; color: var(--text-1); }
.upload-hint-sub { font-size: 13px; color: var(--text-3); }
.upload-formats { font-size: 11px; color: var(--text-3); letter-spacing: 0.06em; margin-top: 4px; }

.upload-btns { display: flex; gap: 8px; margin-top: 8px; }

.btn-upload-cam,
.btn-upload-file {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--text-1);
  transition: background var(--transition), border-color var(--transition);
}
.btn-upload-cam:hover, .btn-upload-file:hover {
  background: var(--surface-2);
  border-color: var(--gold);
  color: var(--gold-light);
}
.btn-upload-cam svg, .btn-upload-file svg { color: var(--gold); }

/* Preview */
#preview-area {
  width: 100%;
  display: flex;
  flex-direction: column;
}
#preview-area.hidden { display: none; }
#preview-img {
  display: block;
  width: 100%;
  max-height: 340px;
  object-fit: contain;
  background: #000;
}
.preview-controls {
  padding: 10px 12px;
  background: var(--surface);
  display: flex;
  justify-content: flex-end;
}
.btn-clear {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-3);
  background: transparent;
  border: none;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}
.btn-clear:hover { color: var(--danger); background: var(--danger-bg); }

/* Analyze button */
.btn-analyze {
  width: 100%;
  padding: 13px;
  border-radius: var(--radius-md);
  border: 1px solid var(--gold);
  background: var(--gold-dim);
  color: var(--gold-light);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.03em;
  transition: background var(--transition), opacity var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
#analyze-label, #analyze-loading { display: flex; align-items: center; gap: 8px; }
.btn-analyze:hover:not(:disabled) { background: rgba(201, 169, 110, 0.28); }
.btn-analyze:disabled { opacity: 0.3; cursor: not-allowed; border-color: var(--border-2); color: var(--text-2); background: transparent; }

/* ============ SPINNER ============ */
.spinner-sm {
  width: 15px;
  height: 15px;
  border: 1.5px solid rgba(201,169,110,0.3);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ RESULTS PANEL ============ */
.results-panel {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  min-height: 400px;
  display: flex;
  flex-direction: column;
}

.results-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-3);
  text-align: center;
  padding: 3rem;
}
.results-empty svg { opacity: 0.3; }
.results-empty p { font-size: 13px; line-height: 1.7; }

.error-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--danger);
  text-align: center;
  padding: 3rem;
}
.error-state p { font-size: 13px; }

/* ============ RESULT CARDS ============ */
#results-content { padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }

.result-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.05em;
}
.result-badge.active { background: var(--success-bg); color: var(--success); }
.result-badge.inactive { background: var(--danger-bg); color: var(--danger); }
.result-badge.unknown { background: var(--muted); color: var(--text-2); }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.result-section-label {
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--text-3);
  font-weight: 500;
  text-transform: uppercase;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.result-section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.r-card {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
}

.r-card-header {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--gold);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 14px;
}

.r-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 24px;
}
.r-field { display: flex; flex-direction: column; gap: 3px; }
.r-field.full { grid-column: 1 / -1; }
.r-field label {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 400;
}
.r-field span {
  font-size: 14px;
  color: var(--text-1);
  word-break: break-word;
}
.r-field .empty-val { color: var(--text-3); font-size: 13px; }

/* Coverage list */
.coverage-list { display: flex; flex-direction: column; gap: 0; }
.coverage-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-1);
}
.coverage-item:last-child { border-bottom: none; }
.coverage-bullet { width: 4px; height: 4px; border-radius: 50%; background: var(--gold); flex-shrink: 0; }

/* Summary */
.summary-text {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.75;
  font-style: italic;
  border-left: 2px solid var(--gold-dim);
  padding-left: 12px;
}

/* Export row */
.export-row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
}
.btn-export {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  border: 1px solid var(--border-2);
  background: transparent;
  color: var(--text-2);
  transition: background var(--transition), color var(--transition);
}
.btn-export:hover { background: var(--surface); color: var(--gold-light); border-color: var(--gold); }

/* ============ HISTORY ============ */
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  display: grid;
  grid-template-columns: 60px 1fr auto;
  gap: 12px;
  align-items: start;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.history-card:hover { border-color: var(--border-2); background: var(--bg-3); }
.history-thumb {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--surface);
  border: 1px solid var(--border);
}
.history-info h3 { font-size: 14px; font-weight: 500; color: var(--text-1); margin-bottom: 4px; }
.history-info p { font-size: 12px; color: var(--text-3); }
.history-meta { font-size: 11px; color: var(--text-3); text-align: right; white-space: nowrap; }

.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-3);
  font-size: 13px;
}

/* ============ MODAL ============ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 14, 12, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.overlay.hidden { display: none; }

.modal {
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  width: 440px;
  max-width: calc(100vw - 2rem);
  padding: 1.5rem;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.modal-header h2 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 20px;
  font-weight: 400;
  color: var(--text-1);
}
.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-3);
  padding: 4px;
  border-radius: 4px;
  transition: color var(--transition);
}
.icon-btn:hover { color: var(--text-1); }

.modal-desc { font-size: 13px; color: var(--text-3); margin-bottom: 1.25rem; line-height: 1.6; }

.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 1.25rem; }
.form-group label { font-size: 12px; color: var(--text-2); font-weight: 500; letter-spacing: 0.04em; }
.input-row { display: flex; gap: 6px; }
.input-row input {
  flex: 1;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text-1);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
}
.input-row input:focus { border-color: var(--gold); }
.toggle-vis {
  padding: 0 10px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text-3);
  transition: color var(--transition);
}
.toggle-vis:hover { color: var(--gold); }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.link-sm {
  font-size: 12px;
  color: var(--gold);
  text-decoration: none;
  opacity: 0.8;
}
.link-sm:hover { opacity: 1; }
.btn-primary {
  padding: 9px 20px;
  background: var(--gold-dim);
  border: 1px solid var(--gold);
  border-radius: var(--radius-sm);
  color: var(--gold-light);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition);
}
.btn-primary:hover { background: rgba(201,169,110,0.28); }

.btn-ghost-danger {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: transparent;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text-3);
  font-size: 13px;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}
.btn-ghost-danger:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-bg); }

/* ============ UTILITIES ============ */
.hidden { display: none !important; }
