/* ============================================
   MaFi Calculator - Complete Stylesheet
   ============================================ */

/* --- CSS Variables / Design Tokens --- */
:root {
  --color-primary: #1B2A6B;
  --color-primary-hover: #152258;
  --color-primary-light: #E8EBF5;
  --color-success: #27AE60;
  --color-success-light: #d4edda;
  --color-error: #E74C3C;
  --color-error-light: #f8d7da;
  --color-warning: #F39C12;
  --color-bg: #F0F2F8;
  --color-surface: #FFFFFF;
  --color-border: #E2E5EA;
  --color-text: #1A1A2E;
  --color-text-secondary: #6B7280;
  --color-text-muted: #9CA3AF;
  --sidebar-width: 220px;
  --sidebar-collapsed: 64px;
  --header-height: 64px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --transition: 250ms ease;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body { font-family: var(--font); color: var(--color-text); background: var(--color-bg); line-height: 1.5; overflow-x: hidden; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: inherit; }
table { border-collapse: collapse; width: 100%; }
img { max-width: 100%; display: block; }
ul, ol { list-style: none; }

/* --- App Layout --- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--header-height) 1fr;
  grid-template-areas: "header header" "sidebar main";
  min-height: 100vh;
  transition: grid-template-columns var(--transition);
}
.app.sidebar-collapsed {
  grid-template-columns: var(--sidebar-collapsed) 1fr;
}

/* --- Header --- */
.header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
}
.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.header-logo {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
}
.header-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-text);
}
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--color-border);
}
.header-username {
  font-size: 0.9rem;
  font-weight: 500;
}
.header-chevron {
  width: 16px;
  height: 16px;
  color: var(--color-text-secondary);
}

/* --- Sidebar --- */
.sidebar {
  grid-area: sidebar;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  transition: width var(--transition);
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
}
.sidebar-nav {
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  transition: all var(--transition);
  white-space: nowrap;
  border-left: 3px solid transparent;
}
.sidebar-link:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
}
.sidebar-link.active {
  background: var(--color-primary-light);
  color: var(--color-primary);
  border-left-color: var(--color-primary);
  font-weight: 600;
}
.sidebar-link svg, .sidebar-link .sidebar-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
.sidebar-label {
  transition: opacity var(--transition);
}
.sidebar-collapsed .sidebar-label {
  opacity: 0;
  width: 0;
  overflow: hidden;
}
.sidebar-collapsed .sidebar-link {
  padding: 10px 22px;
  justify-content: center;
  gap: 0;
}
.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  color: var(--color-text-muted);
  transition: color var(--transition);
}
.sidebar-toggle:hover {
  color: var(--color-primary);
}
.sidebar-toggle svg {
  width: 20px;
  height: 20px;
}

/* --- Main Content --- */
.main {
  grid-area: main;
  padding: 28px 36px;
  min-width: 0;
}

/* --- Page Header --- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}
.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 24px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--color-primary-hover);
}
.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn-outline {
  background: var(--color-surface);
  color: var(--color-primary);
  border: 1.5px solid var(--color-primary);
}
.btn-outline:hover {
  background: var(--color-primary-light);
}
.btn-outline-light {
  background: var(--color-surface);
  color: var(--color-text-secondary);
  border: 1.5px solid var(--color-border);
}
.btn-outline-light:hover {
  background: var(--color-bg);
  color: var(--color-text);
}
.btn-sm {
  padding: 7px 18px;
  font-size: 0.85rem;
}

/* --- Badges --- */
.badge {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #fff;
}
.badge-draft { background: var(--color-warning); }
.badge-completed { background: var(--color-success); }

/* --- Card Grid --- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(265px, 1fr));
  gap: 24px;
}
.calc-card {
  background: var(--color-surface);
  border: 1.5px dashed var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: box-shadow var(--transition);
}
.calc-card:hover {
  box-shadow: var(--shadow);
}
.card-image {
  position: relative;
  padding: 16px;
  background: var(--color-surface);
  min-height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--color-border);
}
.card-image .badge {
  position: absolute;
  top: 12px;
  left: 12px;
}
.card-image svg, .card-image img {
  max-width: 80%;
  height: auto;
  opacity: 0.85;
}
.card-body {
  padding: 0 16px 12px;
}
.card-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 2px;
}
.card-desc {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
}
.card-meta {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 2px;
}
.card-actions {
  display: flex;
  gap: 8px;
  padding: 12px 16px 16px;
}

/* --- Data Tables --- */
.table-wrapper {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  overflow-x: auto;
}
.data-table {
  min-width: 700px;
}
.data-table th {
  text-align: left;
  padding: 14px 16px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  border-bottom: 1.5px solid var(--color-border);
}
.data-table td {
  padding: 12px 16px;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
.data-table tbody tr:last-child td {
  border-bottom: none;
}
.data-table .thumb {
  width: 56px;
  height: 38px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--color-bg);
}
.table-actions {
  display: flex;
  gap: 16px;
}
.table-actions a, .table-actions button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  cursor: pointer;
  background: none;
  border: none;
  font-family: inherit;
}
.table-actions a:hover, .table-actions button:hover {
  color: var(--color-primary);
}
.table-actions svg {
  width: 16px;
  height: 16px;
}

/* --- Form Elements --- */
.form-group {
  margin-bottom: 16px;
}
.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--color-text);
}
.form-input {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color var(--transition);
}
.form-input:focus {
  outline: none;
  border-color: var(--color-primary);
}
.form-input::placeholder {
  color: var(--color-text-muted);
}
textarea.form-input {
  resize: vertical;
  min-height: 80px;
}

/* Suffix input (e.g., "m.", "ton") */
.input-suffix {
  position: relative;
}
.input-suffix .form-input {
  padding-right: 40px;
}
.input-suffix .suffix {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
  color: var(--color-text-muted);
  pointer-events: none;
}

/* Inline input groups (W/H/D, X/Y/Z) */
.input-row {
  display: flex;
  gap: 8px;
}
.input-row .input-suffix {
  flex: 1;
  min-width: 0;
}

/* Search input */
.input-search {
  position: relative;
}
.input-search .form-input {
  padding-right: 36px;
}
.input-search .search-icon {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--color-text-muted);
  pointer-events: none;
}

/* File input */
.file-input {
  width: 100%;
  padding: 8px 12px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  color: var(--color-text-muted);
  background: var(--color-surface);
  cursor: pointer;
}

/* --- Wizard Layout --- */
.calc-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 0;
  min-height: calc(100vh - var(--header-height) - 100px);
}
.viz-panel {
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  padding: 24px;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 500px;
}

/* Viz empty state */
.viz-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.viz-empty svg {
  width: 120px;
  height: 120px;
  opacity: 0.25;
}

/* Viz header row */
.viz-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 8px;
}

/* Viz banner */
.viz-banner {
  padding: 14px 20px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  color: #fff;
}
.viz-banner.success { background: var(--color-success); }
.viz-banner.error { background: var(--color-error); }
.viz-banner h3 { font-size: 0.95rem; font-weight: 700; }
.viz-banner p { font-size: 0.82rem; opacity: 0.9; margin-top: 2px; }

/* Viz specs */
.viz-specs {
  text-align: right;
  margin-bottom: 8px;
}
.viz-specs .spec-name {
  font-weight: 700;
  font-size: 0.95rem;
}
.viz-specs .spec-detail {
  font-size: 0.82rem;
  color: var(--color-text-secondary);
}

/* Viz hint */
.viz-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  font-size: 0.82rem;
  color: var(--color-text-muted);
  margin-top: auto;
}
.viz-hint svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* Load indicators */
.load-indicators {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}
.load-indicator {
  text-align: center;
}
.load-indicator .load-label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}
.load-indicator .load-value {
  font-size: 1rem;
  font-weight: 700;
}
.load-indicator .load-arrow {
  width: 16px;
  height: 16px;
  margin: 0 auto;
  color: var(--color-text-muted);
}

/* SVG container */
.viz-svg-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.viz-svg-container svg {
  width: 100%;
  height: auto;
  max-height: 400px;
}

/* --- Wizard Panel (Right Side) --- */
.wizard-panel {
  padding: 0 0 0 24px;
  display: flex;
  flex-direction: column;
}
.wizard-steps {
  flex: 1;
}

/* Step accordion */
.step {
  border-bottom: 1px solid var(--color-border);
}
.step:last-child {
  border-bottom: none;
}
.step-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 0;
  cursor: pointer;
  user-select: none;
}
.step-number {
  font-weight: 700;
  font-size: 0.95rem;
}
.step-title {
  font-weight: 600;
  font-size: 0.95rem;
  flex: 1;
}
.step-check {
  width: 20px;
  height: 20px;
  color: var(--color-success);
  display: none;
}
.step.completed .step-check {
  display: block;
}
.step-chevron {
  width: 18px;
  height: 18px;
  color: var(--color-text-muted);
  transition: transform var(--transition);
}
.step.active .step-chevron {
  transform: rotate(180deg);
}
.step-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease;
}
.step.active .step-body {
  max-height: 2000px;
}
.step-content {
  padding: 0 0 16px;
}

/* Step states */
.step.pending .step-header {
  color: var(--color-text-muted);
}
.step.pending .step-number,
.step.pending .step-title {
  color: var(--color-text-muted);
}

/* Footprint row */
.footprint-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.footprint-row .input-suffix {
  flex: 1;
}
.btn-add-footprint {
  font-size: 0.8rem;
  padding: 6px 14px;
  border: 1.5px solid var(--color-primary);
  border-radius: var(--radius);
  color: var(--color-primary);
  background: var(--color-surface);
  font-weight: 600;
}
.btn-add-footprint:hover {
  background: var(--color-primary-light);
}
.btn-remove-footprint {
  color: var(--color-text-muted);
  font-size: 1.2rem;
  padding: 4px;
  line-height: 1;
}
.btn-remove-footprint:hover {
  color: var(--color-error);
}

/* Wizard navigation */
.wizard-nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  padding: 16px 0;
  border-top: 1px solid var(--color-border);
  margin-top: auto;
}
.wizard-back {
  font-size: 0.9rem;
  color: var(--color-text-secondary);
}
.wizard-back:hover {
  color: var(--color-primary);
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}
.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  transform: translateY(20px);
  transition: transform var(--transition);
}
.modal-overlay.active .modal {
  transform: translateY(0);
}
.modal h2 {
  font-size: 1.2rem;
  margin-bottom: 20px;
}
.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* --- Chart Container --- */
.chart-container {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.chart-container canvas {
  width: 100%;
  height: 200px;
}

/* Lash question */
.lash-question {
  text-align: center;
  padding: 14px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: var(--color-text);
  margin-top: 12px;
  cursor: pointer;
  transition: border-color var(--transition);
}
.lash-question:hover {
  border-color: var(--color-primary);
}

/* --- Responsive --- */
@media (max-width: 1024px) {
  .main { padding: 20px 24px; }
  .calc-layout { grid-template-columns: 1fr 300px; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}

@media (max-width: 768px) {
  .app {
    grid-template-columns: var(--sidebar-collapsed) 1fr;
  }
  .sidebar-label { opacity: 0; width: 0; overflow: hidden; }
  .sidebar-link { padding: 10px 22px; justify-content: center; gap: 0; }
  .sidebar-toggle { display: none; }
  .main { padding: 16px; }
  .card-grid { grid-template-columns: 1fr; }
  .calc-layout {
    grid-template-columns: 1fr;
  }
  .wizard-panel {
    padding: 16px 0 0;
  }
  .viz-panel {
    min-height: 300px;
  }
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .page-header .btn {
    width: 100%;
  }
  .input-row {
    flex-wrap: wrap;
  }
  .input-row .input-suffix {
    min-width: 100px;
  }
}

@media (max-width: 480px) {
  .header-username { display: none; }
  .header-title { font-size: 1rem; }
  .card-actions { flex-direction: column; }
  .card-actions .btn { width: 100%; }
}
