* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #f8f9fa;
  min-height: 100vh;
  color: #1f2937;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

header {
  padding: 24px 0;
  margin-bottom: 32px;
  border-bottom: 1px solid #e5e7eb;
}

h1 {
  margin: 0 0 8px;
  font-size: 2rem;
  font-weight: 600;
  color: #111827;
}

header p {
  margin: 0;
  color: #6b7280;
  font-size: 0.95rem;
}

/* 2-Column Layout */
.main-layout {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 24px;
  align-items: start;
}

.left-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.right-panel {
  position: sticky;
  top: 24px;
}

.controls {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 20px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.control-group:last-child {
  margin-bottom: 0;
}

.control-group label {
  font-weight: 500;
  color: #374151;
  font-size: 0.875rem;
}

.input-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

input[type="number"],
input[type="text"] {
  padding: 8px 12px;
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.875rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  background: white;
}

input[type="number"]:focus,
input[type="text"]:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

button {
  padding: 8px 16px;
  border: none;
  background: #2563eb;
  color: white;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.875rem;
  transition: background-color 0.2s ease;
  width: 100%;
}

button:hover {
  background: #1d4ed8;
}

button:active {
  background: #1e40af;
}

button.ghost {
  background: white;
  color: #374151;
  border: 1px solid #d1d5db;
}

button.ghost:hover {
  background: #f9fafb;
  border-color: #9ca3af;
}

.control-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.parts-list {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 20px;
}

.parts-list h2 {
  margin: 0 0 16px;
  color: #111827;
  font-size: 1.125rem;
  font-weight: 600;
}

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

thead {
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
}

th {
  padding: 10px 12px;
  text-align: left;
  color: #6b7280;
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid #f3f4f6;
  color: #374151;
}

tbody tr:hover {
  background: #f9fafb;
}

tbody tr:last-child td {
  border-bottom: none;
}

td button {
  padding: 4px 12px;
  font-size: 0.75rem;
}

.layout {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 120px);
}

.layout h2 {
  margin: 0 0 16px;
  color: #111827;
  font-size: 1.125rem;
  font-weight: 600;
}

.layout-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
  flex-shrink: 0;
}

#carpetContainer {
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 16px;
  background: #fafbfc;
  overflow: auto;
  flex: 1;
}

#carpet {
  position: relative;
  background: white;
  border: 1px solid #d1d5db;
  border-radius: 4px;
}

.piece {
  position: absolute;
  background: #2563eb;
  border: 1px solid #1d4ed8;
  border-radius: 4px;
  color: white;
  font-size: 10px;
  font-weight: 500;
  padding: 4px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: pre-line;
  transition: opacity 0.2s ease;
}

.piece:hover {
  opacity: 0.85;
}

.waste {
  position: absolute;
  background: rgba(239, 68, 68, 0.15);
  border: 1px dashed rgba(239, 68, 68, 0.4);
  pointer-events: none;
  border-radius: 2px;
}

#stats {
  font-size: 0.9rem;
  color: #6b7280;
  background: #f9fafb;
  padding: 12px 14px;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  line-height: 1.6;
}

footer {
  padding: 16px 0;
  text-align: center;
  border-top: 1px solid #e5e7eb;
  margin-top: 32px;
}

footer small {
  color: #9ca3af;
  font-size: 0.75rem;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}

.toast {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px 16px;
  min-width: 300px;
  max-width: 400px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: auto;
  animation: slideInRight 0.3s ease;
}

.toast.success {
  border-left: 4px solid #10b981;
}

.toast.error {
  border-left: 4px solid #ef4444;
}

.toast.warning {
  border-left: 4px solid #f59e0b;
}

.toast.info {
  border-left: 4px solid #2563eb;
}

.toast-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}

.toast.success .toast-icon {
  background: #d1fae5;
  color: #10b981;
}

.toast.error .toast-icon {
  background: #fee2e2;
  color: #ef4444;
}

.toast.warning .toast-icon {
  background: #fef3c7;
  color: #f59e0b;
}

.toast.info .toast-icon {
  background: #dbeafe;
  color: #2563eb;
}

.toast-content {
  flex: 1;
  font-size: 0.875rem;
  color: #374151;
}

.toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  padding: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
}

.toast-close:hover {
  color: #374151;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOutRight {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

.toast.removing {
  animation: slideOutRight 0.3s ease forwards;
}

/* Confirmation Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: white;
  border-radius: 8px;
  padding: 24px;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.modal-header {
  margin-bottom: 16px;
}

.modal-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: #111827;
  margin: 0;
}

.modal-content {
  color: #6b7280;
  font-size: 0.875rem;
  margin-bottom: 16px;
}

.modal-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.875rem;
  margin-bottom: 24px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.modal-input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.modal-actions button {
  width: auto;
  min-width: 80px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Responsive Design */
@media (max-width: 1024px) {
  .main-layout {
    grid-template-columns: 1fr;
  }

  .right-panel {
    position: static;
  }

  #carpetContainer {
    max-height: 600px;
  }
}

@media (max-width: 768px) {
  .container {
    padding: 16px;
  }

  h1 {
    font-size: 1.5rem;
  }

  header p {
    font-size: 0.875rem;
  }
}
