/* ==========================================================================
   moai-finance design tokens — m-oai.com mint-dark base
   v2 (2026-05-09): 完璧クオリティ志向のリビルド
   - WCAG 2.2 AA 配慮 (color contrast / focus visible / skip-link)
   - mobile-first responsive (360px 〜)
   - dark mode 用 token は :root で先に確保 (今は未適用)
   ========================================================================== */

:root {
  /* Brand */
  --mint-50:  #effaf5;
  --mint-100: #d8f2e6;
  --mint-200: #b1e5cf;
  --mint-300: #7dd3b1;
  --mint-400: #4FCBA0;
  --mint-500: #2EAB80;
  --mint-600: #1B7A5A;
  --mint-700: #145a43;
  --mint-800: #0e3f2f;

  --mint:        var(--mint-400);
  --mint-dark:   var(--mint-500);
  --mint-darker: var(--mint-600);

  /* Surface */
  --bg:           #f7fbf9;
  --bg-elevated:  #ffffff;
  --surface:      #ffffff;
  --surface-2:    #f0f7f3;
  --surface-3:    #e6f0eb;

  /* Border */
  --border:        #d8e6e0;
  --border-strong: #b9cdc4;
  --border-focus:  rgba(79,203,160,0.55);

  /* Text */
  --text:        #15281f;
  --text-strong: #0a1612;
  --text-mute:   #5d6f68;
  --text-soft:   #889b94;
  --text-on-mint: #ffffff;

  /* Semantic */
  --success:      #2EAB80;
  --success-soft: #d8f2e6;
  --warn:         #d97a06;
  --warn-soft:    #fce8c5;
  --danger:       #c0392b;
  --danger-soft:  #fde0db;
  --info:         #1f6dc4;
  --info-soft:    #dde9fb;

  /* Shadow */
  --shadow-xs: 0 1px 1px rgba(15,40,30,0.04);
  --shadow-sm: 0 1px 2px rgba(15,40,30,0.05), 0 1px 3px rgba(15,40,30,0.04);
  --shadow:    0 1px 2px rgba(15,40,30,0.04), 0 6px 16px rgba(46,171,128,0.08);
  --shadow-md: 0 4px 6px rgba(15,40,30,0.05), 0 12px 28px rgba(46,171,128,0.12);
  --shadow-lg: 0 12px 30px rgba(15,40,30,0.10), 0 24px 60px rgba(46,171,128,0.16);

  /* Radius */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius:    10px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  /* Spacing scale (4-base) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 32px;
  --sp-8: 40px;
  --sp-9: 56px;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Noto Sans JP', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'Menlo', 'Consolas', 'Roboto Mono', monospace;
  --fs-12: 12px;
  --fs-13: 13px;
  --fs-14: 14px;
  --fs-15: 15px;
  --fs-16: 16px;
  --fs-18: 18px;
  --fs-20: 20px;
  --fs-22: 22px;
  --fs-26: 26px;
  --fs-32: 32px;
  --fs-40: 40px;

  /* Layout */
  --header-h: 56px;
  --max-width: 1240px;

  /* Motion */
  --t-fast: 0.12s ease;
  --t-base: 0.2s cubic-bezier(.4,0,.2,1);
  --t-slow: 0.32s cubic-bezier(.4,0,.2,1);

  /* Z-index */
  --z-toast: 9000;
  --z-modal: 8000;
  --z-popover: 7000;
  --z-header: 100;
}

/* dark mode tokens (未適用、将来用) */
@media (prefers-color-scheme: dark) {
  :root.dark-enabled {
    --bg:           #0e1a16;
    --bg-elevated:  #14241e;
    --surface:      #14241e;
    --surface-2:    #1a2f27;
    --border:       #25433a;
    --border-strong:#2f5446;
    --text:         #e8f3ee;
    --text-strong:  #ffffff;
    --text-mute:    #9ab2a8;
    --text-soft:    #6f867f;
  }
}

/* ==========================================================================
   Reset / base
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-14);
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "palt" 1, "tnum" 1;
}

a { color: var(--mint-darker); text-decoration: none; transition: color var(--t-fast); }
a:hover { text-decoration: underline; }
a:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; border-radius: var(--radius-xs); text-decoration: none; }

img, svg { max-width: 100%; display: block; }

button { font-family: inherit; }

/* skip link (a11y) */
.skip-link {
  position: absolute;
  left: 8px; top: 8px;
  background: var(--mint-darker);
  color: white;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 13px;
  z-index: 9999;
  transform: translateY(-200%);
  transition: transform var(--t-base);
}
.skip-link:focus { transform: translateY(0); text-decoration: none; }

/* ==========================================================================
   Header / Nav
   ========================================================================== */

header.app-header {
  position: sticky; top: 0;
  z-index: var(--z-header);
  background: linear-gradient(180deg, var(--mint-600) 0%, var(--mint-700) 100%);
  color: var(--text-on-mint);
  padding: 0 var(--sp-6);
  display: flex; gap: var(--sp-6); align-items: center;
  height: var(--header-h);
  box-shadow: 0 1px 0 rgba(0,0,0,0.06), 0 6px 14px rgba(20,90,67,0.12);
}
header.app-header .brand {
  display: flex; align-items: center; gap: 8px;
  font-size: var(--fs-16); font-weight: 800;
  letter-spacing: 0.04em;
  color: white;
  text-decoration: none;
  white-space: nowrap;
}
header.app-header .brand:hover { text-decoration: none; }
header.app-header .brand .logo {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: rgba(255,255,255,0.18);
  display: grid; place-items: center;
  font-weight: 900; color: #ffd84d;
  font-size: 16px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.22);
}
header.app-header .brand-text {
  font-size: var(--fs-16); font-weight: 800; margin: 0;
  letter-spacing: 0.04em; line-height: 1;
}
header.app-header .brand-text .ai-mark { color: #ffd84d; }
header.app-header nav {
  display: flex; gap: 4px;
  flex: 1;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
header.app-header nav::-webkit-scrollbar { height: 0; }
header.app-header nav a {
  color: rgba(255,255,255,0.82);
  font-weight: 600;
  font-size: var(--fs-13);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast);
  position: relative;
}
header.app-header nav a:hover {
  background: rgba(255,255,255,0.10);
  color: white;
  text-decoration: none;
}
header.app-header nav a.active {
  background: rgba(255,255,255,0.18);
  color: white;
  box-shadow: inset 0 -2px 0 #ffd84d;
}
header.app-header nav a:focus-visible {
  outline: 2px solid #ffd84d; outline-offset: 1px;
}
header.app-header .who {
  font-size: var(--fs-12);
  opacity: 0.95;
  display: flex; align-items: center; gap: 8px;
  color: rgba(255,255,255,0.92);
  white-space: nowrap;
}
header.app-header .who .avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  display: grid; place-items: center;
  font-weight: 700; font-size: 12px;
  color: white;
}

/* ==========================================================================
   Main / page layout
   ========================================================================== */

main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--sp-6);
}

.page-title {
  display: flex; align-items: center; gap: var(--sp-3);
  margin: 0 0 var(--sp-5);
  flex-wrap: wrap;
}
.page-title h2 {
  margin: 0; font-size: var(--fs-22); font-weight: 800;
  color: var(--text-strong);
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.page-title .sub {
  color: var(--text-mute); font-size: var(--fs-13); font-weight: 500;
}
.page-title .spacer { flex: 1; min-width: 8px; }

/* page-level h1 (was h2 prior to v0.4.1 — promoted for proper heading hierarchy + a11y) */
main h1, .page-title h1, body > h1 { font-size: var(--fs-22, 22px); font-weight: 800; margin: 0 0 var(--sp-4); color: var(--text-strong); letter-spacing: 0.005em; }
h2 { font-size: var(--fs-20); font-weight: 700; margin: 0 0 var(--sp-4); color: var(--text-strong); }
h3 { font-size: var(--fs-15); font-weight: 700; margin: 0 0 var(--sp-3); color: var(--text-strong); letter-spacing: 0.01em; }
h4 { font-size: var(--fs-13); font-weight: 700; margin: 0 0 var(--sp-2); color: var(--text-mute); letter-spacing: 0.06em; text-transform: uppercase; }

/* ==========================================================================
   Card
   ========================================================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-5);
  margin-bottom: var(--sp-5);
  transition: box-shadow var(--t-base);
}
.card.flush { padding: 0; overflow: hidden; }
.card .card-head {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: var(--sp-3);
}
.card .card-head h3 { margin: 0; }
.card .card-body { padding: var(--sp-5); }
.card .card-foot {
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  display: flex; gap: var(--sp-2); align-items: center;
}

.card-grid {
  display: grid;
  gap: var(--sp-5);
}
.card-grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }
.card-grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

/* ==========================================================================
   KPI cards
   ========================================================================== */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}
.kpi {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4) var(--sp-5);
  box-shadow: var(--shadow-sm);
  transition: transform var(--t-base), box-shadow var(--t-base);
  overflow: hidden;
}
.kpi:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.kpi::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--mint-darker); opacity: 0.85;
}
.kpi.income::before { background: var(--mint-darker); }
.kpi.expense::before { background: var(--warn); }
.kpi.net.positive::before { background: var(--success); }
.kpi.net.negative::before { background: var(--danger); }
.kpi.overdue::before { background: var(--danger); }
.kpi.count::before { background: var(--info); }

.kpi .label {
  font-size: 11px; color: var(--text-mute); font-weight: 700;
  letter-spacing: 0.05em; text-transform: uppercase;
  display: flex; align-items: center; gap: 6px;
}
.kpi .label .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--mint-darker);
}
.kpi.expense .label .dot { background: var(--warn); }
.kpi.net.positive .label .dot { background: var(--success); }
.kpi.net.negative .label .dot { background: var(--danger); }
.kpi.overdue .label .dot { background: var(--danger); }
.kpi.count .label .dot { background: var(--info); }

.kpi .value {
  font-size: var(--fs-26);
  font-weight: 800;
  color: var(--text-strong);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  letter-spacing: -0.01em;
}
.kpi.income .value { color: var(--mint-darker); }
.kpi.expense .value { color: var(--warn); }
.kpi.net.positive .value { color: var(--success); }
.kpi.net.negative .value { color: var(--danger); }
.kpi.overdue .value { color: var(--danger); }
.kpi.count .value { color: var(--info); }

.kpi .sub {
  font-size: var(--fs-12); color: var(--text-mute); margin-top: 6px;
  font-weight: 500;
}
.kpi .delta {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 700; padding: 2px 8px;
  border-radius: var(--radius-pill); margin-top: 8px;
  background: var(--surface-2); color: var(--text-mute);
}
.kpi .delta.up { background: var(--success-soft); color: var(--mint-darker); }
.kpi .delta.down { background: var(--danger-soft); color: var(--danger); }

/* ==========================================================================
   Alert / banner
   ========================================================================== */

.alert-card {
  display: flex;
  gap: var(--sp-3);
  align-items: center;
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  border-left: 4px solid var(--danger);
  border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-5);
}
.alert-card.warn { background: var(--warn-soft); border-color: var(--warn); border-left-color: var(--warn); }
.alert-card.info { background: var(--info-soft); border-color: var(--info); border-left-color: var(--info); }
.alert-card.success { background: var(--success-soft); border-color: var(--success); border-left-color: var(--success); }

.alert-card .alert-icon {
  width: 28px; height: 28px; flex-shrink: 0;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--danger); color: white;
  font-size: 16px; font-weight: 800;
}
.alert-card.warn .alert-icon { background: var(--warn); }
.alert-card.info .alert-icon { background: var(--info); }
.alert-card.success .alert-icon { background: var(--success); }

.alert-card .alert-body { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.alert-card .alert-body strong { color: var(--text-strong); font-size: var(--fs-14); }
.alert-card .alert-body .muted { font-size: var(--fs-12); color: var(--text-mute); }

/* ==========================================================================
   Table
   ========================================================================== */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-13);
}
table th {
  text-align: left;
  padding: 10px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  color: var(--mint-darker);
  font-size: var(--fs-12);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table tbody tr { transition: background var(--t-fast); }
table tbody tr:hover td { background: var(--surface-2); }
table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table td.muted, table td .muted { color: var(--text-mute); }
.income-cell { color: var(--mint-darker); font-weight: 700; }
.expense-cell { color: var(--warn); font-weight: 700; }

/* sortable */
table th.sortable { cursor: pointer; user-select: none; }
table th.sortable:hover { background: var(--surface-3); }
table th.sortable .arrow { font-size: 10px; opacity: 0.4; margin-left: 4px; }
table th.sortable.active .arrow { opacity: 1; color: var(--mint-darker); }

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center; gap: 6px;
  padding: 8px 16px;
  background: var(--mint-darker);
  color: white;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: var(--fs-13);
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  letter-spacing: 0.02em;
  transition: background var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
  white-space: nowrap;
  line-height: 1.2;
}
.btn:hover { background: var(--mint-500); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.btn.secondary {
  background: var(--surface);
  color: var(--mint-darker);
  border: 1px solid var(--border-strong);
}
.btn.secondary:hover { background: var(--surface-2); border-color: var(--mint-darker); }
.btn.ghost {
  background: transparent;
  color: var(--mint-darker);
  border: 1px solid transparent;
}
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: #a52e21; }
.btn.warn { background: var(--warn); border-color: var(--warn); }
.btn.warn:hover { background: #b56305; }
.btn.small { padding: 5px 10px; font-size: var(--fs-12); }
.btn.large { padding: 12px 22px; font-size: var(--fs-15); }
.btn.block { display: flex; width: 100%; justify-content: center; }
.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.45; cursor: not-allowed; transform: none;
}
.btn .icon { font-size: 14px; line-height: 1; }

.btn-group { display: inline-flex; }
.btn-group .btn {
  border-radius: 0;
  border-right-width: 0;
}
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.btn-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; border-right-width: 1px; }

/* quick action card-button (dashboard) */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}
.quick-action {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: inherit;
  text-decoration: none;
  transition: transform var(--t-base), box-shadow var(--t-base), border-color var(--t-base);
  box-shadow: var(--shadow-sm);
}
.quick-action:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
  border-color: var(--mint-400);
  text-decoration: none;
}
.quick-action:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.quick-action .qa-icon {
  width: 44px; height: 44px; flex-shrink: 0;
  border-radius: var(--radius);
  background: var(--mint-50);
  display: grid; place-items: center;
  font-size: 22px;
}
.quick-action .qa-icon.tx { background: var(--success-soft); color: var(--mint-darker); }
.quick-action .qa-icon.inv { background: var(--info-soft); color: var(--info); }
.quick-action .qa-icon.rcpt { background: var(--warn-soft); color: var(--warn); }
.quick-action .qa-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.quick-action .qa-title { font-weight: 700; font-size: var(--fs-14); color: var(--text-strong); }
.quick-action .qa-desc { font-size: var(--fs-12); color: var(--text-mute); }

/* ==========================================================================
   Form controls
   ========================================================================== */

.row {
  display: flex; gap: var(--sp-3);
  flex-wrap: wrap; align-items: flex-end;
  margin-bottom: var(--sp-3);
}
.row.no-bottom { margin-bottom: 0; }
.row.center { align-items: center; }
.row.tight { gap: var(--sp-2); }

.field {
  display: flex;
  flex-direction: column;
  min-width: 140px;
}
.field.grow { flex: 1; }
.field label, .field .label {
  font-size: 11px;
  color: var(--text-mute);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 5px;
}
.field label .req { color: var(--danger); margin-left: 4px; }
.field input,
.field select,
.field textarea {
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: var(--fs-13);
  font-family: inherit;
  background: white;
  color: var(--text);
  width: 100%;
  transition: border var(--t-fast), box-shadow var(--t-fast);
}
.field input:hover,
.field select:hover,
.field textarea:hover {
  border-color: var(--mint-400);
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--mint);
  box-shadow: 0 0 0 3px rgba(79,203,160,0.18);
}
.field input[disabled],
.field select[disabled],
.field textarea[disabled] {
  background: var(--surface-2);
  color: var(--text-mute);
  cursor: not-allowed;
}
.field textarea { resize: vertical; min-height: 80px; }
.field .hint { font-size: 11px; color: var(--text-soft); margin-top: 4px; }
.field .err { font-size: 11px; color: var(--danger); margin-top: 4px; font-weight: 600; }
.field input.invalid, .field select.invalid, .field textarea.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(192,57,43,0.14);
}

/* numeric input — bigger amount feel */
.field input.amount {
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-18);
  font-weight: 700;
  text-align: right;
  letter-spacing: 0.02em;
}

/* check / radio */
.check {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-13); font-weight: 600; color: var(--text);
  cursor: pointer; user-select: none;
}
.check input { width: 16px; height: 16px; cursor: pointer; }

/* ==========================================================================
   Toolbar / pagination / spacer
   ========================================================================== */

.toolbar {
  display: flex; gap: var(--sp-2);
  flex-wrap: wrap; align-items: center;
  margin-bottom: var(--sp-3);
}
.spacer { flex: 1; }

.pagination {
  display: flex; gap: var(--sp-2);
  align-items: center; justify-content: flex-end;
  padding: var(--sp-3) 0; font-size: var(--fs-12);
  color: var(--text-mute);
}
.pagination .btn { padding: 5px 10px; font-size: var(--fs-12); }

/* ==========================================================================
   Tags / chips / badges
   ========================================================================== */

.tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.tag.income, .tag.success { background: var(--success-soft); color: var(--mint-darker); }
.tag.expense, .tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.info { background: var(--info-soft); color: var(--info); }
.tag.neutral { background: var(--surface-3); color: var(--text-mute); }

/* status badges (invoices) */
.status-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.status-badge::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}
.status-badge.draft { background: var(--surface-3); color: var(--text-mute); }
.status-badge.issued { background: var(--info-soft); color: var(--info); }
.status-badge.sent { background: #e2eedc; color: #50783a; }
.status-badge.paid { background: var(--success-soft); color: var(--mint-darker); }
.status-badge.overdue { background: var(--danger-soft); color: var(--danger); }
.status-badge.cancelled { background: var(--surface-3); color: var(--text-soft); }
.status-badge.refunded { background: var(--warn-soft); color: var(--warn); }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-12); font-weight: 600;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--t-fast), border var(--t-fast);
  user-select: none;
}
.chip:hover { background: var(--surface-3); }
.chip.active { background: var(--mint-darker); color: white; border-color: var(--mint-darker); }
.chip.active:hover { background: var(--mint-500); }
.chip.outline { background: transparent; border-color: var(--border-strong); }
.chip.outline:hover { background: var(--surface-2); }

/* category dot */
.cat-dot {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 50%; margin-right: 6px;
  vertical-align: middle;
  background: var(--mint-400);
}

/* ==========================================================================
   Toast
   ========================================================================== */

.toast {
  position: fixed;
  bottom: var(--sp-6);
  right: var(--sp-6);
  background: var(--text-strong);
  color: white;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: var(--fs-13);
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(20px);
  transition: opacity var(--t-base), transform var(--t-base);
  z-index: var(--z-toast);
  max-width: 360px;
  display: flex; align-items: center; gap: 8px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--mint-darker); }
.toast.error { background: var(--danger); }
.toast.warn { background: var(--warn); }
.toast::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%;
  background: rgba(255,255,255,0.85); flex-shrink: 0;
}

/* ==========================================================================
   Empty state / loading
   ========================================================================== */

.empty {
  padding: var(--sp-7) var(--sp-5);
  text-align: center;
  color: var(--text-mute);
  font-size: var(--fs-13);
}
.empty .empty-icon {
  font-size: 32px;
  margin-bottom: var(--sp-3);
  opacity: 0.6;
}
.empty .empty-title { font-weight: 700; color: var(--text); margin-bottom: 4px; font-size: var(--fs-14); }
.empty .empty-desc { font-size: var(--fs-12); color: var(--text-mute); }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: skel 1.4s linear infinite;
  border-radius: var(--radius-xs);
}
@keyframes skel {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton.line { height: 12px; margin: 6px 0; }
.skeleton.box { height: 60px; }
.skeleton.h1 { height: 28px; width: 40%; margin-bottom: 12px; }

.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--mint-darker);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Modal (dialog)
   ========================================================================== */

dialog.modal {
  border: none;
  border-radius: var(--radius-md);
  padding: 0;
  max-width: 640px;
  width: 92%;
  box-shadow: var(--shadow-lg);
  background: var(--surface);
  color: var(--text);
}
dialog.modal::backdrop { background: rgba(15,40,30,0.45); backdrop-filter: blur(2px); }
dialog.modal[open] { animation: modal-in 0.22s cubic-bezier(.2,.8,.2,1); }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
dialog.modal .modal-header {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-16);
  font-weight: 700;
  color: var(--text-strong);
  display: flex; align-items: center; gap: 8px;
}
dialog.modal .modal-header .close {
  margin-left: auto;
  background: none; border: none;
  font-size: 22px; cursor: pointer; color: var(--text-mute);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  line-height: 1;
}
dialog.modal .modal-header .close:hover { background: var(--surface-2); color: var(--text); }
dialog.modal .modal-body {
  padding: var(--sp-5);
  max-height: 70vh; overflow-y: auto;
}
dialog.modal .modal-footer {
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border);
  display: flex; gap: var(--sp-2); justify-content: flex-end;
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

/* ==========================================================================
   Drag & drop file zone
   ========================================================================== */

.drop-zone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: var(--sp-6);
  text-align: center;
  background: var(--surface-2);
  color: var(--text-mute);
  cursor: pointer;
  transition: all var(--t-base);
  position: relative;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--mint-darker);
  background: var(--mint-50);
  color: var(--text-strong);
}
.drop-zone .dz-icon { font-size: 36px; margin-bottom: 8px; opacity: 0.7; }
.drop-zone .dz-title { font-weight: 700; color: var(--text); margin-bottom: 4px; }
.drop-zone .dz-desc { font-size: var(--fs-12); }
.drop-zone input[type="file"] { display: none; }
.drop-zone .dz-progress {
  margin-top: 12px;
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: hidden;
  display: none;
}
.drop-zone.uploading .dz-progress { display: block; }
.drop-zone .dz-progress-bar {
  height: 100%;
  background: var(--mint-darker);
  width: 30%;
  animation: progress-indet 1.4s linear infinite;
}
@keyframes progress-indet {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

/* ==========================================================================
   Charts (mini SVG)
   ========================================================================== */

.mini-chart {
  width: 100%;
  height: 180px;
  background: var(--surface);
  border-radius: var(--radius-sm);
}
.mini-chart-legend {
  display: flex; gap: 14px; flex-wrap: wrap;
  font-size: 11px; color: var(--text-mute);
  margin-top: 8px;
}
.mini-chart-legend .lg-dot {
  display: inline-block; width: 9px; height: 9px;
  border-radius: 50%; margin-right: 5px;
  vertical-align: middle;
}
.mini-chart-legend .lg-line {
  display: inline-block; width: 14px; height: 2px;
  margin-right: 5px; vertical-align: middle;
}

/* horizontal bar */
.hbar-list { display: flex; flex-direction: column; gap: 8px; }
.hbar {
  display: grid;
  grid-template-columns: minmax(120px, 30%) 1fr auto;
  gap: 10px;
  align-items: center;
  font-size: var(--fs-13);
}
.hbar .hb-label { color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar .hb-track { height: 18px; background: var(--surface-2); border-radius: var(--radius-pill); position: relative; overflow: hidden; }
.hbar .hb-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--mint-400) 0%, var(--mint-darker) 100%);
  transition: width var(--t-slow);
  min-width: 4px;
}
.hbar .hb-fill.expense { background: linear-gradient(90deg, #f5a83d 0%, var(--warn) 100%); }
.hbar .hb-fill.danger { background: linear-gradient(90deg, #e36352 0%, var(--danger) 100%); }
.hbar .hb-value { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text-strong); }

/* ==========================================================================
   Step indicator (invoice wizard)
   ========================================================================== */

.steps {
  display: flex; gap: 0; margin-bottom: var(--sp-5);
  list-style: none; padding: 0;
  font-size: var(--fs-13);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.steps li {
  flex: 1; min-width: 0;
  padding: 10px 14px;
  display: flex; align-items: center; gap: 8px;
  color: var(--text-mute);
  position: relative;
  border-right: 1px solid var(--border);
}
.steps li:last-child { border-right: 0; }
.steps li .step-num {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-3);
  color: var(--text-mute);
  font-weight: 700; font-size: 11px;
  flex-shrink: 0;
}
.steps li.active { color: var(--mint-darker); background: var(--surface); font-weight: 700; }
.steps li.active .step-num { background: var(--mint-darker); color: white; }
.steps li.done { color: var(--text); background: var(--surface); }
.steps li.done .step-num { background: var(--success-soft); color: var(--mint-darker); }
.steps li.done .step-num::before { content: '✓'; }
.steps li.done .step-num span { display: none; }

/* ==========================================================================
   Invoice preview (A4-ish)
   ========================================================================== */

.invoice-preview {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-7);
  max-width: 720px;
  margin: 0 auto;
  box-shadow: var(--shadow);
  font-size: var(--fs-13);
  color: var(--text);
}
.invoice-preview h2 { font-size: var(--fs-22); margin: 0 0 var(--sp-5); }
.invoice-preview table { font-size: var(--fs-12); }
.invoice-preview .ip-meta { display: grid; grid-template-columns: 1fr auto; gap: 16px; margin-bottom: var(--sp-5); }
.invoice-preview .ip-totals { margin-top: var(--sp-4); display: flex; justify-content: flex-end; }
.invoice-preview .ip-totals table { width: auto; min-width: 240px; }

/* timeline (audit-log) */
.timeline { display: flex; flex-direction: column; gap: 0; position: relative; padding-left: 22px; }
.timeline::before {
  content: ''; position: absolute; left: 9px; top: 0; bottom: 0;
  width: 2px; background: var(--border);
}
.tl-item { position: relative; padding: 8px 0 12px 14px; }
.tl-item::before {
  content: ''; position: absolute; left: -17px; top: 13px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--mint-darker);
  box-shadow: 0 0 0 3px var(--surface);
}
.tl-item.insert::before { background: var(--success); }
.tl-item.update::before { background: var(--info); }
.tl-item.delete::before { background: var(--danger); }
.tl-item.restore::before { background: var(--warn); }
.tl-item .tl-time { font-size: 11px; color: var(--text-mute); }
.tl-item .tl-title { font-weight: 700; font-size: var(--fs-13); margin: 2px 0; }
.tl-item .tl-desc { font-size: var(--fs-12); color: var(--text-mute); }

/* ==========================================================================
   Footer
   ========================================================================== */

footer.app-footer {
  max-width: var(--max-width);
  margin: var(--sp-7) auto 0;
  padding: var(--sp-5) var(--sp-6) var(--sp-7);
  border-top: 1px solid var(--border);
  font-size: var(--fs-12);
  color: var(--text-mute);
  display: flex; gap: var(--sp-4); flex-wrap: wrap; align-items: center;
}
footer.app-footer .ft-spacer { flex: 1; }
footer.app-footer a { color: var(--text-mute); text-decoration: underline; text-decoration-color: var(--border); }
footer.app-footer a:hover { color: var(--mint-darker); }

/* ==========================================================================
   Misc utility
   ========================================================================== */

.hidden { display: none !important; }
.tnum { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--text-mute); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.flex-row { display: flex; gap: var(--sp-2); align-items: center; }

/* print: invoice-preview だけ綺麗に */
@media print {
  body { background: white; }
  header.app-header, footer.app-footer, .toolbar, .row, .btn, .card-foot, dialog.modal { display: none !important; }
  .invoice-preview { box-shadow: none; border: none; padding: 0; }
}

/* ==========================================================================
   Responsive (mobile-first refinements)
   ========================================================================== */

@media (max-width: 880px) {
  main { padding: var(--sp-4); }
  .card { padding: var(--sp-4); }
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
  .kpi .value { font-size: var(--fs-22); }
  table th, table td { padding: 8px 8px; font-size: var(--fs-12); }
}
@media (max-width: 640px) {
  :root { --header-h: auto; }
  header.app-header {
    flex-wrap: wrap;
    padding: 8px var(--sp-4);
    gap: var(--sp-2);
    height: auto;
  }
  header.app-header nav {
    order: 3; width: 100%;
    margin-top: 4px;
  }
  header.app-header .who { font-size: 11px; max-width: 140px; }
  header.app-header .who .avatar { width: 24px; height: 24px; }
  header.app-header .who .who-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  main { padding: var(--sp-3); }
  h2 { font-size: var(--fs-18); }
  .page-title h2 { font-size: var(--fs-20); }
  .kpi { padding: var(--sp-3) var(--sp-4); }
  .kpi .value { font-size: var(--fs-20); }
  .row { gap: var(--sp-2); }
  .field { min-width: 0; flex: 1 1 100%; }
  dialog.modal { width: 100%; max-width: 100%; border-radius: var(--radius-md) var(--radius-md) 0 0; margin: auto 0 0; }
  dialog.modal .modal-body { max-height: 60vh; }
  .quick-actions { grid-template-columns: 1fr; }
  .invoice-preview { padding: var(--sp-4); }
  .steps { font-size: var(--fs-12); }
  .steps li { padding: 8px 8px; }
  .steps li .label-text { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
