/* =============================================================================
   RapidGain version 3 - the ONE style sheet (replaces V2's app_style*.css).
   The colours are V2's (Kevin: "I like the way they are"). Every button is .btn:
   squarer, with rounded corners, the same everywhere; .small / .icon / .danger /
   .plain only change its size or colour. The buttons never shrink: when the window
   is narrow they wrap (Wendy runs RapidGain in a third to half of a super wide
   monitor).
   ============================================================================= */

:root {
  --primary: #0f172a;      /* deep navy: the top bar, headings */
  --secondary: #334155;    /* slate */
  --accent: #10b981;       /* emerald: buttons, growth, buy */
  --accent-hover: #059669;
  --bg: #f8fafc;
  --text: #1e293b;
  --muted: #64748b;
  --red: #ef4444;
  --danger: #e2e8f0;       /* delete buttons: a pale bluish grey that almost disappears (Kevin, 2026-Nov-29) */
  --danger-text: #64748b;
  --danger-hover: #cbd5e1;
  --purple: #7c3aed;       /* sell */
  --green: #047857;
  --white: #ffffff;
  --border: #e2e8f0;
  --input-border: #94a3b8;
  --pink: #da70d6;         /* the sort order's key cell */
  --steel: #557c99;
  --shadow: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
  --radius: 6px;
  --page-max: 1200px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
@media (min-width: 600px) { html { scrollbar-gutter: stable; } }
body {
  font-family: "JetBrains Mono", "Liberation Mono", monospace;
  font-size: .9375rem; line-height: 1.5;
  background: var(--bg); color: var(--text);
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--steel); }
h1 { font-size: 1.25rem; color: var(--primary); }
h3 { font-size: 1rem; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.muted { color: var(--muted); }
.small { font-size: .8125rem; }
.nowrap { white-space: nowrap; }
.r { text-align: right; margin-left: auto; }
.up { color: var(--green); }
.down { color: var(--red); }
.flat { color: inherit; }
[hidden] { display: none !important; }

/* ---- Buttons (all of them) ----
   The text is centred by what the eye sees: text-box trims the line to the top of the
   capitals and the baseline, so the font's room for accents and for the tails of g and
   y no longer pushes the text up (Kevin, 2026-Nov-29: every button's text sat high).
   Sizes in rem. */
.btn {
  font: inherit; font-weight: 600; font-size: .9375rem; line-height: 1.2;
  background: var(--accent); color: var(--white);
  border: 0; border-radius: var(--radius);
  padding: .5625rem 1.125rem; min-height: 2.375rem;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: .375rem;
  white-space: nowrap; flex: none;
  transition: background-color .2s ease;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { background: #cbd5e1; color: #f1f5f9; cursor: not-allowed; }
.btn.small { padding: .3125rem .75rem; min-height: 1.875rem; font-size: .8125rem; }
.btn.icon { width: 3.25rem; padding: 0; font-size: 1.25rem; font-weight: 400; }
.btn.danger { background: var(--danger); color: var(--danger-text); font-weight: 500; }
.btn.danger:hover { background: var(--danger-hover); color: var(--secondary); }
.btn.plain { background: transparent; color: var(--muted); }
.btn.plain:hover { background: var(--border); }
/* Browsers with text-box (Chrome, Brave, Edge): the line is trimmed to the capitals and
   the button's height is split evenly above and below them - centred in any font. */
@supports (text-box: trim-both cap alphabetic) and (height: 1cap) {
  .btn { display: inline-block; text-align: center; text-box: trim-both cap alphabetic;
         min-height: 0; padding-top: calc((2.375rem - 1cap) / 2); padding-bottom: calc((2.375rem - 1cap) / 2); }
  .btn.small { padding-top: calc((1.875rem - 1cap) / 2); padding-bottom: calc((1.875rem - 1cap) / 2); }
  .btn.icon, .btn.x { padding: calc((2.375rem - 1cap) / 2) 0; }
  .btn.icon.lift { padding-top: calc((2.375rem - 1cap) / 2 - .14rem); padding-bottom: calc((2.375rem - 1cap) / 2 + .14rem); }
}
/* Other browsers: the same idea by more padding above than below */
@supports not ((text-box: trim-both cap alphabetic) and (height: 1cap)) {
  .btn { padding-top: .6875rem; padding-bottom: .4375rem; }
  .btn.small { padding-top: .4375rem; padding-bottom: .1875rem; }
}

/* ---- Inputs ---- */
.inp {
  font: inherit; color: var(--text); background: var(--white);
  border: 1px solid var(--input-border); border-radius: var(--radius);
  padding: 7px 10px; min-height: 38px; min-width: 0;
}
.inp:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.inp.up { text-transform: uppercase; }
.inp.num { width: 9em; text-align: right; }
.inp.short { width: 11em; }
.inp.wide { width: 100%; }
label { display: block; color: var(--muted); font-size: .875rem; margin: 8px 0 3px; }
.pw-toggle { cursor: pointer; user-select: none; }
.pw-toggle:hover { color: var(--text); }
.pw-hint { font-size: .75rem; color: var(--steel); margin-left: .375rem; }

/* ---- Top bar ---- */
.topbar {
  background: var(--primary); color: var(--white); box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 100;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: 10px 16px;
}
.logo { font-size: 1.4rem; font-weight: 700; color: var(--white); letter-spacing: .02em; }
.logo span { color: var(--accent); }
.who { color: #cbd5e1; font-size: .875rem; }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; flex: 1 1 auto; }
.grp { display: inline-flex; align-items: center; gap: 8px; }
.grp.end { margin-left: auto; }
/* The search boxes: the text centred by eye. A box centres the whole line, room for
   the tails of g and y included; the search term is in capitals (no tails), so it sat
   high - more padding above than below, the box height unchanged (Kevin, 2026-Nov-29). */
.srch { width: 15em; padding-top: .5rem; padding-bottom: .375rem; }
.srch.up { padding-top: .625rem; padding-bottom: .25rem; }
.srch-typ { width: auto; padding-right: .25rem; padding-top: .5rem; padding-bottom: .375rem; }

/* ---- Page ---- */
.page { width: 100%; max-width: var(--page-max); margin: 0 auto; padding: 16px; flex: 1; }
.head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; margin: 4px 0 14px; }
.badge { background: var(--accent); color: var(--white); border-radius: var(--radius); padding: 0 8px; font-size: .8125rem; font-weight: 600; }
.empty { color: var(--muted); text-align: center; padding: 48px 12px; }
.msg { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; border: 1px solid; }
.msg.ok { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.msg.warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.msg.err { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

/* ---- Cards (dashboard, sort options, settings, tools) ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-bottom: 14px; }
.card {
  background: var(--white); border: 1px solid var(--border); border-radius: 8px;
  padding: 16px; box-shadow: 0 2px 4px rgba(0,0,0,.02);
}
.cards .card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.kv { display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
      border-bottom: 1px solid var(--border); padding: 4px 0; }
.kv:last-of-type { border-bottom: 0; }
.kv b { text-align: right; }
.trend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; font-size: .875rem; }
.card .btn { margin-top: 10px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px; }
.row .inp { flex: 1 1 8em; }
.row.end { justify-content: flex-end; }

/* ---- Sort options ---- */
.opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.opt .btn { margin-top: 0; }

/* ---- Stock boxes ---- */
.divider { margin: 18px 0 8px; padding: 6px 10px; border-radius: var(--radius); font-weight: 700; }
.divider.mkt { background: var(--primary); color: var(--white); display: flex; justify-content: space-between; align-items: center; }
.divider.sct { background: #e2e8f0; color: var(--primary); display: flex; align-items: center; gap: 12px; }
/* Counts are labels, not buttons: never the button green. On a coloured bar they take
   the bar's background (text only); on their own they are a slate-blue tag. */
.count { background: var(--steel); color: var(--white); border-radius: var(--radius); padding: 3px 12px; font-size: .875rem; font-weight: 600; white-space: nowrap; cursor: default; }
.divider .cnt { background: transparent; font-size: .875rem; font-weight: 600; margin-left: auto; white-space: nowrap; cursor: default; }
.divider.mkt .cnt { color: #cbd5e1; }
.divider.sct .cnt { color: var(--steel); }
.sct-params i { font-style: normal; color: var(--muted); }
.sct-title { display: flex; flex-direction: column; min-width: 0; }
.sct-params { display: flex; flex-wrap: wrap; gap: 4px 18px; font-weight: 600; font-size: .875rem; color: var(--text); }
/* the tiny pie (as V2): the sector's slice of the market portfolio */
.tiny-pie {
  --size: 36px; width: var(--size); height: var(--size); border-radius: 50%; flex-shrink: 0;
  background: conic-gradient(var(--accent) 0% calc(var(--p) * 1%), var(--primary) calc(var(--p) * 1%) 100%);
  box-shadow: 0 0 0 1px rgba(0,0,0,.1);
}
.boxes { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.box {
  background: var(--white); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; display: flex; flex-direction: column; gap: 4px;
}
.box:hover { border-color: var(--accent); box-shadow: var(--shadow); }
/* the stock opened last (marked when the list is shown again) */
.box.last { outline: 3px solid var(--steel); outline-offset: 1px; background: #eef3f7; }
.box-row { display: grid; grid-template-columns: 30% 1fr 26%; align-items: center; gap: 6px; min-height: 32px; }
.box-row > span { padding: 2px 6px; border: 2px solid transparent; border-radius: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.box-row .cmp { color: var(--muted); font-size: .8125rem; }
.box-row .hl { border-color: var(--pink); }
.box-row.yld { border-top: 1px dashed var(--border); padding-top: 4px; }
.btn.sym { padding: 4px 8px; min-height: 30px; justify-self: start; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }

/* ---- Stock details ---- */
.dtl-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin-bottom: 12px; }
.dtl-sym { font-size: 1.5rem; font-weight: 700; color: var(--primary); }
.dtl-cmp { font-size: 1.1rem; font-weight: 600; }
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.btn.tab { background: var(--white); color: var(--secondary); border: 1px solid var(--border); }
.btn.tab.on { background: var(--primary); color: var(--white); border-color: var(--primary); }
.tabpane { display: none; }
.tabpane.on { display: block; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 12px; }
.figs { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-left: auto; }
.figs > div { display: flex; flex-direction: column; min-width: 6em; }
.figs a { color: var(--steel); }
.tblwrap { overflow-x: auto; }
.tbl { border-collapse: collapse; width: 100%; background: var(--white); }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); padding: 6px 10px; border-bottom: 2px solid var(--border); white-space: nowrap; }
.tbl td { padding: 6px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl th.r, .tbl td.r { text-align: right; }
.tbl td .btn { margin: 0; }
.typ.buy, .typ.own { color: var(--green); font-weight: 600; }
.typ.sell { color: var(--purple); font-weight: 600; font-style: italic; }
.sold { color: var(--purple); }
.cmt { margin-bottom: 8px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 10px 14px; }
.cmt-main { flex: 1 1 24em; min-width: 0; }
.cmt .row { justify-content: space-between; margin-top: 0; }
.cmt-first { margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmt-btns { display: flex; gap: 8px; }
/* View Comment: newspaper columns (rgn.js layoutNews). In view at first: as many columns
   of at least 22.5em (about 38 characters a line, a newspaper column) as fit, at most 6 -
   on Kevin's 2560-wide super-wide screen 6 full width, 3 on half of it; 2 on a laptop,
   1 on a phone. No column is taller
   than the window: the text runs top to bottom, column after column, and the columns
   that do not fit continue to the right, with a horizontal scroll bar (the mouse wheel
   scrolls them sideways). A short comment is spread evenly over the columns in view. */
.news { column-gap: 2.5em; column-rule: 1px solid var(--border); line-height: 1.6;
        overflow-x: auto; overflow-y: hidden; padding-bottom: 6px;
        scrollbar-width: auto; scrollbar-color: var(--steel) var(--border); }
.news::-webkit-scrollbar { height: 14px; }
.news::-webkit-scrollbar-track { background: var(--border); border-radius: 7px; }
.news::-webkit-scrollbar-thumb { background: var(--steel); border-radius: 7px; }
.news-more { margin-right: auto; align-self: center; color: var(--steel); font-weight: 600; }
.news p { margin: 0 0 .9em; }
.news-meta { margin-bottom: 12px; }
.calc { max-width: 640px; }

/* ---- Dialog ---- */
.dlg { border: 0; border-radius: 10px; box-shadow: 0 20px 40px rgba(0,0,0,.25); padding: 0;
       width: min(720px, calc(100vw - 24px)); max-height: calc(100vh - 24px); margin: auto; }
.dlg.wide { width: calc(100vw - 32px); max-width: none; }
.dlg.wide .dlg-body { max-height: none; overflow: hidden; }
.dlg::backdrop { background: rgba(15,23,42,.45); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.dlg-head h2 { font-size: 1.1rem; color: var(--primary); }
.btn.x { width: 2.375rem; padding-left: 0; padding-right: 0; font-size: 1.4rem; }
.dlg-body { padding: 16px; overflow: auto; max-height: calc(100vh - 160px); }
.dlg-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); }
.fgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px 14px; }
.fgrid .inp { width: 100%; }
.dlg-msg { margin-top: 10px; min-height: 1.5em; }
.sets { display: grid; gap: 12px; }
.sets fieldset { border: 1px solid var(--border); }
.sets legend { font-weight: 700; color: var(--primary); padding: 0 6px; }
textarea.inp { width: 100%; min-height: 40vh; resize: vertical; }
.calcbox { text-align: center; }
.calcbox input[type=range] { width: 100%; margin: 14px 0; }
.calcbox .big { font-size: 1.25rem; font-weight: 700; color: var(--green); }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 300;
         background: var(--primary); color: var(--white); padding: 10px 18px; border-radius: var(--radius);
         box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.toast.err { background: var(--red); }

/* ---- Log in ---- */
.login-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; }
.login-card h1 { margin-bottom: 10px; }
.login-card .btn { margin: 16px 0 8px; }

/* ---- SYSDBA Tools ---- */
.admin .card { margin-bottom: 14px; }
.mode { font-size: 1.5rem; font-weight: 700; }
.mode.test { color: #b45309; }
.mode.production { color: var(--green); }
.toolrow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.toolrow:last-child { border-bottom: 0; }
.toolrow form { display: flex; flex-wrap: wrap; gap: 8px; }
.toolrow .btn { margin: 0; min-width: 12em; }
.toolrow .muted { flex: 1 1 20em; }
.report { white-space: pre-wrap; background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: var(--radius); font-size: .8125rem; margin-bottom: 14px; overflow-x: auto; }
details.card summary { cursor: pointer; font-weight: 600; color: var(--primary); }
details.card .report { margin-top: 10px; }
.setrow { display: grid; grid-template-columns: minmax(12em, 1fr) 2fr; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); }
.setrow label { margin: 0; color: var(--text); }
@media (max-width: 640px) { .setrow { grid-template-columns: 1fr; } }
