*, *::before, *::after { box-sizing: border-box; }
body, h1, h2, h3, h4, h5, h6, p, ul, ol { margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: var(--font-md);
  color: var(--text);
  background: var(--bg-cream);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  overflow-x: hidden;
}

a { color: var(--link-color); text-decoration: none; }
a:hover { color: var(--primary); }

h1 { font-size: var(--font-2xl); font-weight: var(--font-semibold); }
h2 { font-size: var(--font-xl); font-weight: var(--font-semibold); }
h3 { font-size: var(--font-lg); font-weight: var(--font-semibold); }

.text-muted { color: var(--text-muted); font-size: var(--font-sm); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.actions-cell { white-space: nowrap; text-align: right; }

/* --- App Layout --- */
.app-container { display: flex; flex-direction: column; min-height: 100vh; }
.main-content { padding: var(--space-lg) var(--space-xl); max-width: var(--content-max-width); margin: 0 auto; width: 100%; }
.main-content.with-header { margin-top: var(--header-height); }

/* --- Header --- */
.bc-header {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  z-index: var(--z-sticky);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  padding: 0 var(--space-xl);
  gap: var(--space-lg);
}

.header-left { display: flex; align-items: center; }
.header-right { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-sm); }

.logo {
  font-weight: var(--font-bold);
  font-size: var(--font-lg);
  letter-spacing: -0.5px;
  color: var(--text);
  text-decoration: none;
}
.logo:hover { color: var(--text); }
.logo i { color: var(--primary); margin-right: 6px; }
.header-logo-img { height: 32px; width: auto; max-width: 160px; object-fit: contain; display: block; }

.user-name { font-size: var(--font-sm); color: var(--text-secondary); }
.user-name-link { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); text-decoration: none; cursor: pointer; transition: color var(--transition-fast); }
.user-name-link:hover { color: var(--primary); }
.user-name-link i { font-size: var(--font-base); }

/* --- Footer --- */
.app-footer {
  text-align: center;
  padding: var(--space-lg) var(--space-xl);
  font-size: var(--font-xs);
  color: var(--text-muted);
  border-top: 1px solid var(--border-light);
  margin-top: auto;
}
.footer-link { color: var(--text-muted); text-decoration: none; transition: color var(--transition-fast); }
.footer-link:hover { color: var(--primary); }
.footer-link i { margin-right: 3px; }
.footer-sep { margin: 0 8px; }

/* --- Navigation --- */
.bc-topbar-nav {
  display: flex;
  justify-content: center;
  align-items: stretch;
  gap: 2px;
  height: 100%;
}

.bc-nav-new {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin: auto 6px auto 0;
  border-radius: 10px;
  background: #16a34a;
  color: #fff;
  font-size: 17px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 1px 3px rgba(22,163,74,.25);
  flex-shrink: 0;
}
.bc-nav-new:hover {
  background: #15803d;
  transform: scale(1.08);
  box-shadow: 0 2px 8px rgba(22,163,74,.35);
}
.bc-nav-new:active {
  transform: scale(0.96);
}

.bc-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px 14px;
  color: var(--text-muted);
  font-weight: var(--font-medium);
  cursor: pointer;
  text-decoration: none;
  position: relative;
  transition: color 0.15s ease, background 0.15s ease;
  border-radius: 0;
  min-width: 64px;
}
.bc-nav-icon {
  font-size: 15px;
  transition: transform 0.15s ease, color 0.15s ease;
  line-height: 1;
}
.bc-nav-label {
  font-size: 10.5px;
  letter-spacing: 0.2px;
  line-height: 1;
  white-space: nowrap;
}
.bc-nav-item:hover {
  color: var(--text);
  background: #f8f9fb;
}
.bc-nav-item:hover .bc-nav-icon {
  transform: translateY(-1px);
}
.bc-nav-item.active {
  color: var(--primary);
  background: transparent;
}
.bc-nav-item.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 8px;
  right: 8px;
  height: 2.5px;
  background: var(--primary);
  border-radius: 2px 2px 0 0;
}
.bc-nav-item.active .bc-nav-icon {
  color: var(--primary);
}

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; font-size: var(--font-base); font-weight: var(--font-medium);
  line-height: 1; border-radius: var(--radius); border: 1px solid transparent;
  cursor: pointer; transition: all var(--transition-base); white-space: nowrap;
  font-family: inherit;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f9fafb; border-color: var(--border-dark); }

.btn-success { background: var(--accent-green); color: #fff; }
.btn-danger { background: var(--accent-red-light); color: var(--accent-red); }
.btn-danger:hover { background: #fca5a5; }

.btn-ghost { background: transparent; color: var(--text-secondary); border: none; }
.btn-ghost:hover { background: #f3f4f6; }

.btn-sm { padding: 6px 12px; font-size: var(--font-sm); }
.btn-icon { width: 32px; height: 32px; padding: 0; border-radius: 50%; }

/* --- Forms --- */
.form-group { margin-bottom: var(--space-lg); }
.form-label { display: block; font-size: var(--font-sm); font-weight: var(--font-medium); color: var(--text); margin-bottom: var(--space-xs); }

.form-input, .form-select, .form-textarea {
  width: 100%; padding: 10px 12px; font-size: var(--font-base); font-family: inherit;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: #fff; color: var(--text);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); outline: none;
}
.form-input::placeholder { color: var(--text-muted); }
.form-error { font-size: var(--font-xs); color: var(--accent-red); margin-top: var(--space-xs); }

/* --- Cards --- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden;
}
.card-header { padding: var(--space-lg) var(--space-xl); border-bottom: 1px solid var(--border-light); }
.card-body { padding: var(--space-xl); }

/* --- Tables --- */
.bc-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.bc-table th {
  text-transform: uppercase; font-size: var(--font-xs); font-weight: var(--font-semibold);
  color: var(--text-muted); padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border); text-align: left;
}
.bc-table td { padding: 10px var(--space-md); border-bottom: 1px solid var(--border-light); vertical-align: middle; }
.bc-table tr:hover { background: #f9fafb; }

/* --- Badges --- */
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px;
  font-size: var(--font-xs); font-weight: var(--font-medium);
  border-radius: 10px; line-height: 1.4;
}
.badge-primary { background: #dbeafe; color: #1d4ed8; }
.badge-secondary { background: #f3f4f6; color: #6b7280; }
.badge-success { background: #dcfce7; color: #16a34a; }
.badge-warning { background: #fef3c7; color: #f59e0b; }
.badge-danger { background: #fee2e2; color: #dc2626; }
.badge-info { background: #dbeafe; color: #3b82f6; }

/* --- Skeleton --- */
.skeleton-card { border-radius: var(--radius-lg); background: #f3f4f6; animation: shimmer 1.5s infinite; }
@keyframes shimmer {
  0% { opacity: 0.6; }
  50% { opacity: 1; }
  100% { opacity: 0.6; }
}

/* --- View Layout --- */
.view-container { }
.view-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-xl); }
.view-actions { display: flex; gap: var(--space-sm); align-items: center; }
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--space-lg); }

/* --- Login --- */
.login-container {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
}
.login-card { width: 100%; max-width: 400px; }
.login-card .card-header { text-align: center; }
.login-card h2 { margin-bottom: var(--space-xs); }

/* --- Modal --- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: var(--z-modal-backdrop);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
}
.modal-backdrop:has(.modal-full) { padding: 0; }

.modal-dialog {
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-height: calc(100vh - 80px);
  display: flex; flex-direction: column;
  z-index: var(--z-modal);
}

.modal-sm { max-width: 420px; }
.modal-md { max-width: 600px; }
.modal-lg { max-width: 900px; }
.modal-xl { max-width: 1100px; }
.modal-full { max-width: 100%; margin: 0; border-radius: 0; max-height: 100vh; height: 100vh; }
.modal-full .modal-body { padding: 0; }

.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: var(--space-lg) var(--space-xl);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}
.modal-header h3 { margin: 0; }

.modal-body {
  padding: var(--space-xl);
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex; justify-content: flex-end; gap: var(--space-sm);
  padding: var(--space-lg) var(--space-xl);
  border-top: 1px solid var(--border-light);
  flex-shrink: 0;
}

.modal-enter-active, .modal-leave-active { transition: opacity 0.2s ease; }
.modal-enter-from, .modal-leave-to { opacity: 0; }
.modal-enter-active .modal-dialog { transition: transform 0.2s ease; }
.modal-enter-from .modal-dialog { transform: translateY(-20px); }

/* --- Toast --- */
.toast-container {
  position: fixed; top: 16px; right: 16px;
  z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: 8px;
  max-width: 400px;
}

.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  font-size: var(--font-base);
  cursor: pointer;
  animation: toast-in 0.25s ease;
}

.toast-success { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }
.toast-error { background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; }
.toast-warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.toast-info { background: #dbeafe; color: #1d4ed8; border: 1px solid #93c5fd; }

.toast i { font-size: 16px; flex-shrink: 0; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

.toast-enter-active { animation: toast-in 0.25s ease; }
.toast-leave-active { transition: all 0.2s ease; }
.toast-leave-to { opacity: 0; transform: translateX(40px); }

/* --- Offer/Order Editor --- */
.editor-categories { margin-top: 16px; }

.editor-category {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  margin-bottom: 12px;
  overflow: hidden;
}

.category-title {
  background: #f9fafb;
  padding: 10px 16px;
  font-size: var(--font-base);
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
}
.category-title i { color: var(--accent-yellow); margin-right: 6px; }

.editor-items { padding: 8px 16px; }

.editor-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--border-light);
}
.editor-item:last-child { border-bottom: none; }

.item-check {
  display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer; font-size: var(--font-base);
}
.item-check input[type="checkbox"] {
  width: 16px; height: 16px; accent-color: var(--primary);
}

.item-fields {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-top: 8px; margin-left: 24px;
}

.item-field {
  display: flex; align-items: center; gap: 4px;
  font-size: var(--font-sm);
}
.item-field label { color: var(--text-muted); white-space: nowrap; }

.item-price {
  margin-left: auto;
  font-weight: var(--font-semibold);
  color: var(--primary);
  font-size: var(--font-sm);
  white-space: nowrap;
}

.price-summary {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  margin-top: 16px;
}

.price-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 0;
  font-size: var(--font-base);
}
.price-row strong { font-size: var(--font-lg); color: var(--primary); }

/* --- Mobile --- */
@media (max-width: 768px) {
  .bc-header { grid-template-columns: 1fr 1fr; gap: 0; }
  .bc-topbar-nav { display: none; }
  .view-header { flex-direction: column; gap: var(--space-md); align-items: stretch; }
  .view-actions { flex-wrap: wrap; }
  .view-actions .form-input { width: 100% !important; }
  .template-grid { grid-template-columns: 1fr; }
}
