* { box-sizing: border-box; }

html, body {
  max-width: 100%;
  overflow-x: hidden;
}

:root {
  --purple: #4b2e83;
  --purple-dark: #3a2266;
  --green-bg: #e3f7ec;
  --green-border: #4cc98a;
  --green-text: #1c7a4c;
  --red-bg: #fdeaea;
  --red-border: #e57373;
  --red-text: #c62828;
  --gray-bg: #f5f5f7;
  --gray-border: #e0e0e5;
  --blue-bg: #e8eaf9;
  --blue-border: #7986cb;
  --text: #1f1f2c;
  --muted: #6b6b78;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: #fafafa;
}

.topbar {
  background: var(--purple);
  color: white;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.topbar-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.user-label {
  font-size: 14px;
  opacity: 0.9;
}

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fafafa;
}

.auth-card {
  background: white;
  border: 1px solid var(--gray-border);
  border-radius: 12px;
  padding: 32px;
  width: 360px;
  max-width: 92vw;
}

.auth-card h1 {
  text-align: center;
  font-size: 20px;
  margin: 0 0 20px;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
}

.auth-tabs .btn-toggle {
  flex: 1;
}

.auth-form label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}

.auth-form input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  border: 1px solid var(--gray-border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}

.auth-form .btn-primary {
  width: 100%;
  padding: 10px;
}

.auth-error {
  color: var(--red-text);
  font-size: 13px;
  margin: -6px 0 14px;
}

.auth-note {
  color: var(--green-text);
  font-size: 13px;
  margin: -6px 0 14px;
}

.topbar h1 {
  font-size: 20px;
  margin: 0;
}

.btn {
  cursor: pointer;
  border: 1px solid var(--gray-border);
  background: white;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  color: var(--text);
}

.btn-primary {
  background: var(--purple);
  color: white;
  border-color: var(--purple);
}

.btn-primary:hover { background: var(--purple-dark); }

.btn-danger {
  background: white;
  color: var(--red-text);
  border-color: var(--red-border);
}

.btn-icon {
  padding: 6px 12px;
  font-size: 16px;
}

.btn-toggle.active {
  background: var(--purple);
  color: white;
  border-color: var(--purple);
}

main {
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 24px 48px;
}

.overall-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.overall-tile {
  background: white;
  border: 1px solid var(--gray-border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.overall-tile-net {
  border-color: var(--purple);
  box-shadow: 0 0 0 1px var(--purple);
}

.overall-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.overall-value {
  font-size: 22px;
  font-weight: 700;
}

.overall-value.positive { color: var(--green-text); }
.overall-value.negative { color: var(--red-text); }

@media (max-width: 720px) {
  .overall-stats { grid-template-columns: repeat(2, 1fr); }
}

.stats-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.stats-left { display: flex; align-items: baseline; gap: 10px; }
.stats-label { color: var(--muted); font-size: 14px; }
.stats-pnl { font-size: 20px; font-weight: 700; }
.stats-pnl.positive { color: var(--green-text); }
.stats-pnl.negative { color: var(--red-text); }
.stats-meta { color: var(--muted); font-size: 13px; }

.stats-right { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.month-label { font-weight: 600; text-align: center; }
.view-toggle { display: flex; gap: 4px; }

.calendar-dow {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.day-cell {
  min-height: 90px;
  border-radius: 10px;
  border: 1px solid var(--gray-border);
  background: white;
  padding: 8px;
  cursor: default;
  font-size: 13px;
}

.day-cell.empty { background: transparent; border-color: transparent; }
.day-cell.has-trades { cursor: pointer; }
.day-cell.today { border-color: var(--blue-border); box-shadow: 0 0 0 1px var(--blue-border); }

.day-cell.profit { background: var(--green-bg); border-color: var(--green-border); }
.day-cell.loss { background: var(--red-bg); border-color: var(--red-border); }
.day-cell.flat { background: var(--gray-bg); }

.day-num { font-weight: 600; float: right; }
.day-pnl { font-weight: 700; margin-top: 18px; }
.day-cell.profit .day-pnl { color: var(--green-text); }
.day-cell.loss .day-pnl { color: var(--red-text); }
.day-trades-count, .day-winrate { color: var(--muted); font-size: 12px; }

.table-wrap { margin-top: 8px; }
.table-filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.table-filters input, .table-filters select {
  padding: 8px 10px;
  border: 1px solid var(--gray-border);
  border-radius: 8px;
  font-size: 14px;
}

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; min-width: 640px; border-collapse: collapse; background: white; }
th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-border);
  font-size: 14px;
}
th { color: var(--muted); font-weight: 600; cursor: pointer; user-select: none; }
tr.row-profit td.pnl-cell { color: var(--green-text); font-weight: 600; }
tr.row-loss td.pnl-cell { color: var(--red-text); font-weight: 600; }
.notes-cell { max-width: 280px; color: var(--muted); }
.row-edit-btn { font-size: 13px; }

.empty-msg { color: var(--muted); text-align: center; padding: 24px; }
.hidden { display: none !important; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-content {
  background: white;
  border-radius: 12px;
  padding: 20px 24px 24px;
  width: 420px;
  max-width: 92vw;
  max-height: 86vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-close {
  border: none;
  background: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--muted);
}

#tradeForm label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}

#tradeForm input, #tradeForm select, #tradeForm textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--gray-border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}
.form-actions-right { display: flex; flex-wrap: wrap; gap: 8px; }

.day-trade-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.day-trade-item {
  border: 1px solid var(--gray-border);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.day-trade-item:hover { filter: brightness(0.97); }
.day-trade-item.profit { background: var(--green-bg); border-color: var(--green-border); }
.day-trade-item.loss { background: var(--red-bg); border-color: var(--red-border); }
.day-trade-symbol { font-weight: 600; }
.day-trade-pnl.positive { color: var(--green-text); font-weight: 600; }
.day-trade-pnl.negative { color: var(--red-text); font-weight: 600; }

#tradePnl.pnl-input-positive {
  background: var(--green-bg);
  border-color: var(--green-border);
  color: var(--green-text);
  font-weight: 600;
}
.import-modal-content { width: 560px; }

#importSummary { font-size: 14px; margin-bottom: 14px; line-height: 1.5; }
#importSummary .count-new { color: var(--green-text); font-weight: 700; }
#importSummary .count-dup { color: var(--muted); font-weight: 700; }
#importSummary .count-skip { color: var(--red-text); font-weight: 700; }

.import-preview-wrap {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--gray-border);
  border-radius: 8px;
  margin-bottom: 14px;
}

.import-preview-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.import-preview-table th {
  position: sticky;
  top: 0;
  background: var(--gray-bg);
  text-align: left;
  padding: 6px 8px;
  color: var(--muted);
  font-weight: 600;
}
.import-preview-table td { padding: 6px 8px; border-top: 1px solid var(--gray-border); }
.import-preview-table tr.dup-row { opacity: 0.5; }
.import-row-badge {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
}
.import-row-badge.new { background: var(--green-bg); color: var(--green-text); }
.import-row-badge.dup { background: var(--gray-bg); color: var(--muted); }

#tradePnl.pnl-input-negative {
  background: var(--red-bg);
  border-color: var(--red-border);
  color: var(--red-text);
  font-weight: 600;
}

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .topbar h1 { font-size: 17px; }

  main { padding: 0 12px 32px; margin: 16px auto; }

  .overall-stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .overall-tile { padding: 10px 12px; }
  .overall-value { font-size: 18px; }

  .stats-bar { gap: 8px; }
  .stats-left { flex-wrap: wrap; }
  .stats-pnl { font-size: 18px; }

  .calendar-grid { gap: 4px; }
  .day-cell { min-height: 64px; padding: 5px; font-size: 11px; }
  .day-pnl { margin-top: 12px; font-size: 12px; }
  .day-trades-count, .day-winrate { font-size: 10px; }

  .table-filters input, .table-filters select { flex: 1 1 140px; }

  .modal-content { padding: 16px; width: 94vw; }
  .auth-card { padding: 22px; }

  .day-trade-item { flex-wrap: wrap; }
}

@media (max-width: 380px) {
  .overall-stats { grid-template-columns: 1fr 1fr; }
  .calendar-dow { font-size: 11px; }
  .day-cell { min-height: 56px; font-size: 10px; }
}
