:root {
  --bg: #0b0e14;
  --surface: rgba(22, 27, 34, 0.55);
  --border: #30363d;
  --text: #ffffff;
  --muted: #8b949e;
  --link: #58a6ff;
  --input-bg: #0d1117;
  --radius: 8px;
  --font: "Inter", system-ui, sans-serif;
  --glass-blur: 14px;
}

* {
  box-sizing: border-box;
}

html,
body,
#root {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  background: radial-gradient(1200px 800px at 20% 10%, rgba(88, 166, 255, 0.25), transparent 60%),
    radial-gradient(1000px 700px at 80% 20%, rgba(217, 70, 239, 0.16), transparent 55%),
    radial-gradient(1200px 800px at 50% 90%, rgba(34, 197, 94, 0.08), transparent 60%),
    var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  font-family: inherit;
  cursor: pointer;
}

input {
  font-family: inherit;
}

.glass {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
}

.glass table th,
.glass table td {
  border-color: rgba(255, 255, 255, 0.10) !important;
}

.sheetTable {
  /* min width + width: max(100%, sum of columns) set inline in PortfolioPage — fixed layout keeps column drag-resize stable */
  min-width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  background: rgba(13, 17, 23, 0.25);
}

.sheetTable th,
.sheetTable td {
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1.25;
  vertical-align: middle;
  /* Row height slider sets minimum; content (news, editing, long text) can grow — scroll is on the panel */
  min-height: var(--sheet-row-height, 28px);
  height: auto;
  box-sizing: border-box;
}

.sheetTable thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: rgba(13, 17, 23, 0.9);
  font-weight: 700;
}

/* Grouped header row (e.g. "Actual Profit", "Estimation STP Profit") — sits above the per-column row. */
.sheetHeadGroupRow th.sheetHeadGroupCell {
  top: 0;
  text-align: center;
  background: rgba(13, 17, 23, 0.92);
  padding: 4px 6px;
  font-size: 11px;
  letter-spacing: 0.2px;
}
.sheetHeadGroupRow th.sheetHeadGroupEmpty {
  background: rgba(13, 17, 23, 0.9);
}
/* Per-column header row sticks below the group row. --sheet-group-h is set on the table. */
.sheetTable thead tr.sheetHeadColRow th {
  top: var(--sheet-group-h, 26px);
}

/* Group boxed borders — emphasize the rectangle around a column group (like the Google Sheet). */
.sheetTable .groupCellFirst { border-left: 2px solid rgba(255, 255, 255, 0.55) !important; }
.sheetTable .groupCellLast  { border-right: 2px solid rgba(255, 255, 255, 0.55) !important; }
.sheetHeadGroupRow th.sheetHeadGroupCell:not(.sheetHeadGroupEmpty) {
  border: 2px solid rgba(255, 255, 255, 0.55) !important;
}

/* Drag states for column reordering. */
.sheetTable thead tr.sheetHeadColRow th.colDragOverBefore { box-shadow: inset 3px 0 0 0 rgba(88, 166, 255, 0.9); }
.sheetTable thead tr.sheetHeadColRow th.colDragOverAfter  { box-shadow: inset -3px 0 0 0 rgba(88, 166, 255, 0.9); }
.sheetTable thead tr.sheetHeadColRow th.colDragging { opacity: 0.5; }

/* Formula popover */
.formulaPopover {
  position: absolute;
  z-index: 60;
  background: rgba(13, 17, 23, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  padding: 10px;
  min-width: 340px;
  max-width: 520px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
}
.formulaPopover textarea {
  width: 100%;
  min-height: 70px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  resize: vertical;
}

.sheetThInner {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sheetColResizer {
  position: absolute;
  top: -6px;
  right: -8px;
  width: 12px;
  height: calc(100% + 12px);
  cursor: col-resize;
}

.sheetColResizer::after {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 100%;
  background: rgba(255, 255, 255, 0.16);
  opacity: 0;
}

.sheetColResizer:hover::after {
  opacity: 1;
}

.sheetTable tbody tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.03);
}

.sheetTable tbody tr:hover td {
  background: rgba(88, 166, 255, 0.10);
}

.sheetTable td input {
  width: 100%;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  box-shadow: none;
}

.sheetTable td input:focus {
  outline: 2px solid rgba(88, 166, 255, 0.55);
  outline-offset: 1px;
}

.sheetTableCompact th,
.sheetTableCompact td {
  padding: 2px 5px;
  font-size: 11px;
  line-height: 1.15;
}

.sheetTableCompact .sheetThInner {
  gap: 4px;
}

.sheetTableCompact .sheetColResizer {
  top: -2px;
  right: -6px;
  width: 10px;
  height: calc(100% + 4px);
}

.glass button,
.glass input,
.glass select {
  background: rgba(13, 17, 23, 0.55);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 6px 10px;
}

.glass button:hover {
  border-color: rgba(255, 255, 255, 0.22);
}

.glass input::placeholder {
  color: rgba(255, 255, 255, 0.45);
}

.column-dd-row:hover {
  background: rgba(255, 255, 255, 0.05);
}

/* -------------------------------------------------------------------------
 * Mobile / tablet responsive layout
 *
 * The portfolio dashboard is built around react-rnd panels with absolute
 * positioning + per-panel saved rects. That layout works great on desktop
 * but is unusable on phones. For small screens we disable the absolute
 * layout entirely and stack the panels vertically, full-width.
 *
 * Everything here is CSS-only so the desktop JS/layout logic is untouched.
 * ------------------------------------------------------------------------- */

/* Prevent iOS Safari from auto-zooming when focusing text inputs (happens
 * when the font-size is below 16px). */
@media (max-width: 768px) {
  input,
  select,
  textarea {
    font-size: 16px;
  }
}

@media (max-width: 900px) {
  .portfolioPage,
  .adminPage {
    padding: 10px !important;
  }

  .howToUsePage {
    margin: 16px auto !important;
    padding: 0 12px !important;
  }

  .portfolioHeader {
    flex-direction: column;
    align-items: stretch !important;
    gap: 8px;
  }

  .portfolioHeader > div {
    flex-wrap: wrap;
  }

  /* Stack the Rnd panels vertically on mobile instead of absolute positioning. */
  .dashboardPanels {
    position: static !important;
    height: auto !important;
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  /* Each direct child of the dashboard container is either an Rnd wrapper
   * (<div style="position:absolute; transform:translate(...)">) or the
   * layout-editor popover. Override their inline absolute positioning so
   * they flow in the normal document order at full width. */
  .dashboardPanels > div {
    position: static !important;
    transform: none !important;
    inset: auto !important;
    left: auto !important;
    top: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
  }

  /* Rnd renders an inner wrapper that also carries a fixed height. */
  .dashboardPanels > div > div {
    height: auto !important;
    min-height: 0 !important;
    max-width: 100% !important;
  }

  /* Hide the Rnd resize handles on mobile — they're useless without the
   * absolute layout and would only get in the way. */
  .dashboardPanels .react-resizable-handle,
  .dashboardPanels [class*="resizable-handle"] {
    display: none !important;
  }

  /* Any panel-internal content that was sized for desktop should be allowed
   * to scroll horizontally rather than blow out the viewport. */
  .dashboardPanels .glass {
    overflow-x: auto;
  }

  /* Admin users table: let it scroll horizontally on narrow screens. */
  .adminPage > table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  /* How-to-use code blocks already scroll horizontally via overflowX. Make
   * the page readable by allowing inline code / text to wrap. */
  .howToUsePage pre,
  .howToUsePage code {
    word-break: break-word;
  }
}

/* Extra-small phones: further tighten spacing. */
@media (max-width: 480px) {
  .portfolioPage,
  .adminPage {
    padding: 8px !important;
  }
}

