/* Forced compact (via JS) regardless of width */
.hu-actions-compact { display: grid !important; grid-auto-flow: row !important; row-gap: 6px !important; justify-items: end !important; }

/* General portrait tightening (larger phones/tablets in portrait) */
@media (orientation: portrait) {
  .higherups-body { padding: 6px; }
  .hucard { padding-bottom: 4px; }
  .higherups-body .hucard:first-of-type { padding-bottom: 0 !important; }
  #huDuesList { margin-top: 0; }
}

/* Wider screens: relax compaction slightly for readability */
@media (min-width: 900px) {
  .huli { padding: 4px 8px; gap: 4px; line-height: 1.2; }
  .hu-dues-row { gap: 6px; font-size: 0.9rem; grid-template-columns: 1.2fr .65fr .6fr auto; }
  .huli .actions .hu-btn { min-height: 28px; height: auto; padding: 4px 8px; font-size: 0.85rem; align-items: center; }
  /* Show button labels on wider screens for clarity */
  .huli .actions .hu-btn span { display: inline; }
}

/* ===== Redesigned dues row layout ===== */
.huli.hu-dues { grid-template-columns: 1fr auto auto; gap: 6px; align-items: center; }
.huli.hu-dues .hu-col { min-width: 0; }
.huli.hu-dues .hu-main { min-width: 0; }
.huli.hu-dues .hu-name { font-weight: 700; color: var(--hu-text); overflow-wrap: anywhere; white-space: normal; }
.huli.hu-dues .hu-sub { display: inline-flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.huli.hu-dues .hu-status { justify-self: start; }
.huli.hu-dues .hu-actions { justify-self: end; }
/* Paid/Unpaid chips for redesigned row */
.hu-paid, .hu-notpaid { font-weight: 700; padding: 2px 8px; border-radius: 999px; line-height: 1; border: 1px solid var(--hu-border); font-size: 0.95rem; }
.hu-paid { color: #23c164; background: rgba(35,193,100,0.30); border-color: rgba(35,193,100,0.55); }
.hu-notpaid { color: #ff3b30; background: rgba(255,59,48,0.32); border-color: rgba(255,59,48,0.55); }
.hu-amount { opacity: 0.9; }
.hu-week { opacity: 0.9; }
@media (max-width: 800px) {
  .huli.hu-dues { grid-template-columns: 1fr; }
  .huli.hu-dues .hu-status { justify-self: start; }
  .huli.hu-dues .hu-actions { justify-self: end; }
}
.hu-actions-compact .hu-btn { padding: 4px !important; width: 28px !important; height: 28px !important; min-width: 28px !important; display: inline-flex !important; align-items: center; justify-content: center; }
.hu-actions-compact .hu-btn span { display: none !important; }
:root {
  --hu-bg: var(--card-bg, #111);
  --hu-panel: var(--panel-bg, #0e0e0e);
  --hu-border: var(--border-color, rgba(255,255,255,0.08));
  --hu-text: var(--text-color, #eaeaea);
  --hu-muted: var(--muted, #9aa0a6);
  --hu-accent: var(--accent, #2e7d32);
  --hu-danger: #e53935;
}

/* Overlay */
#higherUpsOverlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.55);
  z-index: 10020;
  padding: 20px;
}

/* Panel */
#higherUpsPanel {
  width: min(1100px, 96vw);
  height: auto;
  max-height: 71vh;
  display: flex;
  flex-direction: column;
  background: var(--hu-panel);
  color: var(--hu-text);
  border: 1px solid var(--hu-border);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  overflow: hidden;
}

.higherups-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--hu-border);
  background: linear-gradient(180deg, rgba(255,255,255,0.05), transparent);
}
.higherups-header h3 {
  margin: 0;
  font-size: 1.0rem;
  display: flex;
  align-items: center;
  gap: 10px;
}
.higherups-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--hu-border);
  border-radius: 8px;
  background: transparent;
  color: var(--hu-text);
  width: 36px; height: 32px;
  cursor: pointer;
}
.higherups-close:hover { background: rgba(255,255,255,0.06); }

/* Tabs */
.higherups-tabs {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--hu-border);
}
.higherups-tab-btn {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--hu-border);
  background: rgba(255,255,255,0.04);
  color: var(--hu-text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}
.higherups-tab-btn.active {
  border-color: rgba(46,125,50,0.45);
  background: rgba(46,125,50,0.12);
  color: var(--hu-accent);
}

/* Body */
.higherups-body {
  overflow: auto;
  padding: 8px;
  display: grid;
  gap: 8px;
  flex: 1 1 auto;
  min-height: 0;
  /* Prevent tracks from stretching to fill panel height */
  align-content: start;
  grid-auto-rows: max-content;
}

.hucard {
  background: var(--hu-bg);
  border: 1px solid var(--hu-border);
  border-radius: 10px;
  padding: 8px 8px 6px;
}
.hucard h4 { margin: 0 0 4px; font-size: 0.94rem; }
.hucard .helper { color: var(--hu-muted); font-size: 0.85rem; margin-bottom: 6px; }
/* Prevent trailing gaps inside cards */
.hucard > *:last-child { margin-bottom: 0 !important; }
.hucard .hu-row { margin-bottom: 0; }
.hucard .hu-row > * { margin-bottom: 0; }
/* Make the first card (Add Weekly Due) visually hug its content */
.higherups-body .hucard:first-of-type { padding-bottom: 0 !important; }
.higherups-body .hucard:first-of-type > *:last-child { margin-bottom: 0 !important; }
.higherups-body .hucard:first-of-type .hu-row { margin-bottom: 0 !important; padding-bottom: 0 !important; }
.higherups-body .hucard:first-of-type .hu-row .hu-btn { margin-bottom: 0 !important; }

/* Controls */
.hu-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.hu-input, .hu-select, .hu-textarea {
  background: #0a0a0a;
  color: var(--hu-text);
  border: 1px solid var(--hu-border);
  border-radius: 8px;
  padding: 8px 10px;
}
.hu-input.small { width: 96px; }
.hu-textarea { width: 100%; min-height: 80px; resize: vertical; }
.hu-btn { background: rgba(255,255,255,0.05); border: 1px solid var(--hu-border); color: var(--hu-text); padding: 8px 12px; border-radius: 8px; cursor: pointer; }
.hu-btn.primary { background: rgba(46,125,50,0.15); border-color: rgba(46,125,50,0.45); color: var(--hu-accent); }
.hu-btn.danger { background: rgba(229,57,53,0.1); border-color: rgba(229,57,53,0.4); color: var(--hu-danger); }

/* Lists */
#huItemsList, #huDuesList, #huAnnList { display: grid; gap: 3px; }
/* Dues: 2-column layout (responsive) */
#huDuesList { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.hu-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.hu-add-row { display: grid; grid-template-columns: 1fr 120px auto; gap: 8px; align-items: center; }
.hu-add-row #huDuesName { min-width: 0; }
.hu-add-row #huDuesAmt { width: 120px; }
.hu-add-row .hu-btn { white-space: nowrap; }
@media (max-width: 720px) {
  #huDuesList { grid-template-columns: 1fr; }
}
.huli {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 2px;
  padding: 2px 6px;
  border: 0.5px solid var(--hu-border);
  border-radius: 6px;
  background: rgba(255,255,255,0.01);
  line-height: 1.16;
}
.huli:hover { background: rgba(255,255,255,0.02); }
.huli:nth-child(even) { background: rgba(255,255,255,0.018); }
.huli .meta { color: var(--hu-muted); font-size: 0.78rem; }
.huli .actions { display: inline-flex; gap: 4px; }
/* Default (non-stacked) action buttons slightly smaller */
.huli .actions .hu-btn { min-height: 28px; height: auto; padding: 4px 8px; font-size: 0.8rem; line-height: 1.2; display: inline-flex; align-items: center; }
.huli .chip { font-size: 0.68rem; padding: 1px 4px; border: 1px solid var(--hu-border); border-radius: 6px; color: var(--hu-muted); display: inline-flex; align-items: center; line-height: 1; white-space: nowrap; }

/* Dues list specifics */
.hu-dues-row { display: grid; grid-template-columns: 1fr .55fr .5fr auto; gap: 2px; align-items: center; font-size: 0.82rem; }
.hu-dues-row .chip { justify-self: start; align-self: center; }
.hu-dues-row .paid, .hu-dues-row .notpaid {
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  line-height: 1;
  border: 1px solid var(--hu-border);
  justify-self: start;
}
.hu-dues-row .paid { color: var(--hu-accent); background: rgba(46,125,50,0.12); border-color: rgba(46,125,50,0.35); }
.hu-dues-row .notpaid { color: var(--hu-danger); background: rgba(229,57,53,0.10); border-color: rgba(229,57,53,0.30); }

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

/* Tablet and below: make dues action buttons compact and stacked to free width */
@media (max-width: 800px) {
  /* Make each dues list item single-column so actions can sit below */
  #huDuesList .huli { grid-template-columns: 1fr !important; }
  #huDuesList .hu-dues-row { grid-template-columns: 1fr !important; }
  /* Put actions on their own row, right-aligned */
  #huDuesList .huli .actions { display: grid !important; grid-auto-flow: row !important; row-gap: 2px !important; justify-items: end !important; grid-column: 1 / -1 !important; margin-top: 2px; }
  #huDuesList .huli .actions .hu-btn { padding: 4px !important; width: 28px !important; height: 28px !important; min-width: 28px !important; display: inline-flex !important; align-items: center; justify-content: center; line-height: 1; }
  #huDuesList .huli .actions .hu-btn span { display: none !important; }
  #huDuesList .huli .actions .hu-btn i { font-size: 0.85rem !important; }
  #huDuesList .huli .actions .hu-btn { margin: 0 !important; }
}

/* Narrow screens: make dues action buttons compact and avoid cutting off names */
@media (max-width: 600px) {
  /* Stack row content */
  #huDuesList .huli { grid-template-columns: 1fr; }
  #huDuesList .hu-dues-row { grid-template-columns: 1fr; row-gap: 4px; }
  /* Allow long names to wrap instead of clipping */
  #huDuesList .hu-dues-row > div:first-child { overflow-wrap: anywhere; word-break: break-word; }
  /* Compact actions: icon-only, stacked vertically to save width */
  #huDuesList .huli .actions { display: grid; grid-auto-flow: row; row-gap: 2px; justify-items: end; }
  #huDuesList .huli .actions .hu-btn { padding: 6px; width: 34px; height: 34px; min-width: 34px; display: inline-flex; align-items: center; justify-content: center; }
  #huDuesList .huli .actions .hu-btn span { display: none; }
  #huDuesList .huli .actions .hu-btn i { font-size: 0.95rem; }
  #huDuesList .huli .actions .hu-btn { margin: 0; }
}

/* Narrow portrait: shave padding/gaps for minimal layout */
@media (max-width: 480px) {
  .higherups-body { padding: 4px; gap: 4px; }
  .hucard { padding: 4px 6px 2px; }
  .hucard h4 { margin-bottom: 3px; }
  .hucard .helper { margin-bottom: 3px; }
  .hu-add-row { grid-template-columns: 1fr 100px auto; gap: 6px; }
  .hu-add-row #huDuesAmt { width: 100px; }
  #huDuesList { gap: 2px; margin-top: 0; }
  .huli { padding: 2px 4px; }
  .huli.hu-dues { gap: 4px; }
  .huli .actions .hu-btn { min-height: 26px; padding: 3px 6px; }
}

/* Narrow and mobile: align like desktop but condensed (name/sub on left, actions on right) */
@media (max-width: 900px) {
  /* Always single column list on narrow */
  #huDuesList { grid-template-columns: 1fr !important; }
  #huDuesList .huli.hu-dues { grid-template-columns: 1fr auto; grid-template-areas: 'name actions' 'sub actions'; align-items: center; }
  #huDuesList .huli.hu-dues .hu-main { grid-area: name; }
  #huDuesList .huli.hu-dues .hu-status, #huDuesList .huli.hu-dues .hu-sub { grid-area: sub; display: inline-flex; gap: 6px; flex-wrap: wrap; }
  #huDuesList .huli.hu-dues .hu-actions { grid-area: actions; }
  /* Keep actions side-by-side even on narrow */
  #huDuesList .huli.hu-dues .actions { display: inline-flex !important; gap: 4px !important; flex-wrap: nowrap; }
}
