/* 0x730 UI Enhancements (additive, non-breaking)
   - Progressive, low-specificity enhancements layered on top of app.css
   - Improves forms globally and section display
   - Optional gradient utilities for header/footer and backgrounds
*/

/* Respect existing variables from app.css */
:root {
  --enh-focus-ring: var(--ring, rgba(30, 136, 229, 0.55));
  --enh-accent: var(--accent, #1e88e5);
  --enh-card: var(--card, #151b28);
  --enh-muted: var(--muted, #9bb0c5);
  --enh-fg: var(--fg, #e8edf3);
  --enh-border: #22324a;
}

/* Subtle header/footer visual upgrade (keeps colors in same family) */
.site-header {
  background: linear-gradient(135deg, #0e1626 0%, #14203a 100%);
  border-bottom: 1px solid var(--enh-border);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}
footer {
  background: linear-gradient(180deg, rgba(20, 28, 44, 0) 0%, rgba(20, 28, 44, 0.45) 100%);
  border-top: 1px solid var(--enh-border);
}

/* Form enhancements (progressive, low specificity via :where) */
/* Make form rows wrap and breathe without breaking existing layout */
.row {
  flex-wrap: wrap;
  row-gap: 10px;
}
@media (min-width: 900px) {
  /* Prefer 3–4 fields per row by giving children a reasonable basis */
  .row > .w-120,
  .row > .w-140,
  .row > .w-160,
  .row > .w-180,
  .row > .w-200,
  .row > .w-240,
  .row > .w-260,
  .row > .flex-1 {
    flex-basis: calc((100% - 3 * 12px) / 4); /* up to 4 per row */
  }
}
@media (max-width: 899.98px) and (min-width: 640px) {
  /* On medium screens, aim ~3 per row */
  .row > .w-120,
  .row > .w-140,
  .row > .w-160,
  .row > .w-180,
  .row > .w-200,
  .row > .w-240,
  .row > .w-260,
  .row > .flex-1 {
    flex-basis: calc((100% - 2 * 12px) / 3);
  }
}
@media (min-width: 1100px) {
  .row {
    column-gap: 12px;
  }
}
/* Ensure width utility boxes behave well when wrapping */
.w-120 {
  flex: 0 1 auto;
  min-width: 120px;
}
.w-140 {
  flex: 0 1 auto;
  min-width: 140px;
}
.w-160 {
  flex: 0 1 auto;
  min-width: 160px;
}
.w-180 {
  flex: 0 1 auto;
  min-width: 180px;
}
.w-200 {
  flex: 0 1 auto;
  min-width: 200px;
}
.w-240 {
  flex: 0 1 auto;
  min-width: 240px;
  width: 240px;
}
.w-260 {
  flex: 0 1 auto;
  min-width: 260px;
  width: 260px;
}
/* Let flex-1 grow but not shrink too small to avoid crowding */
.flex-1 {
  flex: 1 1 280px;
  min-width: 240px;
}
:where(input, select, textarea) {
  border-radius: 10px;
}
:where(textarea) {
  background: #141e33;
  color: var(--enh-fg);
  border: 1px solid #314564;
  min-height: 84px;
  resize: vertical;
}
:where(input, select, textarea)::placeholder {
  color: var(--enh-muted);
  opacity: 0.95;
}
:where(input, select, textarea):focus-visible {
  outline: none;
  border-color: var(--enh-accent);
  box-shadow: 0 0 0 3px var(--enh-focus-ring);
}
:where(input, select, textarea)[aria-invalid='true'],
:where(input, select, textarea).is-invalid {
  border-color: #e53935;
  box-shadow: 0 0 0 3px rgba(229, 57, 53, 0.28);
}
:where(.help-text) {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--enh-muted);
}

/* Checkbox/Radio modern coloring without breaking older browsers */
:where(input[type='checkbox'], input[type='radio']) {
  accent-color: var(--enh-accent);
}

/* Buttons: slightly smoother hover/focus */
:where(button, .button, .btn) {
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}
:where(button, .button, .btn):hover {
  filter: brightness(1.06);
}
:where(button, .button, .btn):focus-visible {
  outline: none;
  box-shadow:
    0 0 0 3px var(--enh-focus-ring),
    0 1px 0 rgba(0, 0, 0, 0.25);
}

/* Section and card utilities */
.section {
  background: var(--enh-card);
  border: 1px solid var(--enh-border);
  border-radius: 12px;
  padding: 16px;
}
/* Global widget surface similar to Swarms cards background */
.widget,
.card.widget,
.widget.card {
  background: #151521;
  border: 1px solid #2a2a3a;
}
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-elevated {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(0, 0, 0, 0.02)), var(--enh-card);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

/* Responsive auto grid utility */
.grid-auto {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

/* Gentle reveal animation utility (opt-in) */
.reveal {
  opacity: 0;
  transform: translateY(6px);
  animation: reveal-fade 360ms ease forwards;
}
@keyframes reveal-fade {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Table visual polish (non-breaking) */
.table-wrap {
  position: relative;
}
.table-wrap table {
  border-collapse: separate; /* allow sticky header shadow without clipping */
  border-spacing: 0;
}
.table-wrap table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  backdrop-filter: saturate(120%) blur(2px);
}
.table-wrap.table-scroll {
  overflow: auto;
}
.table-wrap table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

/* Optional gradients for utility use (not applied automatically) */
.bg-gradient-1 {
  background-image: linear-gradient(135deg, #1b2a4a 0%, #1a3a6a 100%);
}
.bg-gradient-2 {
  background-image: linear-gradient(135deg, #1a2a2a 0%, #0f3a3a 100%);
}
.bg-gradient-3 {
  background-image: linear-gradient(135deg, #3a1a2a 0%, #6a1a3a 100%);
}

/* Opt-in header/footer gradient helpers */
.gradient-header {
  background-image: linear-gradient(135deg, #0c1a2a 0%, #1c2f4f 100%) !important;
}
.gradient-footer {
  background-image: linear-gradient(
    180deg,
    rgba(12, 26, 42, 0) 0%,
    rgba(12, 26, 42, 0.6) 100%
  ) !important;
}

/* Subtle divider utility */
.hr {
  height: 1px;
  background: linear-gradient(90deg, transparent, #22324a, transparent);
  border: 0;
  margin: 12px 0;
}

/* Back-to-top button refined hover */
.back-to-top {
  background:
    radial-gradient(120px 80px at 60% 120%, rgba(30, 136, 229, 0.35), transparent 70%), #1b2840;
  border: 1px solid #2a3a56;
}
.back-to-top:hover {
  filter: brightness(1.08);
}

/* Field label and help spacing normalization (non-breaking) */
.row > div > label {
  display: block;
  margin-bottom: 4px;
}
.row input,
.row select,
.row textarea {
  margin-top: 2px;
}
.row > div > .help-text {
  min-height: 16px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
/* Ensure a little breathing room on the right of fields when many inline */
.row > div {
  margin-right: 8px;
}
.row > div:last-child {
  margin-right: 0;
}

/* Strategy and Settings form polish (additive) */
.card form > .row {
  align-items: flex-end;
}

/* Symbol pickers: use app theme instead of inline light borders */
#symbol-picker,
#sd-symbol-picker {
  border: 1px solid #22324a !important;
  background: rgba(15, 22, 34, 0.6);
  border-radius: 10px !important;
}
#symbol-picker .row,
#sd-symbol-picker .row {
  flex-wrap: wrap;
  row-gap: 8px;
}
#symbol-picker select[multiple],
#sd-symbol-picker select[multiple] {
  min-height: 112px;
}

/* Filters bars: ensure comfortable spacing */
#sp-filter,
#sd-filter,
#sp-tags,
#sd-tagsFilter {
  min-width: 140px;
}
#sp-search,
#sd-search {
  min-width: 220px;
}

/* Compact check label wrapping */
.inline-chk {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.inline-chk input[type='checkbox'] {
  margin: 0;
}

/* PnL filters layout */
#pnl-filters {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
#pnl-filters select,
#pnl-filters input {
  width: auto;
  min-width: 140px;
}

/* Ensure Symbols picker block takes a full row on forms */
#manual-symbols-block,
#sd-manual-symbols-block {
  width: 100%;
  flex: 0 0 100%;
}
/* Keep inner controls on one line where possible */
#manual-symbols-block > .row,
#sd-manual-symbols-block > .row {
  flex-wrap: nowrap;
}

/* Dashboard filters (Index page) */
#dashboard-filters {
  gap: 8px;
  flex-wrap: nowrap;
}
#dashboard-filters label {
  white-space: nowrap;
}
#dashboard-filters select {
  width: auto;
}
@media (max-width: 1100px) {
  #dashboard-filters {
    flex-wrap: wrap;
  }
}

/* --- Responsive upgrades (global, minimal, non-breaking) --- */
/* Make images and iframes scale within containers */
img,
video,
canvas,
svg,
iframe {
  max-width: 100%;
  height: auto;
}

/* Improve table usability on small screens */
@media (max-width: 768px) {
  .container {
    padding: 12px;
  }
  /* Ensure horizontal scroll instead of squeezing columns */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .table-wrap > table {
    min-width: 680px;
  }
  table {
    font-size: 11px;
  }
  th,
  td {
    padding: 6px;
  }
}

/* Fixed layout helper when specified by templates (e.g., workers table) */
table.fixed {
  table-layout: fixed;
  width: 100%;
}
table.fixed th,
table.fixed td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Mobile navigation for layout.njk (#primary-nav + #nav-toggle) */
@media (max-width: 900px) {
  /* Show hamburger, hide full nav by default */
  #nav-toggle {
    display: inline-flex !important;
    align-items: center;
    gap: 6px;
  }
  #primary-nav {
    display: none;
    flex-direction: column;
    gap: 8px;
    padding-top: 8px;
  }
  #primary-nav.nav--open {
    display: flex;
  }
  #primary-nav a {
    margin-right: 0;
    padding: 8px 0;
  }
  #primary-nav .menu-group {
    margin-right: 0;
  }
  #primary-nav .submenu {
    position: static;
    display: none;
    border: 0;
    padding: 0;
    background: transparent;
  }
  #primary-nav .menu-group:hover .submenu {
    display: flex;
  }
}

/* Nicer Tx link on index page (dashboard trades) */
.tx-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  text-decoration: none;
  line-height: 1;
  border: 1px solid var(--enh-border);
  color: var(--enh-accent);
  background: linear-gradient(180deg, rgba(30, 136, 229, 0.08) 0%, rgba(30, 136, 229, 0.04) 100%);
}
.tx-link:hover {
  background: rgba(30, 136, 229, 0.12);
  border-color: #2b4f75;
}
.tx-link:active {
  transform: translateY(0.5px);
}
.tx-link:focus-visible {
  outline: 2px solid var(--enh-focus-ring);
  outline-offset: 2px;
}
.tx-link svg {
  display: inline-block;
  vertical-align: middle;
}

/* 0x730 UI Enhancements (additive, non-breaking)
   - Progressive, low-specificity enhancements layered on top of app.css
   - Improves forms globally and section display
   - Optional gradient utilities for header/footer and backgrounds
*/

/* Respect existing variables from app.css */
:root {
  --enh-focus-ring: var(--ring, rgba(30, 136, 229, 0.55));
  --enh-accent: var(--accent, #1e88e5);
  --enh-card: var(--card, #151b28);
  --enh-muted: var(--muted, #9bb0c5);
  --enh-fg: var(--fg, #e8edf3);
  --enh-border: #22324a;
}

/* Subtle header/footer visual upgrade (keeps colors in same family) */
.site-header {
  background: linear-gradient(135deg, #0e1626 0%, #14203a 100%);
  border-bottom: 1px solid var(--enh-border);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}
footer {
  background: linear-gradient(180deg, rgba(20, 28, 44, 0) 0%, rgba(20, 28, 44, 0.45) 100%);
  border-top: 1px solid var(--enh-border);
}

/* Form enhancements (progressive, low specificity via :where) */
/* Make form rows wrap and breathe without breaking existing layout */
.row {
  flex-wrap: wrap;
  row-gap: 10px;
}
@media (min-width: 900px) {
  /* Prefer 3–4 fields per row by giving children a reasonable basis */
  .row > .w-120,
  .row > .w-140,
  .row > .w-160,
  .row > .w-180,
  .row > .w-200,
  .row > .w-240,
  .row > .w-260,
  .row > .flex-1 {
    flex-basis: calc((100% - 3 * 12px) / 4); /* up to 4 per row */
  }
}
@media (max-width: 899.98px) and (min-width: 640px) {
  /* On medium screens, aim ~3 per row */
  .row > .w-120,
  .row > .w-140,
  .row > .w-160,
  .row > .w-180,
  .row > .w-200,
  .row > .w-240,
  .row > .w-260,
  .row > .flex-1 {
    flex-basis: calc((100% - 2 * 12px) / 3);
  }
}
@media (min-width: 1100px) {
  .row {
    column-gap: 12px;
  }
}
/* Ensure width utility boxes behave well when wrapping */
.w-120 {
  flex: 0 1 auto;
  min-width: 120px;
}
.w-140 {
  flex: 0 1 auto;
  min-width: 140px;
}
.w-160 {
  flex: 0 1 auto;
  min-width: 160px;
}
.w-180 {
  flex: 0 1 auto;
  min-width: 180px;
}
.w-200 {
  flex: 0 1 auto;
  min-width: 200px;
}
.w-240 {
  flex: 0 1 auto;
  min-width: 240px;
  width: 240px;
}
.w-260 {
  flex: 0 1 auto;
  min-width: 260px;
  width: 260px;
}
/* Let flex-1 grow but not shrink too small to avoid crowding */
.flex-1 {
  flex: 1 1 280px;
  min-width: 240px;
}
:where(input, select, textarea) {
  border-radius: 10px;
}
:where(textarea) {
  background: #141e33;
  color: var(--enh-fg);
  border: 1px solid #314564;
  min-height: 84px;
  resize: vertical;
}
:where(input, select, textarea)::placeholder {
  color: var(--enh-muted);
}

/* Cards breathing */
.card {
  border: 1px solid #1f2a44;
  background: linear-gradient(180deg, #0f1627 0%, #111b2f 100%);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

/* Kraken-inspired global search (non-breaking addition) */
.header-inner {
  gap: 12px;
}
.global-search {
  display: none; /* default hidden on very small screens */
  position: relative;
  flex: 1 1 420px;
  max-width: 680px;
}
.global-search input {
  width: 100%;
  height: 40px;
  padding: 0 68px 0 14px;
  border-radius: 10px;
  border: 1px solid #27344e;
  background: #111a2d;
  color: var(--enh-fg);
  outline: none;
}
.global-search input:focus {
  box-shadow: 0 0 0 3px rgba(146, 116, 255, 0.35);
  border-color: #445c8a;
}
.global-search .search-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  height: 28px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 12px;
  color: #cbd5f0;
  border: 1px solid #39496d;
  background: linear-gradient(180deg, #1a2541, #121a2e);
}
@media (min-width: 860px) {
  .global-search {
    display: block;
  }
}

/* Quick actions (right side) */
.quick-actions {
  display: none;
}
@media (min-width: 860px) {
  .quick-actions {
    display: block;
  }
}
.btn-gradient {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 14px;
  border-radius: 10px;
  background: linear-gradient(90deg, #6d4cff 0%, #9b6bff 100%);
  color: white !important;
  border: 0;
  box-shadow: 0 4px 16px rgba(109, 76, 255, 0.35);
}
.btn-gradient:hover {
  filter: brightness(1.05);
}

/* Navigation spacing tweaks */
.nav .menu-button {
  border-radius: 10px;
}
.nav .menu-list {
  border-radius: 12px;
}

/* Kraken-like font toggle (optional)
   Legal note: This does NOT use Kraken’s proprietary font. It switches the UI to a modern
   system sans-serif stack that is broadly available (Apple/Windows/Linux defaults),
   imitating a similar feel without bundling or referencing any third‑party licensed fonts. */
body.font-kraken {
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Helvetica, Arial,
    'Noto Sans', 'Liberation Sans', Ubuntu, Cantarell, 'Segoe UI Symbol', 'Apple Color Emoji',
    'Segoe UI Emoji', sans-serif;
  letter-spacing: 0.1px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- Small UX tuning additions (opt-in, non-breaking) --- */
/* Zebra-striped tables (apply class="zebra" on tables you want striped) */
:where(table.zebra) tbody tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.015);
}
:where(table.zebra) tbody tr:hover td {
  background: rgba(255, 255, 255, 0.03);
}

/* Improved keyboard focus ring for key interactive elements */
:where(a, button, .button, .btn):focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--enh-focus-ring);
}

/* Generic muted text utility */
.muted {
  color: var(--enh-muted) !important;
}

/* Empty-state helper box (opt-in) */
.empty-state {
  text-align: center;
  color: var(--enh-muted);
  padding: 24px 12px;
  border: 1px dashed var(--enh-border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
}

/* Optional narrower container variant for pages that prefer shorter line length */
.container.narrow {
  max-width: 1200px;
}
