/*
 * File: redmine_sla/assets/stylesheets/redmine_sla.css
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * Redmine SLA - service level agreement plugin
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
 */

/*** display color indicator ***/
.sla_display.good { --c:green; }
.sla_display.warn { --c:orange; }
.sla_display.fail { --c:red; }
.sla_display.doneok { --c:darkgreen; }
.sla_display.doneko { --c:darkred; }

/*** Only display circle for pie and square for bar in mobile mode ***/
@media screen and (max-width: 480px) {
  .sla_display {
    --c:green;
    width: 20px;
    height: 20px;
    font-size: 0;
    color: transparent;
    background: var(--c);
    display: inline-block;
  }
  .sla_bar {
    border-radius: 15%;
  }
  .sla_pie {
    border-radius: 50%;
  }
}

/*** Progress bar ***/
@media screen and (min-width: 481px) {

  .sla_bar {
    --p:50;
    --c:darkgrey;
    background: darkgrey;
    color: transparent;
    font-size: 0;
    height: 25px;
    width: 125px;
    position: relative;
  }
  .sla_bar_square { border-radius: 5%; }
  .sla_bar_square::after { border-radius: 5%; }
  .sla_bar_rounded {
    /* Kept well under half the bar's 25px height: at 12px (~half), a fill
       whose width happens to land near 25px (e.g. ~20% of the 125px bar)
       turns into a near-perfect circle -- reading as "done" instead of a
       partial fill. 8px still looks rounded at any width without ever
       fully closing into a circle/pill at some unlucky percentage. */
    border-radius: 8px;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.15);
  }
  .sla_bar_rounded::after {
    border-radius: 8px;
    /* Below ~2x the radius, the browser clamps the corner curvature down
       to fit the box, so at very low percentages (a couple of px wide)
       the curve shrinks to sub-pixel and the fill reads as a straight
       edge instead of rounded. A floor on the width keeps it a visible
       small pill once it's shown at all (see .sla_bar_no_fill below for
       the even-smaller values where nothing is shown instead). */
    min-width: 12px;
  }
  /* Below 5px (4% of the 125px bar) the sla_display helper adds this
     class instead of letting min-width force a fill: at that point the
     floor above would be pure invention relative to the real value, so
     showing no fill at all reads better than an arbitrary-looking nub.
     Two classes (not one) so this reliably outranks .sla_bar:after's
     `display: block` below regardless of source order -- same specificity
     there would make the later rule in the file win. */
  .sla_bar.sla_bar_no_fill::after { display: none; }

  .sla_bar::before,
  .sla_bar::after {
    content: '';
    z-index: 1;
    top: 0;
    left: 0;
    height: 25px;
    width: 125px;
    position: absolute;
  }
  .sla_bar:before {
    content: attr(label);
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    color:white;
    font-size: 12px;
    font-weight: bold;
    font-family: sans-serif;
    text-shadow: 0 1px 2px rgba(0,0,0,0.55);
    background-color: transparent;
  }
  .sla_bar:after {
    width: calc(var(--p)*1%);
    background: var(--c);
    display: block;
  }

  .sla_pie_modern {
    --p:50;
    --b:6px;
    --w:56px;
    --c:green;
    width: var(--w);
    aspect-ratio: 1;
    position: relative;
    display: inline-grid;
    margin: 4px;
    place-content: center;
    font-size: 11px;
    font-weight: bold;
    font-family: sans-serif;
  }
  .sla_pie_modern:before,
  .sla_pie_modern:after {
    content: "";
    position: absolute;
    border-radius: 50%;
  }
  .sla_pie_modern:before {
    inset: 0;
    background:
      radial-gradient(farthest-side,var(--c) 98%,#0000) top/var(--b) var(--b) no-repeat,
      conic-gradient(var(--c) calc(var(--p)*1%),#0000 0);
    -webkit-mask: radial-gradient(farthest-side,#0000 calc(99% - var(--b)),#000 calc(100% - var(--b)));
            mask: radial-gradient(farthest-side,#0000 calc(99% - var(--b)),#000 calc(100% - var(--b)));
  }
  .sla_pie_modern:after {
    inset: calc(50% - var(--b)/2);
    background: var(--c);
    transform: rotate(calc(var(--p)*3.6deg)) translateY(calc(50% - var(--w)/2));
  }
  /*** Thanks for PieChart to https://www.freecodecamp.org/news/css-only-pie-chart/ ***/

  .sla_pie_flat_base {
    --p: 50;
    --b: 6px;
    --w: 56px;
    --c: green;
    --r: darkgrey;
    width: var(--w);
    height: var(--w);
    margin: 1em auto;
    border-radius: 50%;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 12px;
    font-weight: bold;
    color: #333;
    -webkit-text-stroke: 3px #fff;
    paint-order: stroke fill;
  }
  .sla_pie_flat_base p {
    position: relative;
    z-index: 1;
    font-size: 12px;
  }

  /* Solid disc, filled proportionally to the percentage (classic pie-chart
     wedge) instead of a ring -- no center hole to keep clear, so it's the
     simplest of the flat styles. Transparent everywhere the fill doesn't
     reach, so it blends into any theme background. */
  .sla_pie_plain {
    background: conic-gradient(var(--c) calc(var(--p)*1%), var(--r) calc(var(--p)*1%));
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  }

  /* Transparent center so it blends into any theme. Painting the
     conic-gradient directly on the element (like sla_pie_plain above)
     would fill the whole disc solid -- there'd be nothing carving a hole
     out for the label. So the ring is drawn on a ::before instead (same
     technique as sla_pie_modern) and mask cuts the center hole, leaving a
     real see-through ring with the label floating over it. */
  .sla_pie_flat {
    /* Wider ring than the shared --b:6px default (only affects this
       variant -- sla_pie_plain doesn't use --b, it's a solid disc). */
    --b: 10px;
    /* Grow the whole disc to compensate: the ring eats into the center
       hole (hole radius = w/2 - b), so widening the ring alone shrank the
       hole from ~44px to ~36px, cramping longer labels like ">100%".
       64px restores roughly the original hole size at the new thickness. */
    --w: 64px;
  }
  .sla_pie_flat::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: conic-gradient(var(--c) calc(var(--p)*1%), var(--r) calc(var(--p)*1%));
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(99% - var(--b)), #000 calc(100% - var(--b)));
            mask: radial-gradient(farthest-side, transparent calc(99% - var(--b)), #000 calc(100% - var(--b)));
  }

}

/*** Sla Issue Helper View Responsive with Felxbox ***/
.flex-container {
  display: flex;
  flex-flow: row wrap;
  justify-content: left;
  padding: 0;
  margin: 0;
  list-style: none;
}
.flex-item {
  background: transparent;
  padding: 2px;
  margin: 2px;
}
/*** Thanks for Felxbox to https://css-tricks.com/snippets/css/a-guide-to-flexbox/ ***/

/*** Administration ***/

/* Page headings use the selected icon set at 24px. */
.title-sla-settings {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 8px;
  margin-bottom: 10px;
}
.title-sla-settings h2 { margin-bottom: 0; }
/* anything else in the heading block (e.g. the SLA caches notice) gets its own line */
.title-sla-settings > :not(h2):not(svg) { flex-basis: 100%; }
.title-sla-settings svg.s24 { width: 24px; height: 24px; flex-shrink: 0; }

/*** SLA Explain view ***/
tr.sla-explain-selected { background-color: #e3f3d3; }
tr.sla-explain-interval { background-color: #f0f0f0; font-weight: bold; }
tr.sla-explain-holiday td { color: #a04040; }
tr.sla-explain-no-schedule td { color: #999; font-style: italic; }

/*** SLA Level Terms matrix: per-level SLA type masking ***/
#sla-level-terms-table .sla-type-hidden { display: none; }
#sla-level-terms-table.sla-types-all-visible .sla-type-hidden { display: table-cell; }

.sla-project-marker { margin-inline-start: 4px; }

/* Icon dimensions are explicit for both raster images and SVG sprites. */
.sla-icon-image, .sla-icon-svg { display: inline-block; vertical-align: middle; flex-shrink: 0; }
.sla-icon-label { margin-left: 4px; }
.sla-icon-label-hidden { position: absolute; top: 0; left: 0; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.icon:has(> .sla-icon-image),
.icon:has(> .sla-icon-svg) { background-image: none; padding-left: 0; }
/* Font icon themes draw icon-add, icon-edit... glyphs in ::before; the inline icon replaces them. */
.icon:has(> .sla-icon-image)::before,
.icon:has(> .sla-icon-svg)::before { content: none; }
/* Redmine 5 and its themes give admin menu links a left padding slot for a background
   icon, with selectors (and !important) a plugin cannot reliably override. Moving the
   inline icon into that slot keeps its label aligned whatever the slot width. */
#admin-menu .sla-legacy-menu-icon > .sla-icon-image,
#admin-menu .sla-legacy-menu-icon > .sla-icon-svg { margin-left: -20px; }
.title-sla-settings > .sla-icon-image { flex-basis: auto; }
.redmine_sla_footer { border-top: 1px solid #bbb; font-size: 0.9em; color: #777; padding: 5px; text-align: center; }
.sla-credit-logo { vertical-align: middle; }
/* Redmine 5's icon-only links reserve padding for a background and clip children.
   Inline icons need their own box and an anchor for the accessible label. */
.icon-only:has(> .sla-icon-svg), .icon-only:has(> .sla-icon-image) {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  background-image: none;
  overflow: hidden;
}
.icon-only:has(> .sla-icon-svg)::after,
.icon-only:has(> .sla-icon-image)::after { content: none; }

/* Keep attribution at the bottom of the sidebar as its content grows. */
#sidebar:has(#sla-icon-credit),
#sidebar-wrapper:has(#sla-icon-credit) {
  display: flex;
  flex-direction: column;
}
#sidebar-wrapper:has(#sla-icon-credit) { flex: 1; }
#sidebar #sla-icon-credit { margin-top: auto; padding-top: 12px; }
