/* =========================================================================
   BASE 売上在庫管理 — デザインシステム
   Apple のプロダクトページを参照した、余白と階調で読ませる静かなUI。
   ========================================================================= */

:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
    "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  --font-num: "SF Pro Display", -apple-system, "Segoe UI", "Helvetica Neue", sans-serif;

  --bg: #fbfbfd;
  --bg-elevated: #ffffff;
  --bg-sunken: #f5f5f7;
  --bg-hover: rgba(0, 0, 0, 0.035);
  --nav-bg: rgba(251, 251, 253, 0.72);

  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #86868b;

  --line: rgba(0, 0, 0, 0.09);
  --line-strong: rgba(0, 0, 0, 0.16);

  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-soft: rgba(0, 113, 227, 0.1);

  --green: #00875a;
  --green-soft: rgba(0, 135, 90, 0.1);
  --orange: #b25000;
  --orange-soft: rgba(178, 80, 0, 0.1);
  --purple: #6b4ec9;
  --purple-soft: rgba(107, 78, 201, 0.1);
  --teal: #00786f;
  --teal-soft: rgba(0, 120, 111, 0.1);
  --red: #d13438;
  --red-soft: rgba(209, 52, 56, 0.1);
  --gray-soft: rgba(0, 0, 0, 0.055);

  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 8px rgba(0, 0, 0, 0.04);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.05), 0 12px 32px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.1), 0 40px 80px rgba(0, 0, 0, 0.12);

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --nav-h: 56px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  letter-spacing: 0.005em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

a {
  color: var(--accent);
  text-decoration: none;
}

/* ---------------------------------------------------------------- ナビ --- */

.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 22px;
  background: var(--nav-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
}

.nav__brand {
  margin-right: 22px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  flex: none;
}

.nav__mark {
  height: 24px;
  width: auto;
  display: block;
}

.nav__links {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
  min-width: 0;
}

.nav__links::-webkit-scrollbar {
  display: none;
}

.nav__link {
  padding: 6px 13px;
  border-radius: 980px;
  font-size: 13.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
  cursor: pointer;
  border: none;
  background: none;
}

.nav__link:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.nav__link.is-active {
  color: var(--text);
  background: var(--gray-soft);
  font-weight: 500;
}

.nav__external {
  flex: none;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  padding-left: 16px;
}

/* 画面上部に出す注意喚起の帯 */
.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 22px;
  font-size: 13.5px;
  border-bottom: 1px solid var(--line);
}

.banner--warn {
  background: var(--orange-soft);
  color: var(--orange);
}

.banner--warn .btn {
  background: var(--orange);
  margin-left: auto;
}

/* -------------------------------------------------------------- レイアウト */

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 40px 22px 96px;
  animation: rise 0.5s var(--ease-out);
}

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

.page__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 30px;
}

.page__title {
  font-size: 34px;
  font-weight: 600;
  letter-spacing: -0.021em;
  line-height: 1.15;
}

.page__sub {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 5px;
}

.section {
  margin-top: 46px;
}

.section__title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.012em;
  margin-bottom: 16px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.section__title small {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
}

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

.card {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.card--pad {
  padding: 22px 24px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid--hero {
  grid-template-columns: repeat(auto-fit, minmax(232px, 1fr));
}

.grid--2 {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

/* 主要指標タイル */
.stat {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px 26px 22px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.35s var(--ease-out), box-shadow 0.35s var(--ease-out);
  position: relative;
  overflow: hidden;
}

.stat:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.stat::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--tone, var(--accent));
  opacity: 0.85;
}

.stat__label {
  font-size: 12.5px;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  gap: 7px;
}

.stat__value {
  font-family: var(--font-num);
  font-size: 40px;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.1;
  margin-top: 10px;
  font-variant-numeric: tabular-nums;
}

.stat__value .unit {
  font-size: 19px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-left: 3px;
  letter-spacing: 0;
}

.stat__foot {
  margin-top: 12px;
  font-size: 12.5px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.stat--donation {
  --tone: var(--green);
}
.stat--revenue {
  --tone: var(--accent);
}
.stat--stock {
  --tone: var(--purple);
}
.stat--expense {
  --tone: var(--orange);
}

.delta {
  font-size: 12px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 980px;
  background: var(--gray-soft);
  font-variant-numeric: tabular-nums;
}

.delta--up {
  color: var(--green);
  background: var(--green-soft);
}

.delta--down {
  color: var(--red);
  background: var(--red-soft);
}

/* --------------------------------------------------------------- 部品 --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 17px;
  border-radius: 980px;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s var(--ease), transform 0.15s var(--ease),
    opacity 0.2s var(--ease);
}

.btn:hover {
  background: var(--accent-hover);
}

.btn:active {
  transform: scale(0.975);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn--ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line-strong);
}

.btn--ghost:hover {
  background: var(--bg-hover);
}

.btn--quiet {
  background: transparent;
  color: var(--accent);
  padding: 6px 10px;
}

.btn--quiet:hover {
  background: var(--accent-soft);
}

.btn--danger {
  background: transparent;
  color: var(--red);
  border-color: transparent;
}

.btn--danger:hover {
  background: var(--red-soft);
}

.btn--sm {
  padding: 5px 12px;
  font-size: 13px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field__label {
  font-size: 12.5px;
  color: var(--text-secondary);
  font-weight: 500;
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 9px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--bg-elevated);
  font-size: 14.5px;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
  min-width: 0;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px var(--accent-soft);
}

.input[type="number"] {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.textarea {
  resize: vertical;
  min-height: 74px;
}

.select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-tertiary) 50%),
    linear-gradient(135deg, var(--text-tertiary) 50%, transparent 50%);
  background-position: calc(100% - 16px) 51%, calc(100% - 11px) 51%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.toolbar .field {
  min-width: 130px;
}

.toolbar__grow {
  flex: 1;
  min-width: 160px;
}

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

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sm);
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  z-index: 1;
}

tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr {
  transition: background 0.15s var(--ease);
}

tbody tr:hover {
  background: var(--bg-hover);
}

tbody tr.is-group td {
  background: var(--bg-sunken);
  font-weight: 600;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-num);
  white-space: nowrap;
}

.muted {
  color: var(--text-tertiary);
}

.nowrap {
  white-space: nowrap;
}

.zero {
  color: var(--text-tertiary);
}

.neg {
  color: var(--red);
}

/* -------------------------------------------------------------- タグ類 --- */

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 980px;
  font-size: 12px;
  font-weight: 500;
  background: var(--gray-soft);
  color: var(--text-secondary);
  white-space: nowrap;
}

.tag--blue {
  background: var(--accent-soft);
  color: var(--accent);
}
.tag--green {
  background: var(--green-soft);
  color: var(--green);
}
.tag--orange {
  background: var(--orange-soft);
  color: var(--orange);
}
.tag--purple {
  background: var(--purple-soft);
  color: var(--purple);
}
.tag--teal {
  background: var(--teal-soft);
  color: var(--teal);
}
.tag--red {
  background: var(--red-soft);
  color: var(--red);
}

.dir {
  font-family: var(--font-num);
  font-weight: 600;
}

.dir--in {
  color: var(--green);
}

.dir--out {
  color: var(--text-secondary);
}

/* -------------------------------------------------------------- グラフ --- */

.chart {
  width: 100%;
  height: 240px;
  display: block;
  overflow: visible;
}

.chart__bar {
  transition: opacity 0.2s var(--ease);
  cursor: default;
}

.chart__bar:hover {
  opacity: 0.75;
}

.legend {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 14px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  display: inline-block;
}

/* 内訳バー */
.breakdown {
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.breakdown__row {
  display: grid;
  grid-template-columns: minmax(84px, auto) 1fr minmax(88px, auto);
  align-items: center;
  gap: 14px;
  font-size: 13.5px;
}

.breakdown__track {
  height: 7px;
  border-radius: 980px;
  background: var(--gray-soft);
  overflow: hidden;
}

.breakdown__fill {
  height: 100%;
  border-radius: 980px;
  background: var(--accent);
  transition: width 0.7s var(--ease-out);
}

/* ------------------------------------------------------------ モーダル --- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 22px;
  animation: fade 0.22s var(--ease);
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

.modal {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(760px, 100%);
  max-height: min(88vh, 900px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: pop 0.32s var(--ease-out);
  border: 1px solid var(--line);
}

.modal--wide {
  width: min(1020px, 100%);
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.985);
  }
}

.modal__head {
  padding: 20px 26px 15px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.modal__title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.modal__body {
  padding: 22px 26px;
  overflow-y: auto;
  flex: 1;
}

.modal__foot {
  padding: 15px 26px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: var(--bg-sunken);
}

.icon-btn {
  border: none;
  background: none;
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  transition: background 0.18s var(--ease);
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

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

.form-grid--full {
  grid-column: 1 / -1;
}

/* --------------------------------------------------------------- 認証 --- */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(
      1000px 620px at 50% -8%,
      var(--accent-soft),
      transparent 62%
    ),
    var(--bg);
}

.login__card {
  width: min(392px, 100%);
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: 26px;
  padding: 46px 38px 34px;
  box-shadow: var(--shadow);
  text-align: center;
  animation: pop 0.5s var(--ease-out);
}

.login__mark {
  display: block;
  height: 34px;
  width: auto;
  margin: 0 auto 26px;
}

.login__sub {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 0;
  margin-bottom: 28px;
}

.login .input {
  text-align: center;
  padding: 12px;
  font-size: 16px;
}

.login .btn {
  width: 100%;
  margin-top: 14px;
  padding: 11px;
}

/* -------------------------------------------------------------- 各種 --- */

.empty {
  text-align: center;
  padding: 64px 20px;
  color: var(--text-tertiary);
}

.empty__icon {
  font-size: 34px;
  opacity: 0.4;
  margin-bottom: 10px;
}

.error {
  color: var(--red);
  font-size: 13.5px;
  min-height: 20px;
  margin-top: 10px;
}

.toast-host {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 9px;
  align-items: center;
  pointer-events: none;
}

.toast {
  background: rgba(28, 28, 30, 0.94);
  color: #fff;
  padding: 11px 20px;
  border-radius: 980px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  animation: toast-in 0.32s var(--ease-out);
  max-width: min(560px, 90vw);
}

.toast--error {
  background: rgba(209, 52, 56, 0.95);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}

.spinner {
  width: 17px;
  height: 17px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading {
  display: grid;
  place-items: center;
  padding: 90px;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  font-size: 13.5px;
  user-select: none;
}

.switch input {
  appearance: none;
  width: 40px;
  height: 23px;
  border-radius: 980px;
  background: var(--line-strong);
  position: relative;
  cursor: pointer;
  transition: background 0.24s var(--ease);
  flex: none;
  margin: 0;
}

.switch input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
  transition: transform 0.24s var(--ease-out);
}

.switch input:checked {
  background: var(--green);
}

.switch input:checked::after {
  transform: translateX(17px);
}

.segmented {
  display: inline-flex;
  background: var(--gray-soft);
  border-radius: 980px;
  padding: 3px;
  gap: 2px;
}

.segmented button {
  border: none;
  background: none;
  padding: 5px 14px;
  border-radius: 980px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}

.segmented button.is-active {
  background: var(--bg-elevated);
  color: var(--text);
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}

.drop {
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  color: var(--text-secondary);
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
  cursor: pointer;
}

.drop:hover,
.drop.is-over {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.hint {
  font-size: 12.5px;
  color: var(--text-tertiary);
  line-height: 1.6;
}

.rule-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.line-editor {
  display: grid;
  gap: 8px;
}

.line-editor__row {
  display: grid;
  grid-template-columns: 1fr 96px 34px;
  gap: 9px;
  align-items: center;
}

.pill-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

@media (max-width: 720px) {
  .page {
    padding: 26px 16px 80px;
  }
  .page__title {
    font-size: 27px;
  }
  .stat__value {
    font-size: 33px;
  }
  .nav {
    padding: 0 12px;
  }
  .nav__brand {
    margin-right: 12px;
  }
  .nav__mark {
    height: 20px;
  }
  .nav__external {
    display: none;
  }
}
