:root {
  --bg: #f1f5f9;
  --bg-subtle: #e2e8f0;
  --card: #ffffff;
  --card-inner: #f8fafc;
  --border: #cbd5e1;
  --border-dark: #94a3b8;
  --border-focus: #0284c7;
  --accent: #0284c7;
  --accent-hover: #0369a1;
  --accent-light: #e0f2fe;
  --amber: #b45309;
  --amber-light: #fef3c7;
  --emerald: #047857;
  --text: #0f172a;
  --text-muted: #334155;
  --text-dim: #64748b;
  --radius: 8px;
  --radius-sm: 5px;
  --shadow: 0 1px 4px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  padding: 12px;
  font-size: 14px;
  line-height: 1.45;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

/* Fluid responsive app shell */
.app-shell {
  width: 100%;
  max-width: 1380px;
  min-width: 0;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 30px;
  overflow-x: hidden;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 2px 2px;
  flex-wrap: wrap;
  gap: 8px;
  border-bottom: 2px solid var(--border);
  padding-bottom: 8px;
}

.app-title {
  display: flex;
  flex-direction: column;
}

.app-title h1 {
  font-size: 1.25rem;
  font-weight: 800;
  color: #0f172a;
  letter-spacing: -0.02em;
}

.app-title span {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
}

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

.icon-btn {
  background: #ffffff;
  border: 1px solid var(--border-dark);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.icon-btn:hover {
  background: var(--bg-subtle);
  border-color: var(--text);
}

.icon-btn:active {
  background: #e2e8f0;
}

/* Pattern Tabs (Full width scrollable) */
.tabs-scroll {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
  margin: 0;
  padding: 2px 0;
}
.tabs-scroll::-webkit-scrollbar { display: none; }

.tabs-grid {
  display: flex;
  gap: 6px;
  min-width: max-content;
}

.tab-btn {
  background: #ffffff;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  transition: all 0.15s;
}

.tab-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tab-btn.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  box-shadow: 0 1px 4px rgba(2, 132, 199, 0.3);
}

/* Responsive 2-column Grid */
.app-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  width: 100%;
}

.col-controls,
.col-workspace {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

@media (min-width: 960px) {
  .app-grid {
    grid-template-columns: 440px 1fr;
    align-items: start;
  }
  .col-workspace {
    position: sticky;
    top: 10px;
  }
}

@media (min-width: 1280px) {
  .app-grid {
    grid-template-columns: 480px 1fr;
  }
}

/* Card layout */
.card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--bg-subtle);
}

.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--amber-light);
  color: var(--amber);
  border: 1px solid #fcd34d;
}

/* Mattress Presets */
.presets-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.btn-preset {
  background: #f8fafc;
  color: var(--text);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  padding: 8px 2px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}

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

.btn-preset.active {
  background: #0f172a;
  color: #ffffff;
  border-color: #0f172a;
}

/* Stepper Input Groups */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

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

.input-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  min-width: 0;
  width: 100%;
}

.input-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.input-label span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.input-stepper-wrap {
  display: flex;
  align-items: stretch;
  background: #ffffff;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  overflow: hidden;
  width: 100%;
  min-width: 0;
}

.stepper-btn {
  background: #f1f5f9;
  color: #0f172a;
  border: none;
  padding: 8px 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  min-width: 36px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}

.dim-stepper,
.frame-stepper {
  min-width: 27px;
  padding: 8px 3px;
  font-size: 11px;
}

.stepper-btn:hover {
  background: #e2e8f0;
}

.stepper-btn:active {
  background: #cbd5e1;
}

.stepper-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: #0f172a;
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  padding: 8px 4px;
  outline: none;
  -moz-appearance: textfield;
}
.stepper-input::-webkit-outer-spin-button,
.stepper-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Segmented Toggle Control */
.segmented-group {
  display: flex;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
  width: 100%;
}

.segmented-btn {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 4px;
  padding: 7px 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  white-space: nowrap;
}

.segmented-btn:hover {
  color: var(--text);
}

.segmented-btn.active {
  background: #ffffff;
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

/* Visualizer Card (Light Engineering Canvas) */
.vis-container {
  width: 100%;
  background: #ffffff;
  border: 1px solid var(--border-dark);
  border-radius: 6px;
  padding: 10px;
  overflow: hidden;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

svg#canvas {
  width: 100%;
  height: auto;
  min-height: 240px;
  max-height: 420px;
  display: block;
  background: #ffffff;
}

/* Action bar under sketch */
.sketch-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.btn-action-primary {
  background: #0f172a;
  color: #ffffff;
  border: 1px solid #0f172a;
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s;
}

.btn-action-primary:hover {
  background: #1e293b;
}

.btn-action-primary:active {
  background: #334155;
}

.btn-action-secondary {
  background: #ffffff;
  color: #0f172a;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s;
}

.btn-action-secondary:hover {
  background: var(--bg-subtle);
  border-color: #0f172a;
}

/* Tape Section (Strict Engineering Cards) */
.tape-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tape-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  border-left: 4px solid #0284c7;
}

.tape-title {
  font-size: 12px;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
}

.tape-values {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
  font-size: 13px;
  color: #0284c7;
  word-break: break-all;
  line-height: 1.5;
  font-weight: 700;
}

/* Technology Accordion */
.tech-accordion summary {
  cursor: pointer;
  list-style: none;
  user-select: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}
.tech-accordion summary::-webkit-details-marker { display: none; }

.accordion-arrow {
  color: var(--text-dim);
  font-size: 12px;
  transition: transform 0.2s;
}
.tech-accordion[open] .accordion-arrow {
  transform: rotate(180deg);
}

.tech-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}
@media (max-width: 480px) {
  .tech-grid { grid-template-columns: 1fr; }
}

.tech-summary-badge {
  background: #f8fafc;
  border: 1px dashed var(--border-dark);
  border-radius: 6px;
  padding: 8px 10px;
  margin-top: 10px;
  font-size: 12px;
  color: #334155;
}

/* Parts Specification Table */
.table-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

th {
  background: #f8fafc;
  color: #0f172a;
  border-bottom: 2px solid var(--border-dark);
  padding: 8px 6px;
  font-weight: 700;
  white-space: nowrap;
}

td {
  padding: 8px 6px;
  border-bottom: 1px solid #e2e8f0;
  color: #1e293b;
  white-space: nowrap;
}

tr:nth-child(even) td {
  background: #fbfcfe;
}

/* Project Manager Modal */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(2px);
}

.modal-overlay.active {
  display: flex;
}

.modal-dialog {
  background: #ffffff;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius);
  max-width: 500px;
  width: 100%;
  padding: 16px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #0f172a;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}

.project-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin-bottom: 6px;
}

/* Toast Notifications */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #0f172a;
  color: #ffffff;
  padding: 10px 20px;
  border-radius: 30px;
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 9999;
  pointer-events: none;
}

/* Mobile Fine-Tuning (Phones) */
@media (max-width: 480px) {
  body {
    padding: 8px 6px;
  }
  .card {
    padding: 12px 10px;
  }
  .presets-grid {
    gap: 3px;
  }
  .btn-preset {
    padding: 7px 1px;
    font-size: 11px;
  }
  .stepper-btn {
    min-width: 32px;
    padding: 8px 4px;
    font-size: 12px;
  }
  .sketch-actions {
    grid-template-columns: 1fr;
  }
}

/* Print Styles */
@media print {
  body {
    background: #fff !important;
    color: #000 !important;
    padding: 0;
  }
  .app-shell { max-width: 100% !important; padding: 0 !important; }
  .tabs-scroll, .header-actions, .sketch-actions, .presets-grid, #modeControls, .btn-action-primary, .btn-action-secondary, .toast, .tech-accordion summary {
    display: none !important;
  }
  .app-grid { display: block !important; }
  .card {
    border: 1px solid #ccc !important;
    background: #fff !important;
    color: #000 !important;
    box-shadow: none !important;
    page-break-inside: avoid;
    margin-bottom: 10px !important;
  }
  .vis-container {
    background: #fff !important;
    border: 1px solid #999 !important;
  }
  td, th {
    color: #000 !important;
    border-bottom: 1px solid #ccc !important;
  }
}
