/* ==========================================================================
   CALENDAR — full-viewport calendar with screenshot-proof branding
   ========================================================================== */

/* ---------- Tokens & base ---------- */
.cal-page {
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e5e7eb;
  --border-soft: #f1f5f9;
  --text-1: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;

  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #eff6ff;

  --profit-strong: #047857;
  --profit-soft: #ecfdf5;
  --profit-border: #a7f3d0;

  --loss-strong: #b91c1c;
  --loss-soft: #fef2f2;
  --loss-border: #fecaca;

  --weekly: #6366f1;
  --weekly-soft: #eef2ff;
  --weekly-border: #c7d2fe;

  --brand: #22c55e;
  --brand-dark: #16a34a;

  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-lift: 0 12px 24px -10px rgba(15, 23, 42, 0.16);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);

  /* --- Full-viewport single-column shell --- */
  height: calc(100vh - 64px);           /* 64px = .main-content top+bottom padding */
  box-sizing: border-box;
  margin: 0 auto;
  padding: 0;
  max-width: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-1);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

/* Turbo Frame wrapper must not participate in layout: the calendar's
   flex column height math depends on it being transparent. */
.cal-page > turbo-frame { display: contents; }

/* P&L color utilities */
.cal-page .is-positive { color: var(--profit-strong); }
.cal-page .is-negative { color: var(--loss-strong); }
.cal-page .is-muted    { color: #cbd5e1; }

/* ---------- Page header ---------- */
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.cal-heading h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.025em;
}

.cal-heading p {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--text-2);
}

.cal-header-metrics { display: flex; gap: 8px; flex-wrap: wrap; }

.cal-metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 14px 8px;
  min-width: 118px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  box-shadow: var(--shadow-card);
}

.cal-metric-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-3);
}

.cal-metric-value {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-1);
}

/* ---------- Shared card ---------- */
.cal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
}

/* ==========================================================
   CALENDAR (hero — fills remaining viewport height)
   ========================================================== */
.cal-calendar {
  padding: 18px 20px 12px;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.cal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  flex-shrink: 0;
}

.cal-month-nav { display: flex; align-items: center; gap: 10px; }

.cal-nav-btn {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.cal-nav-btn:hover {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: #bfdbfe;
}

.cal-nav-btn:focus-visible,
.cal-today-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cal-month-title {
  margin: 0;
  min-width: 190px;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.cal-toolbar-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.cal-month-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 700;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-1);
}

.cal-month-badge.is-positive { background: var(--profit-soft); border-color: var(--profit-border); color: var(--profit-strong); }
.cal-month-badge.is-negative { background: var(--loss-soft); border-color: var(--loss-border); color: var(--loss-strong); }

.cal-month-badge-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
}
.cal-month-badge.is-positive .cal-month-badge-label { color: #059669; }
.cal-month-badge.is-negative .cal-month-badge-label { color: #ef4444; }

.cal-today-btn {
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  transition: background 0.15s;
}
.cal-today-btn:hover { background: var(--accent-strong); color: #fff; }

/* ---------- Grid: rows flex to fill height ---------- */
.cal-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr)) 100px;
  grid-template-rows: auto;
  grid-auto-rows: minmax(0, 1fr);
  gap: 6px;
}

.cal-grid-head {
  padding-bottom: 8px;
  text-align: center;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
}

.cal-grid-head--weekly { color: var(--weekly); }

.cal-day {
  position: relative;
  min-height: 0;
  padding: 8px;
  border-radius: 11px;
  border: 1px solid var(--border-soft);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease), border-color 0.15s;
}

.cal-day.is-blank {
  background: transparent;
  border-style: dashed;
  border-color: #e8edf3;
}

.cal-day.is-weekend { background: var(--surface-2); }

.cal-day.has-trades.is-positive { background: var(--profit-soft); border-color: var(--profit-border); }
.cal-day.has-trades.is-negative { background: var(--loss-soft); border-color: var(--loss-border); }

.cal-grid > .cal-day.is-today {
  border-color: #93c5fd;
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px #93c5fd;
}

.cal-day.has-trades:hover,
.cal-grid > .cal-day.is-today:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
  z-index: 2;
}
.cal-grid > .cal-day.is-today:hover { box-shadow: 0 0 0 1px #93c5fd, var(--shadow-lift); }

.cal-day-num {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  flex-shrink: 0;
}

.cal-day.is-today .cal-day-num {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.cal-day-body {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.cal-day-count {
  font-size: 9.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-day-pnl {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.1;
}

/* ---------- Weekly total column ---------- */
.cal-week-total {
  background: var(--surface-2);
  border: 1px solid #e2e8f0;
  border-left: 3px solid var(--weekly-border);
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 6px;
}

.cal-week-total.has-trades {
  background: var(--weekly-soft);
  border-color: var(--weekly-border);
  border-left-color: var(--weekly);
}

.cal-week-total:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px -8px rgba(99, 102, 241, 0.35);
  z-index: 2;
}

.cal-week-tag {
  position: absolute;
  top: 5px;
  left: 8px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #a5b4fc;
}
.cal-week-total.has-trades .cal-week-tag { color: var(--weekly); }

.cal-week-total-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.cal-week-total-count {
  font-size: 9.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-week-total-pnl {
  font-size: 13.5px;
  font-weight: 800;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.cal-week-total-empty {
  font-size: 15px;
  font-weight: 400;
  color: #cbd5e1;
}

/* ---------- Legend (compact) ---------- */
.cal-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-soft);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-2);
  flex-shrink: 0;
}

.cal-legend-item { display: inline-flex; align-items: center; gap: 6px; }

.cal-legend-swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.swatch-today   { background: var(--accent); }
.swatch-profit  { background: #10b981; }
.swatch-loss    { background: #ef4444; }
.swatch-weekend { background: #e2e8f0; }
.swatch-weekly  { background: var(--weekly); border-radius: 3px; }

/* ==========================================================
   BRANDED FOOTER — the screenshot anchor
   Every calendar screenshot ships with this. Keep it visible.
   ========================================================== */
.cal-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 10px;
  padding: 10px 4px 2px;
  border-top: 1px solid var(--border-soft);
  flex-shrink: 0;
}

.cal-brand-lockup {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.cal-brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--brand);
  box-shadow: 0 2px 6px rgba(34, 197, 94, 0.3);
  flex-shrink: 0;
}

.cal-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.cal-brand-name {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-1);
}

.cal-brand-tagline {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-3);
}

.cal-brand-url {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-3);
  white-space: nowrap;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
}

/* ---------- Entrance animation ---------- */
@keyframes cal-rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.cal-header   { animation: cal-rise 0.45s var(--ease) both; }
.cal-calendar { animation: cal-rise 0.45s var(--ease) 0.06s both; }

/* ==========================================================
   RESPONSIVE
   ========================================================== */
@media (max-width: 1200px), (max-height: 780px) {
  .cal-page {
    height: auto;
    min-height: auto;
    overflow: visible;
  }
  .cal-grid {
    grid-auto-rows: minmax(72px, auto);
  }
}

@media (max-width: 900px) {
  .cal-header { flex-direction: column; align-items: flex-start; }
  .cal-header-metrics { width: 100%; }
  .cal-metric { flex: 1 1 0; min-width: 0; }
}

@media (max-width: 768px) {
  .cal-calendar { padding: 14px; }
  .cal-grid { grid-template-columns: repeat(7, minmax(0, 1fr)) 62px; gap: 4px; }
  .cal-day { padding: 5px; border-radius: 8px; }
  .cal-day-num { width: 18px; height: 18px; font-size: 10px; border-radius: 6px; }
  .cal-day-pnl { font-size: 11px; }
  .cal-day-count, .cal-week-tag, .cal-week-total-count { display: none; }
  .cal-week-total-pnl { font-size: 10.5px; }
  .cal-month-title { font-size: 15px; min-width: 150px; }
  .cal-grid-head { font-size: 9.5px; letter-spacing: 0.04em; }
  .cal-heading h1 { font-size: 20px; }
  .cal-heading p { font-size: 12px; }
  .cal-brand-tagline { display: none; }
}

@media (max-width: 640px) {
  .cal-month-badge { display: none; }
}

@media (max-width: 480px) {
  .cal-grid { grid-template-columns: repeat(7, minmax(0, 1fr)) 44px; gap: 3px; }
  .cal-day { padding: 4px; border-radius: 6px; }
  .cal-day-num { width: 16px; height: 16px; font-size: 9.5px; border-radius: 5px; }
  .cal-day-pnl { font-size: 9.5px; }
  .cal-week-total-pnl { font-size: 9px; }
  .cal-week-total-empty { font-size: 11px; }
  .cal-grid-head { font-size: 8.5px; }
  .cal-brand { flex-direction: column; align-items: flex-start; gap: 6px; }
  .cal-brand-url { align-self: flex-start; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .cal-page *,
  .cal-page *::before,
  .cal-page *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ==========================================================================
   GRID LOCK — guarantees the 8-column layout even against other stylesheets.
   Must stay at the very end of this file.
   ========================================================================== */
.cal-page .cal-calendar .cal-grid {
  display: grid !important;
  grid-template-columns: repeat(7, minmax(0, 1fr)) 100px !important;
  grid-template-rows: auto !important;
  grid-auto-rows: minmax(0, 1fr) !important;
}

.cal-page .cal-calendar .cal-grid-head--weekly,
.cal-page .cal-calendar .cal-week-total {
  grid-column: 8 !important;
}

@media (max-width: 1200px), (max-height: 780px) {
  .cal-page .cal-calendar .cal-grid {
    grid-auto-rows: minmax(72px, auto) !important;
  }
}

@media (max-width: 768px) {
  .cal-page .cal-calendar .cal-grid {
    grid-template-columns: repeat(7, minmax(0, 1fr)) 62px !important;
  }
}

@media (max-width: 480px) {
  .cal-page .cal-calendar .cal-grid {
    grid-template-columns: repeat(7, minmax(0, 1fr)) 44px !important;
  }
}
