/*
 * Application Stylesheet - Swiss Army Knife
 * Clean, accessible, modern design system
 */

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-dark: #1e40af;
  --success: #10b981;
  --success-light: #ecfdf5;
  --accent: #f59e0b;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border: #e2e8f0;
  --border-focus: #3b82f6;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.04);
}

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

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.calculator-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  padding: 2.5rem 1.5rem 2rem;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
}

.brand-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  background: var(--primary-light);
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.brand-title {
  margin: 0 0 0.5rem;
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.025em;
}

.brand-description {
  margin: 0;
  font-size: 1.05rem;
  color: var(--text-muted);
  max-width: 720px;
}

/* Layout */
.main-layout {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.layout-grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 960px) {
  .layout-grid {
    grid-template-columns: 1fr;
  }
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: 1.5rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
}

.card-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
}

.card-subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.card-body {
  padding: 1.5rem;
}

/* Form Styles */
.calculator-form .form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.35rem;
}

.label-with-presets {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.label-with-presets .form-label {
  margin-bottom: 0;
}

.help-text {
  display: block;
  font-size: 0.775rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.form-row {
  display: flex;
  gap: 1rem;
}

.flex-1 {
  flex: 1;
}

.form-input, .form-select {
  width: 100%;
  padding: 0.625rem 0.75rem;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-main);
  background: #ffffff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-input.input-error {
  border-color: var(--danger);
  background-color: var(--danger-light);
}

.input-with-prefix, .input-with-suffix {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-prefix .prefix, .input-with-suffix .suffix {
  position: absolute;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  pointer-events: none;
}

.input-with-prefix .prefix {
  left: 0.75rem;
}

.input-with-prefix input {
  padding-left: 1.75rem;
}

.input-with-suffix .suffix {
  right: 0.75rem;
}

.input-with-suffix input {
  padding-right: 1.75rem;
}

/* Fieldset reset */
.segmented-fieldset {
  border: none;
  margin: 0 0 1.25rem 0;
  padding: 0;
}

/* Accessible Segmented Control */
.segmented-control {
  display: flex;
  background: #f1f5f9;
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.segmented-option {
  flex: 1;
  position: relative;
  cursor: pointer;
  margin: 0;
}

/* Visually hidden radio inputs for accessibility */
.segmented-radio {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.segmented-label {
  display: block;
  text-align: center;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: all 0.15s ease;
}

.segmented-radio:checked + .segmented-label {
  background: #ffffff;
  color: var(--text-main);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.segmented-radio:focus-visible + .segmented-label {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

/* Presets */
.preset-buttons {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.preset-title {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 0.2rem;
}

.preset-btn {
  background: #f1f5f9;
  border: 1px solid var(--border);
  color: var(--text-main);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.preset-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.preset-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.year-presets {
  margin-top: -0.5rem;
  margin-bottom: 1rem;
}

.mt-3 {
  margin-top: 1rem;
}

/* Primary Button */
.btn-primary {
  display: block;
  width: 100%;
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.15s ease, transform 0.05s ease;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-primary:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.5);
  outline-offset: 2px;
}

.btn-primary:active {
  transform: translateY(1px);
}

.form-errors {
  background: var(--danger-light);
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 0.875rem 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.25rem;
  font-size: 0.875rem;
}

.form-errors h4 {
  margin: 0 0 0.5rem;
  font-size: 0.875rem;
  font-weight: 700;
}

.form-errors ul {
  margin: 0;
  padding-left: 1.25rem;
}

/* Results Section */
.results-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Hero Summary */
.hero-summary {
  background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 50%, #2563eb 100%);
  color: #ffffff;
  padding: 1.75rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.hero-badge {
  display: inline-block;
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  margin-bottom: 0.75rem;
}

.hero-title {
  margin: 0 0 0.75rem;
  font-size: 1.35rem;
  font-weight: 500;
  line-height: 1.4;
}

.highlight-amount {
  display: block;
  font-size: 2.25rem;
  font-weight: 800;
  color: #ffffff;
  margin: 0.35rem 0;
  letter-spacing: -0.02em;
}

.hero-meta {
  margin: 0;
  font-size: 0.875rem;
  opacity: 0.85;
}

/* KPI Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

@media (max-width: 768px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.15rem 1rem;
  box-shadow: var(--shadow-sm);
}

.kpi-label {
  font-size: 0.775rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}

.kpi-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.kpi-subtext {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.kpi-subtext.positive {
  color: #d97706;
  font-weight: 600;
}

/* Growth Visual */
.growth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-sm);
}

.growth-title {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
}

.growth-bars {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.growth-bar-item {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.growth-bar-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
}

.bar-track {
  height: 10px;
  background: #f1f5f9;
  border-radius: 9999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 9999px;
  transition: width 0.3s ease;
}

.bar-fill.base {
  background: #94a3b8;
}

.bar-fill.mid {
  background: var(--primary);
}

.bar-fill.max {
  background: #8b5cf6;
}

/* Table Card */
.table-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table-card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.table-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.table-subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.825rem;
  color: var(--text-muted);
}

.table-responsive {
  max-height: 480px;
  overflow-y: auto;
}

.schedule-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.schedule-table th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  padding: 0.75rem 1.25rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  z-index: 1;
}

.schedule-table td,
.schedule-table th[scope="row"] {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid #f1f5f9;
  color: var(--text-main);
}

.font-normal-weight {
  font-weight: 500;
  text-align: left;
}

.schedule-table tr:hover td,
.schedule-table tr:hover th[scope="row"] {
  background-color: #f8fafc;
}

.schedule-table tr.highlight-row td,
.schedule-table tr.highlight-row th[scope="row"] {
  background-color: var(--primary-light);
  font-weight: 600;
}

.badge-year {
  display: inline-block;
  background: #f1f5f9;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.badge-age {
  display: inline-block;
  background: #ede9fe;
  color: #6d28d9;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
}

.highlight-row .badge-year {
  background: #dbeafe;
  color: var(--primary-dark);
}

.font-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.font-medium {
  font-weight: 500;
}

.font-semibold {
  font-weight: 600;
}

.text-right {
  text-align: right;
}

.text-muted {
  color: var(--text-muted);
}

/* History Card */
.history-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-sm);
}

.history-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.history-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.history-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: #f1f5f9;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-main);
  font-size: 0.85rem;
  transition: all 0.15s ease;
}

.history-item:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}

.history-item.active {
  background: #eff6ff;
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.history-item-main {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.history-id {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  background: #e2e8f0;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

.history-ages {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.history-item-result {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: 0.8rem;
}

.history-time {
  font-size: 0.7rem;
  color: var(--text-light);
}

/* Insights Box */
.insights-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
}

.insights-box h4 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 700;
}

.insights-box ul {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.insights-box li {
  margin-bottom: 0.5rem;
}

.insights-box li strong {
  color: var(--text-main);
}

.empty-state {
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 3rem;
  text-align: center;
  color: var(--text-muted);
}
