/* 名刺管理の見た目。スマホの幅（360px〜）から組む */
:root {
  --bg: #f4f6f9; --panel: #fff; --text: #1d2430; --muted: #667085; --line: #dfe3ea;
  --accent: #1f4e79; --accent-2: #2f6fa8; --accent-text: #fff;
  --warn-bg: #fff4d6; --warn: #8a5a00; --bad-bg: #fde8e8; --bad: #b42318; --ok: #067647;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151c; --panel: #1a2029; --text: #e6e9ef; --muted: #98a2b3; --line: #2c3542;
    --accent: #5b9bd5; --accent-2: #7fb3e3; --accent-text: #0b1220;
    --warn-bg: #3a2e10; --warn: #f5c451; --bad-bg: #3b1717; --bad: #ff8a80; --ok: #6ce9a6;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif; }
a { color: var(--accent-2); }
h2 { font-size: 1.25rem; margin: 8px 0 12px; }
h3 { font-size: 1.05rem; margin: 16px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--bad); background: var(--bad-bg); padding: 8px 12px; border-radius: 8px; }
.grow { flex: 1; }
[hidden] { display: none !important; }

/* 上の帯 */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--accent); color: var(--accent-text); }
.top .brand { color: inherit; font-weight: 700; text-decoration: none; font-size: 1.05rem; }
.top nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.top nav a { color: inherit; text-decoration: none; padding: 6px 10px; border-radius: 8px; white-space: nowrap; opacity: .85; }
.top nav a.on { background: rgba(255,255,255,.18); opacity: 1; }
.top nav a.add { background: rgba(255,255,255,.92); color: #1f4e79; font-weight: 700; opacity: 1; }
.top .who { display: flex; align-items: center; gap: 8px; font-size: .85rem; margin: 0; }
.top .who .link { color: inherit; }
@media (max-width: 640px) {
  .top { row-gap: 4px; }
  .top .brand { flex: 1; }
  .top nav { order: 3; flex: 1 0 100%; }
  .top nav a { flex: 1; text-align: center; padding: 6px 4px; }
}
main { max-width: 1100px; margin: 0 auto; padding: 16px; padding-bottom: max(32px, env(safe-area-inset-bottom)); }

/* 部品 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel); color: var(--text); font: inherit; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--accent-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 700; }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: .85rem; }
.btn.big { min-height: 56px; font-size: 1.05rem; }
button.link { background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; font: inherit; }
a.link { text-decoration: none; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 40px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-2); outline-offset: -1px; }
textarea { resize: vertical; }
.badge { display: inline-block; font-size: .75rem; padding: 1px 8px; border-radius: 999px; background: var(--line); color: var(--text); margin-right: 4px; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.tag { display: inline-block; font-size: .75rem; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); margin-right: 4px; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1d2430; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 50; max-width: calc(100% - 32px); }
.toast.bad { background: var(--bad); }

/* 一覧 */
.toolbar { margin-bottom: 8px; }
.toolbar input { font-size: 16px; min-height: 44px; }
.filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 8px; }
@media (min-width: 760px) { .filters { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.bar { display: flex; align-items: center; gap: 8px; margin: 8px 0 12px; }
.chips { margin-bottom: 4px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--accent-2); border-radius: 999px; padding: 2px 4px 2px 12px; font-size: .9rem; }
.chip .x { border: 0; background: none; font-size: 1.1rem; cursor: pointer; color: var(--muted); padding: 0 6px; }
.grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.card { display: flex; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; color: inherit; text-decoration: none; min-width: 0; }
.card:hover { border-color: var(--accent-2); }
.card .thumb { flex: 0 0 104px; height: 64px; border-radius: 6px; overflow: hidden; background: var(--bg); display: flex; align-items: center; justify-content: center; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.noimg { font-size: .75rem; color: var(--muted); }
.card .info { min-width: 0; flex: 1; }
.card .co { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .nm { font-weight: 700; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tablewrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.tbl { border-collapse: collapse; width: 100%; font-size: .9rem; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.tbl th { background: var(--bg); font-weight: 600; position: sticky; top: 0; }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover { background: var(--bg); }

/* 追加 */
.addbtns { display: grid; gap: 10px; grid-template-columns: 1fr; margin: 12px 0; }
@media (min-width: 640px) { .addbtns { grid-template-columns: repeat(3, 1fr); } }
.uplist { display: grid; gap: 8px; margin-top: 12px; }
.uprow { display: flex; gap: 10px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; }
.uprow img { width: 72px; height: 46px; object-fit: cover; border-radius: 4px; background: var(--bg); }
.uprow .fn { font-size: .8rem; color: var(--muted); word-break: break-all; }
.uprow.ok .st { color: var(--ok); }
.uprow.bad .st { color: var(--bad); }

/* 1件 */
.edithead { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.edithead h2 { margin: 4px 0; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.editgrid { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .editgrid { grid-template-columns: 420px 1fr; } }
.imgs { display: grid; gap: 8px; }
.imgs .big { display: block; position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: var(--panel); }
.imgs .big img { display: block; width: 100%; height: auto; }
.imgs .big span { position: absolute; left: 8px; top: 8px; background: rgba(0,0,0,.6); color: #fff; font-size: .75rem; padding: 1px 8px; border-radius: 999px; }
.addimg { width: 100%; border-style: dashed; }
.raw { margin-top: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; }
.raw pre { white-space: pre-wrap; word-break: break-word; font-size: .85rem; max-height: 300px; overflow: auto; }
.edit { display: grid; gap: 10px; grid-template-columns: 1fr; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
@media (min-width: 560px) { .edit { grid-template-columns: repeat(2, minmax(0, 1fr)); } .fld-address, .fld-memo, .fld-tags, .fld-url, .actions { grid-column: 1 / -1; } }
.fld { display: grid; gap: 2px; min-width: 0; }
.fld > span { font-size: .8rem; color: var(--muted); }
.fld input, .fld textarea { font-size: 16px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 4px; }
.dups { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; margin-top: 12px; }
.duprow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 6px 0; border-top: 1px solid var(--line); }

/* 会社・重複 */
.colist { display: grid; gap: 6px; }
.corow { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; color: inherit; text-decoration: none; }
.corow:hover { border-color: var(--accent-2); }
.corow .count { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.dupgroup { margin-bottom: 16px; }

/* ログイン */
body.login { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
.login-box { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; display: grid; gap: 14px; }
.login-box h1 { margin: 0; font-size: 1.4rem; color: var(--accent); }
.login-box .dev { display: grid; gap: 10px; border-top: 1px dashed var(--line); padding-top: 14px; }
.login-box label { display: grid; gap: 2px; font-size: .85rem; color: var(--muted); }
.login-box p { margin: 0; }
.apps { border-top: 1px solid var(--line); padding-top: 14px; display: grid; gap: 8px; }
.apps h2 { font-size: 1rem; margin: 0; }
.app-how { background: var(--bg); border-radius: 8px; padding: 8px 12px; font-size: .9rem; }
.app-how ol { margin: 4px 0 0; padding-left: 1.3em; }
.app-how li { margin: 2px 0; }
.app-how p { margin-top: 8px; }
