:root {
  --bg: #f5f6f8;
  --card-bg: #fff;
  --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --card-shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.12);
  --text: #1a1a2e;
  --text-muted: #5c5c6e;
  --border: #e2e4e8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --profit: #059669;
  --loss: #dc2626;
  --neutral: #64748b;
  --radius: 8px;
  --radius-sm: 6px;
  --font-sans: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --transition: 0.2s ease;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.header {
  background: var(--card-bg);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--card-shadow);
}

.header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
}

.subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.main {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem;
}

.view {
  display: block;
}

.view.hidden {
  display: none;
}

.detail-toolbar {
  margin-bottom: 1rem;
}

.fund-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.fund-list-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  cursor: pointer;
  transition: box-shadow var(--transition), background var(--transition);
  border: 1px solid transparent;
}

.fund-list-item:hover,
.fund-list-item:focus {
  box-shadow: var(--card-shadow-hover);
  outline: none;
}

.fund-list-item:focus-visible {
  border-color: var(--primary);
}

.fund-list-item-name {
  font-weight: 600;
  flex: 1;
  min-width: 0;
}

.fund-list-item-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.fund-list-item-meta .fund-list-item-value {
  color: var(--text);
  font-weight: 500;
}

.fund-list-item-arrow {
  color: var(--text-muted);
  font-size: 1.1rem;
}

.fund-list-item-pl.profit { color: var(--profit); }
.fund-list-item-pl.loss { color: var(--loss); }

.view-list .section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.section-header h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.fund-detail-container {
  margin-top: 0.5rem;
}

.fund-cards {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.fund-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 1.25rem;
  transition: box-shadow var(--transition);
}

.fund-card:hover {
  box-shadow: var(--card-shadow-hover);
}

.fund-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.fund-name {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.fund-basic-info {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem 1.25rem;
  margin-bottom: 1.25rem;
}

.info-row,
.calc-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.info-row .label,
.calc-item .label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.info-row .value,
.calc-item .value {
  font-weight: 500;
}

.daily-nav-section,
.calculations-section,
.history-section {
  margin-top: 1.25rem;
}

.daily-nav-section h4,
.calculations-section h4,
.history-section h4 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.daily-nav-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-group label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.form-group input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  min-width: 140px;
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.calculations-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem 1rem;
}

.value.profit {
  color: var(--profit);
}

.value.loss {
  color: var(--loss);
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.history-table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.history-table th,
.history-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.history-table th {
  background: var(--bg);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.history-table tbody tr:last-child td {
  border-bottom: none;
}

.history-table .pl-profit {
  color: var(--profit);
}

.history-table .pl-loss {
  color: var(--loss);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  font-family: inherit;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition), transform 0.1s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  background: #d1d5db;
}

.btn-icon {
  padding: 0.4rem 0.75rem;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.btn-icon:hover {
  background: var(--bg);
  color: var(--text);
}

.btn-delete {
  color: var(--text-muted);
}

.btn-delete:hover {
  background: #fef2f2;
  color: var(--loss);
}

.btn-small {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

.btn-clear-history {
  color: var(--text-muted);
}

.btn-clear-history:hover {
  color: var(--loss);
  background: #fef2f2;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition);
}

.modal.is-open {
  opacity: 1;
  visibility: visible;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  cursor: pointer;
}

.modal-content {
  position: relative;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.modal-form {
  padding: 1.25rem;
}

.modal-form .form-group {
  margin-bottom: 1rem;
}

.modal-form .form-group:last-of-type {
  margin-bottom: 1.25rem;
}

.modal-form input {
  width: 100%;
  min-width: 0;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

@media (max-width: 600px) {
  .main {
    padding: 1rem;
  }

  .fund-card {
    padding: 1rem;
  }

  .daily-nav-form {
    flex-direction: column;
    align-items: stretch;
  }

  .form-group input {
    min-width: 0;
  }

  .calculations-grid {
    grid-template-columns: 1fr 1fr;
  }
}
