:root { color-scheme: light; }
* { box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  margin: 0; background: #f5f6f8; color: #1c1e21; font-size: 14px;
}
a { color: #1d4ed8; }
h1 { font-size: 20px; margin: 0 0 12px; }
h2 { font-size: 16px; margin: 0 0 10px; }

/* ヘッダー */
.site-header { background: #12324a; color: #fff; }
.header-top { padding: 10px 20px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 16px; }
.book-switcher { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #cfe0ee; }
.book-switcher select { padding: 4px 8px; border-radius: 6px; border: none; font-size: 14px; }
.user-nav { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 13px; }
.user-nav a { color: #cfe0ee; text-decoration: none; }
.user-nav a:hover { color: #fff; }
.user-nav a.active { color: #fff; font-weight: 700; text-decoration: underline; text-underline-offset: 4px; }
.btn-logout { padding: 4px 10px; font-size: 12px; background: #2d4d66; color: #fff; border: none; border-radius: 6px; cursor: pointer; }
.book-nav { background: #1d4a6b; padding: 0 20px; display: flex; gap: 2px; flex-wrap: wrap; align-items: stretch; }
.book-nav .book-name { color: #ffd98a; font-weight: 700; padding: 9px 12px 9px 0; margin-right: 6px; border-right: 1px solid #3c6a8c; }
.book-nav a { color: #dbe7f1; text-decoration: none; padding: 9px 12px; font-size: 13px; }
.book-nav a:hover { background: #255a80; color: #fff; }
.book-nav a.active { background: #f5f6f8; color: #12324a; font-weight: 700; border-radius: 6px 6px 0 0; }
form.inline { display: inline; }

main { max-width: 1200px; margin: 20px auto; padding: 0 16px 48px; }
main.wide { max-width: none; }

/* 共通部品 */
.card { background: #fff; border-radius: 8px; padding: 18px 20px; box-shadow: 0 1px 3px rgba(0,0,0,.08); margin-bottom: 18px; }
.card-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-header h1, .card-header h2 { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn {
  display: inline-block; background: #2563eb; color: #fff; padding: 8px 16px;
  border: none; border-radius: 6px; font-size: 14px; cursor: pointer; text-decoration: none; line-height: 1.4;
}
.btn:hover { background: #1d4ed8; }
.btn-secondary { background: #6b7280; }
.btn-secondary:hover { background: #4b5563; }
.btn-outline { background: #fff; color: #1d4ed8; border: 1px solid #93b4f5; }
.btn-outline:hover { background: #eef3ff; }
.btn-danger { background: #dc2626; }
.btn-danger:hover { background: #b91c1c; }
.btn-small { padding: 4px 10px; font-size: 12px; }
.link-button { background: none; border: none; color: #b91c1c; cursor: pointer; padding: 0; font-size: 13px; text-decoration: underline; }
.muted { color: #6b7280; font-size: 13px; }
.help { color: #6b7280; font-size: 12px; margin-top: 4px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 9px; border-bottom: 1px solid #e5e7eb; vertical-align: middle; }
th { background: #f3f4f6; font-size: 12px; color: #374151; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.inactive td { color: #9ca3af; }
.table-scroll { overflow-x: auto; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-ok, .badge-receipt { background: #dbeafe; color: #1e40af; }
.badge-shipment { background: #fce7f3; color: #9d174d; }
.badge-adjustment { background: #ede9fe; color: #5b21b6; }
.badge-rename { background: #ffedd5; color: #9a3412; }
.badge-opening { background: #e5e7eb; color: #374151; }
.badge-admin { background: #d1fae5; color: #065f46; }
.num-minus { color: #b91c1c; font-weight: 700; }
.num-plus { color: #1e40af; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; background: #d1fae5; color: #065f46; }
.flash-alert { background: #fee2e2; color: #991b1b; }
.error { color: #b91c1c; }
.error-box { background: #fef2f2; border: 1px solid #fecaca; border-radius: 6px; padding: 10px 14px; color: #991b1b; margin-bottom: 12px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 4px; color: #374151; }
.field input[type=text], .field input[type=number], .field input[type=email], .field input[type=password],
.field input[type=date], .field input[type=month], .field input[type=file], .field select, .field textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px; background: #fff;
}
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 16px; }
.field .required::after { content: " *"; color: #dc2626; }
.checkbox-label { display: flex !important; align-items: center; gap: 6px; font-weight: 400 !important; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin-bottom: 0; }
.filters .field input, .filters .field select { width: auto; min-width: 120px; }

/* ダッシュボード */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: #fff; border-radius: 8px; padding: 14px 18px; box-shadow: 0 1px 3px rgba(0,0,0,.08); text-decoration: none; color: inherit; display: block; }
.stat:hover { box-shadow: 0 2px 8px rgba(0,0,0,.14); }
.stat .label { font-size: 12px; color: #6b7280; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 2px; }
.stat.danger .value { color: #b91c1c; }
.stat.warning .value { color: #b45309; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 18px; }

.book-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.book-card { background: #fff; border-radius: 10px; padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,.08); text-decoration: none; color: inherit; border: 2px solid transparent; display: block; }
.book-card:hover { border-color: #2563eb; }
.book-card h2 { font-size: 18px; margin-bottom: 6px; }
.book-card dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 12px 0 0; font-size: 13px; }
.book-card dt { color: #6b7280; }
.book-card dd { margin: 0; font-weight: 700; }

/* 月次在庫表 */
.sheet-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.month-nav { display: flex; align-items: center; gap: 6px; }
.month-nav strong { font-size: 18px; min-width: 110px; text-align: center; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs a { padding: 5px 12px; border-radius: 6px 6px 0 0; background: #e5e7eb; color: #374151; text-decoration: none; font-size: 13px; border-bottom: 2px solid transparent; }
.tabs a.active { background: #fff; color: #12324a; font-weight: 700; border-bottom-color: #2563eb; }
.sheet-wrap { overflow: auto; max-height: calc(100vh - 230px); background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
table.sheet { border-collapse: separate; border-spacing: 0; font-size: 12px; width: max-content; min-width: 100%; }
table.sheet th, table.sheet td { padding: 3px 5px; border-right: 1px solid #e5e7eb; border-bottom: 1px solid #e5e7eb; white-space: nowrap; }
table.sheet thead th { position: sticky; top: 0; z-index: 3; background: #eef2f7; text-align: center; }
table.sheet th.sticky, table.sheet td.sticky { position: sticky; z-index: 2; background: #fff; }
table.sheet thead th.sticky { z-index: 4; background: #eef2f7; }
table.sheet .c-carry { left: 0; width: 64px; min-width: 64px; }
table.sheet .c-name { left: 64px; width: 220px; min-width: 220px; max-width: 220px; white-space: normal; }
table.sheet .c-spec { left: 284px; width: 70px; min-width: 70px; }
table.sheet .c-pack { left: 354px; width: 44px; min-width: 44px; }
table.sheet .c-label { left: 398px; width: 66px; min-width: 66px; border-right: 2px solid #9ca3af; }
table.sheet td.day { width: 34px; min-width: 34px; text-align: right; }
table.sheet td.day.has-detail { cursor: pointer; }
table.sheet td.day.has-detail:hover, table.sheet td.day.pinned-cell { background: #fff7d6 !important; outline: 1px solid #f59e0b; }
.sheet-popover { position: absolute; z-index: 50; background: #fff; border: 1px solid #d1d5db; border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 8px 10px; max-width: min(720px, calc(100vw - 16px)); font-size: 13px; }
.sheet-popover[hidden] { display: none; }
.sheet-popover.pinned { border-color: #f59e0b; box-shadow: 0 8px 28px rgba(0,0,0,.28); }
.sheet-popover-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-weight: 700; margin-bottom: 6px; }
.sheet-popover-close { display: none; border: none; background: none; font-size: 18px; line-height: 1; cursor: pointer; color: #6b7280; }
.sheet-popover.pinned .sheet-popover-close { display: inline; }
.sheet-popover table { width: 100%; border-collapse: collapse; }
.sheet-popover th, .sheet-popover td { padding: 3px 8px; border-bottom: 1px solid #f3f4f6; text-align: left; white-space: nowrap; }
.sheet-popover td:last-child { white-space: normal; min-width: 160px; }
.sheet-popover th.num, .sheet-popover td.num { text-align: right; }
table.sheet td.day.filled { font-weight: 700; }
table.sheet th.sat, table.sheet td.sat { background: #f0f6ff; }
table.sheet th.sun, table.sheet td.sun { background: #fff1f1; }
table.sheet th.today, table.sheet td.today { background: #fffbe6; }
table.sheet tr.r-receipt td { border-top: 2px solid #9ca3af; }
table.sheet tr.r-receipt td.day.filled { color: #1e40af; }
table.sheet tr.r-ship-pack td.day.filled, table.sheet tr.r-ship-case td.day.filled { color: #9d174d; }
table.sheet td.total { text-align: right; background: #f9fafb; font-variant-numeric: tabular-nums; }
table.sheet td.stock { text-align: right; font-weight: 700; font-size: 13px; background: #f0fdf4; }
table.sheet td.stock.minus { color: #b91c1c; background: #fef2f2; }
table.sheet td.stock.low { background: #fffbeb; color: #b45309; }
table.sheet td.label { color: #6b7280; font-size: 11px; }
table.sheet tr.category-row td { background: #12324a; color: #fff; font-weight: 700; position: sticky; left: 0; }
.sheet-legend { font-size: 12px; color: #6b7280; margin: 8px 0; }

dialog { border: none; border-radius: 10px; padding: 0; box-shadow: 0 10px 40px rgba(0,0,0,.3); width: min(420px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog .dialog-body { padding: 18px 20px; }
dialog .dialog-title { font-weight: 700; margin-bottom: 4px; }

/* 入出庫まとめて入力 */
table.bulk input[type=number] { width: 80px; padding: 5px 6px; border: 1px solid #d1d5db; border-radius: 4px; text-align: right; font-size: 14px; }
table.bulk input[type=text] { width: 100%; min-width: 120px; padding: 5px 6px; border: 1px solid #d1d5db; border-radius: 4px; }
table.bulk input.has-value { background: #fffbe6; border-color: #f59e0b; }
.sticky-submit { position: sticky; bottom: 0; background: #fff; padding: 12px 0 4px; border-top: 1px solid #e5e7eb; margin-top: 10px; display: flex; gap: 12px; align-items: center; }

.pagination { display: flex; gap: 14px; justify-content: center; align-items: center; margin-top: 14px; font-size: 13px; }
.detail-grid { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; margin: 0; }
.detail-grid dt { color: #6b7280; font-size: 13px; }
.detail-grid dd { margin: 0; }
.stock-big { font-size: 32px; font-weight: 700; }
.stock-big small { font-size: 14px; color: #6b7280; font-weight: 400; }
code { background: #f3f4f6; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

@media print {
  .site-header, .sheet-toolbar, .tabs, .no-print, .flash { display: none !important; }
  main { margin: 0; padding: 0; }
  .sheet-wrap { max-height: none; overflow: visible; box-shadow: none; }
  table.sheet { font-size: 9px; }
  table.sheet .sticky, table.sheet thead th { position: static !important; }
}
@media (max-width: 640px) {
  .grid-2 { grid-template-columns: 1fr; }
  .user-nav { margin-left: 0; }
}
