:root {
  --bg-main: #070a12;
  --bg-sidebar: #0b1020;
  --bg-card: #11182b;
  --bg-card-soft: #151d33;
  --bg-input: #0c1222;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);
  --text-main: #f4f7fb;
  --text-muted: #8d98b3;
  --accent-blue: #3b82f6;
  --accent-violet: #8b5cf6;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #facc15;
  --orange: #fb923c;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(59, 130, 246, 0.18), transparent 35%),
    radial-gradient(circle at top right, rgba(139, 92, 246, 0.18), transparent 35%),
    var(--bg-main);
  color: var(--text-main);
}

button,
input,
select,
textarea {
  font-family: inherit;
}

button {
  border: none;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 280px;
  padding: 24px;
  background: linear-gradient(180deg, var(--bg-sidebar), rgba(11, 16, 32, 0.86));
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-violet));
  display: grid;
  place-items: center;
  font-weight: 800;
  box-shadow: 0 12px 30px rgba(59, 130, 246, 0.35);
}

.brand-logo {
  overflow: hidden;
  padding: 0;
  background: #050816;
  border: 1px solid rgba(91, 92, 255, 0.35);
}

.brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.08em;
}

.brand p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.nav-link {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  padding: 13px 14px;
  border-radius: var(--radius-sm);
  text-align: left;
  cursor: pointer;
  font-size: 15px;
  transition: 0.2s ease;
}

.nav-link:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.nav-link.active {
  color: var(--text-main);
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.22), rgba(139, 92, 246, 0.22));
  border-color: rgba(139, 92, 246, 0.35);
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 13px;
}

.main-content {
  flex: 1;
  padding: 28px;
  overflow: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 28px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-blue);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
}

.topbar h2 {
  margin: 0;
  font-size: 32px;
}

.topbar-card {
  min-width: 170px;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
}

.topbar-card span {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.topbar-card strong {
  font-size: 16px;
}

.page {
  display: none;
  animation: fadeIn 0.22s ease;
}

.active-page {
  display: block;
}

.page-header {
  margin-bottom: 22px;
}

.page-header h3 {
  margin: 0 0 8px;
  font-size: 24px;
}

.page-header p {
  margin: 0;
  color: var(--text-muted);
  max-width: 820px;
  line-height: 1.6;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 22px;
}

.dashboard-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stats-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric-card,
.content-card {
  background: linear-gradient(180deg, var(--bg-card), var(--bg-card-soft));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 22px;
}

.metric-card span {
  display: block;
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 14px;
}

.metric-card strong {
  display: block;
  font-size: 32px;
  margin-bottom: 10px;
}

.metric-card .metric-small,
.metric-small {
  font-size: 19px;
  line-height: 1.35;
}

.metric-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

.content-card {
  padding: 24px;
  margin-bottom: 18px;
}

.content-card h4 {
  margin: 0 0 10px;
  font-size: 18px;
}

.content-card p {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.7;
}

.dashboard-details,
.settings-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.overview-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.overview-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 13px 14px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.overview-row span {
  color: var(--text-muted);
  font-size: 14px;
}

.overview-row strong {
  text-align: right;
  font-size: 15px;
}

.crv-layout,
.portfolio-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr);
  gap: 18px;
  align-items: start;
}

.portfolio-layout {
  grid-template-columns: minmax(360px, 0.85fr) minmax(0, 1.15fr);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group-full {
  grid-column: 1 / -1;
}

.form-group label {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  color: var(--text-main);
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  font-size: 15px;
  outline: none;
  transition: 0.2s ease;
}

.form-group textarea {
  resize: vertical;
  min-height: 96px;
}

.form-group input::placeholder,
.form-group textarea::placeholder {
  color: rgba(141, 152, 179, 0.65);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: rgba(59, 130, 246, 0.85);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.13);
}

.form-actions,
.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-top: 4px;
}

.backup-actions {
  margin-top: 18px;
}

.btn,
.file-import-label {
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  cursor: pointer;
  font-weight: 700;
  transition: 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-violet));
  box-shadow: 0 12px 28px rgba(59, 130, 246, 0.25);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 16px 34px rgba(59, 130, 246, 0.32);
}

.btn-success {
  background: linear-gradient(135deg, #16a34a, var(--green));
  box-shadow: 0 12px 28px rgba(34, 197, 94, 0.2);
}

.btn-success:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 16px 34px rgba(34, 197, 94, 0.28);
}

.btn-secondary,
.file-import-label {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover,
.file-import-label:hover {
  background: rgba(255, 255, 255, 0.11);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.18);
  color: #fecaca;
  border: 1px solid rgba(239, 68, 68, 0.34);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.26);
}

.file-input {
  display: none;
}

.alert {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  line-height: 1.5;
  font-size: 14px;
  margin-bottom: 16px;
}

.alert-error {
  color: #fecaca;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.28);
}

.alert-success {
  color: #bbf7d0;
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.28);
}

.hidden {
  display: none !important;
}

.result-card {
  position: sticky;
  top: 28px;
}

.result-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.result-header p {
  font-size: 14px;
}

.mini-status,
.info-box {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 13px 14px;
  margin-bottom: 16px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.info-box {
  justify-content: flex-start;
  align-items: flex-start;
  color: var(--text-muted);
  line-height: 1.55;
}

.info-box strong {
  color: var(--text-main);
}

.mini-status span {
  color: var(--text-muted);
  font-size: 13px;
}

.mini-status strong {
  font-size: 18px;
}

.rating-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  padding: 8px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  border: 1px solid var(--border);
}

.rating-badge.neutral {
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
}

.rating-badge.bad {
  color: #fecaca;
  background: rgba(239, 68, 68, 0.13);
  border-color: rgba(239, 68, 68, 0.28);
}

.rating-badge.okay {
  color: #fed7aa;
  background: rgba(251, 146, 60, 0.13);
  border-color: rgba(251, 146, 60, 0.28);
}

.rating-badge.good {
  color: #bfdbfe;
  background: rgba(59, 130, 246, 0.14);
  border-color: rgba(59, 130, 246, 0.3);
}

.rating-badge.very-good {
  color: #bbf7d0;
  background: rgba(34, 197, 94, 0.14);
  border-color: rgba(34, 197, 94, 0.3);
}

.empty-state {
  min-height: 230px;
  display: grid;
  place-items: center;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 24px;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.result-item {
  padding: 15px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.result-item span {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.result-item strong {
  display: block;
  font-size: 18px;
  word-break: break-word;
}

.result-item.success strong {
  color: var(--green);
}

.result-item.danger strong {
  color: var(--red);
}

.section-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.section-toolbar h4 {
  margin-bottom: 6px;
}

.section-toolbar p {
  font-size: 14px;
}

.table-wrapper {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
  background: rgba(255, 255, 255, 0.025);
}

.portfolio-table {
  min-width: 1180px;
}

.data-table th,
.data-table td {
  padding: 14px 13px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  white-space: nowrap;
}

.data-table th {
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.045);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.035);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.ticker-cell {
  font-weight: 800;
  color: var(--text-main);
}

.muted-cell {
  color: var(--text-muted);
}

.direction-pill,
.status-pill,
.category-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.direction-pill.long {
  color: #bbf7d0;
  background: rgba(34, 197, 94, 0.13);
  border: 1px solid rgba(34, 197, 94, 0.28);
}

.direction-pill.short {
  color: #fecaca;
  background: rgba(239, 68, 68, 0.13);
  border: 1px solid rgba(239, 68, 68, 0.28);
}

.status-pill.open {
  color: #bfdbfe;
  background: rgba(59, 130, 246, 0.13);
  border: 1px solid rgba(59, 130, 246, 0.28);
}

.status-pill.closed {
  color: #d1d5db;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-strong);
}

.category-pill {
  color: #ddd6fe;
  background: rgba(139, 92, 246, 0.13);
  border: 1px solid rgba(139, 92, 246, 0.28);
}

.profit-value {
  color: var(--green);
  font-weight: 800;
}

.loss-value {
  color: var(--red);
  font-weight: 800;
}

.result-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.result-cell small {
  color: var(--text-muted);
  font-size: 12px;
}

.table-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.table-btn {
  padding: 8px 10px;
  border-radius: 9px;
  color: var(--text-main);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.table-btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.table-btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-strong);
}

.table-btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.13);
}

.table-btn-danger {
  background: rgba(239, 68, 68, 0.16);
  color: #fecaca;
  border: 1px solid rgba(239, 68, 68, 0.28);
}

.table-btn-danger:hover {
  background: rgba(239, 68, 68, 0.24);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(10px);
}

.modal-card {
  width: min(560px, 100%);
  background: linear-gradient(180deg, var(--bg-card), var(--bg-card-soft));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
  padding: 24px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.modal-header h3 {
  margin: 0;
  font-size: 24px;
}

.modal-x {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  cursor: pointer;
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border-strong);
  font-size: 24px;
  line-height: 1;
}

.modal-x:hover {
  background: rgba(255, 255, 255, 0.12);
}

.close-trade-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.summary-item {
  padding: 13px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--border);
}

.summary-item span {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.summary-item strong {
  display: block;
  font-size: 16px;
}

.modal-form {
  margin-top: 0;
}

.footer {
  margin-top: 28px;
  padding: 18px 0 0;
  color: var(--text-muted);
  font-size: 13px;
  border-top: 1px solid var(--border);
}

.app-footer {
  margin-top: 2rem;
  padding: 1.5rem 0 0;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

.footer-main p {
  margin: 0 0 0.35rem;
}

.footer-main p:first-child {
  color: var(--text-muted);
}

.footer-main p:last-child {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.footer-links {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  font-size: 0.9rem;
}

.footer-links a,
.footer-links span,
.footer-action {
  color: #c7d2fe;
  text-decoration: none;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  background: rgba(91, 92, 255, 0.12);
  border: 1px solid rgba(91, 92, 255, 0.35);
  font: inherit;
  line-height: 1;
}

.footer-action {
  cursor: pointer;
}

.footer-links a:hover,
.footer-action:hover {
  color: #ffffff;
  border-color: rgba(91, 92, 255, 0.8);
  background: rgba(91, 92, 255, 0.22);
}

.muted-text {
  color: var(--text-muted);
  font-size: 0.9rem;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1350px) {
  .dashboard-grid,
  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 1180px) {
  .crv-layout,
  .portfolio-layout,
  .dashboard-details,
  .settings-layout {
    grid-template-columns: 1fr;
  }

  .result-card {
    position: relative;
    top: 0;
  }
}

@media (max-width: 1100px) {
  .card-grid,
  .dashboard-grid,
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sidebar {
    width: 250px;
  }
}

@media (max-width: 820px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    padding: 18px;
  }

  .nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .main-content {
    padding: 20px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-card {
    width: 100%;
  }

  .card-grid,
  .dashboard-grid,
  .stats-grid,
  .form-grid,
  .result-grid {
    grid-template-columns: 1fr;
  }

  .section-toolbar,
  .overview-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .overview-row strong {
    text-align: left;
  }

  .close-trade-summary {
    grid-template-columns: 1fr;
  }

  .app-footer {
    flex-direction: column;
  }

  .footer-links {
    justify-content: flex-start;
  }
}

@media (max-width: 520px) {
  .brand {
    align-items: flex-start;
  }

  .brand h1 {
    font-size: 15px;
  }

  .nav {
    grid-template-columns: 1fr;
  }

  .topbar h2 {
    font-size: 26px;
  }

  .metric-card strong {
    font-size: 28px;
  }

  .metric-card .metric-small,
  .metric-small {
    font-size: 18px;
  }

  .form-actions,
  .backup-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .btn,
  .file-import-label {
    width: 100%;
  }

  .footer-links a,
  .footer-links span,
  .footer-action {
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  .result-header {
    flex-direction: column;
  }

  .mini-status,
  .info-box {
    align-items: flex-start;
    flex-direction: column;
  }

  .modal-card {
    padding: 18px;
  }
}