/* =========================================================
   YORIAI — shared design tokens & primitives
   ========================================================= */

:root {
  /* Brand — warm sage green */
  --sage-900: #22362B;
  --sage-800: #2E4A3A;
  --sage-700: #3C6049;
  --sage-600: #4C7358;
  --sage-500: #5E8A69;
  --sage-400: #7CA487;
  --sage-300: #A6C4AE;
  --sage-200: #CFE0D4;
  --sage-100: #E6EFE8;
  --sage-050: #F1F6F2;

  /* Accent — soft terracotta / peach */
  --clay-700: #A9512F;
  --clay-600: #C2653E;
  --clay-500: #D98C6A;
  --clay-400: #E7A886;
  --clay-300: #F2C7AC;
  --clay-100: #FBEADF;

  /* Neutrals — warm */
  --ink-900: #241F1B;
  --ink-800: #332D27;
  --ink-700: #4A423B;
  --ink-600: #6B615A;
  --ink-500: #8A807A;
  --ink-400: #ABA29B;
  --ink-300: #CFC7C0;
  --ink-200: #E5DED7;
  --ink-100: #F1EBE4;
  --cream: #FBF8F3;
  --cream-deep: #F6F1E9;
  --white: #FFFFFF;

  /* Cool neutrals (admin) */
  --slate-950: #14201A;
  --slate-900: #1C2A23;
  --slate-800: #26362E;
  --slate-700: #33463C;
  --slate-100: #EEF1F0;
  --slate-050: #F5F7F6;
  --line: #E3E7E5;

  /* Semantic */
  --ok-600: #2F7D5C;
  --ok-100: #E1F2E8;
  --warn-700: #96601B;
  --warn-600: #B5791F;
  --warn-100: #FBEFD6;
  --risk-700: #A33A2E;
  --risk-600: #C0483A;
  --risk-100: #FBE5E1;
  --info-700: #2A5F86;
  --info-100: #E2EEF7;
  --violet-700: #5B4A8A;
  --violet-100: #EBE6F7;

  /* Shape & motion */
  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-pill: 999px;
  --sh-xs: 0 1px 2px rgba(36, 31, 27, .06);
  --sh-sm: 0 2px 6px rgba(36, 31, 27, .06), 0 1px 2px rgba(36, 31, 27, .04);
  --sh-md: 0 8px 24px -8px rgba(36, 31, 27, .16), 0 2px 6px rgba(36, 31, 27, .05);
  --sh-lg: 0 24px 48px -16px rgba(36, 31, 27, .22), 0 4px 12px rgba(36, 31, 27, .06);
  --ease: cubic-bezier(.22, .61, .36, 1);

  --font-jp: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Yu Gothic",
    "Noto Sans JP", "Meiryo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-num: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-jp);
  color: var(--ink-800);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "palt" 1;
  line-height: 1.7;
}

h1, h2, h3, h4, h5 { margin: 0; line-height: 1.35; font-weight: 700; letter-spacing: .01em; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
button { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
svg { flex: none; }
input, select, textarea { font: inherit; color: inherit; }

:focus-visible {
  outline: 3px solid var(--sage-400);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: fixed; top: 8px; left: 8px; z-index: 200;
  padding: 10px 16px; background: var(--sage-700); color: #fff;
  border-radius: var(--r-sm); transform: translateY(-160%);
  transition: transform .18s var(--ease);
}
.skip-link:focus { transform: none; }

.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* =========================================================
   Demo mode switch
   ========================================================= */
.demo-switch {
  position: fixed; z-index: 120; bottom: 18px; left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 4px;
  padding: 5px 6px 5px 12px;
  background: rgba(28, 42, 35, .94);
  backdrop-filter: blur(10px);
  border-radius: var(--r-pill);
  box-shadow: var(--sh-lg);
  border: 1px solid rgba(255, 255, 255, .1);
}
.demo-switch__label {
  font-size: 10px; font-weight: 800; letter-spacing: .16em;
  color: rgba(255, 255, 255, .5); padding-right: 6px;
}
.demo-switch__btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 0; cursor: pointer; padding: 8px 15px;
  font-size: 13px; font-weight: 600;
  color: rgba(255, 255, 255, .68);
  background: transparent; border-radius: var(--r-pill);
  transition: color .16s var(--ease), background .16s var(--ease);
  white-space: nowrap;
}
.demo-switch__btn:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.demo-switch__dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: rgba(255, 255, 255, .3);
}
.demo-switch__btn.is-active { background: var(--white); color: var(--ink-900); }
.demo-switch__btn[data-mode="user"].is-active .demo-switch__dot { background: var(--sage-500); }
.demo-switch__btn[data-mode="admin"].is-active .demo-switch__dot { background: var(--clay-500); }
.demo-switch__btn b { font-weight: 600; }

.demo-switch__sep {
  width: 1px; height: 20px; margin: 0 2px;
  background: rgba(255, 255, 255, .16); flex: none;
}
.demo-switch__lang {
  border: 0; cursor: pointer; padding: 8px 12px;
  font-family: var(--font-num); font-size: 12px; font-weight: 700; letter-spacing: .04em;
  color: rgba(255, 255, 255, .72); background: transparent;
  border-radius: var(--r-pill); white-space: nowrap;
  transition: color .16s var(--ease), background .16s var(--ease);
}
.demo-switch__lang b { font-weight: 700; }
.demo-switch__lang:hover { color: #fff; background: rgba(255, 255, 255, .12); }

@media (max-width: 560px) {
  /* Sits above the mobile tab bar so it never covers the header or navigation. */
  .demo-switch { bottom: calc(68px + env(safe-area-inset-bottom, 0px)); padding: 4px 5px 4px 10px; }
  .demo-switch__label { display: none; }
  .demo-switch__btn { padding: 6px 10px; font-size: 12px; }
  .demo-switch__lang { padding: 6px 9px; font-size: 11px; }
}

/* English typography: Latin faces first, slightly tighter tracking. */
body.is-en {
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  letter-spacing: -.005em;
}

/* =========================================================
   Buttons
   ========================================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: var(--r-pill);
  padding: 11px 20px; font-size: 15px; font-weight: 700;
  cursor: pointer; background: var(--white); color: var(--ink-800);
  transition: transform .12s var(--ease), box-shadow .18s var(--ease),
    background .18s var(--ease), border-color .18s var(--ease), color .18s var(--ease);
  text-align: center; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--sage-700); color: #fff; box-shadow: var(--sh-sm); }
.btn--primary:hover { background: var(--sage-800); box-shadow: var(--sh-md); }
.btn--accent { background: var(--clay-600); color: #fff; box-shadow: var(--sh-sm); }
.btn--accent:hover { background: var(--clay-700); }
.btn--ghost { background: transparent; border-color: var(--ink-200); color: var(--ink-700); }
.btn--ghost:hover { background: var(--white); border-color: var(--ink-300); }
.btn--soft { background: var(--sage-100); color: var(--sage-800); }
.btn--soft:hover { background: var(--sage-200); }
.btn--quiet { background: transparent; color: var(--ink-600); padding: 8px 12px; font-weight: 600; }
.btn--quiet:hover { color: var(--ink-900); background: var(--ink-100); }
.btn--danger { background: var(--risk-100); color: var(--risk-700); }
.btn--danger:hover { background: #F7D6D0; }
.btn--lg { padding: 15px 28px; font-size: 16.5px; }
.btn--sm { padding: 7px 14px; font-size: 13px; border-radius: var(--r-pill); }
.btn--block { width: 100%; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn[disabled]:active { transform: none; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--white);
  cursor: pointer; color: var(--ink-600);
  transition: background .16s var(--ease), color .16s var(--ease);
}
.icon-btn:hover { background: var(--ink-100); color: var(--ink-900); }

/* =========================================================
   Tags / badges / chips
   ========================================================= */
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: var(--r-pill);
  font-size: 12px; font-weight: 700; line-height: 1.6;
  background: var(--ink-100); color: var(--ink-700);
  white-space: nowrap;
}
.tag svg { width: 13px; height: 13px; }
.tag--ok { background: var(--ok-100); color: var(--ok-600); }
.tag--warn { background: var(--warn-100); color: var(--warn-700); }
.tag--risk { background: var(--risk-100); color: var(--risk-700); }
.tag--info { background: var(--info-100); color: var(--info-700); }
.tag--sage { background: var(--sage-100); color: var(--sage-800); }
.tag--clay { background: var(--clay-100); color: var(--clay-700); }
.tag--violet { background: var(--violet-100); color: var(--violet-700); }
.tag--outline { background: transparent; border: 1px solid var(--line); color: var(--ink-600); }
.tag--dot::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: .85;
}

.stars { display: inline-flex; align-items: center; gap: 3px; color: var(--clay-500); }
.stars svg { width: 14px; height: 14px; }

/* =========================================================
   Toast + modal
   ========================================================= */
.toast-layer {
  position: fixed; z-index: 300; left: 50%; bottom: 84px;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 10px; align-items: center;
  pointer-events: none; width: min(92vw, 460px);
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 20px; border-radius: var(--r-pill);
  background: var(--slate-900); color: #fff;
  box-shadow: var(--sh-lg); font-size: 14px; font-weight: 600;
  animation: toast-in .28s var(--ease);
}
.toast svg { width: 17px; height: 17px; color: var(--sage-300); }
.toast--out { animation: toast-out .3s var(--ease) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(.96); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(10px) scale(.97); } }

.modal-layer[hidden] { display: none; }
.modal-layer {
  position: fixed; inset: 0; z-index: 250;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(36, 31, 27, .42);
  backdrop-filter: blur(3px);
  animation: fade-in .18s var(--ease);
}
.modal {
  background: var(--white); border-radius: var(--r-lg);
  box-shadow: var(--sh-lg); width: min(94vw, 520px);
  padding: 28px; animation: pop-in .22s var(--ease);
  max-height: 88vh; overflow: auto;
}
.modal h3 { font-size: 20px; margin-bottom: 10px; }
.modal p { color: var(--ink-600); font-size: 14.5px; }
.modal__actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; flex-wrap: wrap; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(12px) scale(.97); } }

/* =========================================================
   Shared micro-layout helpers
   ========================================================= */
.row { display: flex; align-items: center; gap: 10px; }
.row--between { justify-content: space-between; }
.row--wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; }
.grow { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--ink-500); }
.hairline { height: 1px; background: var(--line); border: 0; margin: 0; }

.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; font-weight: 800; color: #fff;
  background: var(--sage-500); flex: none;
  width: 44px; height: 44px; font-size: 15px;
  letter-spacing: .02em; font-family: var(--font-num);
}
.avatar--sm { width: 32px; height: 32px; font-size: 12px; }
.avatar--lg { width: 68px; height: 68px; font-size: 22px; }
.avatar--xl { width: 92px; height: 92px; font-size: 28px; }
.avatar--clay { background: var(--clay-500); }
.avatar--ink { background: var(--ink-500); }
.avatar--deep { background: var(--sage-700); }
.avatar--info { background: #5B85A8; }
.avatar--violet { background: #7A6AA8; }

.fade-in { animation: page-in .34s var(--ease); }
@keyframes page-in { from { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001s !important; transition-duration: .001s !important; }
}

/* =========================================================
   Charts (shared by both sides)
   ========================================================= */
.chart-wrap { width: 100%; }
.chart { width: 100%; height: 190px; display: block; }
.chart--area { height: 170px; }
.chart-xlabels {
  display: flex; justify-content: space-between; margin-top: 8px;
  font-size: 11px; color: var(--ink-500); font-family: var(--font-num);
}
.chart-xlabels span { flex: 1; text-align: center; }
.chart-xlabels--val { margin: 0 0 4px; font-weight: 700; color: var(--ink-600); font-size: 11.5px; }

.chart-donut { width: 132px; height: 132px; flex: none; }
.donut-num { font: 800 24px var(--font-num); fill: var(--ink-900); }
.donut-sub { font: 600 10px var(--font-jp); fill: var(--ink-500); }

.chart-legend { display: flex; flex-direction: column; gap: 9px; }
.chart-legend li { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--ink-600); }
.chart-legend i { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.chart-legend span { flex: 1; }
.chart-legend b { color: var(--ink-900); font-size: 13.5px; }

.hbars { display: flex; flex-direction: column; gap: 11px; }
.hbars li { display: grid; grid-template-columns: 128px 1fr 58px; gap: 12px; align-items: center; }
.hbars__label { font-size: 13px; color: var(--ink-600); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbars__track { height: 9px; background: var(--ink-100); border-radius: var(--r-pill); overflow: hidden; }
.hbars__track i { display: block; height: 100%; border-radius: var(--r-pill); transition: width .5s var(--ease); }
.hbars__val { font-size: 13px; font-weight: 700; text-align: right; }

.stackbar { display: flex; height: 12px; border-radius: var(--r-pill); overflow: hidden; background: var(--ink-100); }
.stackbar i { display: block; height: 100%; }

.ring { width: 128px; height: 128px; flex: none; }
.ring-num { font: 800 34px var(--font-num); fill: var(--ink-900); }
.ring-sub { font: 600 11px var(--font-num); fill: var(--ink-500); }

.spark { width: 88px; height: 26px; flex: none; }
.spark--empty { color: var(--ink-300); font-size: 12px; }

.meter { margin-bottom: 14px; }
.meter__top { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: var(--ink-600); margin-bottom: 6px; }
.meter__top b { font-size: 14px; color: var(--ink-900); }
.meter__track { height: 8px; background: var(--ink-100); border-radius: var(--r-pill); overflow: hidden; }
.meter__track i { display: block; height: 100%; border-radius: var(--r-pill); transition: width .5s var(--ease); }
.meter__hint { font-size: 11.5px; color: var(--ink-500); margin-top: 5px; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--ink-300) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--ink-300); border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-400); background-clip: content-box; }
