:root {
  --bg: #f4f2ee;
  --card: #ffffff;
  --ink: #1f2a37;
  --sub: #6b7280;
  --line: #e2ded6;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --warn: #b45309;
  --danger: #b91c1c;
  --chip: #ece8e0;
  --radius: 10px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ヘッダー */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--ink); color: #fff;
}
.brand { font-weight: 700; letter-spacing: .02em; display: flex; align-items: baseline; gap: 8px; }
.brand small { font-weight: 400; opacity: .55; font-size: 11px; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a {
  color: #d7dde5; text-decoration: none; padding: 6px 12px; border-radius: 8px; font-size: 14px;
}
.nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.nav a.primary { background: var(--accent); color: #fff; font-weight: 600; }
.me { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #cbd5e1; }
.link { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; padding: 0; }

main { max-width: 1080px; margin: 0 auto; padding: 16px; padding-bottom: 120px; }

/* 共通部品 */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 15px; margin: 0 0 12px; }
h1.page { font-size: 20px; margin: 4px 0 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 180px; min-width: 0; }
label.f { display: block; font-size: 12px; color: var(--sub); margin-bottom: 10px; }
label.f > span { display: block; margin-bottom: 3px; }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=tel], input[type=email], input:not([type]), select, textarea {
  width: 100%; padding: 9px 10px; border: 1px solid #d4cfc5; border-radius: 8px; background: #fff; font-size: 16px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid #cfc9be; background: #fff; cursor: pointer; font-size: 14px; white-space: nowrap;
  text-decoration: none; color: var(--ink);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--danger); border-color: #f1c7c7; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.muted { color: var(--sub); font-size: 13px; }
.err { color: var(--danger); font-size: 14px; margin: 8px 0; }

/* チップ（種類・区分の選択） */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  border: 1px solid transparent; background: var(--chip); padding: 7px 13px; border-radius: 999px; cursor: pointer; font-size: 14px;
}
.chip.on { background: var(--ink); color: #fff; }
.chip.cat.on { background: var(--accent); }

/* 一覧 */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters input[type=search] { flex: 1 1 240px; padding: 9px 12px; border: 1px solid #d4cfc5; border-radius: 8px; font-size: 16px; }
.filters select { width: auto; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.li {
  display: grid; grid-template-columns: 92px 1fr auto; gap: 4px 12px; padding: 11px 14px; border-top: 1px solid var(--line);
  text-decoration: none; color: inherit; align-items: center;
}
.li:first-child { border-top: 0; }
.li:hover { background: #faf8f4; }
.li .d { font-size: 13px; color: var(--sub); }
.li .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .meta { grid-column: 2 / 3; font-size: 12px; color: var(--sub); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .amt { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.li .acts { grid-column: 3 / 4; text-align: right; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 4px; background: var(--chip); margin-right: 4px; }
.tag.t-estimate { background: #e0f2fe; } .tag.t-invoice { background: #fde68a; } .tag.t-delivery { background: #e9d5ff; }
.tag.t-receipt { background: #bbf7d0; } .tag.t-order { background: #fecaca; }
.tag.unpaid { background: #fee2e2; color: var(--danger); }
.empty { padding: 30px; text-align: center; color: var(--sub); }

/* 明細 */
.items { width: 100%; border-collapse: collapse; }
.items th { font-size: 12px; color: var(--sub); font-weight: 500; text-align: left; padding: 4px 4px 6px; }
.items td { padding: 3px; vertical-align: top; }
.items td input, .items td select { padding: 7px 8px; font-size: 15px; }
.items .c-name { width: auto; }
.items .c-price { width: 120px; } .items .c-qty { width: 76px; } .items .c-unit { width: 64px; }
.items .c-tax { width: 104px; } .items .c-amt { width: 110px; text-align: right; font-variant-numeric: tabular-nums; padding-top: 10px; }
.items .c-op { width: 72px; white-space: nowrap; }
.items input.num { text-align: right; }
.iconbtn { border: 0; background: none; cursor: pointer; padding: 6px; font-size: 15px; color: var(--sub); }
.iconbtn:hover { color: var(--ink); }
.hint { font-size: 12px; color: var(--accent); padding: 2px 4px 6px; cursor: pointer; }

.totals { display: grid; grid-template-columns: 1fr auto; gap: 4px 20px; max-width: 360px; margin-left: auto; font-variant-numeric: tabular-nums; }
.totals .k { color: var(--sub); }
.totals .v { text-align: right; }
.totals .big { font-size: 20px; font-weight: 700; color: var(--ink); }

/* 下に固定の操作バー */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  background: rgba(255,255,255,.96); border-top: 1px solid var(--line);
  padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom));
  display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;
}
.actionbar .sum { margin-right: auto; font-weight: 700; font-size: 18px; align-self: center; font-variant-numeric: tabular-nums; }

/* ログイン */
.auth { max-width: 380px; margin: 60px auto; }
.auth h1 { font-size: 22px; margin: 0 0 4px; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
.stamp-preview { width: 90px; height: 90px; border: 1px dashed #ccc; border-radius: 8px; display: flex; align-items: center; justify-content: center; background: #fff; }
.stamp-preview img { max-width: 100%; max-height: 100%; }
table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple th, table.simple td { padding: 8px 6px; border-top: 1px solid var(--line); text-align: left; }
table.simple th { font-size: 12px; color: var(--sub); font-weight: 500; border-top: 0; }

/* スマホ */
@media (max-width: 720px) {
  .top { gap: 8px; }
  .nav { order: 3; width: 100%; flex: 1 1 100%; }
  .me { order: 2; }
  .actionbar { flex-wrap: nowrap; gap: 6px; padding-left: 10px; padding-right: 10px; }
  .actionbar .sum { font-size: 15px; }
  .actionbar .btn { padding: 9px 10px; }
  .me { width: 100%; justify-content: space-between; }
  .li { grid-template-columns: 1fr auto; }
  .li .d { grid-column: 1 / 3; }
  .li .meta { grid-column: 1 / 2; }
  .li .acts { grid-column: 2 / 3; }
  .items thead { display: none; }
  .items, .items tbody, .items tr, .items td { display: block; width: 100%; }
  .items tr { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; padding: 10px 0; border-top: 1px solid var(--line); }
  .items td { padding: 0; width: auto !important; }
  .items td.c-name { grid-column: 1 / 4; }
  .items td.c-tax { grid-column: 1 / 3; }
  .items td.c-amt { text-align: right; padding-top: 8px; }
  .items td.c-op { grid-column: 1 / 4; text-align: right; }
  .items td::before { content: attr(data-l); display: block; font-size: 11px; color: var(--sub); }
  .items td.c-op::before, .items td.c-name::before { display: none; }
}
