:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --text: #1d2330;
    --muted: #6b7280;
    --border: #d9dde3;
    --accent: #1f5fbf;
    --accent-text: #ffffff;
    --debit: #eef4ff;
    --credit: #fff4ec;
    --ok: #13795b;
    --error: #b42318;
    --sidebar: #1d2330;
    --sidebar-text: #cfd5df;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
    font-size: 14px;
}

a { color: var(--accent); }

.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 200px;
    flex-shrink: 0;
    background: var(--sidebar);
    color: var(--sidebar-text);
    padding: 16px 0;
}
.sidebar .brand { font-weight: 700; font-size: 18px; color: #fff; padding: 0 20px 12px; }
.sidebar .nav-group { font-size: 11px; color: #8a93a3; padding: 16px 20px 4px; }
.sidebar a { display: block; padding: 7px 20px; color: var(--sidebar-text); text-decoration: none; }
.sidebar a:hover { background: #2a3242; }
.sidebar a.active { background: var(--accent); color: #fff; }

.content { flex: 1; padding: 24px 32px; min-width: 0; overflow-x: auto; }

h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }

.muted { color: var(--muted); }
.ok { color: var(--ok); font-weight: 600; }
.error { color: var(--error); font-weight: 600; }
.errors { color: var(--error); background: #fef3f2; border: 1px solid #fecdca; border-radius: 6px; padding: 10px 28px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 20px; }

.form-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 16px; }
.form-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form-row label.grow { flex: 1; min-width: 240px; }
.form-row label.check { flex-direction: row; align-items: center; color: var(--text); font-size: 14px; }

input, select {
    font: inherit;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #fff;
    color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button, .button {
    font: inherit;
    padding: 7px 14px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}
button.primary, .button { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--error); border-color: #fecdca; }
button.link { border: none; background: none; color: var(--accent); padding: 2px 6px; }
button:disabled { opacity: .5; cursor: default; }

.actions { display: flex; gap: 8px; margin: 16px 0; }
.spacer { flex: 1; }

table.grid { border-collapse: collapse; width: 100%; background: var(--surface); }
table.grid th, table.grid td { border: 1px solid var(--border); padding: 5px 8px; vertical-align: middle; }
table.grid th { background: #eef0f3; font-weight: 600; text-align: left; white-space: nowrap; }
table.grid tfoot td { background: #f3f4f6; font-weight: 600; }
table.grid tbody.entry:nth-of-type(even) td { background: #fafbfc; }
table.grid tr.group-head td { background: #e8ecf2; font-weight: 700; }
table.grid tr.subtotal td { font-weight: 600; background: #f7f8fa; }
table.grid tr.subtle td { color: var(--muted); }
table.grid tr.inactive td { color: var(--muted); }

.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }

.journal-input th.debit-head { background: var(--debit); text-align: center; }
.journal-input th.credit-head { background: var(--credit); text-align: center; }
.journal-input td { padding: 3px; }
.journal-input select, .journal-input input { width: 100%; }
.journal-input select { min-width: 110px; }
.journal-input input.num { min-width: 100px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.tile {
    display: flex; flex-direction: column; gap: 6px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    padding: 16px; text-decoration: none; color: var(--text);
}
.tile:hover { border-color: var(--accent); }
.tile span { color: var(--muted); font-size: 12px; }

.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
button.small { padding: 3px 10px; font-size: 12px; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.panel.narrow { max-width: 420px; }

fieldset.plain { border: none; padding: 0; margin: 0; min-width: 0; }
fieldset.plain:disabled input, fieldset.plain:disabled select { background: #f3f4f6; color: var(--text); }

.notice { background: #eef4ff; border: 1px solid #c7d7f5; border-radius: 6px; padding: 8px 12px; }
.notice.warn { background: #fffaeb; border-color: #fedf89; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; vertical-align: middle; white-space: nowrap; }
.status-draft { background: #f2f4f7; color: #475467; }
.status-pendingapproval { background: #fffaeb; color: #b54708; }
.status-posted { background: #ecfdf3; color: var(--ok); }
.status-rejected { background: #fef3f2; color: var(--error); }

.entry-meta { display: flex; flex-wrap: wrap; gap: 16px; color: var(--muted); font-size: 12px; margin: -8px 0 12px; }
.approve-panel { border-color: #fedf89; }

details pre { white-space: pre-wrap; font-size: 12px; background: #f7f8fa; padding: 8px; border-radius: 4px; max-height: 320px; overflow: auto; }

.user-box { margin: 24px 12px 0; padding: 12px 8px 0; border-top: 1px solid #2f3747; }
.user-box .user-name { color: #fff; font-weight: 600; padding: 0 8px; }
.user-box .user-role { font-size: 12px; color: #8a93a3; padding: 0 8px 6px; }
.user-box a { padding: 5px 8px; font-size: 13px; }
.user-box button.logout { color: var(--sidebar-text); padding: 5px 8px; font-size: 13px; }

.account-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.account-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 28px; }
.account-brand { font-weight: 700; font-size: 18px; color: var(--accent); margin-bottom: 12px; }
.account-card .errors { padding: 10px 12px; }

.badge.opening { background: #f4ebff; color: #6941c6; margin-left: 4px; }

input.short { width: 72px; }
.warn-text { color: #b54708; }
.inline-inputs { display: flex; align-items: center; gap: 4px; color: var(--text); font-size: 14px; }

/* 決算書のプレビュー（A4 の紙面に近い見た目） */
.report-preview { display: flex; flex-direction: column; gap: 20px; align-items: center; }
.report-page { background: #fff; border: 1px solid var(--border); box-shadow: 0 1px 4px rgba(0,0,0,.08); width: 100%; max-width: 820px; padding: 32px 40px; font-family: "Yu Mincho", "游明朝", serif; }
.report-page.cover { text-align: center; padding: 80px 40px; }
.cover-period { font-size: 20px; }
.cover-title { font-size: 32px; font-weight: 700; margin: 12px 0 20px; letter-spacing: .1em; }
.cover-company { font-size: 22px; font-weight: 700; margin: 80px 0 10px; }
.report-header { margin-bottom: 10px; }
.report-title { text-align: center; font-size: 20px; font-weight: 700; letter-spacing: .1em; }
.report-period { text-align: center; margin: 4px 0 10px; }
.report-meta { display: flex; justify-content: space-between; font-size: 13px; }
.report-table { font-size: 13px; }
.report-table td:first-child { width: 55%; }
.report-table tr.report-heading td, .report-table tr.report-total td { font-weight: 700; }
.report-table tr.report-total td { background: #eee; }
.report-table tr.report-note td { font-size: 11px; color: var(--muted); }
.bs-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.bs-columns .report-table { font-size: 12px; }
.bs-head { text-align: center; background: #eee; border: 1px solid var(--border); padding: 4px; font-weight: 600; }
.notes-editor { width: 100%; font: inherit; font-family: "Yu Mincho", "游明朝", serif; font-size: 14px; line-height: 1.7; padding: 10px; border: 1px solid var(--border); border-radius: 4px; }
.notes-view { white-space: pre-wrap; font-family: inherit; font-size: 14px; line-height: 1.7; }
@media (max-width: 720px) { .bs-columns { grid-template-columns: 1fr; } .report-page { padding: 20px 16px; } }
.statement h3 { font-size: 14px; margin: 16px 0 6px; }
.return-table { width: auto; min-width: 640px; }
.return-table th { width: 360px; font-weight: 400; background: #fafbfc; white-space: normal; }
.return-table td.num { width: 140px; }
.return-table tr.line-total th, .return-table tr.line-total td { font-weight: 700; background: #e8ecf2; }
.total-box { display: inline-flex; gap: 16px; align-items: baseline; border: 2px solid var(--accent); border-radius: 8px; padding: 10px 16px; margin: 8px 0; }
.total-box strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.total-box.refund { border-color: var(--ok); }
.adjust-table input.num { width: 120px; }
.danger-text { color: var(--error) !important; }
.partner { display: inline-block; font-size: 12px; background: #f2f4f7; border-radius: 4px; padding: 0 6px; margin-right: 4px; }
.import-table select { max-width: 170px; }
.import-table tr.rule-editor td { background: #f7f9ff; }
.tax-kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-top: 16px; }
.tax-kpis .panel { margin: 0; }
.tax-kpis strong { font-size: 20px; font-variant-numeric: tabular-nums; }

/* 決算書 */
.statement { max-width: 960px; }
.statement-head { margin-bottom: 8px; }
.statement-head h2 { font-size: 18px; margin-bottom: 4px; }
.statement-table td:first-child { min-width: 260px; }
.statement-table tr.line-heading td { font-weight: 700; background: #f7f8fa; }
.statement-table tr.line-subtotal td { font-weight: 600; border-top: 1px solid #b8bfca; }
.statement-table tr.line-total td { font-weight: 700; background: #e8ecf2; }
.statement-table tr.line-note td { color: var(--muted); font-size: 12px; }
table.kv { width: auto; min-width: 420px; margin-bottom: 12px; }
.statement.wide { max-width: none; overflow-x: auto; }
.statement-table.wide { width: auto; font-size: 13px; }
.statement-table.wide td:first-child, .statement-table.wide th:first-child { position: sticky; left: 0; z-index: 1; min-width: 220px; }
.statement-table.wide th:first-child { background: #eef0f3; }
/* 固定した列は下の列が透けないよう、行の種類ごとに背景を付ける */
.statement-table.wide td:first-child { background: var(--surface); box-shadow: 1px 0 0 var(--border); }
.statement-table.wide tr.line-heading td:first-child { background: #f7f8fa; }
.statement-table.wide tr.line-total td:first-child { background: #e8ecf2; }
.statement-table.wide td.num, .statement-table.wide th.num { min-width: 92px; }
.statement-table.wide th.num:last-child, .statement-table.wide td.num:last-child { font-weight: 600; }
table.kv th { width: 220px; }
table.kv tr.line-total th, table.kv tr.line-total td { font-weight: 700; background: #e8ecf2; }

@media print {
    .sidebar, .no-print, #blazor-error-ui { display: none !important; }
    body { background: #fff; }
    .content { padding: 0; }
    a { color: inherit; text-decoration: none; }
    .notice { border: 1px solid #999; }
}

#blazor-error-ui {
    display: none;
    position: fixed; bottom: 0; left: 0; right: 0;
    background: #fef3c7; padding: 10px 20px; box-shadow: 0 -1px 4px rgba(0,0,0,.2);
}
#blazor-error-ui .reload { margin-left: 12px; }

@media (max-width: 720px) {
    .shell { flex-direction: column; }
    .sidebar { width: auto; }
    .content { padding: 16px; }
}
