:root {
  --primary: #E53D3D;
  --primary-hover: #C53030;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-muted: #6b7280;
  --danger: #ef4444;
  --success: #E53D3D;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

input[type="checkbox"] {
  accent-color: var(--primary);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

body,
button,
input,
select,
textarea {
  font-family: 'Nunito Sans', sans-serif;
}

html {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  width: 100%;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin: 0;
  padding: 0;
}

/* Layout */
.app-container {
  display: flex;
  flex: 1;
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
}

.product-tabs-bar {
  height: 64px;
  padding: 0 16px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  flex-shrink: 0;
}

.product-tab {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f9fafb;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.product-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.add-product-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f3f4f6;
  border: 1px dashed #d1d5db;
  border-radius: 6px;
  cursor: pointer;
  color: #6b7280;
}

.add-product-btn:hover {
  background: #e5e7eb;
  color: var(--text);
}

.tab-actions {
  display: flex;
  gap: 4px;
  margin-left: 4px;
  border-left: 1px solid rgba(0, 0, 0, 0.1);
  padding-left: 4px;
}

.tab-btn-icon {
  padding: 2px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tab-btn-icon:hover {
  background: rgba(0, 0, 0, 0.1);
}

.sidebar {
  width: 480px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: row;
  flex-shrink: 0;
  z-index: 10;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.02);
}

/* Vertical Icon Nav Rail */
.side-nav {
  width: 64px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 0;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}

.side-nav-btn {
  width: 52px;
  height: 54px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 10px;
  margin: 2px 0;
  transition: all 0.18s;
  padding: 0;
}

.side-nav-btn:hover {
  background: #f3f4f6;
  color: var(--text);
}

.side-nav-btn.active {
  background: rgba(229, 61, 61, 0.12);
  color: var(--primary);
}

.side-nav-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.side-nav-btn .nav-label {
  font-size: 0.55rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  line-height: 1;
}

/* Content Panel beside icon nav */
.sidebar-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main-content {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
header.top-bar {
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}

.brand {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Legacy tabs-nav hidden – replaced by side-nav */
.tabs-nav {
  display: none;
}

/* Content */
.tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.tab-pane {
  display: none;
  animation: fadeIn 0.3s ease;
}

.tab-pane.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Form Elements */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
}

.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.15s;
}

/* Features List */
.feature-item {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  padding: 12px;
  border-radius: 6px;
  margin-bottom: 10px;
}

.feature-item-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Radio Cards */
.radio-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 10px;
}

.radio-card {
  position: relative;
}

.radio-card input {
  position: absolute;
  opacity: 0;
}

.radio-card-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  height: 100%;
  font-size: 0.9rem;
}

.radio-card input:checked+.radio-card-content {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.05);
  color: var(--primary);
  font-weight: 600;
  box-shadow: 0 0 0 1px var(--primary);
}

/* Canvas Area */
.canvas-wrapper {
  flex: 1;
  background: #e5e7eb;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 40px;
}

.canvas-container {
  background: #f8fafc;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  border-radius: 4px;
  max-width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

#previewCanvas {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Bottom Status Bar */
.status-bar {
  height: auto;
  min-height: 60px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  flex-shrink: 0;
}

.price-block {
  display: flex;
  flex-direction: column;
}

.price-tag {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

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

.btn {
  padding: 10px 20px;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
  border: none;
}

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

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

.btn-secondary {
  background: white;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  background: #f9fafb;
  border-color: #d1d5db;
}

.btn-danger-sm {
  background: #fee2e2;
  color: #991b1b;
  padding: 4px 8px;
  font-size: 0.75rem;
  border-radius: 4px;
  border: none;
  cursor: pointer;
}

.alert {
  padding: 12px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 0.9rem;
  border: 1px solid transparent;
}

.alert-info {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1e40af;
}

/* Cost Table in Calc Tab */
.cost-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin-top: 10px;
}

.cost-table td {
  padding: 8px 0;
  border-bottom: 1px solid #f3f4f6;
}

.cost-table .val {
  text-align: right;
  font-weight: 500;
}

.cost-table .total-row td {
  border-top: 2px solid #e5e7eb;
  font-weight: 700;
  padding-top: 12px;
  font-size: 1rem;
}

/* Modal */
/* Window Tabs (New Organic Layout) */
.product-tabs-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  position: relative;
  /* Ensure it doesn't float */
  z-index: 5;
}

.product-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  margin: 4px 0;
  background: #f3f4f6;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}

.product-tab:hover {
  background: #e5e7eb;
  color: var(--text);
}

.product-tab.active {
  background: white;
  border-color: var(--border);
  color: var(--primary);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.product-tab .tab-actions {
  display: flex;
  gap: 6px;
  margin-left: 8px;
  opacity: 0.6;
}

.product-tab:hover .tab-actions {
  opacity: 1;
}

.add-product-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f3f4f6;
  border: 1px dashed #d1d5db;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s;
}

.add-product-btn:hover {
  background: #e5e7eb;
  color: var(--primary);
  border-color: var(--primary);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

@media (min-width: 992px) and (max-width: 1200px) {
  .sidebar {
    width: 400px;
  }
}

@media (max-width: 991px), (max-width: 1024px) and (orientation: portrait) {
  body {
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100vw;
  }

  .app-container {
    flex-direction: column;
    height: calc(100vh - 54px);
    height: calc(100dvh - 54px);
    /* Subtract header height */
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    max-width: 100vw;
  }

  /* Hide Scrollbars */
  .side-nav,
  .product-tabs-bar,
  .tab-content,
  .sidebar-panel,
  #orders-list {
    -ms-overflow-style: none !important;
    scrollbar-width: none !important;
  }

  .side-nav::-webkit-scrollbar,
  .product-tabs-bar::-webkit-scrollbar,
  .tab-content::-webkit-scrollbar,
  .sidebar-panel::-webkit-scrollbar,
  #orders-list::-webkit-scrollbar {
    display: none !important;
  }

  .top-bar {
    padding: 0 8px;
    height: 54px;
    flex-shrink: 0;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
  }

  .top-bar .brand {
    font-size: 0;
    /* Hide text */
  }

  .top-bar .brand svg {
    width: 50px;
    height: 25px;
  }

  .top-bar div[style*="display: flex; gap: 10px;"] {
    gap: 4px !important;
  }

  .mobile-hide {
    display: none !important;
  }

  .sidebar {
    width: 100%;
    height: auto;
    border-right: none;
    border-top: 1px solid var(--border);
    flex-direction: column;
    order: 2;
    padding-bottom: calc(120px + env(safe-area-inset-bottom, 0px));
    /* Space for fixed bottom bar including mobile safe areas */
  }

  .side-nav {
    width: 100%;
    height: auto;
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    justify-content: flex-start;
    padding: 6px 20px 6px 6px;
    /* Extra right padding */
    gap: 8px;
    -webkit-overflow-scrolling: touch;
  }

  .side-nav-btn {
    min-width: 54px;
    height: 50px;
    flex-shrink: 0;
  }

  .side-nav-btn svg {
    width: 14px;
    height: 14px;
  }

  .main-content {
    order: 1;
    height: auto;
    min-height: 350px;
    flex-shrink: 0;
    width: 100%;
  }

  .canvas-wrapper {
    padding: 10px;
    min-height: 300px;
    width: 100%;
  }

  .product-tabs-bar {
    padding: 6px 12px;
    height: auto;
    flex-wrap: nowrap;
    overflow-x: auto;
    width: 100%;
  }

  .status-bar {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    z-index: 1000;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px)) 12px;
    background: white;
    box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  .price-tag {
    font-size: 1.1rem;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .radio-cards {
    grid-template-columns: repeat(3, 1fr) !important;
  }

  .radio-card-content {
    padding: 12px 6px;
    font-size: 0.8rem;
  }

  /* Fullscreen Modals */
  dialog {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    border: none !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
  }

  .shape-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    padding: 10px !important;
  }

  .canvas-container {
    min-height: 250px;
  }

  .tech-modal-grid {
    grid-template-columns: 1fr !important;
    height: auto !important;
  }

  #techModal .dialog-content {
    grid-template-columns: 1fr !important;
  }

  .sidebar-panel {
    max-height: none;
    overflow-y: visible;
  }
}

.canvas-container {
  min-height: 500px;
}

.tech-modal-grid {
  height: 80vh;
}

@media print {
  body * {
    visibility: hidden;
  }

  #techModal,
  #techModal * {
    visibility: visible;
  }

  #techModal {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    max-width: 100% !important;
    margin: 0;
    padding: 0;
    border: none;
    box-shadow: none;
    background: white;
  }

  #techModal button,
  .btn {
    display: none !important;
  }

  .no-print {
    display: none !important;
  }
}

/* Shape Previews Global Fix */
.shape-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  width: 100%;
}

.shape-card {
  cursor: pointer;
  padding: 12px 8px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.shape-card:hover {
  transform: translateY(-2px);
  background: #f1f5f9;
  border-color: #cbd5e1;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.shape-preview {
  width: 70px;
  height: 70px;
  position: relative;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.shape-preview-inner {
  width: 100%;
  height: 100%;
  background: #3b82f6; /* Beautiful solid blue color for clear visibility */
}

.shape-name {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #334155;
  text-align: center;
  word-break: break-word;
}


/* Hide Spinners in Number Inputs */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type=number] {
  -moz-appearance: textfield;
  appearance: textfield;
}
