/* =====================================================
   MoneyForward Me ダッシュボード: プレミアムスタイル
   ===================================================== */

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

:root {
  --sidebar-width: 250px;
  --sidebar-bg: #111827;
  /* Gray-900 */
  --sidebar-text: #9ca3af;
  /* Gray-400 */
  --sidebar-hover: #1f2937;
  /* Gray-800 */
  --sidebar-active-bg: #374151;
  /* Gray-700 */
  --sidebar-active-text: #f9fafb;
  /* Gray-50 */

  --bg-color: #f3f4f6;
  /* Gray-100 */
  --card-bg: #ffffff;
  --text-main: #111827;
  /* Gray-900 */
  --text-muted: #6b7280;
  /* Gray-500 */
  --border-color: #e5e7eb;
  /* Gray-200 */

  --primary: #3b82f6;
  /* Blue-500 */
  --positive: #059669;
  /* Emerald-600 */
  --negative: #dc2626;
  /* Red-600 */

  --card-radius: 16px;
  --card-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

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

body {
  font-family: 'Inter', 'Noto Sans JP', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  display: flex;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* =====================================================
   SIDEBAR
   ===================================================== */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--sidebar-bg);
  color: var(--sidebar-text);
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  z-index: 100;
  padding-top: 16px;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  margin-bottom: 24px;
}

.sidebar-logo .logo-icon {
  font-size: 28px;
}

.sidebar-logo .logo-text {
  font-size: 16px;
  font-weight: 700;
  color: var(--sidebar-active-text);
  letter-spacing: -0.02em;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  text-decoration: none;
  color: var(--sidebar-text);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.nav-item:hover {
  background-color: var(--sidebar-hover);
  color: var(--sidebar-active-text);
}

.nav-item.active {
  background-color: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  border-right: 4px solid var(--primary);
}

.nav-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

/* =====================================================
   MAIN LAYOUT & CARDS
   ===================================================== */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page-header {
  padding: 32px 40px 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.page-header h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-main);
}

.content {
  padding: 32px 40px;
  flex: 1;
}

.card {
  background: var(--card-bg);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  padding: 24px 32px;
  margin-bottom: 24px;
}

.card-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* =====================================================
   TYPOGRAPHY & UTILS
   ===================================================== */
.amount-xl {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-main);
}

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

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

.fw-600 {
  font-weight: 600;
}

.fw-700 {
  font-weight: 700;
}

.positive {
  color: var(--positive);
}

.negative {
  color: var(--negative);
}

.flex {
  display: flex;
}

.flex-col {
  display: flex;
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.gap-8 {
  gap: 32px;
}

.gap-4 {
  gap: 16px;
}

/* =====================================================
   TABLES
   ===================================================== */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.data-table td {
  padding: 16px;
  font-size: 14px;
  color: var(--text-main);
  border-bottom: 1px solid #f9fafb;
}

.data-table tbody tr:hover {
  background-color: #f9fafb;
}

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

/* =====================================================
   LEGEND
   ===================================================== */
.legend-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  border-bottom: 1px solid #f3f4f6;
}

.legend-item:last-child {
  border-bottom: none;
}

.legend-label-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 4px;
}

.legend-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-main);
}

.legend-amount {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
}

.legend-pct {
  font-size: 13px;
  color: var(--text-muted);
  margin-left: 8px;
  font-weight: 400;
}

/* =====================================================
   FORMS & CONTROLS
   ===================================================== */
.form-select {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background-color: #fff;
  color: var(--text-main);
  font-size: 14px;
  outline: none;
  cursor: pointer;
}

.form-select:focus {
  border-color: var(--primary);
}

/* =====================================================
   EMPTY STATE
   ===================================================== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .icon {
  font-size: 48px;
  margin-bottom: 16px;
}

/* =====================================================
   LINKED ACCOUNTS & CARDS
   ===================================================== */
.grid-auto {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.account-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 16px;
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.2s, box-shadow 0.2s;
  height: 100%;
}

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

.account-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.account-balance {
  font-weight: 700;
  font-size: 24px;
  color: var(--text-main);
  margin-top: 4px;
  margin-bottom: 4px;
}

.account-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px dashed var(--border-color);
}

.account-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  background: #e5e7eb;
  padding: 4px 12px;
  border-radius: 16px;
  display: inline-block;
  margin-bottom: 12px;
}

.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.badge-normal {
  background-color: #d1fae5;
  color: #065f46;
}

.badge-error {
  background-color: #fee2e2;
  color: #b91c1c;
}

.badge-updating {
  background-color: #fef3c7;
  color: #92400e;
}

.badge-auto {
  background-color: #e0e7ff;
  color: #3730a3;
}

.mb-4 {
  margin-bottom: 4px;
}

.mb-16 {
  margin-bottom: 16px;
}

.mb-24 {
  margin-bottom: 24px;
}

.mt-8 {
  margin-top: 8px;
}

.divider {
  height: 1px;
  background-color: var(--border-color);
  margin: 24px 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-link {
  text-decoration: none;
  color: var(--primary);
  font-weight: 600;
  font-size: 14px;
}

.header-link:hover {
  text-decoration: underline;
}

/* =====================================================
   FUNDS FLOW (DRAGGABLE BLOCKS & ARROWS)
   ===================================================== */
.funds-container {
  position: relative;
  width: 100%;
  height: calc(100vh - 120px);
  background: var(--card-bg);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  overflow-y: auto;
  overflow-x: hidden;
  /* Prevent horizontal scrolling, allow vertical */
}

.funds-canvas {
  position: relative;
  width: 100%;
  /* Fit screen width */
  height: 4000px;
}

.funds-svg-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.fund-block {
  position: absolute;
  width: 140px;
  /* Reduced to ~0.8x from 180px */
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-top: 4px solid var(--primary);
  border-radius: 8px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  padding: 6px 10px;
  /* Reduced padding */
  z-index: 2;
  cursor: grab;
  user-select: none;
}

.fund-block:active {
  cursor: grabbing;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  z-index: 10;
}

.fund-header {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 5px;
  /* Tighter margin */
  padding-bottom: 3px;
  /* Tighter padding */
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 6px;
}

.fund-header-icon {
  font-size: 11px;
  /* Slightly smaller icon */
}

.fund-row {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  /* Smaller font for details */
  margin-bottom: 3px;
  /* Tighter row spacing */
}

.fund-row:last-child {
  margin-bottom: 0;
}

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

.fund-value {
  font-weight: 600;
  color: var(--text-main);
}

.fund-block-delete {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 16px;
  height: 16px;
  background: #ef4444;
  color: white;
  border-radius: 50%;
  border: none;
  font-size: 10px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 6;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  display: none;
}

.fund-block-edit {
  position: absolute;
  bottom: 0px;
  right: 0px;
  width: 26px;
  height: 26px;
  background: #e5e7eb;
  border-bottom-right-radius: 8px;
  border: none;
  cursor: pointer;
  z-index: 5;
  display: none;
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
  align-items: flex-end;
  justify-content: flex-end;
  padding: 0 3px 3px 0;
  box-sizing: border-box;
  font-size: 10px;
  transition: background 0.2s;
}

.fund-block-edit:hover {
  background: #d1d5db;
}

.fund-block:hover .fund-block-delete,
.fund-block:hover .fund-block-edit {
  display: flex;
}

/* =====================================================
   GRID & DONUT LEGEND
   ===================================================== */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: center;
}

.donut-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* =====================================================
   UTILITY CLASSES
   ===================================================== */
.text-sm {
  font-size: 13px;
}

.mb-8 {
  margin-bottom: 8px;
}

.logo-sub {
  font-size: 12px;
  color: var(--sidebar-text);
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.w-100 {
  width: 100%;
}

.icon {
  font-size: 18px;
}