/* =========================================================
   CardStock — soft minimal UI
   やわらかく、静かで、心地よい。
   ========================================================= */
:root {
  --bg:        #eaedf3;
  --bg-2:      #f3f5f9;
  --surface:   #ffffff;
  --surface-2: #f6f7fb;
  --ink:       #2a3140;
  --ink-soft:  #5b6577;
  --muted:     #8b94a6;
  --line:      #e4e8f0;
  --accent:    #6b73e6;
  --accent-ink:#5159d6;
  --accent-soft:#eef0fe;
  --danger:    #d8607a;
  --danger-soft:#fbeef1;
  --ok:        #4fa07e;
  --ok-soft:   #e9f6f0;

  --radius:    20px;
  --radius-sm: 13px;
  --radius-pill: 999px;

  /* やわらかい多層シャドウ */
  --shadow-soft: 0 1px 2px rgba(36,44,63,.04), 0 8px 24px rgba(36,44,63,.07);
  --shadow-lift: 0 2px 4px rgba(36,44,63,.06), 0 16px 40px rgba(36,44,63,.12);
  --shadow-inset: inset 0 1px 2px rgba(36,44,63,.05);

  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
          "Yu Gothic", "Noto Sans JP", "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 85% -10%, #f6f3ff 0%, rgba(246,243,255,0) 55%),
    radial-gradient(1000px 600px at -10% 0%, #eef6ff 0%, rgba(238,246,255,0) 50%),
    var(--bg);
  background-attachment: fixed;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── App bar ───────────────────────────────────────────── */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px max(16px, env(safe-area-inset-left)) 12px max(16px, env(safe-area-inset-right));
  background: rgba(247, 248, 252, .78);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid rgba(228,232,240,.7);
}
.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--ink); font-weight: 700; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 11px;
  color: #fff; background: linear-gradient(145deg, #7c84ff, #5b62d8);
  box-shadow: 0 4px 12px rgba(91,98,216,.35);
}
.brand-name { font-size: 17px; letter-spacing: .2px; }
.appbar-actions { display: flex; gap: 8px; }

/* ── Layout ────────────────────────────────────────────── */
.main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 22px max(16px, env(safe-area-inset-left)) 120px max(16px, env(safe-area-inset-right));
}
.main-bare { min-height: 100vh; }

/* ── Buttons ───────────────────────────────────────────── */
.btn-primary, .btn-ghost, .btn-danger {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; font: inherit; font-weight: 600; cursor: pointer;
  border-radius: var(--radius-pill); padding: 11px 20px;
  border: 1px solid transparent; transition: transform .12s ease, box-shadow .2s ease, background .2s ease;
}
.btn-primary {
  color: #fff; background: linear-gradient(145deg, #7b83ff, #5d64dd);
  box-shadow: 0 6px 16px rgba(93,100,221,.35);
}
.btn-primary:hover { box-shadow: 0 8px 22px rgba(93,100,221,.45); text-decoration: none; }
.btn-primary:active { transform: translateY(1px); }
.btn-ghost {
  color: var(--ink-soft); background: var(--surface);
  border-color: var(--line); box-shadow: var(--shadow-soft);
}
.btn-ghost:hover { color: var(--ink); text-decoration: none; box-shadow: var(--shadow-lift); }
.btn-danger {
  color: var(--danger); background: var(--danger-soft); border-color: #f3d8df;
}
.btn-danger:hover { background: #f8e3e9; text-decoration: none; }
.btn-block { width: 100%; }

/* ── Toolbar (search + sort) ───────────────────────────── */
.toolbar {
  display: flex; gap: 12px; align-items: center;
  margin-bottom: 18px; flex-wrap: wrap;
}
.search {
  position: relative; flex: 1 1 280px; display: flex; align-items: center;
}
.search-icon {
  position: absolute; left: 16px; color: var(--muted); display: inline-flex; pointer-events: none;
}
.search-input {
  width: 100%; font: inherit; color: var(--ink);
  padding: 13px 42px 13px 44px;
  border: 1px solid var(--line); border-radius: var(--radius-pill);
  background: var(--surface); box-shadow: var(--shadow-soft);
  transition: box-shadow .2s ease, border-color .2s ease;
}
.search-input::placeholder { color: var(--muted); }
.search-input:focus {
  outline: none; border-color: #c5c9f6;
  box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow-soft);
}
.search-clear {
  position: absolute; right: 14px; width: 22px; height: 22px;
  display: grid; place-items: center; border-radius: 50%;
  color: var(--muted); background: var(--surface-2); font-size: 16px; line-height: 1;
}
.search-clear:hover { color: var(--ink); text-decoration: none; background: var(--line); }
.sort { display: flex; align-items: center; gap: 8px; }
.sort-label { font-size: 13px; color: var(--muted); }
.sort-select {
  font: inherit; color: var(--ink-soft); padding: 11px 14px;
  border: 1px solid var(--line); border-radius: var(--radius-pill);
  background: var(--surface); box-shadow: var(--shadow-soft); cursor: pointer;
}
.sort-select:focus { outline: none; border-color: #c5c9f6; box-shadow: 0 0 0 4px var(--accent-soft); }

.result-count { color: var(--muted); font-size: 13px; margin: 0 2px 14px; }

/* ── Card grid ─────────────────────────────────────────── */
.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
}
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-soft); overflow: hidden;
  transition: transform .16s ease, box-shadow .2s ease;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lift); }
.card-link { display: block; color: inherit; }
.card-link:hover { text-decoration: none; }
.card-thumb {
  position: relative; aspect-ratio: 16 / 10; background: var(--surface-2);
  display: grid; place-items: center; overflow: hidden;
}
.card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.card-initial {
  font-size: 34px; font-weight: 700; color: #b9c0d4;
  width: 64px; height: 64px; border-radius: 50%;
  display: grid; place-items: center; background: #fff;
  box-shadow: var(--shadow-inset);
}
.card-initial.big { width: 110px; height: 110px; font-size: 52px; }
.card-body { padding: 13px 15px 15px; }
.card-name { margin: 0; font-weight: 700; font-size: 15.5px; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-company { margin: 3px 0 0; font-size: 12.5px; color: var(--ink-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-date { margin: 10px 0 0; font-size: 11.5px; color: var(--muted); }

/* ── Chips ─────────────────────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.chip {
  font-size: 11.5px; color: var(--accent-ink);
  background: var(--accent-soft); border-radius: var(--radius-pill);
  padding: 3px 10px; line-height: 1.5; white-space: nowrap;
}
a.chip:hover { background: #e2e5fd; text-decoration: none; }
.chip-more { color: var(--muted); background: var(--surface-2); }

/* ── Empty state ───────────────────────────────────────── */
.empty {
  text-align: center; padding: 70px 20px; color: var(--muted);
}
.empty-art {
  width: 84px; height: 84px; margin: 0 auto 18px;
  display: grid; place-items: center; color: #b6bdd0;
  background: var(--surface); border-radius: 24px; box-shadow: var(--shadow-soft);
}
.empty-title { font-size: 16px; font-weight: 700; color: var(--ink-soft); margin: 0 0 6px; }
.empty-sub { font-size: 13.5px; margin: 0; }

/* ── FAB ───────────────────────────────────────────────── */
.fab {
  position: fixed; right: max(20px, env(safe-area-inset-right));
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 22px; z-index: 30;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(145deg, #7c84ff, #5b62d8);
  box-shadow: 0 10px 26px rgba(91,98,216,.45);
  transition: transform .15s ease, box-shadow .2s ease;
}
.fab:hover { transform: translateY(-2px) scale(1.03); text-decoration: none;
  box-shadow: 0 14px 32px rgba(91,98,216,.55); }
.fab:active { transform: translateY(0) scale(.98); }

/* ── Page head ─────────────────────────────────────────── */
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 18px;
}
.back { color: var(--ink-soft); font-weight: 600; font-size: 14px; }
.back:hover { color: var(--ink); text-decoration: none; }
.page-title { font-size: 20px; margin: 0; font-weight: 700; }

/* ── Forms ─────────────────────────────────────────────── */
.form-card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-soft); padding: 20px; max-width: 720px; margin: 0 auto;
}
.grid-fields {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 18px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field.span-2 { grid-column: 1 / -1; }
.field-label { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.field-note { font-weight: 400; color: var(--muted); font-size: 11.5px; }
.input {
  font: inherit; color: var(--ink); width: 100%;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); transition: box-shadow .2s ease, border-color .2s ease, background .2s ease;
}
.input::placeholder { color: var(--muted); }
.input:focus {
  outline: none; background: #fff; border-color: #c5c9f6;
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.textarea { resize: vertical; min-height: 96px; line-height: 1.6; }

.form-actions {
  display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px;
}

/* ── Photo drop / preview ──────────────────────────────── */
.photo-drop {
  display: block; cursor: pointer; border-radius: var(--radius-sm);
  border: 1.5px dashed #cfd5e6; background: var(--surface-2);
  overflow: hidden; transition: border-color .2s ease, background .2s ease;
}
.photo-drop:hover { border-color: var(--accent); background: var(--accent-soft); }
.photo-placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 38px 20px; color: var(--ink-soft); text-align: center;
}
.photo-placeholder svg { color: var(--accent); }
.photo-text { font-weight: 600; font-size: 14.5px; }
.photo-hint { font-size: 12px; color: var(--muted); }
.photo-preview { background: #11151f; }
.photo-preview img { display: block; width: 100%; max-height: 420px; object-fit: contain; }

/* ── OCR ───────────────────────────────────────────────── */
.ocr-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px; margin-top: 12px;
}
.btn-ocr {
  display: inline-flex; align-items: center; gap: 7px; font: inherit; font-weight: 600;
  color: var(--accent-ink); background: var(--accent-soft); cursor: pointer;
  border: 1px solid #dadcfb; border-radius: var(--radius-pill); padding: 9px 16px;
  transition: background .2s ease, box-shadow .2s ease;
}
.btn-ocr:hover { background: #e3e5fd; }
.btn-ocr:disabled { opacity: .55; cursor: default; }
.ocr-hint-inline { font-size: 12px; color: var(--muted); }
.ocr-progress { display: flex; align-items: center; gap: 10px; width: 100%; }
.ocr-progress-track {
  flex: 1; height: 7px; border-radius: 999px; background: var(--surface-2);
  overflow: hidden; box-shadow: var(--shadow-inset);
}
#ocrProgressFill {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, #8a91ff, #5d64dd); transition: width .25s ease;
}
.ocr-progress-label { font-size: 12px; color: var(--ink-soft); white-space: nowrap; min-width: 6em; }
.ocr-result {
  margin-top: 14px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); overflow: hidden;
}
.ocr-result-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 13px; border-bottom: 1px solid var(--line);
}
.ocr-result-title { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
.ocr-mini {
  font: inherit; font-size: 12px; font-weight: 600; color: var(--accent-ink);
  background: #fff; border: 1px solid #dadcfb; border-radius: var(--radius-pill);
  padding: 4px 12px; cursor: pointer;
}
.ocr-mini:hover { background: var(--accent-soft); }
.ocr-text {
  margin: 0; padding: 12px 13px; max-height: 180px; overflow: auto;
  font-size: 12.5px; line-height: 1.7; color: var(--ink-soft);
  white-space: pre-wrap; word-break: break-word;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.ocr-note { margin: 0; padding: 8px 13px 11px; font-size: 11.5px; color: var(--muted); }
.input.field-autofilled {
  background: #fffbe9; border-color: #f0dfa0;
  box-shadow: 0 0 0 4px rgba(240,223,160,.35);
  transition: background .4s ease, box-shadow .4s ease, border-color .4s ease;
}

/* ── CSV button ────────────────────────────────────────── */
.btn-csv { padding: 11px 16px; gap: 7px; }
@media (max-width: 460px) {
  .btn-csv-label { display: none; }
  .btn-csv { padding: 11px 13px; }
}

/* ── Detail ────────────────────────────────────────────── */
.detail {
  display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 22px; align-items: start;
}
.detail-photo {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-soft); overflow: hidden;
}
.detail-photo img { display: block; width: 100%; height: auto; }
.detail-noimg { aspect-ratio: 16 / 10; display: grid; place-items: center; background: var(--surface-2); }
.detail-info {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-soft); padding: 22px;
}
.detail-name { font-size: 24px; margin: 0; font-weight: 700; }
.detail-company { margin: 6px 0 0; color: var(--ink-soft); font-size: 14.5px; }
.detail-list { margin: 18px 0 0; display: flex; flex-direction: column; }
.detail-row {
  display: grid; grid-template-columns: 84px 1fr; gap: 12px;
  padding: 12px 0; border-top: 1px solid var(--line);
}
.detail-row dt { color: var(--muted); font-size: 13px; }
.detail-row dd { margin: 0; color: var(--ink); font-size: 14px; word-break: break-word; }
.detail-memo { white-space: normal; line-height: 1.7; }

/* ── Delete zone ───────────────────────────────────────── */
.delete-zone { max-width: 720px; margin: 26px auto 0; text-align: center; }

/* ── Alerts ────────────────────────────────────────────── */
.alert {
  max-width: 720px; margin: 0 auto 16px; padding: 12px 16px;
  border-radius: var(--radius-sm); font-size: 14px;
  color: var(--danger); background: var(--danger-soft); border: 1px solid #f3d8df;
}
.alert-ok { color: var(--ok); background: var(--ok-soft); border-color: #cdeadd; }

/* ── Login ─────────────────────────────────────────────── */
.bare {
  background:
    radial-gradient(900px 500px at 80% -5%, #efeaff 0%, rgba(239,234,255,0) 60%),
    radial-gradient(800px 500px at 10% 110%, #e6f1ff 0%, rgba(230,241,255,0) 55%),
    var(--bg);
}
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 380px; text-align: center;
  background: var(--surface); border-radius: 26px;
  box-shadow: var(--shadow-lift); padding: 38px 30px 32px;
}
.auth-logo {
  width: 60px; height: 60px; margin: 0 auto 16px; border-radius: 18px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(145deg, #7c84ff, #5b62d8);
  box-shadow: 0 10px 24px rgba(91,98,216,.4);
}
.auth-title { font-size: 22px; margin: 0; font-weight: 700; letter-spacing: .3px; }
.auth-sub { color: var(--muted); font-size: 13.5px; margin: 6px 0 24px; }
.auth-form { display: flex; flex-direction: column; gap: 16px; text-align: left; }

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 720px) {
  .detail { grid-template-columns: 1fr; }
  .grid-fields { grid-template-columns: 1fr; }
  .field.span-2 { grid-column: auto; }
  .page-title { font-size: 18px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 13px; }
}
@media (max-width: 380px) {
  .grid { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
