@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;600;700;800&display=swap');

:root {
  --primary: #16a34a;
  --primary-light: #f0fdf4;
  --primary-dark: #15803d;
  --expense: #ef4444;
  --income: #16a34a;
  --sidebar-bg: #14332a;
  --gray-50: #f8faf9;
  --gray-100: #f1f5f3;
  --gray-200: #e2e8e5;
  --gray-300: #cbd5d0;
  --gray-400: #94a3a0;
  --gray-500: #64756f;
  --gray-700: #334145;
  --gray-900: #0f1f1a;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Noto Sans JP', 'Hiragino Sans', -apple-system, sans-serif;
  background: var(--gray-100);
  color: var(--gray-900);
  min-height: 100vh;
}

/* Layout */
.app { display: flex; min-height: 100vh; }
.main { flex: 1; padding: 20px 16px 40px; overflow: auto; }
@media (min-width: 768px) {
  .main { padding: 28px 36px; }
}

/* Sidebar (desktop) */
.sidebar {
  display: none; width: 220px; min-height: 100vh;
  background: var(--sidebar-bg); padding: 20px 10px;
  flex-direction: column; gap: 2px;
  border-right: 1px solid rgba(255,255,255,0.06);
}
@media (min-width: 768px) { .sidebar { display: flex; } }

.sidebar-brand { padding: 8px 14px 20px; border-bottom: 1px solid rgba(255,255,255,0.08); margin-bottom: 8px; }
.sidebar-brand-label { font-size: 10px; font-weight: 700; letter-spacing: 2px; color: rgba(255,255,255,0.3); text-transform: uppercase; }
.sidebar-brand-name { font-size: 17px; font-weight: 800; color: #e2e8f0; margin-top: 4px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 10px; border: none;
  background: transparent; color: rgba(255,255,255,0.4);
  font-size: 13px; font-weight: 500; cursor: pointer;
  width: 100%; text-align: left; transition: all 0.15s;
}
.sidebar-item:hover { background: rgba(255,255,255,0.05); color: rgba(255,255,255,0.6); }
.sidebar-item.active { background: rgba(99,102,241,0.15); color: #a5b4fc; font-weight: 700; }

.sidebar-user {
  margin-top: auto; padding: 12px 14px; border-radius: 10px;
  background: rgba(255,255,255,0.04);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, #16a34a, #22c55e);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12px; font-weight: 700;
}
.sidebar-user-name { font-size: 13px; font-weight: 600; color: #e2e8f0; }
.sidebar-user-role { font-size: 10px; color: rgba(255,255,255,0.3); }
.sidebar-logout {
  margin-left: auto; background: none; border: none;
  color: rgba(255,255,255,0.3); cursor: pointer; padding: 4px;
}
.sidebar-logout:hover { color: rgba(255,255,255,0.6); }

/* Mobile home screen */
.mobile-home {
  display: none; min-height: 100vh; background: var(--gray-50);
  flex-direction: column; width: 100%;
}
@media (max-width: 767px) {
  .mobile-home { display: flex; }
  .sidebar { display: none !important; }
  .main.desktop-only { display: none !important; }
}

.home-grid {
  padding: 0 16px; display: grid;
  grid-template-columns: 1fr 1fr; gap: 12px;
}
.home-card {
  background: #fff; border-radius: 16px; padding: 20px 16px;
  border: 1px solid var(--gray-200); cursor: pointer;
  text-align: left; font-family: inherit;
  transition: all 0.15s; display: flex; flex-direction: column; gap: 8px;
}
.home-card:active { transform: scale(0.97); background: var(--gray-50); }
.home-card-icon {
  width: 44px; height: 44px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
}
.home-card-label { font-size: 15px; font-weight: 700; color: var(--gray-900); }
.home-card-desc { font-size: 11px; color: var(--gray-400); line-height: 1.4; }

.home-footer {
  margin-top: auto; padding: 20px;
  display: flex; align-items: center; justify-content: space-between;
}
.home-logout-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--gray-200);
  background: #fff; font-size: 12px; font-weight: 600; color: var(--gray-500);
  cursor: pointer; font-family: inherit;
}

/* Mobile fullscreen modal */
.mobile-modal {
  display: none; position: fixed; inset: 0; z-index: 60;
  background: var(--gray-50); flex-direction: column;
}
.mobile-modal:not(.hidden) { display: flex; }
@media (min-width: 768px) { .mobile-modal { display: none !important; } }

.mobile-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: #fff;
  border-bottom: 1px solid var(--gray-200);
  position: sticky; top: 0; z-index: 10;
}
.mobile-modal-close {
  width: 40px; height: 40px; border-radius: 10px; border: none;
  background: var(--gray-50); display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--gray-500);
}
.mobile-modal-close:active { background: var(--gray-100); }
.mobile-modal-title { font-size: 16px; font-weight: 700; color: var(--gray-900); }
.mobile-modal-body { flex: 1; overflow: auto; padding: 20px 16px 40px; }

/* Bottom nav - removed */
.mobile-nav { display: none; }

/* Mobile header - removed */
.mobile-header { display: none; }

/* Slide menu - removed */
.mobile-menu-overlay { display: none; }

/* Page header */
.page-title { font-size: 20px; font-weight: 800; color: var(--gray-900); }
.page-subtitle { font-size: 13px; color: var(--gray-400); margin-top: 2px; }

/* Cards */
.card {
  background: #fff; border-radius: 16px; padding: 20px;
  border: 1px solid var(--gray-200);
}
.card-sm { border-radius: 12px; padding: 14px; }

/* Form elements */
.label { display: block; font-size: 12px; font-weight: 600; color: var(--gray-500); margin-bottom: 5px; }
.label .req { color: var(--expense); }

.input {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1.5px solid var(--gray-200); background: #fff;
  font-size: 14px; color: var(--gray-900); outline: none;
  transition: border-color 0.15s; font-family: inherit;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.08); }
.input::placeholder { color: var(--gray-400); }
.input-icon { position: relative; }
.input-icon .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--gray-400); pointer-events: none; }
.input-icon .input { padding-left: 36px; }

select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 36px;
}

/* Selector button (opens bottom sheet) */
.selector-btn {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1.5px solid var(--gray-200); background: #fff;
  display: flex; align-items: center; gap: 10px;
  cursor: pointer; text-align: left; font-family: inherit; font-size: 14px;
  transition: border-color 0.15s;
}
.selector-btn:hover { border-color: var(--gray-300); }
.selector-btn .label-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selector-btn .label-text.empty { color: var(--gray-400); font-weight: 400; }
.selector-btn .label-text.filled { color: var(--gray-900); font-weight: 600; }

/* Type toggle */
.type-toggle { display: flex; gap: 8px; margin-bottom: 24px; }
.type-btn {
  flex: 1; padding: 12px 0; border-radius: 12px;
  border: 2px solid var(--gray-200); background: #fff;
  font-size: 14px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: all 0.15s; font-family: inherit;
}
.type-btn.expense.active { border-color: var(--expense); color: var(--expense); background: rgba(239,68,68,0.04); }
.type-btn.income.active { border-color: var(--income); color: var(--income); background: rgba(16,185,129,0.04); }
.type-btn:not(.active) { color: var(--gray-400); }

/* Tax rate buttons */
.tax-group { display: flex; gap: 8px; }
.tax-btn {
  flex: 1; padding: 10px 0; border-radius: 10px;
  border: 2px solid var(--gray-200); background: #fff;
  font-size: 13px; font-weight: 700; cursor: pointer; transition: all 0.15s; font-family: inherit;
}
.tax-btn.active { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.tax-btn:not(.active) { color: var(--gray-400); }

/* Toggle switch */
.toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--gray-500); font-weight: 500; }
.toggle-track {
  width: 40px; height: 22px; border-radius: 11px; padding: 2px;
  background: var(--gray-300); transition: background 0.2s; cursor: pointer;
}
.toggle-track.on { background: var(--primary); }
.toggle-thumb {
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15); transition: transform 0.2s;
}
.toggle-track.on .toggle-thumb { transform: translateX(18px); }

/* Buttons */
.btn {
  padding: 14px 36px; border-radius: 12px; border: none;
  font-size: 15px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: all 0.15s; font-family: inherit;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 16px rgba(99,102,241,0.25); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { background: var(--gray-200); box-shadow: none; cursor: default; }
.btn-sm { padding: 8px 16px; font-size: 13px; border-radius: 10px; }

/* Stat cards */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px; }
.stat { background: #fff; border-radius: 12px; padding: 14px; border: 1px solid var(--gray-200); }
.stat-label { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--gray-400); font-weight: 600; margin-bottom: 6px; }
.stat-value { font-size: 18px; font-weight: 800; font-feature-settings: "tnum"; }
.stat-value.expense { color: var(--expense); }
.stat-value.income { color: var(--income); }

/* Journal preview */
.journal-preview {
  padding: 14px 16px; border-radius: 12px;
  background: var(--gray-50); border: 1px solid var(--gray-200);
}
.journal-preview-label { font-size: 10px; font-weight: 700; color: var(--gray-400); letter-spacing: 1px; text-transform: uppercase; margin-bottom: 10px; }
.journal-preview-row { display: flex; align-items: center; }
.journal-preview-col { flex: 1; text-align: center; }
.journal-preview-col .side { font-size: 10px; color: var(--gray-400); margin-bottom: 2px; }
.journal-preview-col .acct { font-size: 14px; font-weight: 700; color: var(--gray-900); }
.journal-preview-col .amt { font-size: 15px; font-weight: 800; color: var(--primary); font-feature-settings: "tnum"; margin-top: 2px; }
.journal-preview-divider { width: 1px; height: 40px; background: var(--gray-200); margin: 0 12px; }

/* Extra fields toggle */
.extra-toggle {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 0; border: none; background: none;
  color: var(--primary); font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}

/* Upload area */
.upload-area {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px; border-radius: 12px;
  border: 2px dashed var(--gray-300); background: var(--gray-50);
  cursor: pointer; font-size: 14px; font-weight: 500; color: var(--gray-500);
}
.upload-area.has-file { border-color: var(--income); background: #f0fdf4; color: var(--income); }
.upload-area input { display: none; }

/* Recent list */
.recent-list { background: #fff; border-radius: 14px; border: 1px solid var(--gray-200); overflow: hidden; }
.recent-header {
  padding: 14px 16px; border-bottom: 1px solid var(--gray-100);
  display: flex; justify-content: space-between; align-items: center;
}
.recent-header-title { font-size: 13px; font-weight: 700; color: var(--gray-900); }
.recent-item {
  padding: 11px 16px; display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--gray-50);
}
.recent-item:last-child { border-bottom: none; }
.recent-item-desc { font-size: 14px; font-weight: 600; color: var(--gray-900); }
.recent-item-meta { font-size: 11px; color: var(--gray-400); margin-top: 2px; }
.recent-item-amount { font-size: 14px; font-weight: 700; font-feature-settings: "tnum"; white-space: nowrap; margin-left: 12px; }
.recent-item-amount.expense { color: var(--expense); }
.recent-item-amount.income { color: var(--income); }

/* Bottom sheet */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; justify-content: flex-end;
}
.overlay-bg { position: absolute; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(2px); }
.sheet {
  position: relative; background: #fff; border-radius: 20px 20px 0 0;
  max-height: 70vh; display: flex; flex-direction: column;
  animation: sheetUp 0.25s ease-out;
}
.sheet-header {
  padding: 16px 20px 12px; border-bottom: 1px solid var(--gray-100);
  display: flex; justify-content: space-between; align-items: center;
}
.sheet-title { font-size: 16px; font-weight: 700; color: var(--gray-900); }
.sheet-close {
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: var(--gray-100); display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.sheet-body { overflow: auto; padding: 8px 0; }
.sheet-item {
  width: 100%; padding: 14px 20px; border: none; background: #fff;
  display: flex; align-items: center; gap: 12px;
  cursor: pointer; border-bottom: 1px solid var(--gray-50);
  font-family: inherit; text-align: left;
}
.sheet-item.selected { background: var(--primary-light); }
.sheet-item-name { font-size: 15px; font-weight: 500; color: var(--gray-900); }
.sheet-item.selected .sheet-item-name { font-weight: 700; color: var(--primary); }
.sheet-item-desc { font-size: 12px; color: var(--gray-400); margin-top: 2px; }

/* Toast */
.toast {
  position: fixed; top: 16px; left: 16px; right: 16px; z-index: 200;
  padding: 14px 18px; border-radius: 14px;
  background: var(--gray-900); color: #fff;
  font-size: 14px; font-weight: 600;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  display: flex; align-items: center; gap: 10px;
  animation: slideDown 0.25s ease-out;
}
.toast-icon {
  width: 24px; height: 24px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.toast-icon.success { background: var(--income); }
.toast-icon.error { background: var(--expense); }

/* Transaction list */
.tx-list { background: #fff; border-radius: 12px; border: 1px solid var(--gray-200); overflow: hidden; }
.tx-item {
  padding: 12px 16px; display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--gray-50);
}
.tx-item:last-child { border-bottom: none; }
.tx-item-info { flex: 1; min-width: 0; }
.tx-item-desc { font-size: 14px; font-weight: 600; color: var(--gray-900); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-item-meta { font-size: 11px; color: var(--gray-400); margin-top: 2px; }
.tx-item-amount { font-size: 14px; font-weight: 700; font-feature-settings: "tnum"; white-space: nowrap; }
.tx-item-delete { padding: 6px; background: none; border: none; color: var(--gray-300); cursor: pointer; }
.tx-item-delete:hover { color: var(--expense); }

/* Journal table */
.journal-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }
.journal-table th { text-align: left; padding: 10px 16px; font-size: 11px; font-weight: 600; color: var(--gray-400); border-bottom: 1px solid var(--gray-100); }
.journal-table th.right { text-align: right; }
.journal-table td { padding: 8px 16px; border-bottom: 1px solid var(--gray-50); }
.journal-table td.right { text-align: right; font-weight: 700; font-feature-settings: "tnum"; }
.journal-table td.bold { font-weight: 600; }
.journal-table tr:last-child td { border-bottom: none; }

/* Filter bar */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.filter-bar select { padding: 8px 12px; border-radius: 10px; border: 1px solid var(--gray-200); font-size: 13px; font-weight: 600; background: #fff; font-family: inherit; }

/* Export cards */
.export-card { background: #fff; border-radius: 12px; padding: 20px; border: 1px solid var(--gray-200); display: flex; align-items: flex-start; gap: 16px; }
.export-icon { width: 40px; height: 40px; border-radius: 12px; background: var(--primary-light); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.export-info { flex: 1; min-width: 0; }
.export-title { font-size: 14px; font-weight: 700; color: var(--gray-900); }
.export-desc { font-size: 12px; color: var(--gray-500); margin-top: 4px; line-height: 1.5; }

/* Login */
.login-page { min-height: 100vh; min-height: 100dvh; background: var(--gray-50); display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-box { width: 100%; max-width: 360px; }
.login-brand { text-align: center; margin-bottom: 32px; }
.login-error { margin-bottom: 16px; padding: 12px 16px; border-radius: 12px; background: #fef2f2; color: var(--expense); font-size: 13px; font-weight: 500; }

/* Desktop two-column */
@media (min-width: 768px) {
  .two-col { display: grid; grid-template-columns: 1fr 320px; gap: 28px; align-items: start; }
  .desktop-only { display: block; }
  .mobile-only { display: none; }
}
@media (max-width: 767px) {
  .desktop-only { display: none; }
  .mobile-only { display: block; }
}

/* Animations */
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes slideDown { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* Spinner */
.spinner { width: 24px; height: 24px; border: 2px solid var(--gray-200); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.6s linear infinite; margin: 0 auto; }

/* Utility */
.hidden { display: none !important; }
.tabnum { font-feature-settings: "tnum"; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-sm { display: flex; flex-direction: column; gap: 16px; }
.gap-md { display: flex; flex-direction: column; gap: 20px; }
.mb-sm { margin-bottom: 12px; }
.mb-md { margin-bottom: 20px; }
.text-hint { font-size: 11px; color: var(--gray-500); margin-top: 4px; padding-left: 2px; }