/* Calcumber Variables
 * Is added automatically to injected calcumber and dialog backdrops.
 * Manually added in body of PWA.
 */
.calcumber-vars {
  --color-frame-fg: white;
  --color-frame-bg: hsl(215 50% 50%);
  --color-io-fg: black;
  --color-io-bg: hsl(215, 60%, 95%);
  --color-io-bg-focus: hsl(215, 60%, 98%);
  --color-border: hsl(215 20% 75%);
  --color-io-border-focus: hsl(215 30% 55%);
  --border-width: 0;
}

.calcumber-pwa,
.calcumber-pwa .calcumber-vars {
  /* overrides */
  --color-io-bg: hsl(215, 60%, 98%);
  --color-io-bg-focus: hsl(215, 60%, 99%);
  --border-width: 0.15rem;

  /* PWA only definitions */
  --color-bg: hsl(215, 30%, 95%);
  --color-button-fg: #222;
  --color-button-bg: hsl(215 50% 93%);
  --color-button-bg-hover: hsl(215 50% 80%);
  --color-shadow: rgba(0, 0, 0, 0.4);
  --color-backdrop-bg: rgba(0, 0, 0, 0.2);
  --color-menu-bg-hover: hsl(215, 50%, 92%);
}

/* Background color in pwa is used outside container */
body {
  background: var(--color-bg);
}

/* Variabls Static Table */
.calcumber-table {
  --color-table-bg: hsl(215, 60%, 95%);
  --color-table-bg-dark: hsl(215, 60%, 80%);
}

/* Calcumber UI Font */
.calcumber-pwa,
.calcumber-container {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu,
    Cantarell, "Helvetica Neue", sans-serif;
}

/* Calcumber Monospace Font */
.calcumber-table,
.calcumber-io-row {
  font-family: Consolas, "Courier New", monospace;
}

/* 
 * static calcumber table
 */

.calcumber-table {
  font-size: 80%;
  border-collapse: separate;
  border-spacing: 0.1em;
  margin-bottom: 1em;
}

.calcumber-table th,
.calcumber-table td {
  padding: 0.2em 1em 0.2em 0.4em;
}

/* hide header of calcumber tables */
.calcumber-table.no-header thead {
  display: none;
}

.calcumber-table th {
  background-color: var(--color-table-bg-dark);
}

.calcumber-table td {
  background-color: var(--color-table-bg);
}

/*
 * Calcumber Container
 */

.calcumber-container {
  display: flex;
  flex-direction: column;
  width: fit-content;
  background-color: var(--color-frame-bg);
  max-width: 100%;
  min-height: 0;
  color: var(--color-frame-fg);
}

.calcumber-pwa .calcumber-container {
  background: none;
  gap: 0.5rem;
  flex: 1 1 auto;
}

/*
 * Top Row
 */

.calcumber-top-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  width: 100%;
  padding: 0em;
  gap: 0.3em;
  font-size: 70%;
}

.calcumber-top-row .calcumber-icon-link {
  display: inline-flex;
  padding: 0;
}

.calcumber-top-row .calcumber-icon-link img {
  height: 1.2em;
  width: auto;
  margin: 0.1em 0.2em 0.1em 0.3em;
}

.calcumber-top-row .calcumber-title {
  color: inherit;
  margin: 0;
  line-height: 1;
}

.calcumber-full-app {
  width: fit-content;
  height: fit-content;
  padding: 0;
  margin: 0;
  color: inherit;
  background: none;
  border: none;
}

.calcumber-icon-link:hover,
.calcumber-full-app:hover {
  background-color: hsl(0 0% 100% / 15%);
}

.calcumber-icon-link:active,
.calcumber-full-app:active {
  background-color: hsl(0 0% 100% / 25%);
}

.calcumber-icon-link:focus-visible,
.calcumber-full-app:focus-visible {
  outline: 0.1em solid currentColor;
  outline-offset: 0.1em;
}

.calcumber-full-app svg {
  height: 0.8em;
  width: auto;
  margin-left: 0.3em;
  margin-right: 0.5em;
  fill: none;
  stroke: currentColor;
  stroke-width: 0.18em;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/*
 * Input - Output Row
 */

.calcumber-io-row {
  display: flex;
  flex-direction: row;
  flex: 0 1 auto;
  gap: 0.1em;
  padding: 0;
  margin: 0.2em;
  margin-top: 0;
  color: var(--color-io-fg);
  overflow-y: auto;
  min-height: 0;
}

.calcumber-wpa .calcumber-io-row {
  gap: 0.3em;
  margin: 0;
}

.calcumber-input,
.calcumber-output {
  box-sizing: content-box; /* App sets content height excluding border*/
  flex: 0 1 auto;
  padding: 0.2em 0.5em;

  overflow-x: auto; /* horizontal scroll */
  overflow-y: hidden; /* no own vertical scroll */
  resize: none;

  font: inherit; /*otherwise browser default font settings are used*/
  line-height: 1.8em;
  color: inherit;
  background: var(--color-io-bg);
  border-width: var(--border-width);
  border-color: var(--color-border);
  border-style: solid;

  white-space: pre; /* no wrapping */
  word-wrap: normal;
  overflow-wrap: normal;
}

/* Min Width of Input and Output */
.calcumber-input {
  min-width: 20ch;
}

.calcumber-output {
  min-width: 10ch;
}

/* Input Output Focus Style */
.calcumber-input:focus-visible,
.calcumber-output:focus-visible {
  outline: none;
}
.calcumber-input:focus-visible {
  background-color: var(--color-io-bg-focus);
  border-color: var(--color-io-border-focus);
}

/*
 *  Handle calcumber-grow flag
 */
.calcumber-container.calcumber-grow {
  width: 100%;
}
.calcumber-container.calcumber-grow .calcumber-input {
  flex-grow: 1;
}

/*
 * WPA page
 */

html {
  box-sizing: border-box; /* width and height specification should include the border. */
  height: 100%;
  font-size: 100%; /* this defines rem unit */
}

/* all elements and some pseudo elements */
*,
*::before,
*::after {
  box-sizing: inherit;
}

body {
  height: 100%;
  margin: 0;
  padding: 0.5em;
  /* width specifications include border and padding */
}

/*Actual page*/
.page {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/*
 * Header
 */

#header {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  color: inherit;
  text-decoration: none;
}

#icon {
  height: 5rem;
  width: auto;
  padding: 0.5em;
}

#title-block {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#title-block p {
  margin: 0;
}

/*
 * Bottom Button Row
 */

.calcumber-bottom-row {
  display: flex;
  gap: 0.5rem;
}

button {
  padding: 0.45rem 0.9rem;
  font: inherit;
  color: var(--color-button-fg);

  background: var(--color-button-bg);
  border-width: var(--border-width);
  border-style: solid;
  border-color: var(--color-border);
  border-radius: 0.5rem;

  cursor: pointer;
  transition:
    background 0.15s,
    transform 0.05s;
}

button:hover {
  background: var(--color-button-bg-hover);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible {
  outline: none;
  border: 2px solid var(--color-focus-border);
}

/*
 * Dialog
 */

.dialog {
  display: none;

  /* center on viewport */
  position: fixed;
  top: 3rem;
  bottom: 3rem;

  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: calc(100vw - 6rem);
  height: calc(100vh - 6rem);
  /*specify max-width and max-height directly on element*/

  background-color: var(--color-bg);
  border: 3px solid var(--color-border);
  z-index: 1000;

  padding: 1rem;
}

.dialog.open {
  display: flex;
}

.dialog > button {
  align-self: center;
  margin: 1rem;
  flex: 0 0 auto;
}

.dialog-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 999;
  background-color: var(--color-backdrop-bg);
}

.dialog-backdrop.open {
  display: block;
}

.scrollable-content {
  padding: 1rem;
  flex: 1 1 auto;
  overflow-y: auto;

  background: white;
  border: 0.1rem solid hsl(215 20% 70%);
}

/*
 * Flyouts
*/

.menu-container {
  position: relative;
  display: inline-block;
}

.flyout {
  position: absolute;
  bottom: 0%;
  left: 0;
  margin-bottom: 1rem;
  min-width: 14rem;
  background: var(--color-button-bg);
  border: 1px solid var(--color-button-text);
  box-shadow: 0 0.2rem 0.6rem var(--color-shadow);
  display: none;
  z-index: 1000;
  font-size: 80%; /* Quick fix for menu out of sreen */
}

.flyout.open {
  display: block;
}

.flyout button {
  display: block;
  width: 100%;
  padding: 0.25rem 0.8rem;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  /*prevent line breaks in buttons */
}

.flyout button:hover {
  background: var(--color-menu-bg-hover);
}

/*
 * General CSS
 */

/* only visible to screen readers */
.calcumber-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  white-space: nowrap;
  border: 0;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
}
