:root {
  --bg: #f4f6f8; --panel: #fff; --ink: #1b2430; --muted: #6b7785;
  --line: #d7dee6; --accent: #0a6ebd; --accent-ink: #fff;
  --danger: #c0392b; --ok: #1f7a4d; --warn: #9a6b00; --warn-bg: #fff6e0;
  --radius: 8px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 14px; line-height: 1.6;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ===== ヘッダー / タスクバー ===== */
.topbar { background: #16324f; color: #fff; padding: 0 16px; display: flex; align-items: center; gap: 16px; min-height: 52px; flex-wrap: wrap; }
.topbar h1 { font-size: 17px; margin: 0; font-weight: 600; letter-spacing: .02em; }
.tabs { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.tab { background: rgba(255,255,255,.1); color: #fff; border: 1px solid rgba(255,255,255,.2); padding: 6px 14px; border-radius: 999px; cursor: pointer; }
.tab.active { background: #fff; color: #16324f; font-weight: 600; }
.topbar .who { font-size: 13px; opacity: .9; }
.navbar { background: #1f4a73; display: flex; gap: 2px; padding: 0 16px; flex-wrap: wrap; }
.navbar button { background: none; border: none; color: #d6e6f5; padding: 10px 16px; cursor: pointer; border-bottom: 3px solid transparent; }
.navbar button.active { color: #fff; font-weight: 600; border-bottom-color: #7ec8ff; }
.navbar button:hover { color: #fff; }

.wrap { max-width: 1080px; margin: 20px auto 60px; padding: 0 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.card h2 { margin: 0 0 4px; font-size: 16px; }
.card h3 { margin: 18px 0 8px; font-size: 14px; color: var(--muted); }
.hint { color: var(--muted); font-size: 12.5px; margin: 0 0 12px; }

/* ===== フォーム ===== */
.grid { display: grid; gap: 12px 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid #9ecbf0; border-color: var(--accent); }
.inline { display: flex; gap: 8px; align-items: center; }
.inline .field { flex: 1; }
.inline > input { flex: 1 1 0; min-width: 0; }
.radios { display: flex; gap: 14px; padding-top: 6px; }
.radios label { display: inline-flex; gap: 5px; align-items: center; font-size: 14px; color: var(--ink); font-weight: 400; white-space: nowrap; }

.btn { background: var(--accent); color: var(--accent-ink); border: none; padding: 9px 18px; border-radius: 6px; cursor: pointer; font-weight: 600; }
.btn:hover { filter: brightness(1.08); }
.btn.sec { background: #e9eef3; color: #27384a; }
.btn.danger { background: var(--danger); }
.btn.ghost { background: none; border: 1px solid var(--line); color: var(--ink); font-weight: 400; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; font-weight: 500; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.actions.right { justify-content: flex-end; }

/* ===== テーブル ===== */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th, .tbl td { border-bottom: 1px solid var(--line); padding: 7px 8px; text-align: left; vertical-align: middle; }
.tbl th { background: #eef3f7; font-size: 12.5px; color: #44586b; white-space: nowrap; }
.tbl tr:hover td { background: #f8fbfe; }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl .nowrap { white-space: nowrap; }
.scroll { overflow: auto; max-height: 520px; border: 1px solid var(--line); border-radius: 6px; }

.badge { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: #e9eef3; color: #44586b; white-space: nowrap; }
.badge.done { background: #e3f3ea; color: var(--ok); }
.badge.todo { background: #fdeee9; color: #b4512f; }
.badge.cat { background: #eaf2fb; color: #17588f; }

.msg { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; font-size: 13.5px; }
.msg.err { background: #fdecea; color: #a0261a; border: 1px solid #f3c2bc; }
.msg.ok { background: #e8f6ee; color: #1b6b45; border: 1px solid #b9e2cb; }
.msg.warn { background: var(--warn-bg); color: var(--warn); border: 1px solid #f0d79a; }
.empty { text-align: center; color: var(--muted); padding: 32px 0; }

/* ===== ログイン ===== */
.login { max-width: 420px; margin: 8vh auto; }
.login .card { padding: 28px; }
.login h2 { font-size: 20px; margin-bottom: 18px; }

/* ===== 医薬品オートコンプリート ===== */
.drug-row { display: grid; grid-template-columns: minmax(0,1fr) 96px 140px auto; gap: 10px; align-items: start; margin-bottom: 10px; }
.drug-row > input, .ac > input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.ac { position: relative; min-width: 0; }
.ac-list { position: absolute; z-index: 30; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 0 0 6px 6px; max-height: 280px; overflow: auto; box-shadow: 0 8px 20px rgba(0,0,0,.12); }
.ac-item { padding: 7px 10px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.ac-item:hover, .ac-item.sel { background: #eaf3fb; }
.ac-item .nm { flex: 1; }
.ac-item .mt { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.ac-empty { padding: 10px; color: var(--muted); font-size: 13px; }
.unit-hint { font-size: 12px; color: var(--muted); padding-top: 9px; white-space: nowrap; }

.calc-note { font-size: 12.5px; color: var(--muted); margin: 2px 0 0 2px; }
.calc-warn { font-size: 12.5px; color: var(--warn); margin: 2px 0 0 2px; }

/* ===== 処方箋プレビュー ===== */
.preview-wrap { background: #5a6673; padding: 18px; border-radius: var(--radius); overflow: auto; }
.preview-wrap .rx-page { box-shadow: 0 4px 16px rgba(0,0,0,.3); }
#print-root { display: none; }

.split { display: grid; grid-template-columns: minmax(0,1fr) 556px; gap: 18px; align-items: start; }
@media (max-width: 1100px) { .split { grid-template-columns: minmax(0,1fr); } .g3, .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }

.mode-chip { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: rgba(255,255,255,.15); }
.ta-paste { width: 100%; min-height: 160px; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
