/* ---------------------------------------------------------
   Additions for the hosted app: account menu, save status,
   toast, and the Reports screen. Built on the theme variables
   in styles.css so every theme restyles them.
--------------------------------------------------------- */

[hidden]{ display: none !important; }

.rr-loading{ font-family: var(--font-mono); color: var(--ink-soft); text-align: center; padding: 80px 0; }

/* ---------- account menu ---------- */
.rr-account{
  position: fixed; top: calc(16px + env(safe-area-inset-top, 0px)); right: calc(16px + env(safe-area-inset-right, 0px)); z-index: 56;
  display: flex; align-items: center; gap: 8px;
}
.rr-new-set{
  display: inline-flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; padding: 0; border-radius: 50%; flex: none;
  background: var(--burgundy); color: var(--on-accent); border: 0;
  box-shadow: 0 3px 8px rgba(0,0,0,0.15); cursor: pointer;
}
.rr-new-set svg{ width: 22px; height: 22px; }
.rr-new-set:hover, .rr-new-set:focus-visible{ filter: brightness(1.08); }
.rr-user{
  height: 46px; max-width: 216px; padding: 0 17px; border-radius: 23px;
  background: var(--paper-dark); border: 1.5px solid var(--rule); color: var(--ink-soft);
  font-family: var(--font-mono); font-size: 14px; cursor: pointer;
  box-shadow: 0 3px 8px rgba(0,0,0,0.15);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rr-user:hover, .rr-user[aria-expanded="true"]{ color: var(--ink); border-color: var(--brass-light); }
.rr-menu{
  position: absolute; top: 53px; right: 0; min-width: 170px;
  background: var(--paper); border: 1.5px solid var(--rule); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.18); padding: 6px; display: flex; flex-direction: column;
}
.rr-menu button{
  text-align: left; background: none; border: 0; color: var(--ink); padding: 9px 10px;
  font-family: var(--font-serif); font-size: 14px; border-radius: var(--radius); cursor: pointer;
}
.rr-menu button:hover, .rr-menu button:focus-visible{ background: var(--sapphire-tint); }
.rr-sync{
  /* Sits below the top-left back button (when one is showing) so its changing
     width never nudges anything else — its own position is fixed either way. */
  position: fixed; top: calc(70px + env(safe-area-inset-top, 0px)); left: calc(16px + env(safe-area-inset-left, 0px)); z-index: 55;
  font-family: var(--font-mono); font-size: 11px; color: var(--ink-soft);
  background: var(--paper-dark); border: 1px solid var(--rule); border-radius: 12px; padding: 3px 9px;
  opacity: 0; transition: opacity .3s ease;
}
.rr-sync[data-kind="saving"], .rr-sync[data-kind="offline"], .rr-sync[data-kind="error"]{ opacity: 1; }
.rr-sync[data-kind="saved"]{ opacity: 0.85; animation: rr-fade 2.4s ease forwards; }
.rr-sync[data-kind="error"]{ color: var(--error); }
@keyframes rr-fade{ 0%, 60%{ opacity: .85; } 100%{ opacity: 0; } }

.rr-toast{
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(24px + env(safe-area-inset-bottom, 0px)); z-index: 70;
  background: var(--forest); color: var(--on-accent); font-family: var(--font-serif);
  padding: 10px 18px; border-radius: var(--radius); box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  max-width: calc(100vw - 32px);
}

@media (max-width: 680px){
  .rr-account{ top: calc(10px + env(safe-area-inset-top, 0px)); right: calc(10px + env(safe-area-inset-right, 0px)); }
  .rr-user{ max-width: 132px; height: 41px; padding: 0 12px; }
  .rr-new-set{ width: 41px; height: 41px; }
  .rr-new-set svg{ width: 20px; height: 20px; }
  .rr-sync{ display: none; }
  .wrap{ padding-top: 44px; } /* room for the fixed account menu */
}

/* ---------- reports ---------- */
.rr-filters{ display: flex; flex-direction: column; gap: 14px; margin: 0 0 16px; }
.rr-filter-block{ margin-top: 0; }
.rr-filter-block + .rr-filter-block{ margin-left: 20px; }
.rr-filters .option-row{ flex-wrap: wrap; }
.rr-refetching{ opacity: .6; transition: opacity .2s; }

.rr-tiles{ display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.rr-tile{
  background: var(--paper); border: 1.5px solid var(--rule); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}
.rr-tile-label{ font-family: var(--font-mono); font-size: 11px; letter-spacing: .06em; color: var(--ink-soft); }
.rr-tile-value{ font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-weight: 600; font-size: 28px; color: var(--ink); margin-top: 4px; }
.rr-tile-of{ font-size: 15px; font-weight: 500; color: var(--ink-soft); }
.rr-tile-note{ font-size: 12px; color: var(--ink-soft); margin-top: 2px; }

.rr-table-wrap{ overflow-x: auto; margin-top: 8px; }
.rr-table{ width: 100%; border-collapse: collapse; font-size: 14px; }
.rr-table th{
  text-align: left; font-family: var(--font-mono); font-weight: 400; font-size: 11px; letter-spacing: .05em;
  color: var(--ink-soft); padding: 6px 8px; border-bottom: 1.5px solid var(--rule);
}
.rr-table td{ padding: 8px; border-bottom: 1px solid var(--rule); vertical-align: top; color: var(--ink); }
.rr-table .num{ text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rr-def{ font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; max-width: 42ch; }
.rr-muted{ color: var(--ink-soft); font-size: 12.5px; }
.rr-actions{ margin-top: 14px; }

/* ---------- charts ----------
   A fixed chart surface with a palette validated for colorblind
   separation (categorical slots 1–3, all pairs) and an ordinal
   blue ramp. .viz-dark is set by reports.js from the theme's paper. */
.viz-panel{
  --viz-surface: #fcfcfb; --viz-ink: #0b0b0b; --viz-ink-2: #52514e; --viz-muted: #898781;
  --viz-grid: #e1e0d9; --viz-axis: #c3c2b7; --viz-border: rgba(11,11,11,0.10);
  --viz-s1: #2a78d6; --viz-s2: #eb6834; --viz-s3: #1baf7a;
  --viz-o1: #104281; --viz-o2: #2a78d6; --viz-o3: #86b6ef; --viz-track: #e1e0d9;
  position: relative; margin: 14px 0 0; padding: 14px 16px 12px;
  background: var(--viz-surface); color: var(--viz-ink);
  border: 1px solid var(--viz-border); border-radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
.viz-panel.viz-dark{
  color-scheme: dark;
  --viz-surface: #1a1a19; --viz-ink: #ffffff; --viz-ink-2: #c3c2b7; --viz-muted: #898781;
  --viz-grid: #2c2c2a; --viz-axis: #383835; --viz-border: rgba(255,255,255,0.10);
  --viz-s1: #3987e5; --viz-s2: #d95926; --viz-s3: #199e70;
  --viz-o1: #9ec5f4; --viz-o2: #3987e5; --viz-o3: #184f95; --viz-track: #2c2c2a;
}
.viz-panel figcaption{ display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.viz-title{ font-weight: 600; font-size: 14px; }
.viz-sub{ font-size: 12.5px; color: var(--viz-ink-2); }
.viz-empty{ font-size: 13px; color: var(--viz-ink-2); margin: 6px 0 2px; }
.viz-legend{ display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--viz-ink-2); margin: 2px 0 6px; }
.viz-legend:empty{ display: none; }
.viz-key{ display: inline-flex; align-items: center; gap: 6px; }
.viz-plot{ width: 100%; }
.viz-plot svg{ display: block; overflow: visible; }
.viz-grid{ stroke: var(--viz-grid); stroke-width: 1; }
.viz-axis{ stroke: var(--viz-axis); stroke-width: 1; }
.viz-tick{ fill: var(--viz-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.viz-rowlabel{ fill: var(--viz-ink-2); font-size: 12px; }
.viz-label{ fill: var(--viz-ink-2); font-size: 11.5px; font-weight: 600; }
.viz-cross{ stroke: var(--viz-axis); stroke-width: 1; pointer-events: none; }
.viz-seg{ cursor: default; outline: none; }
.viz-seg:hover, .viz-seg:focus-visible{ filter: brightness(1.12); }
.viz-plot rect[tabindex]:focus-visible{ outline: 2px solid var(--viz-s1); outline-offset: -2px; }
.viz-tip{
  position: absolute; z-index: 5; pointer-events: none; min-width: 120px;
  background: var(--viz-surface); color: var(--viz-ink); border: 1px solid var(--viz-border);
  border-radius: 6px; padding: 7px 10px; font-size: 12.5px; box-shadow: 0 6px 18px rgba(0,0,0,0.16);
}
.viz-tip-head, .viz-tip-sub{ color: var(--viz-ink-2); font-size: 12px; }
.viz-tip-head{ margin-bottom: 3px; }
.viz-tip-row{ display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.viz-tip-row i{ display: inline-block; width: 12px; height: 2px; border-radius: 1px; }
.viz-tip-row span{ color: var(--viz-ink-2); }
.viz-table{ margin-top: 8px; font-size: 12.5px; }
.viz-table summary{ cursor: pointer; color: var(--viz-ink-2); }
.viz-table .rr-table td, .viz-table .rr-table th{ color: var(--viz-ink); border-color: var(--viz-grid); font-family: inherit; }

@media (max-width: 560px){
  .rr-hide-sm, .rr-def{ display: none; }
  .rr-table{ font-size: 13px; }
  .rr-table td, .rr-table th{ padding: 7px 5px; }
  .rr-tile-value{ font-size: 24px; }
}

/* ---------- study sets: Library tiles ---------- */
.set-desc{ display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.set-tile .cat-name{ overflow-wrap: anywhere; }

/* ---------- study sets: Home line for a created set ---------- */
.se-owner-line{
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  font-family: var(--font-mono); font-size: 12px; color: var(--ink-soft); margin: 10px 0 0;
}
.se-edit-btn{ font-size: 13px; padding: 6px 12px; }

/* ---------- study sets: editor ---------- */
.set-editor .se-input{ font-size: 16px; }
.set-editor textarea.se-input{ min-height: 0; overflow: hidden; resize: none; }
.se-note{
  font-size: 14px; color: var(--ink-soft); background: var(--sapphire-tint);
  border-radius: var(--radius); padding: 8px 12px; margin: 0 0 6px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
}
.se-count{ color: var(--ink-soft); letter-spacing: 0.04em; }
.se-cards{ list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.se-card{
  display: grid; grid-template-columns: 28px minmax(0, 1fr) minmax(0, 1.6fr) 36px; gap: 12px; align-items: start;
  padding: 14px; border: 1.5px solid var(--rule); border-radius: var(--radius); background: var(--paper);
}
.se-card:focus-within{ border-color: var(--brass-light); }
.se-num{ font-family: var(--font-mono); font-size: 13px; color: var(--ink-soft); padding-top: 30px; text-align: right; }
.se-side{ display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.se-side-label{ font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-soft); }
.se-card .written-input{ padding: 10px 12px; }
.se-card textarea.written-input{ font-size: 15px; }
.se-remove{
  width: 36px; height: 36px; margin-top: 24px; border-radius: 50%;
  background: transparent; border: 1.5px solid var(--rule); color: var(--ink-soft);
  cursor: pointer; font-size: 14px; line-height: 1;
}
.se-remove:hover:not(:disabled), .se-remove:focus-visible{ color: var(--error); border-color: var(--error); }
.se-remove:disabled{ opacity: .35; cursor: not-allowed; }
.se-add{ width: 100%; border-style: dashed; }
.se-add:disabled{ opacity: .5; cursor: not-allowed; }
.set-editor [aria-invalid="true"]{ border-color: var(--error); }
.se-delete{ margin-left: auto; padding: 10px 16px; font-size: 15px; }
.se-confirm{
  margin-top: 16px; padding: 14px 16px; border: 1.5px solid var(--error); border-radius: var(--radius);
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
}
.se-confirm p{ margin: 0 0 4px; flex-basis: 100%; color: var(--ink); }
.se-confirm .btn-danger{ padding: 10px 16px; font-size: 15px; }

@media (max-width: 680px){
  .se-card{ grid-template-columns: 24px minmax(0, 1fr) 36px; grid-template-areas: "num term remove" "num def def"; }
  .se-num{ grid-area: num; padding-top: 30px; }
  .se-card .se-side:not(.se-side-def){ grid-area: term; }
  .se-side-def{ grid-area: def; }
  .se-remove{ grid-area: remove; }
  .se-delete{ margin-left: 0; }
}
