:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --border: #dfe3ea;
    --text: #1d2430;
    --muted: #6b7688;
    --primary: #2563c9;
    --primary-dark: #1c4da3;
    --alert: #c0392b;
    --alert-bg: #fdf1ef;
    --in: #1f8a53;
    --out: #c0662b;
    --adj: #5b6b8c;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.6;
}

a { color: var(--primary); }
[hidden] { display: none !important; }

/* ------------------------------ ヘッダー ------------------------------ */

.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 20px;
    background: #1f2a3d;
    color: #fff;
    flex-wrap: wrap;
}

.topbar .brand { font-weight: 700; font-size: 16px; padding: 14px 0; letter-spacing: .04em; }

.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }

.topbar nav a {
    color: #c9d3e3;
    text-decoration: none;
    padding: 14px 14px;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
}

.topbar nav a:hover { color: #fff; background: rgba(255,255,255,.06); }
.topbar nav a.active { color: #fff; border-bottom-color: #6ea8ff; }

.topbar .badge {
    display: inline-block;
    margin-left: 6px;
    background: var(--alert);
    color: #fff;
    border-radius: 10px;
    padding: 0 7px;
    font-size: 11px;
    font-weight: 700;
}

.topbar .user { display: flex; align-items: center; gap: 12px; color: #9fb0c9; font-size: 13px; }
.topbar .logout { color: #9fb0c9; text-decoration: none; }
.topbar .logout:hover { color: #fff; text-decoration: underline; }

main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 60px; }

.page-title { font-size: 20px; margin: 4px 0 16px; }
.sub-title { font-size: 15px; margin: 32px 0 10px; color: var(--muted); }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 16px; }

/* ------------------------------ メッセージ ------------------------------ */

.msg { padding: 11px 14px; border-radius: var(--radius); margin: 0 0 14px; border: 1px solid transparent; }
.msg.success { background: #eaf7ef; border-color: #b7e2c8; color: #17683d; }
.msg.error   { background: var(--alert-bg); border-color: #f0c0b8; color: #a3271a; }
.msg.warn    { background: #fff7e6; border-color: #f0dcae; color: #8a6100; }

/* ------------------------------ カード類 ------------------------------ */

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat-label { color: var(--muted); font-size: 12px; }
.stat-value { font-size: 24px; font-weight: 700; letter-spacing: .02em; }
.stat-unit { color: var(--muted); font-size: 12px; }
.stat.is-alert { border-color: #f0c0b8; background: var(--alert-bg); }
.stat.is-alert .stat-value { color: var(--alert); }
.stat.triple .stat-value { font-size: 19px; white-space: nowrap; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 18px;
}

/* ------------------------------ ツールバー ------------------------------ */

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.search { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search input[type="search"] { width: 320px; max-width: 100%; }
.check { display: flex; align-items: center; gap: 5px; color: var(--muted); white-space: nowrap; }
.result-count { color: var(--muted); margin: 0; }

/* ------------------------------ フォーム ------------------------------ */

label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 13px; }

input[type="text"], input[type="search"], input[type="number"], input[type="date"],
input[type="password"], select {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
    color: var(--text);
    background: #fff;
    margin-top: 4px;
}

input:focus, select:focus { outline: 2px solid #b7cdf2; border-color: var(--primary); }
input:disabled { background: #f2f4f7; color: var(--muted); }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 16px; }
.grid4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 16px; }

.req { color: var(--alert); font-size: 11px; }
.hint { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
.form-title { font-size: 16px; margin: 0 0 16px; }
.form-actions { display: flex; gap: 8px; margin-top: 8px; }
.filter-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filter-actions input[type="search"] { flex: 1; min-width: 220px; }
.mt { margin-top: 16px; }

/* 入出庫の種別選択 */
.type-select { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }

.type-option {
    flex: 1;
    min-width: 110px;
    margin: 0;
    text-align: center;
    padding: 12px 8px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    color: var(--muted);
    background: #fafbfd;
}

.type-option input { display: none; }
.type-option.selected { color: #fff; }
.type-option.type-in.selected  { background: var(--in);  border-color: var(--in); }
.type-option.type-out.selected { background: var(--out); border-color: var(--out); }
.type-option.type-adj.selected { background: var(--adj); border-color: var(--adj); }

.entry-form input[name="qty"] { font-size: 20px; font-weight: 700; padding: 12px; }

/* ------------------------------ ボタン ------------------------------ */

.btn {
    display: inline-block;
    padding: 9px 16px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    border-radius: 8px;
    font: inherit;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}

.btn:hover { background: #f0f3f8; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { background: #e9edf4; }
.btn.danger { color: var(--alert); border-color: #f0c0b8; }
.btn.danger:hover { background: var(--alert-bg); }
.btn.mini { padding: 4px 9px; font-size: 12px; }
.btn.wide { width: 100%; padding: 12px; font-size: 15px; }

/* ------------------------------ テーブル ------------------------------ */

.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { background: #eef1f6; color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #f7f9fc; }

.table .num { text-align: right; white-space: nowrap; }
.table .code { white-space: nowrap; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.table .strong { font-weight: 700; }
.table .unit { color: var(--muted); font-weight: 400; font-size: 12px; }
.table .muted { color: var(--muted); }
.table .small { font-size: 12px; }
.table .nowrap { white-space: nowrap; }
.table .plus { color: var(--in); font-weight: 600; }
.table .minus { color: var(--out); font-weight: 600; }
.table .actions { white-space: nowrap; display: flex; gap: 4px; align-items: center; }
.table .empty { text-align: center; color: var(--muted); padding: 28px; }
.table .row-alert { background: var(--alert-bg); }
.table .row-alert:hover { background: #fbe7e3; }
.table .row-off td { opacity: .55; }
.inline { display: inline; margin: 0; }

/* 列が多い表は横スクロールさせ、折り返しで行が崩れないようにする */
.table-scroll { overflow-x: auto; border-radius: var(--radius); }
.wide-table { min-width: 1080px; }

.tag { display: inline-block; white-space: nowrap; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.tag.alert { background: var(--alert); color: #fff; margin-left: 6px; }
.tag.t-in  { background: #e4f4ea; color: var(--in); }
.tag.t-out { background: #fdeee2; color: var(--out); }
.tag.t-adj { background: #eaedf4; color: var(--adj); }

.ok { color: var(--in); }
.alert { color: var(--alert); }

/* ------------------------ ログイン・セットアップ ------------------------ */

.plain-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login { width: 340px; max-width: 100%; }
.login h1 { font-size: 18px; margin: 0 0 18px; text-align: center; }
.setup { width: 560px; max-width: 100%; }
.setup h1 { font-size: 18px; margin: 0 0 16px; }

@media (max-width: 720px) {
    .topbar { gap: 8px; }
    .topbar nav a { padding: 10px 10px; font-size: 13px; }
    .table { display: block; overflow-x: auto; white-space: nowrap; }
    .search input[type="search"] { width: 100%; }
}

/* ---------------------- まとめて登録まわり ---------------------- */

.quick-bar {
    display: flex;
    gap: 14px;
    align-items: flex-end;
    flex-wrap: wrap;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 10px;
}

.quick-bar label { margin-bottom: 0; flex: 1; min-width: 150px; }
.quick-bar .quick-submit { flex: 0 0 auto; }
.lines-hint { color: var(--muted); font-size: 12px; margin: 0 0 12px; }

.row-qty { width: 110px; text-align: right; margin-top: 0; }
.table tr.row-filled { background: #eaf2fd; }
.table tr.row-filled:hover { background: #dfeafb; }

.entry-lines th { font-size: 11px; }
.entry-lines td { padding: 6px 12px; }
.entry-lines .line-code { margin-top: 0; }
.entry-lines .line-qty { margin-top: 0; text-align: right; font-weight: 700; }
.entry-lines .line-name { font-size: 13px; }

.check-block {
    display: block;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 10px;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
}

.check-block:hover { background: #f7f9fc; }
