:root {
  --green: #1f8f4a;
  --green-dark: #16703a;
  --red: #d63d3d;
  --blue: #2872e2;
  --surface: #ffffff;
  --ink: #1d2b1f;
  --muted: #5a6c5f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Be Vietnam Pro", "Segoe UI", sans-serif;
  color: var(--ink);
  min-height: 100vh;
  background: linear-gradient(170deg, #e8f6ec 0%, #f8fcf9 60%, #ecf6ff 100%);
}

.page-bg {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 8% 10%, rgba(40, 114, 226, 0.12), transparent 35%),
    radial-gradient(circle at 90% 80%, rgba(31, 143, 74, 0.12), transparent 40%);
  z-index: -1;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.app-header {
  background: linear-gradient(120deg, var(--green) 0%, #2fba63 100%);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-left-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #0aa43a;
  border-radius: 10px;
  padding: 10px 12px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  min-height: 88px;
  flex: 1 1 68%;
}

.left-banner-text p {
  margin: 0;
  color: #e7ffe9;
  font-weight: 700;
  line-height: 1.28;
}

.left-banner-text p:nth-child(1) { font-size: 0.95rem; }
.left-banner-text p:nth-child(2) { font-size: 1.06rem; margin-top: 2px; }
.left-banner-text p:nth-child(3) {
  font-size: 0.76rem;
  margin-top: 6px;
  border-top: 1px solid rgba(210, 255, 220, 0.8);
  padding-top: 6px;
  letter-spacing: 0.04em;
}

.logo {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background: #fff;
  object-fit: contain;
  border: 3px solid #fff;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22);
}

.header-text h1 {
  margin: 0;
  font-size: clamp(1rem, 1.95vw, 1.34rem);
  letter-spacing: 0.02em;
}

.header-text p {
  margin: 8px 0 0;
  opacity: 0.9;
  font-size: 0.86rem;
}

.header-right {
  text-align: right;
  min-width: 300px;
  max-width: 34%;
}

.app-main {
  padding: 24px 16px;
  display: flex;
  justify-content: center;
  align-items: start;
}

.screen {
  width: min(980px, 100%);
  background: var(--surface);
  border-radius: 18px;
  box-shadow: 0 14px 34px rgba(20, 61, 31, 0.12);
  padding: 56px 24px 24px;
  display: none;
  animation: fadeIn 0.35s ease;
  position: relative;
}

.screen.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

h2 {
  margin-top: 0;
  margin-bottom: 14px;
  color: #1c3f27;
}

.selected-info {
  margin: 8px 0;
  color: #2d4c38;
}

label {
  display: block;
  margin-top: 10px;
  margin-bottom: 8px;
  font-weight: 600;
}

select,
input[type="number"] {
  width: 100%;
  border: 1px solid #c9dbcf;
  border-radius: 10px;
  padding: 12px;
  font-size: 1rem;
  background: #fcfffd;
}

small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
}

.button-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 11px 18px;
  min-width: 132px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.btn:hover {
  opacity: 0.95;
  transform: translateY(-1px);
}

.btn-primary { background: var(--blue); }
.btn-danger { background: var(--red); margin-top: 16px; }
.btn-success { background: var(--green); margin-top: 16px; }
.btn-secondary { background: #6b7280; }
.btn-confirm { margin-left: auto; }

.back-arrow {
  position: absolute;
  top: 14px;
  left: 14px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid #cde2d4;
  background: #f4fbf6;
  color: #1b5d33;
  font-weight: 700;
  cursor: pointer;
}

.back-arrow:hover {
  background: #e5f6ea;
}

.group-tooltip {
  margin-top: 10px;
  line-height: 1.5;
  background: #f2fbf5;
  border: 1px dashed #cde6d6;
  padding: 10px;
  border-radius: 8px;
}

.top-actions {
  margin-top: 0;
  margin-bottom: 10px;
}

.criteria-list {
  display: grid;
  gap: 10px;
  margin-top: 8px;
}

.criteria-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border: 1px solid #d9e9de;
  border-radius: 10px;
  background: #f8fdf9;
}

.summary-box {
  border: 1px solid #d2e7d8;
  border-radius: 10px;
  background: #f6fcf8;
  padding: 12px;
  margin-bottom: 14px;
}

.history-panel {
  border: 1px solid #dbe8f8;
  border-radius: 12px;
  background: #f7fbff;
  padding: 14px;
  margin-bottom: 16px;
}

.history-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.history-panel-header h3 {
  margin: 0;
  font-size: 1rem;
  color: #184126;
}

.history-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.history-btn {
  margin-top: 0;
  min-width: auto;
  padding: 8px 12px;
}

.history-hint {
  margin: 10px 0 0;
}

.weight-history-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.weight-history-empty {
  color: var(--muted);
  font-style: italic;
}

.weight-history-item {
  border: 1px solid #d8e5f4;
  background: #fff;
  border-radius: 10px;
  padding: 12px;
}

.weight-history-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.weight-history-item-title {
  font-weight: 700;
  color: #213547;
}

.weight-history-meta {
  font-size: 0.88rem;
  color: var(--muted);
}

.weight-history-values {
  font-size: 0.93rem;
  color: #2f4250;
  line-height: 1.6;
  white-space: pre-line;
}

.weight-history-item .btn {
  margin-top: 0;
}

.pairwise-container {
  display: grid;
  gap: 16px;
}

.pair-item {
  border: 1px solid #ddebe1;
  border-radius: 12px;
  padding: 12px;
  background: #fbfffc;
}

.pair-title {
  font-weight: 600;
  margin-bottom: 10px;
}

.slider-row {
  display: grid;
  grid-template-columns: 1fr 140px 1fr;
  align-items: center;
  gap: 10px;
}

.slider-row input[type="range"] {
  grid-column: 1 / span 3;
  width: 100%;
}

.value-box {
  background: #eaf6ef;
  border: 1px solid #cde6d7;
  border-radius: 8px;
  text-align: center;
  font-weight: 700;
  padding: 6px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}

th,
td {
  border-bottom: 1px solid #e5eee8;
  text-align: left;
  padding: 10px;
  vertical-align: top;
}

th {
  background: #ebf8ef;
  color: #184126;
}

.row-action {
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}

.app-footer {
  background: linear-gradient(120deg, var(--green-dark), var(--green));
  color: #effff3;
  text-align: center;
  padding: 14px 16px;
  font-size: 0.93rem;
}

@media (max-width: 700px) {
  .app-header {
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
  }

  .header-right {
    text-align: center;
    max-width: 100%;
    min-width: 0;
  }

  .screen {
    padding: 18px;
    padding-top: 52px;
  }

  .slider-row {
    grid-template-columns: 1fr;
  }
}

/* ── Gemini modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 30, 15, 0.55);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(10, 30, 15, 0.22);
  width: min(680px, 94vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  position: relative;
  animation: fadeIn 0.25s ease;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid #d4e6da;
  background: #f4fbf6;
  color: #1b5d33;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover { background: #e5f6ea; }

.modal-title {
  margin: 0;
  padding: 20px 52px 16px 22px;
  font-size: 1.1rem;
  color: #1c3f27;
  border-bottom: 1px solid #e3efe7;
}

.modal-body {
  padding: 18px 22px 22px;
  overflow-y: auto;
  flex: 1;
}

.modal-loading {
  color: var(--muted);
  font-style: italic;
}

.modal-content-text {
  line-height: 1.75;
  color: #1d2b1f;
  font-size: 0.97rem;
}

.modal-error {
  color: var(--red);
  font-weight: 600;
}
