/* ============================================================
   3Dプリンター材料 在庫管理 — Design System
   ============================================================ */
:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --line: #e6e5e1;
  --line-strong: #d4d3ce;
  --text: #1a1917;
  --text-2: #6b6a66;
  --text-3: #9c9b96;
  --ink: #1a1917;
  --danger: #c2410c;
  --danger-bg: #fdf1ec;
  --warn: #a16207;
  --warn-bg: #fdf6e3;
  --ok: #2f7a4a;
  --ok-bg: #edf6ef;
  --radius: 8px;
  --font: "Inter", "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Hiragino Sans", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  font-feature-settings: "tnum" 1, "cv11" 1;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: default; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p, dl, dd { margin: 0; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Layout ---------- */
.container { max-width: 1120px; margin: 0 auto; padding: 0 24px; }
@media (max-width: 640px) { .container { padding: 0 16px; } }

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.site-header .container {
  height: 56px;
  display: flex; align-items: center; gap: 32px;
}
.brand { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; white-space: nowrap; }
.brand small { color: var(--text-3); font-weight: 400; margin-left: 8px; }
.nav { display: flex; gap: 4px; margin-right: auto; }
.nav button {
  padding: 6px 12px; border-radius: 6px;
  color: var(--text-2); font-weight: 500;
}
.nav button:hover { color: var(--text); background: var(--bg); }
.nav button.is-active { color: var(--text); background: #ecebe7; }
.header-tools { display: flex; align-items: center; gap: 12px; }
.operator {
  width: 120px; height: 32px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--bg);
  font-size: 13px;
}
.operator::placeholder { color: var(--text-3); }
.operator:focus { outline: none; border-color: var(--line-strong); background: var(--surface); }
.link-quiet { color: var(--text-2); font-size: 13px; }
.link-quiet:hover { color: var(--text); }
@media (max-width: 640px) {
  .site-header .container { gap: 16px; }
  .brand small, .operator { display: none; }
}

main { padding: 32px 0 96px; }
@media (max-width: 640px) { main { padding-top: 20px; } }

/* ---------- Panels ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.panel-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { font-size: 14px; font-weight: 600; }
.panel-head .count { color: var(--text-3); font-weight: 400; margin-left: 6px; }
.empty { padding: 40px 20px; text-align: center; color: var(--text-3); font-size: 13px; }

/* ---------- Dashboard ---------- */
.stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  margin-bottom: 24px;
}
.stat {
  text-align: left; padding: 20px 24px;
  border-right: 1px solid var(--line);
  transition: background 0.12s;
}
.stat:last-child { border-right: 0; }
.stat:hover { background: #fbfbfa; }
.stat .label { font-size: 12px; color: var(--text-2); font-weight: 500; letter-spacing: 0.02em; }
.stat .value { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; margin-top: 6px; }
.stat .value small { font-size: 13px; color: var(--text-3); font-weight: 400; margin-left: 4px; letter-spacing: 0; }
.stat .foot { margin-top: 10px; font-size: 12px; color: var(--text-3); display: flex; gap: 12px; }
.stat .foot .alert { color: var(--danger); font-weight: 500; }
@media (max-width: 640px) {
  .stats { grid-template-columns: 1fr; }
  .stat { border-right: 0; border-bottom: 1px solid var(--line); padding: 16px 20px; }
  .stat:last-child { border-bottom: 0; }
}

.dash-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 24px; align-items: start; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: 6px;
  font-size: 13px; font-weight: 500; white-space: nowrap;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #333; }
.btn-danger { color: var(--danger); border-color: #f0c9b8; }
.btn-danger:hover { background: var(--danger-bg); }
.btn-lg { height: 44px; font-size: 14px; width: 100%; }
.btn-text { color: var(--text-2); font-size: 13px; padding: 0; height: auto; border: 0; background: none; }
.btn-text:hover { color: var(--text); background: none; text-decoration: underline; }

/* ---------- Material rows ---------- */
.rows > * { border-bottom: 1px solid var(--line); }
.rows > *:last-child { border-bottom: 0; }

.mrow {
  display: grid; grid-template-columns: 18px 1fr auto; align-items: center; gap: 14px;
  padding: 12px 20px;
  transition: background 0.4s;
}
.mrow.flash { background: #fbf7df; }
.swatch {
  width: 18px; height: 18px; border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12);
}
.mrow .info { min-width: 0; cursor: pointer; }
.mrow .name { font-weight: 500; display: flex; align-items: center; gap: 8px; min-width: 0; }
.mrow .name span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mrow .info:hover .name span:first-child { text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.mrow .meta { font-size: 12px; color: var(--text-3); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mrow .meta .sep { margin: 0 6px; }

.cat-tag {
  font-size: 11px; color: var(--text-2); font-weight: 500;
  padding: 0 5px; border: 1px solid var(--line); border-radius: 4px; line-height: 16px;
}
.status {
  font-size: 11px; font-weight: 500; padding: 0 6px; border-radius: 4px; line-height: 18px;
}
.status-out { color: var(--danger); background: var(--danger-bg); }
.status-low { color: var(--warn); background: var(--warn-bg); }

.qty { display: flex; align-items: center; gap: 4px; }
.qty-btn {
  width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--line-strong); color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px; line-height: 1;
  transition: background 0.12s, color 0.12s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
}
.qty-btn:hover { background: var(--ink); border-color: var(--ink); color: #fff; }
.qty-btn:active { transform: scale(0.9); }
.qty-btn:disabled { opacity: 0.3; background: none; border-color: var(--line-strong); color: var(--text-2); transform: none; }
.qty-value {
  min-width: 76px; text-align: right; padding: 4px 8px; border-radius: 6px;
  display: inline-flex; align-items: baseline; justify-content: flex-end; gap: 4px;
}
.qty-value:hover { background: var(--bg); }
.qty-value b { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.qty-value.is-out b { color: var(--danger); }
.qty-value.is-low b { color: var(--warn); }
.qty-value small { font-size: 11px; color: var(--text-3); }
@media (max-width: 640px) {
  .mrow { padding: 12px 16px; gap: 10px; }
  .qty-value { min-width: 60px; padding: 4px 4px; }
}

/* ---------- Transactions ---------- */
.trow {
  display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center;
  padding: 10px 20px;
}
.trow .t-main { min-width: 0; display: flex; align-items: center; gap: 8px; }
.trow .dot { width: 8px; height: 8px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12); flex-shrink: 0; }
.trow .t-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trow .t-meta { font-size: 12px; color: var(--text-3); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trow .t-delta { text-align: right; }
.trow .t-delta b { font-size: 14px; font-weight: 600; }
.trow .t-delta .in { color: var(--ok); }
.trow .t-delta .out { color: var(--danger); }
.trow .t-delta .adjust { color: var(--text-2); }
.trow .t-delta small { display: block; font-size: 11px; color: var(--text-3); }

/* ---------- Inventory toolbar ---------- */
.toolbar { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.segmented {
  display: inline-flex; background: #ecebe7; border-radius: 8px; padding: 3px;
}
.segmented button {
  padding: 6px 14px; border-radius: 6px; font-weight: 500; color: var(--text-2); font-size: 13px;
}
.segmented button.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,0.06); }
.search {
  flex: 1; min-width: 200px; height: 34px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--surface);
}
.search::placeholder { color: var(--text-3); }
.search:focus { outline: none; border-color: var(--line-strong); }
.hint { font-size: 12px; color: var(--text-3); margin: -4px 0 16px; }
.group-title {
  font-size: 11px; font-weight: 600; color: var(--text-3); letter-spacing: 0.06em; text-transform: uppercase;
  padding: 0 2px; margin: 20px 0 8px;
}
.group-title:first-child { margin-top: 0; }
.group-title .count { font-weight: 400; margin-left: 4px; }

.filters { display: flex; gap: 8px; margin-left: auto; }
.select {
  height: 32px; padding: 0 28px 0 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236b6a66' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 10px center;
  appearance: none; font-size: 13px;
}
.page-title { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(26, 25, 23, 0.35);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
  animation: fade 0.15s ease;
}
.modal {
  background: var(--surface); width: 100%; max-width: 480px;
  border-radius: 14px 14px 0 0; max-height: 92vh; overflow-y: auto;
  animation: rise 0.2s ease;
}
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; padding: 24px; }
  .modal { border-radius: 12px; border: 1px solid var(--line); box-shadow: 0 20px 50px rgba(0,0,0,0.12); }
}
.modal-body { padding: 24px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 20px; }
.modal-head h2 { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.3; }
.modal-head .sub { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.modal-head .sub b { color: var(--text); font-weight: 600; }
.close { width: 28px; height: 28px; border-radius: 6px; color: var(--text-3); font-size: 18px; line-height: 1; margin: -4px -6px 0 0; }
.close:hover { background: var(--bg); color: var(--text); }
.title-with-swatch { display: flex; align-items: center; gap: 12px; }

.choice { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 20px; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice span {
  display: block; text-align: center; padding: 8px 0; border-radius: 6px;
  border: 1px solid var(--line); font-weight: 500; font-size: 13px; color: var(--text-2); cursor: pointer;
}
.choice input:checked + span { background: var(--ink); border-color: var(--ink); color: #fff; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 5px; font-weight: 500; }
.field .req { color: var(--danger); }
.input, textarea.input {
  width: 100%; height: 36px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--surface);
}
textarea.input { height: auto; padding: 8px 10px; resize: vertical; }
.input:focus { outline: none; border-color: var(--text-3); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.grid-2 .field, .grid-3 .field { margin-bottom: 0; }
.stack > * + * { margin-top: 14px; }

.qty-input-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.qty-input-row .qty-btn { width: 40px; height: 40px; font-size: 20px; }
.qty-input {
  flex: 1; height: 56px; text-align: center; font-size: 28px; font-weight: 600;
  border: 1px solid var(--line); border-radius: 8px; letter-spacing: -0.02em;
}
.qty-input:focus { outline: none; border-color: var(--text-3); }
.qty-input::-webkit-outer-spin-button, .qty-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 20px; }
.chip {
  height: 28px; padding: 0 12px; border-radius: 14px;
  border: 1px solid var(--line); font-size: 13px; color: var(--text-2);
}
.chip:hover { border-color: var(--text-3); color: var(--text); }
.preview {
  padding: 10px 12px; border-radius: 6px; background: var(--bg);
  font-size: 13px; color: var(--text-2); margin: 16px 0 20px;
}
.preview b { color: var(--text); }
.preview .warn { color: var(--danger); font-weight: 500; margin-left: 8px; }

.color-row { display: flex; align-items: center; gap: 8px; }
.color-picker { width: 36px; height: 36px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.palette { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.palette button {
  width: 22px; height: 22px; border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12); transition: transform 0.1s;
}
.palette button:hover { transform: scale(1.15); }

/* Detail */
.detail-stock {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin-bottom: 20px;
}
.detail-stock .label { font-size: 12px; color: var(--text-2); }
.detail-stock .value { font-size: 30px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.detail-stock .value small { font-size: 13px; color: var(--text-3); font-weight: 400; margin-left: 4px; letter-spacing: 0; }
.detail-stock .value.is-out { color: var(--danger); }
.detail-stock .value.is-low { color: var(--warn); }
.detail-stock .actions { display: flex; gap: 6px; }
.dl { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin-bottom: 20px; }
.dl dt { font-size: 11px; color: var(--text-3); }
.dl dd { font-size: 13px; margin-top: 1px; }
.detail-actions { display: flex; gap: 8px; margin-bottom: 24px; }
.detail-actions .btn:first-child { flex: 1; }
.section-title { font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 8px; }
.history-box { border: 1px solid var(--line); border-radius: var(--radius); max-height: 260px; overflow-y: auto; }
.history-box .trow { padding: 10px 14px; }

/* ---------- Toast ---------- */
#toast-host {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: none;
}
.toast {
  background: var(--ink); color: #fff; padding: 9px 14px; border-radius: 8px;
  font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,0.15);
  animation: rise 0.2s ease;
}
.toast.is-error { background: var(--danger); }

.spinner { padding: 60px; text-align: center; color: var(--text-3); font-size: 13px; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- User / Auth ---------- */
.user { display: flex; align-items: center; gap: 10px; padding-left: 12px; border-left: 1px solid var(--line); }
.avatar { width: 24px; height: 24px; border-radius: 50%; }
.user-name { font-size: 13px; font-weight: 500; }
@media (max-width: 640px) { .user-name { display: none; } }

.login-body {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card {
  width: 100%; max-width: 440px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; padding: 36px;
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.login-brand img { border-radius: 9px; }
.login-brand h1 { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.3; }
.login-brand p { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.login-lead { font-size: 15px; font-weight: 500; margin-bottom: 8px; }
.login-note { font-size: 13px; color: var(--text-2); margin-bottom: 24px; line-height: 1.6; }
.login-note b { color: var(--text); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 500; }
.login-error {
  font-size: 13px; color: var(--danger); background: var(--danger-bg);
  padding: 10px 12px; border-radius: 6px; margin-bottom: 20px; line-height: 1.5;
}
.btn-google {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  height: 48px; border-radius: 8px; background: var(--ink); color: #fff;
  font-size: 15px; font-weight: 500; transition: background 0.12s;
}
.btn-google:hover { background: #333; }
.btn-google svg { background: #fff; border-radius: 50%; padding: 3px; width: 22px; height: 22px; }
