/* 経費精算システム — スマホ優先の画面 */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #5f6b7a;
  --line: #dde2e8;
  --accent: #0f766e;        /* 在宅薬歴と同じティール */
  --accent-ink: #ffffff;
  --accent-soft: #e6f5f3;
  --ok: #1f7a4a;
  --ok-soft: #e4f4ea;
  --warn: #9a5b00;
  --warn-soft: #fff3db;
  --err: #b42318;
  --err-soft: #fde8e6;
  --info-soft: #e8f0fb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1b2029;
    --text: #e8ebf0;
    --muted: #9aa5b4;
    --line: #2d3440;
    --accent: #2dd4bf;      /* ダーク用の明るいティール */
    --accent-ink: #042f2e;  /* 明るいティールの上は濃い文字で読みやすく */
    --accent-soft: #12302d;
    --ok: #5fcf8f;
    --ok-soft: #173225;
    --warn: #f0b44c;
    --warn-soft: #3a2d12;
    --err: #ff7b6e;
    --err-soft: #3d1b18;
    --info-soft: #1b2a40;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 16px; line-height: 1.6;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.6rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* ヘッダー */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: .75rem; padding: .55rem 16px; padding-top: calc(.55rem + env(safe-area-inset-top));
}
.topbar .brand { font-weight: 700; color: var(--text); text-decoration: none; display: flex; gap: .45rem; align-items: center; }
.topbar .brand img { width: 26px; height: 26px; }
.topbar nav { margin-left: auto; display: flex; gap: .2rem; flex-wrap: wrap; justify-content: flex-end; }
.topbar nav a { color: var(--muted); text-decoration: none; font-size: .9rem; padding: .3rem .55rem; border-radius: 8px; }
.topbar nav a.on, .topbar nav a:hover { color: var(--text); background: var(--bg); }
.topbar .who { font-size: .8rem; color: var(--muted); }

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

/* 下のタブ（スマホ） */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(4, 1fr); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { text-align: center; padding: .45rem 0 .5rem; font-size: .72rem; color: var(--muted); text-decoration: none; position: relative; }
.tabbar a .ico { display: block; font-size: 1.35rem; line-height: 1.2; }
.tabbar a.on { color: var(--accent); font-weight: 600; }
.tabbar .badge { position: absolute; top: 2px; left: calc(50% + 6px); }
@media (min-width: 900px) {
  .tabbar { display: none; }
  body { padding-bottom: 24px; }
}
@media (max-width: 899px) {
  .topbar nav .main-link { display: none; }
}

/* 部品 */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 12px; }
.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; text-decoration: none; color: var(--text); }
.stat .v { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { font-size: .85rem; color: var(--muted); }
.stat.alert { border-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: .5rem 1rem;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--err); border-color: var(--err); }
.btn.big { min-height: 56px; font-size: 1.05rem; width: 100%; }
.btn.small { min-height: 34px; padding: .2rem .7rem; font-size: .85rem; font-weight: 500; }
.btn.link { border: none; background: none; color: var(--accent); padding: 0 .3rem; min-height: 0; font-weight: 500; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.badge { display: inline-block; min-width: 1.3em; padding: 0 .4em; border-radius: 999px; font-size: .72rem; font-weight: 700; text-align: center; background: var(--accent); color: var(--accent-ink); line-height: 1.5; }
.tag { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .75rem; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.tag.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tag.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag.err { background: var(--err-soft); color: var(--err); border-color: transparent; }
.tag.info { background: var(--info-soft); color: var(--text); border-color: transparent; }

.flash { padding: .7rem 1rem; border-radius: 10px; margin-bottom: 10px; white-space: pre-line; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--err-soft); color: var(--err); }
.notice { padding: .7rem 1rem; border-radius: 10px; background: var(--info-soft); margin-bottom: 12px; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }

/* フォーム */
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .2rem; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); width: 100%; min-height: 44px;
  border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem;
}
input[type=checkbox], input[type=radio] { width: 22px; flex: none; height: 22px; min-height: 0; accent-color: var(--accent); vertical-align: middle; }
textarea { min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.field { margin-bottom: 10px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px 10px; }
.check { display: flex; gap: .5rem; align-items: center; color: var(--text); font-size: .95rem; }

/* 表 */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: .8rem; background: var(--bg); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tr.deleted td { opacity: .55; text-decoration: line-through; }
td a { text-decoration: none; }

/* 撮影 */
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 10px; }
.mode-switch button { min-height: 44px; border: none; border-radius: 9px; background: none; font: inherit; color: var(--muted); font-weight: 600; cursor: pointer; }
.mode-switch button.on { background: var(--accent); color: var(--accent-ink); }
.camera { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 3 / 4; max-height: 70vh; margin: 0 auto; }
@media (min-width: 700px) { .camera { aspect-ratio: 4 / 3; } }
.camera video { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera .guide { position: absolute; left: 8px; right: 8px; top: 8px; color: #fff; background: rgba(0,0,0,.45); padding: .35rem .6rem; border-radius: 8px; font-size: .85rem; }
.camera .frame { position: absolute; inset: 12% 8%; border: 2px dashed rgba(255,255,255,.65); border-radius: 10px; pointer-events: none; }
.camera .flash-fx { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .25s; }
.camera .flash-fx.on { opacity: .7; transition: none; }
.camera-off { display: flex; align-items: center; justify-content: center; text-align: center; color: #ddd; padding: 2rem; height: 100%; }
.shutter-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 12px 0; }
.shutter { width: 76px; height: 76px; border-radius: 50%; border: 5px solid var(--line); background: var(--accent); cursor: pointer; flex: none; }
.shutter:active { transform: scale(.95); }
.queue { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.queue .item { position: relative; border-radius: 8px; overflow: hidden; background: var(--line); aspect-ratio: 3 / 4; }
.queue .item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.queue .item .ph { display: flex; align-items: center; justify-content: center; height: 100%; font-weight: 700; color: var(--muted); }
.queue .item .st { position: absolute; left: 0; right: 0; bottom: 0; font-size: .7rem; text-align: center; padding: 2px; background: rgba(0,0,0,.6); color: #fff; }
.queue .item .rm { position: absolute; top: 3px; right: 3px; width: 26px; height: 26px; border-radius: 50%; border: none; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; }

/* 確認画面の領収書カード */
.rcpt { display: grid; grid-template-columns: 110px 1fr; gap: 12px; }
@media (min-width: 700px) { .rcpt { grid-template-columns: 180px 1fr; } }
.rcpt .thumb { display: block; border-radius: 8px; overflow: hidden; background: var(--line); align-self: start; border: 1px solid var(--line); }
.rcpt .thumb img { width: 100%; display: block; }
.rcpt .thumb .noimg { aspect-ratio: 3/4; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: .8rem; text-align: center; padding: 6px; }
.rcpt .head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.rcpt .head .amt { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.rcpt .tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 8px; }
.rcpt.selected { outline: 2px solid var(--accent); }
.rcpt details summary { cursor: pointer; color: var(--accent); font-size: .9rem; margin: 6px 0; }
.submitbar {
  position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 10; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 14px; display: flex; gap: 10px; align-items: center; justify-content: space-between; box-shadow: 0 4px 16px rgba(0,0,0,.12);
}
@media (min-width: 900px) { .submitbar { bottom: 12px; } }
.submitbar .sum { font-weight: 700; font-variant-numeric: tabular-nums; }

.receipt-view img { max-width: 100%; border-radius: 8px; border: 1px solid var(--line); }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: .4rem 0; border-bottom: 1px dashed var(--line); font-size: .9rem; }
.spinner { display: inline-block; width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }

@media (max-width: 600px) { .hide-sm { display: none; } }

/* 文書の登録（ドラッグ＆ドロップ） */
.drop { display: block; border: 2px dashed var(--line); border-radius: var(--radius); padding: 40px 16px; text-align: center; cursor: pointer; color: var(--text); background: var(--bg); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
