:root {
    --bg: #f4f6f9;
    --panel: #fff;
    --ink: #1c2733;
    --sub: #5d6b7a;
    --line: #dde3ea;
    --main: #0b4c93;
    --main-soft: #e7eff9;
    --ok: #1e7a4a;
    --ok-soft: #e3f3ea;
    --warn: #a86400;
    --warn-soft: #fdf1dc;
    --ng: #b3261e;
    --ng-soft: #fbe6e4;
    --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: "Noto Sans JP", system-ui, sans-serif; font-size: 15px; line-height: 1.7; }
a { color: var(--main); }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 28px 0 10px; }
h3 { font-size: 15px; margin: 18px 0 6px; }
p { margin: 0 0 10px; }
.muted { color: var(--sub); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* ヘッダー */
.topbar { background: #04213f; color: #fff; position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 20px; min-height: 56px; flex-wrap: wrap; }
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 15px; white-space: nowrap; }
.brand span { font-weight: 400; opacity: .7; margin-left: 8px; font-size: 13px; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a { color: #cfdcec; text-decoration: none; padding: 6px 10px; border-radius: 6px; font-size: 14px; white-space: nowrap; }
.nav a.on, .nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.me { display: flex; gap: 10px; align-items: center; font-size: 13px; color: #cfdcec; }
.me .link { color: #fff; }

.main { max-width: 1180px; margin: 0 auto; padding: 24px 16px 60px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.head-row h1 { margin: 0; }

/* ボタン・入力 */
button, .btn { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--main); background: var(--main); color: #fff; padding: 8px 16px; font-weight: 500; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:disabled { opacity: .5; cursor: default; }
.btn-sub { background: #fff; color: var(--main); }
.btn-ng { background: var(--ng); border-color: var(--ng); }
.btn-ok { background: var(--ok); border-color: var(--ok); }
button.link { background: none; border: 0; padding: 0; color: var(--main); text-decoration: underline; font-weight: 400; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

label { display: block; font-weight: 500; font-size: 14px; margin-bottom: 4px; }
.req::after { content: "必須"; font-size: 11px; background: var(--ng); color: #fff; border-radius: 4px; padding: 1px 6px; margin-left: 6px; vertical-align: 1px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=date], input[type=search], select, textarea {
    font: inherit; width: 100%; padding: 9px 11px; border: 1px solid #c3ccd6; border-radius: 8px; background: #fff; color: var(--ink);
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc1ea; border-color: var(--main); }
.field { margin-bottom: 16px; }
.field .hint { font-size: 12px; color: var(--sub); margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 20px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
.check input { margin-top: 5px; }
.error { background: var(--ng-soft); color: var(--ng); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; white-space: pre-line; font-size: 14px; }

/* 表 */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
thead th { background: #f0f3f7; font-size: 12px; color: var(--sub); font-weight: 500; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: #f7fafd; }
.kv th { width: 180px; background: #f7f9fb; font-weight: 500; font-size: 13px; color: var(--sub); }
.kv td { word-break: break-all; }

/* 状態バッジ */
.badge { display: inline-block; font-size: 12px; padding: 1px 9px; border-radius: 99px; white-space: nowrap; font-weight: 500; }
.st-pending { background: var(--warn-soft); color: var(--warn); }
.st-approved { background: var(--main-soft); color: var(--main); }
.st-running { background: var(--ok-soft); color: var(--ok); }
.st-ended, .st-cancelled { background: #eceff3; color: var(--sub); }
.st-rejected { background: var(--ng-soft); color: var(--ng); }

/* キーワードの枠 */
.slot { display: inline-flex; gap: 4px; vertical-align: middle; }
.slot i { width: 14px; height: 14px; border-radius: 3px; background: #dfe5ec; display: inline-block; }
.slot i.used { background: var(--main); }
.slot.full i.used { background: var(--ng); }
.kw-result { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 14px 16px; border-radius: 8px; background: var(--main-soft); margin-top: 12px; }
.kw-result.full { background: var(--ng-soft); }
.kw-result .big { font-size: 20px; font-weight: 700; }
.kw-inline { margin-top: 6px; font-size: 13px; display: flex; gap: 8px; align-items: center; }
.kw-inline.full { color: var(--ng); font-weight: 500; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input, .filters select { width: auto; min-width: 160px; }

/* ルール本文 */
.rules h2 { border-left: 4px solid var(--main); padding-left: 10px; font-size: 16px; }
.rules h2:first-child { margin-top: 0; }
.rules ul { padding-left: 1.3em; margin: 0 0 10px; }

.summary-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card .n { font-size: 24px; font-weight: 700; }
.card .l { font-size: 12px; color: var(--sub); }

.copy-row { display: flex; gap: 8px; }
.copy-row input { font-size: 12px; font-family: ui-monospace, monospace; }

.log { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.log li { padding: 6px 0; border-bottom: 1px dashed var(--line); }
.log time { color: var(--sub); margin-right: 8px; }

/* ログイン */
.login { max-width: 380px; margin: 10vh auto 0; }
.login h1 { text-align: center; font-size: 19px; }
.login h1 span { display: block; font-size: 13px; color: var(--sub); font-weight: 400; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1c2733; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 14px; z-index: 50; max-width: calc(100% - 32px); }

/* 発注書（印刷） */
.sheet { background: #fff; border: 1px solid var(--line); padding: 40px; max-width: 800px; margin: 0 auto; }
.sheet h1 { text-align: center; font-size: 24px; letter-spacing: .3em; margin-bottom: 24px; }
.sheet .meta { display: flex; justify-content: space-between; margin-bottom: 20px; font-size: 14px; }
.sheet table { border: 1px solid #555; }
.sheet th, .sheet td { border: 1px solid #555; }
.sheet .kv th { color: var(--ink); }
.sheet .sign { margin-top: 30px; font-size: 13px; }

@media (max-width: 760px) {
    .grid2, .grid3 { grid-template-columns: 1fr; }
    .summary-cards { grid-template-columns: 1fr 1fr; }
    .kv th { width: 110px; }
    .sheet { padding: 20px; }
    .me span { display: none; }
}

@media print {
    body { background: #fff; }
    .topbar, .no-print, .toast { display: none !important; }
    .main { padding: 0; max-width: none; }
    .sheet { border: 0; padding: 0; max-width: none; }
}

/* 表示の調整 */
button, .btn { white-space: nowrap; flex-shrink: 0; }
.copy-row { align-items: center; }
.panel > h2:first-child, .panel > .error[hidden] + h2 { margin-top: 0; }
.table-wrap { margin-bottom: 16px; }
.kw-result { margin-bottom: 12px; }
.filters input[type=search] { min-width: 260px; }
table.orders td { white-space: nowrap; }
@media (max-width: 760px) {
    .topbar-inner { gap: 0 12px; padding: 8px 16px 0; }
    .brand { flex: 1; }
    .nav { order: 3; flex: 0 0 100%; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; }
    .filters input[type=search] { min-width: 0; flex: 1 1 100%; }
    .copy-row { flex-wrap: wrap; }
    .copy-row input { flex: 1 1 100%; }
}
