:root {
  --bg: #f4f3ef;
  --card-bg: #ffffff;
  --accent: #1c7c54;
  --accent-soft: #e2f1e8;
  --text-main: #222222;
  --text-muted: #777777;
  --border-soft: #e0ded7;
  --danger: #c0392b;
  --radius-lg: 16px;
  --radius-sm: 10px;
  --shadow-soft: 0 8px 20px rgba(0, 0, 0, 0.06);
  --spacing: 10px;
  --font-system: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  font-family: var(--font-system);
  color: var(--text-main);
}

#app {
  height: 100vh;
  width: 100vw;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.person-selector {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.person-chips {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 6px;
  padding-bottom: 2px;
}

.person-chip {
  border-radius: 999px;
  padding: 5px 10px;
  background: #e9e6dc;
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 23px;
  white-space: nowrap;
}

.person-chip.active {
  background: var(--accent);
  color: #fff;
}

.person-chip button {
  border: none;
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: 14px;
  line-height: 1;
}

.icon-btn {
  min-width: 32px;
  height: 32px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-soft);
}

.icon-btn:active {
  opacity: 0.8;
}

.layout {
  flex: 1;
  display: grid;
  grid-template-rows: minmax(0, 1.1fr) minmax(0, 1.3fr) minmax(0, 1.1fr);
  gap: 8px;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.card-title {
  font-weight: 600;
  font-size: 14px;
}

.inputs-card {
  padding-bottom: 6px;
}

.inputs-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.field-group label {
  font-size: 11px;
  color: var(--text-muted);
}

.field-group input {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  padding: 6px 8px;
  font-size: 13px;
  background: #faf8f2;
}

.field-group input:focus {
  outline: none;
  border-color: var(--accent);
  background: #ffffff;
}

.card-footer {
  margin-top: auto;
}

.ratio-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding-top: 4px;
  border-top: 1px solid var(--border-soft);
  margin-top: 4px;
}

.ratio-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
}

.ratio-value {
  font-size: 13px;
  font-weight: 600;
}

.table-wrapper {
  flex: 0 0 auto;
  margin-bottom: 4px;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 19px;
}

.results-table thead {
  background: #f0ede6;
}

.results-table th,
.results-table td {
  padding: 3px 4px;
  text-align: right;
}

.results-table th:first-child,
.results-table td:first-child {
  text-align: left;
}

.results-table tbody tr:nth-child(odd) {
  background: #fbfaf6;
}

.results-table tfoot td {
  font-weight: 600;
}

.results-table.compact th,
.results-table.compact td {
  padding: 2px 3px;
}

.charts-row {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  align-items: stretch;
}

.charts-row canvas {
  width: 100% !important;
  height: 100% !important;
}

.footer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
  border-top: 1px solid var(--border-soft);
  padding-top: 4px;
}

.actions-row {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  margin-top: 4px;
}

.text-btn {
  border-radius: 999px;
  border: none;
  padding: 4px 10px;
  font-size: 11px;
  background: var(--accent-soft);
  color: var(--accent);
}

.text-btn:active {
  opacity: 0.8;
}

.export-buttons {
  display: flex;
  gap: 4px;
}

.history-content {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1.4fr);
  gap: 6px;
  flex: 1;
  min-height: 0;
}

.history-table-wrapper {
  overflow: auto;
}

.history-card canvas {
  width: 100% !important;
  height: 100% !important;
}

/* Scrollbars */
.person-chips::-webkit-scrollbar,
.history-table-wrapper::-webkit-scrollbar {
  height: 3px;
  width: 3px;
}
.person-chips::-webkit-scrollbar-thumb,
.history-table-wrapper::-webkit-scrollbar-thumb {
  background: #c5c0b1;
  border-radius: 999px;
}

/* Print */
@media print {
  body {
    background: #ffffff;
  }
  #app {
    padding: 0;
  }
  .layout {
    grid-template-rows: auto auto auto;
    height: auto;
  }
  .card {
    box-shadow: none;
    border-radius: 0;
  }
  .icon-btn,
  .text-btn {
    display: none !important;
  }
}

