/* ==========================================================================
   Design System — 共有ビジュアルトークン & 基本コンポーネント
   ==========================================================================
   交易列表・予算管理・在庫監控の3ページ間で共有するデザインシステム。
   他ページは導航・ページ背景のみ継承し、主体レイアウトは変更しない。
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. VISUAL TOKENS — Colors, Fonts, Spacing
   -------------------------------------------------------------------------- */
:root {
  /* --- Page & Surface --- */
  --ds-bg-page:         #f5f3f0;       /* warm gray page background */
  --ds-bg-card:         #ffffff;
  --ds-card-radius:     14px;
  --ds-card-shadow:     0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --ds-card-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.08);

  /* --- Typography --- */
  --ds-font-family:     'Noto Sans JP', system-ui, -apple-system, 'Hiragino Kaku Gothic ProN', 'Yu Gothic UI', sans-serif;
  --ds-text-primary:    #1a1a1a;       /* near-black */
  --ds-text-secondary:  #6b7280;       /* neutral gray */
  --ds-text-muted:      #9ca3af;
  --ds-text-on-dark:    #ffffff;
  --ds-text-on-dark-50: rgba(255, 255, 255, 0.5);

  /* --- Brand & Accent --- */
  --ds-brand-primary:   #1e1e2e;       /* near-black */
  --ds-brand-accent:    #6366f1;       /* indigo */
  --ds-brand-selected:  #7c3aed;       /* purple */
  --ds-brand-selected-bg: rgba(99, 102, 241, 0.1);

  /* --- Status Colors --- */
  --ds-color-success:     #22c55e;     /* green */
  --ds-color-success-bg:  #f0fdf4;
  --ds-color-success-text:#15803d;
  --ds-color-warning:     #f59e0b;     /* amber */
  --ds-color-warning-bg:  #fffbeb;
  --ds-color-warning-text:#92400e;
  --ds-color-danger:      #ef4444;     /* red */
  --ds-color-danger-bg:   #fef2f2;
  --ds-color-danger-text: #991b1b;
  --ds-color-neutral:     #9ca3af;     /* gray */
  --ds-color-neutral-bg:  #f3f4f6;
  --ds-color-neutral-text:#4b5563;

  /* --- Navbar --- */
  --ds-nav-bg:          #1e1e2e;
  --ds-nav-height:      56px;
  --ds-nav-link-color:  rgba(255, 255, 255, 0.7);
  --ds-nav-link-hover:  rgba(255, 255, 255, 0.95);
  --ds-nav-link-active: #ffffff;
  --ds-nav-active-indicator: #6366f1;

  /* --- Spacing --- */
  --ds-space-xs:  4px;
  --ds-space-sm:  8px;
  --ds-space-md:  16px;
  --ds-space-lg:  24px;
  --ds-space-xl:  32px;
  --ds-space-2xl: 48px;

  /* --- Misc --- */
  --ds-border-color:    #e5e7eb;
  --ds-border-radius-sm: 6px;
  --ds-border-radius-md: 10px;
  --ds-transition:      0.15s ease;
}

/* --------------------------------------------------------------------------
   2. GLOBAL BASE — Page & Typography
   -------------------------------------------------------------------------- */
body {
  font-family: var(--ds-font-family);
  background-color: var(--ds-bg-page);
  color: var(--ds-text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --------------------------------------------------------------------------
   3. NAVBAR — Dark navigation bar
   -------------------------------------------------------------------------- */
.ds-navbar {
  background-color: var(--ds-nav-bg);
  height: var(--ds-nav-height);
  padding: 0 var(--ds-space-lg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  z-index: 1030;
}

.ds-navbar .navbar-brand {
  color: var(--ds-text-on-dark);
  font-weight: 700;
  font-size: 1rem;
  padding: 0;
  display: flex;
  align-items: center;
  gap: var(--ds-space-sm);
}

.ds-navbar .ds-brand-block {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--ds-brand-accent), var(--ds-brand-selected));
  border-radius: var(--ds-border-radius-sm);
  color: #fff;
  font-size: 1rem;
}

.ds-navbar .nav-link {
  color: var(--ds-nav-link-color);
  font-size: 0.875rem;
  font-weight: 500;
  padding: var(--ds-space-md) var(--ds-space-sm);
  transition: color var(--ds-transition);
  position: relative;
  white-space: nowrap;
}

.ds-navbar .nav-link:hover,
.ds-navbar .nav-link:focus {
  color: var(--ds-nav-link-hover);
}

.ds-navbar .nav-link.ds-nav-active {
  color: var(--ds-nav-link-active);
}

.ds-navbar .nav-link.ds-nav-active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: var(--ds-space-sm);
  right: var(--ds-space-sm);
  height: 2px;
  background: var(--ds-nav-active-indicator);
  border-radius: 1px;
}

/* Dropdown parent: selected but no underline bar */
.ds-navbar .nav-link.ds-nav-parent-active {
  color: var(--ds-nav-link-active);
}

.ds-navbar .dropdown-menu {
  background: var(--ds-bg-card);
  border: 1px solid var(--ds-border-color);
  border-radius: var(--ds-border-radius-md);
  box-shadow: var(--ds-card-shadow);
  padding: var(--ds-space-xs) 0;
  min-width: 200px;
}

.ds-navbar .dropdown-item {
  font-size: 0.875rem;
  padding: var(--ds-space-sm) var(--ds-space-md);
  color: var(--ds-text-primary);
  transition: background var(--ds-transition);
}

.ds-navbar .dropdown-item:hover,
.ds-navbar .dropdown-item:focus {
  background: var(--ds-brand-selected-bg);
  color: var(--ds-brand-accent);
}

.ds-navbar .dropdown-item[aria-current="page"] {
  background: var(--ds-brand-selected-bg);
  color: var(--ds-brand-accent);
  font-weight: 600;
}

.ds-navbar .dropdown-menu.ds-settings-menu {
  min-width: 272px;
  padding: 14px 12px;
  background: #15151b;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28), 0 2px 8px rgba(0, 0, 0, 0.22);
}

.ds-settings-menu__section-label {
  padding: 2px 6px 8px;
  color: rgba(255, 255, 255, 0.42);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0;
}

.ds-navbar .ds-settings-menu__item {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 5px 6px;
  border-radius: 9px;
  color: #f5f5f7;
}

.ds-navbar .ds-settings-menu__item:hover,
.ds-navbar .ds-settings-menu__item:focus {
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
}

.ds-navbar .ds-settings-menu__item[aria-current="page"] {
  background: rgba(124, 58, 237, 0.16);
  color: #ffffff;
  font-weight: 500;
}

.ds-settings-menu__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.ds-settings-menu__icon--card {
  background: rgba(79, 70, 229, 0.28);
  color: #818cf8;
}

.ds-settings-menu__icon--payment {
  background: rgba(5, 150, 105, 0.26);
  color: #34d399;
}

.ds-settings-menu__icon--category {
  background: rgba(180, 83, 9, 0.28);
  color: #fbbf24;
}

.ds-settings-menu__icon--tag {
  background: rgba(190, 24, 93, 0.28);
  color: #f472b6;
}

.ds-settings-menu__icon--product {
  background: rgba(3, 105, 161, 0.28);
  color: #38bdf8;
}

.ds-settings-menu__icon--store {
  background: rgba(88, 28, 135, 0.32);
  color: #a78bfa;
}

.ds-settings-menu__content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.ds-settings-menu__title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ds-settings-menu__title {
  color: #f6f6f8;
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ds-settings-menu__description {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.43);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.28;
  white-space: normal;
}

.ds-settings-menu__divider {
  height: 1px;
  margin: 10px -12px 12px;
  background: rgba(255, 255, 255, 0.08);
}

.ds-settings-menu__badge {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 8px;
  border-radius: 9999px;
  background: rgba(124, 58, 237, 0.34);
  color: #c4b5fd;
  font-size: 0.625rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0;
  flex-shrink: 0;
}

.ds-navbar .ds-nav-user {
  color: var(--ds-text-on-dark-50);
  font-size: 0.8125rem;
  display: flex;
  align-items: center;
  gap: var(--ds-space-xs);
}

.ds-navbar .ds-logout-btn {
  color: var(--ds-nav-link-color);
  border-color: rgba(255, 255, 255, 0.25);
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: var(--ds-border-radius-sm);
  transition: all var(--ds-transition);
}

.ds-navbar .ds-logout-btn:hover {
  color: var(--ds-text-on-dark);
  border-color: rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.08);
}

.ds-split-nav { display: flex; position: relative; }
.ds-split-nav > .dropdown-toggle-split { padding-left: 0; padding-right: .45rem; border: 0; background: transparent; }
.ds-new-expense { align-self: center; margin: 7px 8px; padding: 8px 14px !important; border-radius: 8px; color: #fff !important; background: linear-gradient(135deg, #7c3aed, #5b4be0); }
.ds-account-toggle { color: rgba(255,255,255,.86); border: 0; }
.ds-account-toggle:hover, .ds-account-toggle:focus { color: #fff; }
.ds-account-menu { min-width: 240px !important; }

.management-layout { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: calc(100vh - var(--ds-nav-height)); }
.management-sidebar { position: sticky; top: var(--ds-nav-height); height: calc(100vh - var(--ds-nav-height)); overflow-y: auto; flex-direction: column; padding: 18px 12px; color: #f7f7fb; background: #242738; z-index: 1010; }
.management-sidebar__header { display: flex; justify-content: space-between; align-items: center; padding: 0 10px 12px; }
.management-sidebar__toggle { color: rgba(255,255,255,.7); }
.management-nav-label { margin: 18px 10px 6px; color: rgba(255,255,255,.48); font-size: .7rem; font-weight: 700; }
.management-nav-item { display: flex; align-items: center; gap: 12px; min-height: 42px; padding: 9px 10px; border-radius: 8px; color: rgba(255,255,255,.82); font-size: .875rem; line-height: 1.5; text-decoration: none; }
.management-nav-item:hover, .management-nav-item:focus, .management-nav-item.active { color: #fff; background: rgba(124,58,237,.26); }
.management-content { min-width: 0; }
.management-groups { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 18px; }
.management-groups .ds-card-body { display: grid; gap: 10px; }
.management-groups a { display: flex; justify-content: space-between; padding: 10px 0; color: var(--ds-text-primary); font-size: .875rem; text-decoration: none; border-bottom: 1px solid var(--ds-border-color); }
.management-groups small { color: var(--ds-text-secondary); }
.management-cleanup__active .ds-stat-card__value { color: var(--ds-brand-accent); }
.management-layout.sidebar-collapsed { grid-template-columns: 72px minmax(0,1fr); }
.management-layout.sidebar-collapsed .management-sidebar span, .management-layout.sidebar-collapsed .management-nav-label, .management-layout.sidebar-collapsed .management-sidebar__header strong { display: none; }
.management-layout.sidebar-collapsed .management-nav-item { justify-content: center; }

.mobile-bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1035; height: calc(62px + env(safe-area-inset-bottom)); padding: 5px 12px env(safe-area-inset-bottom); background: #1e1e2e; box-shadow: 0 -2px 10px rgba(0,0,0,.15); justify-content: space-around; align-items: center; }
.mobile-bottom-nav a, .mobile-bottom-nav button { display: flex; flex: 1; flex-direction: column; align-items: center; gap: 2px; border: 0; color: rgba(255,255,255,.72); background: none; font-size: .7rem; text-decoration: none; }
.mobile-bottom-nav i { font-size: 1.2rem; }
.mobile-bottom-nav__add { transform: translateY(-10px); }
.mobile-bottom-nav__add i { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%; color: white; background: #7c3aed; }
.mobile-more-drawer { height: min(70vh, 560px) !important; }
.mobile-more-drawer .offcanvas-body > a { display: block; padding: 14px; border-bottom: 1px solid var(--ds-border-color); color: var(--ds-text-primary); text-decoration: none; }
.mobile-bottom-nav .active { color: #fff; }
.management-mobile-links { display: flex; flex-direction: column; }
.management-mobile-links .management-nav-item { color: var(--ds-text-primary); }
.management-mobile-links .management-nav-label { color: var(--ds-text-secondary); }

@media (min-width: 992px) and (max-width: 1199.98px) {
  .management-layout.sidebar-collapsed { grid-template-columns: 72px minmax(0,1fr); }
}
@media (max-width: 991.98px) {
  body { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
  .ds-navbar { height: 52px; }
  .management-layout { display: block; min-height: 0; }
  .management-groups { grid-template-columns: 1fr; }
}

/* --------------------------------------------------------------------------
   4. CARDS — Content containers
   -------------------------------------------------------------------------- */
.ds-card {
  background: var(--ds-bg-card);
  border-radius: var(--ds-card-radius);
  box-shadow: var(--ds-card-shadow);
  border: none;
  transition: box-shadow var(--ds-transition);
}

.ds-card:hover {
  box-shadow: var(--ds-card-shadow-hover);
}

.ds-card-body {
  padding: var(--ds-space-lg);
}

/* --------------------------------------------------------------------------
   5. STAT CARDS — Summary statistics
   -------------------------------------------------------------------------- */
.ds-stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--ds-space-md);
}

.ds-stat-card {
  background: var(--ds-bg-card);
  border-radius: var(--ds-card-radius);
  box-shadow: var(--ds-card-shadow);
  padding: var(--ds-space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-xs);
}

.ds-stat-card__label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--ds-text-secondary);
  letter-spacing: 0.025em;
}

.ds-stat-card__value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ds-text-primary);
  line-height: 1.2;
}

.ds-stat-card__value--success { color: var(--ds-color-success-text); }
.ds-stat-card__value--warning { color: var(--ds-color-warning-text); }
.ds-stat-card__value--danger  { color: var(--ds-color-danger-text); }
.ds-stat-card__value--accent  { color: var(--ds-brand-accent); }

/* Page header icon block (colored square preceding the page title) */
.ds-page-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--ds-border-radius-md);
  background: var(--ds-brand-selected-bg);
  color: var(--ds-brand-selected);
  font-size: 1.125rem;
  margin-right: var(--ds-space-sm);
  vertical-align: middle;
}

/* Category color dot used in budget/category list rows */
.ds-category-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: var(--ds-space-xs);
  flex-shrink: 0;
}

.ds-list-row--danger {
  background: var(--ds-color-danger-bg);
}

/* Thin proportional bar under a category sidebar row */
.ds-category-bar-track {
  height: 3px;
  margin-top: 4px;
  background: #e3ddd2;
  border-radius: 2px;
}

.ds-category-bar-track__fill {
  height: 100%;
  border-radius: 2px;
}

/* Simplified monthly bar strip (no axis, no gridlines) above the expense list */
.ds-month-bars {
  display: flex;
  align-items: flex-end;
  gap: var(--ds-space-sm);
  height: 80px;
  padding-top: var(--ds-space-sm);
}

.ds-month-bars__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  cursor: pointer;
}

.ds-month-bars__item--future {
  cursor: default;
}

.ds-month-bars__track {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
}

.ds-month-bars__fill {
  width: 100%;
  background: var(--ds-color-neutral);
  border-radius: 6px 6px 0 0;
  min-height: 2px;
  transition: height 0.2s ease;
}

.ds-month-bars__fill--current {
  background: var(--ds-brand-accent);
}

.ds-month-bars__label {
  margin-top: var(--ds-space-xs);
  font-size: 0.75rem;
  color: var(--ds-text-secondary);
}

.ds-month-bars__label--current {
  color: var(--ds-brand-accent);
  font-weight: 700;
}

.ds-month-bars__item--future .ds-month-bars__label {
  color: var(--ds-text-muted);
  opacity: 0.6;
}

/* --------------------------------------------------------------------------
   6. BUTTONS — Primary, Secondary, Icon, Danger
   -------------------------------------------------------------------------- */
.ds-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--ds-space-xs);
  font-family: var(--ds-font-family);
  font-size: 0.875rem;
  font-weight: 500;
  padding: var(--ds-space-sm) var(--ds-space-md);
  border-radius: var(--ds-border-radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--ds-transition);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.5;
}

.ds-btn--primary {
  background: var(--ds-brand-primary);
  color: var(--ds-text-on-dark);
  border-color: var(--ds-brand-primary);
}
.ds-btn--primary:hover {
  background: #2d2d3f;
  border-color: #2d2d3f;
  color: var(--ds-text-on-dark);
}

.ds-btn--secondary {
  background: var(--ds-bg-card);
  color: var(--ds-text-primary);
  border-color: var(--ds-border-color);
}
.ds-btn--secondary:hover {
  background: var(--ds-color-neutral-bg);
  border-color: #d1d5db;
}

.ds-btn--danger {
  background: var(--ds-color-danger-bg);
  color: var(--ds-color-danger-text);
  border-color: transparent;
}
.ds-btn--danger:hover {
  background: #fecaca;
}

.ds-btn--icon {
  padding: var(--ds-space-xs) var(--ds-space-sm);
  background: transparent;
  color: var(--ds-text-secondary);
  border: none;
}
.ds-btn--icon:hover {
  color: var(--ds-text-primary);
  background: var(--ds-color-neutral-bg);
}

.ds-btn--sm {
  font-size: 0.75rem;
  padding: 4px 10px;
}

/* --------------------------------------------------------------------------
   7. STATUS BADGES
   -------------------------------------------------------------------------- */
.ds-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 9999px;
  line-height: 1.5;
  white-space: nowrap;
}

.ds-badge--success {
  background: var(--ds-color-success-bg);
  color: var(--ds-color-success-text);
}
.ds-badge--warning {
  background: var(--ds-color-warning-bg);
  color: var(--ds-color-warning-text);
}
.ds-badge--danger {
  background: var(--ds-color-danger-bg);
  color: var(--ds-color-danger-text);
}
.ds-badge--neutral {
  background: var(--ds-color-neutral-bg);
  color: var(--ds-color-neutral-text);
}

/* --------------------------------------------------------------------------
   8. SEGMENT FILTER BUTTONS
   -------------------------------------------------------------------------- */
.ds-filter-group {
  display: inline-flex;
  gap: 2px;
  background: var(--ds-color-neutral-bg);
  border-radius: var(--ds-border-radius-sm);
  padding: 2px;
}

.ds-filter-btn {
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--ds-text-secondary);
  cursor: pointer;
  transition: all var(--ds-transition);
  white-space: nowrap;
}

.ds-filter-btn:hover {
  color: var(--ds-text-primary);
}

.ds-filter-btn[aria-pressed="true"],
.ds-filter-btn.active {
  background: var(--ds-bg-card);
  color: var(--ds-text-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  font-weight: 600;
}

.ds-filter-btn--accent.active {
  background: var(--ds-brand-accent);
  color: var(--ds-text-on-dark);
  box-shadow: none;
}

/* --------------------------------------------------------------------------
   9. LIST / TABLE CONTAINERS & ROWS
   -------------------------------------------------------------------------- */
.ds-list-container {
  background: var(--ds-bg-card);
  border-radius: var(--ds-card-radius);
  box-shadow: var(--ds-card-shadow);
  overflow: hidden;
}

.ds-list-header {
  padding: var(--ds-space-md) var(--ds-space-lg);
  border-bottom: 1px solid var(--ds-border-color);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ds-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ds-list-row {
  display: flex;
  align-items: center;
  padding: var(--ds-space-md) var(--ds-space-lg);
  border-bottom: 1px solid var(--ds-border-color);
  transition: background var(--ds-transition);
}

.ds-list-row:last-child {
  border-bottom: none;
}

.ds-list-row:hover {
  background: #fafafa;
}

/* Date group header for expense list */
.ds-date-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--ds-space-sm) var(--ds-space-lg);
  background: var(--ds-color-neutral-bg);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ds-text-secondary);
  border-bottom: 1px solid var(--ds-border-color);
}

.ds-date-group-header__subtotal {
  font-weight: 700;
  color: var(--ds-text-primary);
}

/* --------------------------------------------------------------------------
   10. PROGRESS BARS
   -------------------------------------------------------------------------- */
.ds-progress {
  height: 8px;
  background: var(--ds-color-neutral-bg);
  border-radius: 9999px;
  overflow: hidden;
}

.ds-progress__bar {
  height: 100%;
  border-radius: 9999px;
  transition: width 0.3s ease;
}

.ds-progress__bar--success { background: var(--ds-color-success); }
.ds-progress__bar--warning { background: var(--ds-color-warning); }
.ds-progress__bar--danger  { background: var(--ds-color-danger); }
.ds-progress__bar--neutral { background: var(--ds-color-neutral); }

/* --------------------------------------------------------------------------
   11. PAGINATION
   -------------------------------------------------------------------------- */
.ds-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--ds-space-sm);
  padding: var(--ds-space-md) 0;
}

.ds-pagination__btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.875rem;
  font-weight: 500;
  padding: var(--ds-space-sm) var(--ds-space-md);
  border-radius: var(--ds-border-radius-sm);
  border: 1px solid var(--ds-border-color);
  background: var(--ds-bg-card);
  color: var(--ds-text-primary);
  cursor: pointer;
  transition: all var(--ds-transition);
  text-decoration: none;
}

.ds-pagination__btn:hover {
  background: var(--ds-color-neutral-bg);
  border-color: #d1d5db;
  color: var(--ds-text-primary);
}

.ds-pagination__btn:disabled,
.ds-pagination__btn.disabled {
  opacity: 0.4;
  pointer-events: none;
}

.ds-pagination__info {
  font-size: 0.8125rem;
  color: var(--ds-text-secondary);
}

/* --------------------------------------------------------------------------
   12. LOADING / EMPTY / ERROR STATES (visual layer)
   -------------------------------------------------------------------------- */

/* Loading spinner */
.ds-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--ds-space-2xl) var(--ds-space-lg);
  gap: var(--ds-space-md);
}

.ds-loading__spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--ds-border-color);
  border-top-color: var(--ds-brand-accent);
  border-radius: 50%;
  animation: ds-spin 0.6s linear infinite;
}

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

.ds-loading__text {
  font-size: 0.875rem;
  color: var(--ds-text-secondary);
}

/* Empty state */
.ds-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--ds-space-2xl) var(--ds-space-lg);
  gap: var(--ds-space-md);
  text-align: center;
}

.ds-empty__icon {
  font-size: 2.5rem;
  color: var(--ds-text-muted);
}

.ds-empty__title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ds-text-primary);
}

.ds-empty__message {
  font-size: 0.875rem;
  color: var(--ds-text-secondary);
  max-width: 360px;
}

/* Error state */
.ds-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--ds-space-2xl) var(--ds-space-lg);
  gap: var(--ds-space-md);
  text-align: center;
}

.ds-error__icon {
  font-size: 2.5rem;
  color: var(--ds-color-danger);
}

.ds-error__title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ds-text-primary);
}

.ds-error__message {
  font-size: 0.875rem;
  color: var(--ds-text-secondary);
  max-width: 360px;
}

.ds-error__retry {
  margin-top: var(--ds-space-sm);
}

/* --------------------------------------------------------------------------
   13. PAGE LAYOUT HELPERS
   -------------------------------------------------------------------------- */
.ds-page-container {
  max-width: 1080px;
  margin: 0 auto;
  padding: var(--ds-space-lg);
}

.ds-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--ds-space-lg);
  flex-wrap: wrap;
  gap: var(--ds-space-md);
}

.ds-page-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--ds-text-primary);
  margin: 0;
}

.ds-unified-page-title {
  font-size: 22px !important;
  font-weight: 800 !important;
  line-height: 1.2;
  letter-spacing: -.02em;
}

.ds-list-page-kicker {
  display: block;
  margin-bottom: 2px;
  color: #989ba2;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .16em;
  line-height: 1.5;
}

.ds-list-page-title {
  color: #17171c;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -.02em;
  line-height: 1.2;
}

.ds-page-description {
  font-size: 0.875rem;
  color: var(--ds-text-secondary);
  margin: 0;
}

.ds-page-actions {
  display: flex;
  align-items: center;
  gap: var(--ds-space-sm);
}

.ds-section {
  margin-bottom: var(--ds-space-lg);
}

/* Compact period selector on the budget page. */
.budget-period-filter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ds-space-lg);
  min-height: 72px;
  padding: 12px var(--ds-space-lg);
  background: var(--ds-bg-card);
  border: 1px solid var(--ds-border-color);
  border-radius: var(--ds-card-radius);
  box-shadow: var(--ds-card-shadow);
}

.budget-period-filter__label,
.budget-period-filter__controls,
.budget-period-filter__field {
  display: flex;
  align-items: center;
}

.budget-period-filter__label {
  gap: var(--ds-space-sm);
  min-width: 0;
}

.budget-period-filter__icon {
  display: inline-flex;
  flex: 0 0 38px;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--ds-brand-selected-bg);
  color: var(--ds-brand-selected);
}

.budget-period-filter__label-copy {
  display: flex;
  flex-direction: column;
}

.budget-period-filter__title {
  color: var(--ds-text-primary);
  font-size: 0.875rem;
  font-weight: 700;
}

.budget-period-filter__hint {
  margin-top: 2px;
  color: var(--ds-text-secondary);
  font-size: 0.6875rem;
}

.budget-period-filter__controls {
  flex: 0 0 auto;
  gap: var(--ds-space-sm);
}

.budget-period-filter__field {
  gap: 6px;
}

.budget-period-filter__select {
  height: 42px;
  padding-top: 0.375rem;
  padding-bottom: 0.375rem;
  border-color: var(--ds-border-color);
  border-radius: 10px;
  background-color: #fbfbfa;
  color: var(--ds-text-primary);
  font-weight: 600;
}

.budget-period-filter__select:focus {
  background-color: var(--ds-bg-card);
  border-color: var(--ds-brand-accent);
  box-shadow: 0 0 0 3px var(--ds-brand-selected-bg);
}

.budget-period-filter__select--year { width: 116px; }
.budget-period-filter__select--month { width: 78px; }

.budget-period-filter__unit {
  color: var(--ds-text-secondary);
  font-size: 0.8125rem;
  font-weight: 600;
}

.budget-period-filter__separator {
  color: var(--ds-border-color);
  font-size: 1.125rem;
}

@media (max-width: 575.98px) {
  .budget-period-filter {
    gap: var(--ds-space-sm);
    min-height: 64px;
    padding: 10px var(--ds-space-md);
  }

  .budget-period-filter__label { gap: 6px; }

  .budget-period-filter__icon {
    flex-basis: 34px;
    width: 34px;
    height: 34px;
  }

  .budget-period-filter__hint,
  .budget-period-filter__separator { display: none; }

  .budget-period-filter__controls { gap: 6px; }
  .budget-period-filter__field { gap: 3px; }

  .budget-period-filter__select {
    height: 40px;
    padding-left: 0.625rem;
    padding-right: 1.75rem;
    background-position: right 0.45rem center;
    background-size: 12px 9px;
    font-size: 0.875rem;
  }

  .budget-period-filter__select--year { width: 91px; }
  .budget-period-filter__select--month { width: 58px; }
  .budget-period-filter__unit { font-size: 0.75rem; }
}

/* Budget categories that have actual spending but no configured budget. */
.budget-unallocated-hint {
  margin-top: 4px;
  color: var(--ds-text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.3;
}

.budget-unallocated-hint--over {
  color: var(--ds-color-danger-text);
  font-weight: 700;
}

.budget-allocation {
  padding: var(--ds-space-lg);
  border: 1px solid var(--ds-border-color);
  border-radius: var(--ds-radius-md);
  background: var(--ds-surface, #fff);
}

.budget-allocation__title {
  margin: 0;
  color: var(--ds-text-primary);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
}

.budget-allocation__subtitle {
  margin: 4px 0 0;
  color: var(--ds-text-secondary);
  font-size: 0.8125rem;
  line-height: 1.4;
}

.budget-allocation__body {
  display: flex;
  align-items: center;
  gap: var(--ds-space-xl);
  margin-top: var(--ds-space-lg);
}

.budget-allocation-donut {
  position: relative;
  width: 160px;
  height: 160px;
  flex-shrink: 0;
}

.budget-allocation-donut svg {
  display: block;
  width: 100%;
  height: 100%;
}

.budget-allocation-donut__track {
  fill: none;
  stroke-width: 22;
  stroke: #f0ede5;
}

.budget-allocation-donut__center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.budget-allocation-donut__center span {
  color: var(--ds-text-secondary);
  font-size: 10px;
  font-weight: 600;
}

.budget-allocation-donut__center strong {
  color: var(--ds-text-primary);
  font-size: 15px;
  font-weight: 700;
}

.budget-allocation-donut__over {
  margin-top: 2px;
  color: var(--ds-color-danger-text);
  font-size: 9px;
  font-weight: 600;
  font-style: normal;
  text-align: center;
  line-height: 1.2;
}

.budget-allocation__legend {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.budget-allocation__legend-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.budget-allocation__swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.budget-allocation__legend-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ds-text-primary);
  font-size: 0.875rem;
  font-weight: 600;
}

.budget-allocation__legend-amount {
  color: var(--ds-text-primary);
  font-size: 0.875rem;
  font-weight: 700;
  white-space: nowrap;
}

@media (max-width: 575.98px) {
  .budget-allocation__body {
    flex-direction: column;
    align-items: stretch;
  }

  .budget-allocation-donut {
    margin: 0 auto;
  }
}

.budget-uncovered {
  border: 0;
}

.budget-uncovered__header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(120px, auto) 120px;
  align-items: center;
  gap: var(--ds-space-lg);
}

.budget-uncovered__heading {
  display: flex;
  align-items: center;
  gap: var(--ds-space-sm);
  min-width: 0;
}

.budget-uncovered__title {
  margin: 0;
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
  letter-spacing: inherit;
  line-height: 1.3;
  text-transform: none;
}

.budget-uncovered__count {
  flex: 0 0 auto;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--ds-color-neutral-bg);
  color: var(--ds-text-secondary);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: normal;
  text-transform: none;
}

.budget-uncovered__actual-heading {
  text-align: right;
}

.budget-uncovered__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(120px, auto) 120px;
  align-items: center;
  gap: var(--ds-space-lg);
  min-height: 60px;
  padding: var(--ds-space-md) var(--ds-space-lg);
  border-bottom: 1px solid var(--ds-border-color);
  transition: background var(--ds-transition);
}

.budget-uncovered__row:last-child {
  border-bottom: 0;
}

.budget-uncovered__row:hover {
  background: #fafafa;
}

.budget-uncovered__category {
  min-width: 0;
}

.budget-uncovered__category-name {
  display: block;
  overflow-wrap: anywhere;
  color: var(--ds-text-primary);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.4;
}

.budget-uncovered__actual {
  text-align: right;
}

.budget-uncovered__actual-value {
  display: block;
  color: var(--ds-text-primary);
  font-size: 0.9375rem;
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
}

.budget-uncovered__action {
  justify-self: end;
  white-space: nowrap;
}

@media (max-width: 575.98px) {
  .budget-uncovered__header {
    grid-template-columns: minmax(0, 1fr) auto;
    padding: var(--ds-space-md);
  }

  .budget-uncovered__actual-heading,
  .budget-uncovered__header > span:last-child {
    display: none;
  }

  .budget-uncovered__row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--ds-space-sm) var(--ds-space-md);
    padding: var(--ds-space-md);
  }

  .budget-uncovered__category {
    grid-column: 1 / -1;
  }

  .budget-uncovered__actual {
    text-align: left;
  }

  .budget-uncovered__action {
    grid-column: 2;
  }
}

/* Category budget list rows (budget_list.html) */
.budget-category-row {
  display: flex;
  align-items: center;
  gap: var(--ds-space-md);
  width: 100%;
}

.budget-category-row__name {
  flex: 1 1 auto;
  min-width: 0;
}

.budget-category-row__budget,
.budget-category-row__actual,
.budget-category-row__remaining {
  flex: 0 0 80px;
  text-align: right;
  font-size: 0.875rem;
}

.budget-category-row__usage {
  flex: 0 0 180px;
}

.budget-category-row__actions {
  flex: 0 0 80px;
  text-align: right;
}

@media (max-width: 767.98px) {
  .ds-list-header.budget-category-row {
    display: none;
  }

  .ds-list-row.budget-category-row {
    flex-direction: column;
    align-items: stretch;
    gap: var(--ds-space-sm);
  }

  .budget-category-row__budget,
  .budget-category-row__actual,
  .budget-category-row__remaining,
  .budget-category-row__usage,
  .budget-category-row__actions {
    flex: none;
    width: 100%;
  }

  .budget-category-row__budget,
  .budget-category-row__actual,
  .budget-category-row__remaining {
    display: flex;
    justify-content: space-between;
    text-align: left;
    color: var(--ds-text-secondary);
  }

  .budget-category-row__budget::before,
  .budget-category-row__actual::before,
  .budget-category-row__remaining::before {
    content: attr(data-label);
    font-weight: 600;
  }

  .budget-category-row__actions {
    display: flex;
    justify-content: flex-end;
  }
}

/* --------------------------------------------------------------------------
   14. STOCK CARD (fade-in animation)
   -------------------------------------------------------------------------- */
.ds-stock-card {
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.ds-stock-card.ds-fade-in {
  animation: ds-fadeIn 0.2s ease forwards;
}

@keyframes ds-fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ds-stock-card.ds-fade-in {
    animation: none;
  }

  .ds-loading__spinner {
    animation-duration: 1.5s;
  }
}

/* --------------------------------------------------------------------------
   15. POPUP NOTIFICATIONS
   -------------------------------------------------------------------------- */
.ds-notification-stack {
  position: fixed;
  top: calc(1rem + env(safe-area-inset-top));
  right: calc(1rem + env(safe-area-inset-right));
  z-index: 1090;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: min(420px, calc(100vw - 2rem));
  pointer-events: none;
}

.ds-notification {
  margin: 0;
  border-radius: 0.75rem;
  box-shadow: 0 0.75rem 2rem rgba(15, 23, 42, 0.18);
  pointer-events: auto;
}

@media (max-width: 575.98px) {
  .ds-notification-stack {
    right: 1rem;
    left: 1rem;
    width: auto;
  }
}

/* --------------------------------------------------------------------------
   16. NOTO SANS JP FONT IMPORT
   -------------------------------------------------------------------------- */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;600;700&display=swap');
