﻿:root {
  --background: 0 0% 100%;
  --foreground: 0 0% 3.9%;
  --card: 0 0% 100%;
  --card-foreground: 0 0% 3.9%;
  --popover: 0 0% 100%;
  --popover-foreground: 0 0% 3.9%;
  --primary: 221.2 83.2% 53.3%;
  --primary-foreground: 210 40% 98%;
  --secondary: 210 40% 96.1%;
  --secondary-foreground: 222.2 47.4% 11.2%;
  --muted: 210 40% 96.1%;
  --muted-foreground: 215.4 16.3% 46.9%;
  --accent: 210 40% 96.1%;
  --accent-foreground: 222.2 47.4% 11.2%;
  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 210 40% 98%;
  --border: 214.3 31.8% 91.4%;
  --input: 214.3 31.8% 91.4%;
  --ring: 221.2 83.2% 53.3%;

  --menu-background: 0 0% 100%;
  --menu-foreground: 0 0% 3.9%;
  --menu-accent: 210 40% 96.1%;
  --menu-accent-foreground: 222.2 47.4% 11.2%;
  --menu-border: 214.3 31.8% 91.4%;

  --radius: 0.5rem;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
}

.dark {
  --background: 222.2 84% 4.9%;
  --foreground: 210 40% 98%;
  --card: 222.2 84% 4.9%;
  --card-foreground: 210 40% 98%;
  --popover: 222.2 84% 4.9%;
  --popover-foreground: 210 40% 98%;
  --primary: 217.2 91.2% 59.8%;
  --primary-foreground: 222.2 47.4% 11.2%;
  --secondary: 217.2 32.6% 17.5%;
  --secondary-foreground: 210 40% 98%;
  --muted: 217.2 32.6% 17.5%;
  --muted-foreground: 215 20.2% 65.1%;
  --accent: 217.2 32.6% 17.5%;
  --accent-foreground: 210 40% 98%;
  --destructive: 0 62.8% 30.6%;
  --destructive-foreground: 210 40% 98%;
  --border: 217.2 32.6% 17.5%;
  --input: 217.2 32.6% 17.5%;
  --ring: 224.3 76.3% 48%;

  --menu-background: 224 71% 4%;
  --menu-foreground: 210 40% 98%;
  --menu-accent: 217.2 32.6% 17.5%;
  --menu-accent-foreground: 210 40% 98%;
  --menu-border: 217.2 32.6% 17.5%;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Geist", sans-serif;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
}

input,
select,
button {
  font: inherit;
}

button:disabled,
input:disabled,
select:disabled,
.nav-item[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.app-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr;
}

.sidebar {
  background: hsl(var(--menu-background));
  border-bottom: 1px solid hsl(var(--menu-border));
  padding: var(--space-4);
}

.brand {
  font-size: 1.125rem;
  font-weight: 700;
  margin-bottom: var(--space-4);
}

.nav-title {
  margin: 0 0 var(--space-2);
  color: hsl(var(--muted-foreground));
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.nav-list {
  display: grid;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  color: hsl(var(--menu-foreground));
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.nav-icon {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  fill: currentColor;
}

.nav-item:hover {
  background: hsl(var(--menu-accent));
  color: hsl(var(--menu-accent-foreground));
}

.nav-item:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px hsl(var(--ring));
}

.nav-item.active {
  background: hsl(var(--menu-accent));
  color: hsl(var(--primary));
  border-color: hsl(var(--border));
}

.page {
  padding: var(--space-4);
}

.page-view {
  display: none;
}

.page-view.is-active {
  display: block;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.page-header h1 {
  margin: 0;
  font-size: 1.875rem;
  line-height: 1.25;
}

.page-header p {
  margin: var(--space-1) 0 0;
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
}

.page-actions {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.report-menu {
  position: relative;
}

.theme-toggle,
.report-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 2rem;
  padding: 0 var(--space-2);
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.theme-toggle:hover,
.report-toggle:hover {
  background: hsl(var(--accent));
  border-color: hsl(var(--ring));
}

.theme-toggle:focus-visible,
.report-toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px hsl(var(--ring));
}

.theme-toggle:active,
.report-toggle:active {
  background: hsl(var(--secondary));
}

.theme-icon,
.report-icon {
  width: 1rem;
  height: 1rem;
  fill: currentColor;
}

.theme-icon-moon {
  display: none;
}

.dark .theme-icon-sun {
  display: none;
}

.dark .theme-icon-moon {
  display: inline;
}

.theme-label {
  font-size: 0.75rem;
  font-weight: 600;
}

.report-toggle span {
  font-size: 0.75rem;
  font-weight: 600;
}

.report-popup {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  z-index: 20;
  display: grid;
  gap: var(--space-3);
  width: 14rem;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  padding: var(--space-3);
  box-shadow: 0 1rem 2rem hsl(var(--foreground) / 0.12);
}

.report-popup[hidden] {
  display: none;
}

.report-popup button {
  height: 2.25rem;
  border: 1px solid hsl(var(--primary));
  border-radius: var(--radius);
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font-size: 0.8125rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.report-popup button:hover {
  background: hsl(var(--primary) / 0.92);
  border-color: hsl(var(--primary) / 0.92);
}

.report-popup button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px hsl(var(--ring));
}

.report-feedback {
  min-height: 1rem;
  margin: 0;
  color: hsl(var(--muted-foreground));
  font-size: 0.75rem;
  line-height: 1.4;
}

.content-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
}

.panel {
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) + 0.25rem);
  padding: var(--space-4);
}

.panel-header {
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid hsl(var(--border));
}

.panel-header h2 {
  margin: 0;
  font-size: 1rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
}

label {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  color: hsl(var(--foreground));
  font-size: 0.875rem;
  font-weight: 500;
}

input,
select {
  width: 100%;
  height: 2.5rem;
  border: 1px solid hsl(var(--input));
  border-radius: var(--radius);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  padding: 0 var(--space-3);
  transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

input:hover,
select:hover {
  background: hsl(var(--muted));
}

input:focus,
select:focus {
  outline: none;
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 2px hsl(var(--ring) / 0.3);
}

input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  flex: 0 0 auto;
  padding: 0;
  accent-color: hsl(var(--primary));
  cursor: pointer;
}

button[type="submit"] {
  grid-column: 1 / -1;
  height: 2.75rem;
  border: 1px solid hsl(var(--primary));
  border-radius: var(--radius);
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

button[type="submit"]:hover {
  background: hsl(var(--primary) / 0.92);
  border-color: hsl(var(--primary) / 0.92);
}

button[type="submit"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px hsl(var(--ring));
}

button[type="submit"]:active {
  background: hsl(var(--primary) / 0.84);
}

.hint {
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
}

.result-list {
  display: grid;
  gap: var(--space-2);
}

.result-pill {
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--secondary));
  padding: var(--space-2) var(--space-3);
  font-size: 0.875rem;
}

.badge {
  display: inline-flex;
  margin-top: var(--space-3);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  font-size: 0.75rem;
  font-weight: 600;
}

.badge.ok {
  background: hsl(var(--accent));
  color: hsl(var(--foreground));
}

.badge.error {
  background: hsl(var(--destructive) / 0.12);
  color: hsl(var(--destructive));
}

.diagram-wrap {
  width: 100%;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
  padding: var(--space-2);
  overflow-x: auto;
}

.diagram-svg {
  display: block;
  width: 100%;
  min-width: 0;
  height: auto;
}

.visual-card {
  display: flex;
  flex-direction: column;
}

.visual-card .diagram-wrap {
  flex: 1;
  min-height: 17.5rem;
}

.pile-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
}

.pile-form {
  display: grid;
  gap: var(--space-4);
}

.tip-limit-control {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: var(--space-3);
  background: hsl(var(--card));
}

.checkbox-field {
  flex-direction: row;
  align-items: center;
}

.percent-input {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.percent-input span {
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
  font-weight: 500;
}

.profile-wrap {
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: var(--space-3);
  background: hsl(var(--card));
}

.profile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.profile-head h3 {
  margin: 0;
  font-size: 0.875rem;
}

.secondary-btn {
  height: 2rem;
  border: 1px solid hsl(var(--input));
  border-radius: var(--radius);
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  padding: 0 var(--space-3);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.secondary-btn:hover {
  background: hsl(var(--accent));
  border-color: hsl(var(--ring));
}

.secondary-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px hsl(var(--ring));
}

.table-wrap {
  max-height: 22rem;
  overflow: auto;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
}

.profile-table,
.result-table {
  width: 100%;
  border-collapse: collapse;
  background: hsl(var(--card));
}

.profile-table th,
.profile-table td,
.result-table th,
.result-table td {
  padding: var(--space-2);
  border-bottom: 1px solid hsl(var(--border));
  text-align: left;
  font-size: 0.8125rem;
}

.profile-table th,
.result-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: hsl(var(--secondary));
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.profile-table tbody tr:nth-child(even),
.result-table tbody tr:nth-child(even) {
  background: hsl(var(--muted) / 0.45);
}

.profile-table input,
.profile-table select {
  height: 2.125rem;
}

.pile-result-card .hint {
  margin: 0;
}

.result-table-wrap {
  overflow: auto;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
}

.method-note {
  margin-top: var(--space-3);
  color: hsl(var(--muted-foreground));
  font-size: 0.75rem;
}

.summary-row td {
  font-weight: 600;
}

.chart-canvas-wrap {
  position: relative;
  flex: 1;
  width: 100%;
  min-height: clamp(24rem, 52vh, 42rem);
}

.chart-canvas-wrap canvas {
  width: 100%;
  height: 100%;
}

@media (min-width: 640px) {
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .app-layout {
    grid-template-columns: 15rem 1fr;
  }

  .sidebar {
    border-bottom: none;
    border-right: 1px solid hsl(var(--menu-border));
  }

  .content-grid {
    grid-template-columns: 1.3fr 0.9fr 1.2fr;
  }

  .pile-grid {
    grid-template-columns: 1.2fr 1fr;
    grid-template-areas:
      "pile-input pile-graph"
      "pile-result pile-result";
  }

  .pile-input-card {
    grid-area: pile-input;
  }

  .pile-graph-card {
    grid-area: pile-graph;
  }

  .pile-result-card {
    grid-area: pile-result;
  }
}

@media (min-width: 1280px) {
  .page {
    padding: var(--space-5);
  }
}
