/* =========================================================
   app.css
   Layout + app-specific components + states
   ========================================================= */

/* -------------------------
   1) Base document sizing
------------------------- */
html, body {
  height: 100%;
  margin: 0;
  overflow-x: hidden;
}

:root {
  --app-vh: 95vh;
  --app-pad: 30px; /* matches your #app-background padding */
  --app-minh: calc(var(--app-vh) - var(--app-pad));
  --app-h: calc(var(--app-vh) - var(--app-pad));
}

/* -------------------------
   2) App outer layout
------------------------- */
#app {
  width: min(1200px, calc(100% - 24px));
  margin: clamp(12px, 3vh, 80px) auto;

  height: var(--app-h);
  min-height: var(--app-h); /* optional, but keeps it stable */
  max-height: var(--app-h); /* critical: prevents growth */
  overflow: hidden;         /* ensures children can't push it */

  display: flex;
  flex-direction: column;
  box-shadow: 4px 4px 6px rgba(0, 0, 0, 0.25);
}

#app-header {
  width: 100%;
  display: flex;
  flex-direction: column;
  text-align: left;
  flex: 0 0 auto;
}

#app-background {
  /* layout only */
  display: flex;
  align-items: stretch;
  justify-content: stretch;

  height: 100%;
  width: 100%;
  min-height: 0; /*min-height: var(--app-minh);*/

  padding: 20px;
  box-sizing: border-box;

  flex: 1 1 auto;
}

.main-inner {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 0px;

  flex: 1 1 auto;
  min-height: 0;
  height: auto;
}

/* -------------------------
   3) Common helpers
------------------------- */
.mono {
  font-family: ui-monospace, monospace;
}

input[type="text"] {
  width: 200px;
  max-width: 100%;
}

.span-2 {
  grid-column: 1 / -1;
}

/* -------------------------
   4) Page layout (two panels)
------------------------- */
.button-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;

  height: 100%;
  min-height: 0;
  align-content: stretch;
  align-items: stretch;
}

/* -------------------------
   5) Forms
------------------------- */
.form-grid {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 10px 12px;
  align-items: center;
}

.input {
  max-width: 90px;
  width: 100%;
}

/* -------------------------
   6) Panels sizing (app-specific)
------------------------- */
.inner-panel {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow: hidden;
}

#issuesPanel,
#bountiesPanel {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* header row inside the bounties panel */
#bountiesPanel .panel-header {
  height: 50px;
  padding: 6px 10px;

  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;

  background: transparent;
  border-bottom: 1px solid var(--kde-border);
  box-shadow: inset 0 -1px 0 var(--kde-highlight);
}

#bountiesPanel .panel-title {
  white-space: nowrap;
}

#bountiesPanel .panel-meta {
  flex: 1 1 auto;
  min-width: 0;

  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

#factoryAddress {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#factoryBountyCount {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* -------------------------
   7) Scrollable lists
------------------------- */
#bountiesList {
  flex: 1 1 auto;
  overflow-y: auto;
  padding-right: 6px;
}

#bountiesList {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;

  display: flex;          /* add */
  flex-direction: column; /* add */
  gap: 12px;              /* optional: spacing between bounty rows */
}

.issues-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding-right: 6px;
  border-top: 1px solid var(--kde-border);
  box-shadow: inset 0 1px 0 var(--kde-highlight);
}

/* only the shrink fix here */
#issuesList,
#bountiesList,
.issues-list {
  min-height: 0;
}

/* -------------------------
   8) Issue rows
------------------------- */
.issue-row {
  padding: 10px 12px;
  border-bottom: 1px solid var(--kde-border);
  box-shadow: inset 0 1px 0 var(--kde-highlight);
  cursor: pointer;
}
.issue-row:hover {
  filter: brightness(1.03);
}
.issue-row.selected {
  outline: 2px solid #222;
  box-shadow:
    inset 0 0 0 1px var(--kde-highlight),
    2px 2px 0 #222;
}

.issue-title {
  font-weight: bold;
}

.issue-meta {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  opacity: 0.85;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.issue-body {
  font-size: 12px;
  opacity: 0.9;
  margin-top: 4px;

  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;

  white-space: pre-wrap;
}

/* -------------------------
   9) Bounty row
------------------------- */
.bounty-row {
  background-color: var(--kde-panel);
  border: 1px solid var(--kde-border);
  padding: 12px 16px;
  border-radius: 4px;
  box-shadow:
    inset 0 0 0 1px var(--kde-highlight),
    2px 2px 4px rgba(0,0,0,0.3);
}

.bounty-row .mono {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  word-break: break-all;
}

/* -------------------------
   10) Loading states / spinners
------------------------- */
#bountiesList.is-loading {
  opacity: 0.6;
  pointer-events: none;
}
#bountiesList.is-loading::before {
  display: block;
  font-style: italic;
  margin-bottom: 8px;
  /* NOTE: there is no `content:` in your current CSS,
     so this pseudo-element renders nothing. Add one if desired:
     content: "Loading…";
  */
}

#issuesList.is-loading {
  opacity: 0.6;
  pointer-events: none;
}

/* Refresh button spinner */
#refreshButton.is-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.85;
}
#refreshButton.is-loading::after {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 8px;
  vertical-align: -2px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}




/* Outer window frame layout */
.kde-window {
  display: flex;
  flex-direction: column;
  min-height: var(--app-minh); /* or your existing app height var */
  position: relative;          /* important if corners are absolute */
}

.kde-window-row {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: stretch; /* makes left/right lips full height */
}

.kde-window-inner {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Make teal area take remaining height under header */
#app-background {
  flex: 1 1 auto;
  min-height: 0;
}



/* =========================================================
   Portrait / mobile layout: stack panels + give them more height
   ========================================================= */
@media (max-aspect-ratio: 1/1), (max-width: 820px) {

  /* Let the window become a vertical page (instead of a fixed 95vh box) */
  #app {
    height: auto;
    min-height: calc(100vh - 24px);
    max-height: none;
  }

  /* Let the teal area size naturally with content */
  #app-background {
    height: auto;
    min-height: 0;
  }

  /* Force single-column stack (even if 420px might otherwise still “fit”) */
  .button-group {
    grid-template-columns: 1fr;
    grid-auto-rows: auto;
    align-content: start;
  }

  /* Make each panel feel “taller” in the vertical format */
  #issuesPanel,
  #bountiesPanel {
    height: auto;
  }

  /* Give panels a minimum vertical presence, but still allow growth */
  .inner-panel {
    min-height: min(520px, 70vh);
  }

  /* Lists should scroll within their panel once they get big */
  #issuesList,
  #bountiesList {
    max-height: 55vh;
    overflow-y: auto;
  }
}




/* =========================================================
   11) Bounty rows — compact layout + state tint + details popover
   ========================================================= */

/* Compact layout wrapper (keeps your existing .bounty-row skin) */
.bounty-row.bounty-row-compact {
  padding: 10px 12px;              /* a touch tighter than your 12px 16px */
  display: grid;
  grid-template-columns: 1fr auto; /* left stack | right stack */
  grid-template-rows: auto auto;   /* title row | meta row */
  column-gap: 12px;
  row-gap: 6px;
}

/* Top-left: "#123 — Title" */
.bounty-compact-title {
  grid-column: 1;
  grid-row: 1;
  font-weight: 700;
  line-height: 1.15;
  min-width: 0;

  /* keep titles compact */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Bottom-left: "owner/repo" */
.bounty-compact-repo {
  grid-column: 1;
  grid-row: 2;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  opacity: 0.85;

  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

/* Top-right: funding */
.bounty-compact-funding {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
  align-self: start;
  font-family: ui-monospace, monospace;
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
}

/* Bottom-right: details icon button */
.bounty-compact-more {
  grid-column: 2;
  grid-row: 2;
  justify-self: end;
  align-self: end;

  width: 26px;
  height: 22px;
  padding: 0;
  line-height: 1;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  cursor: pointer;
  user-select: none;
}

/* Make the icon button feel KDE-ish without fighting your .button skin */
.bounty-compact-more.button.kde {
  min-width: unset;
}

/* ---------- State tint backgrounds ----------
   These are subtle overlays so your KDE bevel/borders still read.
   Apply one of these classes on the bounty row container:
   .bounty-state-base / empty / ready / calculating / paid
*/
.bounty-row.bounty-state-base {
  background-image: linear-gradient(to bottom, rgba(0,0,0,0.00), rgba(0,0,0,0.02));
}

.bounty-row.bounty-state-empty {
  background-image: linear-gradient(to bottom, rgba(160,160,160,0.15), rgba(160,160,160,0.06));
}

.bounty-row.bounty-state-ready {
  background-image: linear-gradient(to bottom, rgba(110,190,120,0.22), rgba(110,190,120,0.08));
}

.bounty-row.bounty-state-calculating {
  background-image: linear-gradient(to bottom, rgba(255,210,90,0.26), rgba(255,210,90,0.10));
}

.bounty-row.bounty-state-paid {
  background-image: linear-gradient(to bottom, rgba(120,160,255,0.24), rgba(120,160,255,0.09));
}

/* Optional: tiny badge style if you ever add it later */
.bounty-state-pill {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  padding: 2px 6px;
  border: 1px solid var(--kde-border);
  box-shadow: inset 0 0 0 1px var(--kde-highlight);
  border-radius: 3px;
  white-space: nowrap;
}

/* ---------- Details popover ----------
   Single shared popover element, positioned by JS.
   IMPORTANT: allow text selection; prevent click-off close only when clicking inside.
*/
#bountyDetailsPopover {
  position: fixed; /* fixed so it doesn't get clipped by #app overflow:hidden */
  z-index: 9999;

  width: min(520px, calc(100vw - 24px));
  max-height: min(420px, calc(100vh - 24px));
  overflow: auto;

  background: var(--kde-panel);
  border: 1px solid var(--kde-border);
  box-shadow:
    inset 0 0 0 1px var(--kde-highlight),
    4px 4px 0 rgba(0,0,0,0.25);

  border-radius: 4px;
  padding: 10px 12px;

  user-select: text; /* selectable text */
}

#bountyDetailsPopover[hidden] {
  display: none;
}

#bountyDetailsPopover .details-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 6px 10px;
  align-items: start;
}

#bountyDetailsPopover .details-k {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  opacity: 0.85;
}

#bountyDetailsPopover .details-v {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  word-break: break-all;
  white-space: pre-wrap;
}

/* Keep links readable in KDE palette */
#bountyDetailsPopover a {
  color: #0033aa;
  text-decoration: underline;
}
