/* ============================================================
   Trading Playground Journal — Main Stylesheet
   Clean, professional design with no frontend frameworks.
   Uses CSS custom properties (variables) for easy theming.
   ============================================================ */

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Colors */
  --color-primary:      #1a56db;
  --color-primary-dark: #1245b0;
  --color-bg:           #f4f6f9;
  --color-surface:      #ffffff;
  --color-border:       #e2e8f0;
  --color-text:         #1e293b;
  --color-text-muted:   #64748b;
  --color-win:          #16a34a;
  --color-win-bg:       #dcfce7;
  --color-loss:         #dc2626;
  --color-loss-bg:      #fee2e2;
  --color-open:         #d97706;
  --color-open-bg:      #fef3c7;
  --color-nav-bg:       #0f172a;
  --color-nav-text:     #cbd5e1;
  --color-nav-active:   #ffffff;
  --color-nav-hover:    #1e293b;

  /* Spacing */
  --nav-width: 220px;
  --header-height: 60px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.10);

  /* Border radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.6;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ---------- Layout ---------- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar Navigation ---------- */
.sidebar {
  width: var(--nav-width);
  background: var(--color-nav-bg);
  color: var(--color-nav-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-logo .logo-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-nav-active);
  line-height: 1.3;
}

.sidebar-logo .logo-subtitle {
  font-size: 0.75rem;
  color: var(--color-nav-text);
  margin-top: 2px;
  opacity: 0.7;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 0;
  list-style: none;
}

.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 20px;
  color: var(--color-nav-text);
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent;
}

.sidebar-nav li a:hover {
  background: var(--color-nav-hover);
  color: var(--color-nav-active);
  text-decoration: none;
}

.sidebar-nav li a.active {
  background: var(--color-nav-hover);
  color: var(--color-nav-active);
  border-left-color: var(--color-primary);
}

.sidebar-nav .nav-icon {
  font-size: 1.1rem;
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 0.75rem;
  color: var(--color-nav-text);
  opacity: 0.5;
}

/* ---------- Main Content Area ---------- */
.main-content {
  margin-left: var(--nav-width);
  flex: 1;
  padding: 32px;
  min-width: 0;
}

.page-header {
  margin-bottom: 28px;
}

.page-header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--color-text);
}

.page-header p {
  color: var(--color-text-muted);
  margin-top: 4px;
}

/* ---------- Stat Cards ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm);
}

.stat-card .stat-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}

.stat-card .stat-value {
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.1;
}

.stat-card .stat-value.positive { color: var(--color-win); }
.stat-card .stat-value.negative { color: var(--color-loss); }

/* ---------- Cards ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--color-border);
}

.card-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
}

.card-body {
  padding: 24px;
}

/* ---------- Tables ---------- */
.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  background: var(--color-bg);
  padding: 10px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  border-bottom: 2px solid var(--color-border);
}

tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

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

tbody tr:hover {
  background: #f8fafc;
}

.symbol-cell {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.03em;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-win      { background: var(--color-win-bg);  color: var(--color-win);  }
.badge-loss     { background: var(--color-loss-bg); color: var(--color-loss); }
.badge-open     { background: var(--color-open-bg); color: var(--color-open); }
.badge-breakeven { background: #e2e8f0; color: #475569; }
.badge-long     { background: #dbeafe; color: #1d4ed8; }
.badge-short    { background: #fce7f3; color: #9d174d; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
}

.btn:hover { opacity: 0.88; text-decoration: none; }

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-success {
  background: var(--color-win);
  color: #fff;
}

/* ---------- Forms ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text);
}

label .required {
  color: var(--color-loss);
  margin-left: 2px;
}

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
  padding: 9px 13px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.15);
}

textarea {
  resize: vertical;
  min-height: 90px;
}

.form-hint {
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.form-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 8px;
  padding-top: 24px;
  border-top: 1px solid var(--color-border);
}

/* ---------- Alerts ---------- */
.alert {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 20px;
  display: none; /* shown via JS */
}

.alert.show { display: block; }
.alert-success { background: var(--color-win-bg);  color: #14532d; border-left: 4px solid var(--color-win);  }
.alert-error   { background: var(--color-loss-bg); color: #7f1d1d; border-left: 4px solid var(--color-loss); }

/* ---------- Loading State ---------- */
.loading-text {
  color: var(--color-text-muted);
  font-size: 0.875rem;
  padding: 24px;
  text-align: center;
}

/* ---------- Empty State ---------- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--color-text-muted);
}

.empty-state .empty-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.empty-state p {
  margin-bottom: 16px;
}

/* ---------- Error Page ---------- */
.error-page {
  max-width: 480px;
  margin: 80px auto;
  text-align: center;
  padding: 32px;
}

.error-page h1 {
  font-size: 2rem;
  margin-bottom: 12px;
}

.error-page p {
  color: var(--color-text-muted);
  margin-bottom: 24px;
}

/* ---------- Utility ---------- */
.text-win  { color: var(--color-win);  font-weight: 600; }
.text-loss { color: var(--color-loss); font-weight: 600; }
.text-muted { color: var(--color-text-muted); }
.text-right { text-align: right; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }

/* ---------- Auth Pages ---------- */
.auth-body {
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px 16px;
}

.auth-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 40px;
  width: 100%;
  max-width: 420px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}

.auth-logo-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-text);
}

.auth-logo-sub {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.auth-heading {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 24px;
  text-align: center;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.auth-submit {
  width: 100%;
  justify-content: center;
  padding: 11px;
  font-size: 0.95rem;
  margin-top: 4px;
}

.auth-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

/* ---------- Sidebar user block ---------- */
.sidebar-user {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-user-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-nav-active);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-logout-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--color-nav-text);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 0.75rem;
  cursor: pointer;
  width: 100%;
  text-align: center;
  transition: background 0.15s;
}

.sidebar-logout-btn:hover {
  background: rgba(255,255,255,0.08);
  color: var(--color-nav-active);
}

/* ---------- Schwab Banner ---------- */
.schwab-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
  gap: 12px;
}

.schwab-banner-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.schwab-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #94a3b8;
  flex-shrink: 0;
}

.dot-connected    { background: var(--color-win); box-shadow: 0 0 0 3px var(--color-win-bg); }
.dot-disconnected { background: #94a3b8; }

.schwab-banner-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--color-text);
}

.schwab-banner-sub {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 1px;
}

.schwab-banner-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- Positions Footer ---------- */
.positions-footer {
  padding: 12px 24px;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
}

.positions-summary {
  display: flex;
  gap: 32px;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.positions-summary strong {
  color: var(--color-text);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 999;
  max-width: 360px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-success { border-left: 4px solid var(--color-win);  }
.toast-error   { border-left: 4px solid var(--color-loss); }

/* ---------- Extra Badge + Button sizes ---------- */
.badge-schwab { background: #ede9fe; color: #5b21b6; font-size: 0.68rem; }

.btn-sm { padding: 6px 13px; font-size: 0.8rem; }
.btn-danger { background: var(--color-loss); color: #fff; }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .sidebar-nav {
    display: flex;
    flex-direction: row;
    padding: 0;
    overflow-x: auto;
  }

  .sidebar-nav li a {
    padding: 12px 16px;
    white-space: nowrap;
    border-left: none;
    border-bottom: 3px solid transparent;
  }

  .sidebar-nav li a.active {
    border-left: none;
    border-bottom-color: var(--color-primary);
  }

  .sidebar-footer { display: none; }

  .main-content {
    margin-left: 0;
    padding: 20px 16px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
}
