* { box-sizing: border-box; }

:root {
  --green: #39b54a;
  --lime: #a8cf35;
  --yellow: #f6c915;
  --orange: #f7941d;
  --red: #ed1c24;
  --text: #303030;
}

html { font-size: 16px; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  font-family: "Poppins", sans-serif;
  color: var(--text);
  background: #fff;
}

button, input { font: inherit; }

/* Rating screen */
.rating-page {
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.rating-container {
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  padding: 2rem 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.rating-content {
  width: min(92rem, 100%);
  text-align: center;
}

.rating-content h1 {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 3rem);
  line-height: 1.2;
  font-weight: 600;
}

.subtitle {
  margin: .75rem 0 2.5rem;
  color: #777;
  font-size: clamp(.95rem, 1.5vw, 1.25rem);
}

.ratings {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(.5rem, 2vw, 2rem);
  align-items: start;
}

.rating {
  border: 0;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
  background: transparent;
  padding: .5rem;
  cursor: pointer;
  color: inherit;
  transition: transform .12s ease;
}

.rating:hover { transform: scale(1.04); }
.rating:active { transform: scale(.97); }

.rating svg {
  width: min(14vw, 12rem);
  height: min(14vw, 12rem);
  display: block;
  margin: 0 auto 1rem;
}

.rating .face-ring,
.rating .mouth {
  fill: none;
  stroke: currentColor;
  stroke-width: 8;
  stroke-linecap: round;
}

.rating .eye { fill: currentColor; }

.rating span {
  display: block;
  font-size: clamp(.9rem, 1.6vw, 1.45rem);
  line-height: 1.15;
  font-weight: 500;
}

.rating-5 { color: var(--green); }
.rating-4 { color: var(--lime); }
.rating-3 { color: var(--yellow); }
.rating-2 { color: var(--orange); }
.rating-1 { color: var(--red); }

.thank-you {
  min-height: 2rem;
  margin-top: 1.5rem;
  font-size: 1.1rem;
  color: #555;
  opacity: 0;
  transition: opacity .15s ease;
}

.thank-you.visible { opacity: 1; }

.metrics-button {
  position: fixed;
  right: calc(1rem + env(safe-area-inset-right));
  bottom: calc(1rem + env(safe-area-inset-bottom));
  width: 2.75rem;
  height: 2.75rem;
  display: grid;
  place-items: center;
  color: #777;
  background: rgba(255,255,255,.9);
  border: 1px solid #ddd;
  border-radius: 50%;
  text-decoration: none;
  box-shadow: 0 .2rem .7rem rgba(0,0,0,.08);
  opacity: .1;
  transition: opacity .12s ease;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

.metrics-button:active {
  opacity: .1;
}

.metrics-button svg {
  width: 1.35rem;
  height: 1.35rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/* Metrics */
.metrics-page { background: #f6f6f6; }

.metrics-container {
  max-width: 72rem;
  margin: 0 auto;
  padding: 2.25rem 1.5rem 4rem;
}

.metrics-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1.25rem;
  margin-bottom: 1.75rem;
}

.metrics-header h1 { margin: 0 0 .35rem; font-size: 2rem; }
.metrics-header p { margin: 0; color: #777; }

.back-link {
  color: #333;
  text-decoration: none;
  white-space: nowrap;
  font-size: .9rem;
}

.back-link:hover { text-decoration: underline; }

.controls, .summary-card, .chart-card, .table-card, .admin-card {
  background: #fff;
  border-radius: .75rem;
  padding: 1.25rem;
  box-shadow: 0 .15rem .65rem rgba(0,0,0,.06);
}

.controls {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1.1rem;
}

.controls input {
  padding: .5rem .65rem;
  font-size: 1rem;
  border: 1px solid #ccc;
  border-radius: .4rem;
}

.summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.1rem;
  margin-bottom: 1.1rem;
}

.summary-card strong {
  display: block;
  font-size: 2.1rem;
  margin-bottom: .25rem;
}

.summary-card span { color: #777; }

.chart-card, .table-card, .admin-card { margin-bottom: 1.1rem; }

.chart-card h2, .table-card h2, .admin-card h2 {
  margin-top: 0;
  font-size: 1.15rem;
}

.chart {
  height: 18rem;
  display: flex;
  align-items: flex-end;
  gap: .3rem;
  border-bottom: 1px solid #ddd;
  padding: .9rem .3rem 0;
  overflow-x: auto;
}

.bar-wrap {
  min-width: 1.4rem;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  position: relative;
}

.bar {
  width: 1.1rem;
  min-height: .15rem;
  border-radius: .25rem .25rem 0 0;
  background: #555;
  position: relative;
}

.bar:hover::after {
  content: attr(data-value);
  position: absolute;
  bottom: calc(100% + .3rem);
  left: 50%;
  transform: translateX(-50%);
  background: #222;
  color: #fff;
  padding: .25rem .4rem;
  border-radius: .25rem;
  font-size: .7rem;
  white-space: nowrap;
}

.day-label {
  position: absolute;
  bottom: -1.35rem;
  font-size: .65rem;
  color: #777;
}

.empty {
  color: #777;
  display: none;
  text-align: center;
  margin: 2rem 0;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: .7rem .5rem;
  border-bottom: 1px solid #eee;
}

th { color: #777; font-weight: 600; }

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
}

.admin-actions button, .password-card button, .modal-actions button {
  border: 0;
  border-radius: .45rem;
  padding: .65rem 1rem;
  cursor: pointer;
  font-weight: 500;
}

.secondary-button {
  background: #eee;
  color: #333;
}

.secondary-button:hover { background: #e3e3e3; }

.danger-button {
  background: #ed1c24;
  color: #fff;
}

.danger-button:hover { background: #d71920; }

.admin-note {
  margin: .8rem 0 0;
  color: #777;
  font-size: .8rem;
}


.metrics-error {
  min-height: 1.25rem;
  margin: 0 0 1rem;
  color: #b00020;
  text-align: center;
}

/* Password screen and modal */
.password-screen {
  min-height: calc(100vh - 4rem);
  display: grid;
  place-items: center;
}

.password-card {
  width: min(26rem, 100%);
  background: #fff;
  padding: 2rem;
  border-radius: .9rem;
  box-shadow: 0 .25rem 1.2rem rgba(0,0,0,.08);
  text-align: center;
}

.password-card h1 { margin: 0 0 .35rem; }
.password-card p { color: #777; margin: 0 0 1.5rem; }

.password-card form {
  display: grid;
  gap: .75rem;
}

.password-card input, .modal-card input {
  width: 100%;
  padding: .75rem .8rem;
  border: 1px solid #ccc;
  border-radius: .45rem;
  outline: none;
}

.password-card input:focus, .modal-card input:focus {
  border-color: #777;
}

.password-card button {
  background: #333;
  color: #fff;
}

.password-card .back-link {
  display: inline-block;
  margin-top: 1.25rem;
}

.lock-icon {
  width: 2.5rem;
  height: 2.5rem;
  margin: 0 auto 1rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #f0f0f0;
  color: #555;
  font-size: 1.5rem;
}

.form-error {
  min-height: 1.1rem;
  color: #d71920;
  font-size: .8rem;
}

.hidden { display: none !important; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background: rgba(0,0,0,.45);
}

.modal-card {
  width: min(28rem, 100%);
  background: #fff;
  border-radius: .8rem;
  padding: 1.5rem;
  position: relative;
  box-shadow: 0 .5rem 2rem rgba(0,0,0,.2);
}

.modal-card h2 { margin-top: 0; }
.modal-card p { color: #666; }

.modal-card form {
  display: grid;
  gap: .7rem;
}

.modal-close {
  position: absolute;
  right: .8rem;
  top: .65rem;
  border: 0;
  background: transparent;
  font-size: 1.6rem;
  color: #777;
  cursor: pointer;
}

#modalNewPasswordWrap {
  display: grid;
  gap: .7rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: .6rem;
  margin-top: .3rem;
}

/* Small screens */
@media (max-width: 52rem) {
  .rating-container { padding: 1.5rem; }
  .ratings {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    row-gap: 1rem;
  }
  .rating-5 { order: 1; }
  .rating-4 { order: 2; }
  .rating-3 { order: 3; }
  .rating-2 { order: 4; }
  .rating-1 { order: 5; }
  .rating svg {
    width: min(22vw, 10rem);
    height: min(22vw, 10rem);
  }
}

@media (max-width: 34rem) {
  .rating-container { padding: 1rem; }
  .ratings { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rating-3 { grid-column: 1 / -1; }
  .rating svg {
    width: min(30vw, 9rem);
    height: min(30vw, 9rem);
  }
  .subtitle { margin-bottom: 1.25rem; }
  .metrics-button {
    right: calc(.75rem + env(safe-area-inset-right));
    bottom: calc(.75rem + env(safe-area-inset-bottom));
    width: 2.5rem;
    height: 2.5rem;
  }
  .summary { grid-template-columns: 1fr; }
  .metrics-header {
    align-items: flex-start;
    flex-direction: column;
  }
}


@media (max-width: 900px) {
  .rating-container { padding: 1.5rem; }
  .rating-content h1 { font-size: clamp(1.5rem, 5vw, 2.2rem); }
  .subtitle { margin-bottom: 1.75rem; }
  .ratings { gap: .25rem; }
  .rating { padding: .25rem; }
  .rating svg { width: min(16vw, 8.5rem); height: min(16vw, 8.5rem); }
  .rating span { font-size: clamp(.75rem, 2.1vw, 1.05rem); }
}

@media (max-width: 600px) {
  .rating-container { padding: 1rem .65rem; }
  .rating-content h1 { font-size: 1.35rem; }
  .subtitle { margin: .5rem 0 1.25rem; font-size: .8rem; }
  .rating svg { width: min(18vw, 5.5rem); height: min(18vw, 5.5rem); margin-bottom: .55rem; }
  .rating span { font-size: .68rem; }
  .thank-you { margin-top: .75rem; font-size: .9rem; }
  .metrics-button { width: 2.5rem; height: 2.5rem; }
}

@media (pointer: coarse) {
  .rating:hover { transform: none; }
  .metrics-button:active { opacity: .1; }
}
