*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang HK',
    'Microsoft JhengHei', sans-serif;
  font-size: 14px;
  color: #1a1a1a;
  background: #f0f2f5;
  line-height: 1.5;
}

a {
  color: #1565c0;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  color: #333;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  background: #f5f5f5;
  text-decoration: none;
}

.btn-primary {
  background: #1565c0;
  border-color: #1565c0;
  color: #fff;
}

.btn-primary:hover {
  background: #0d47a1;
}

.btn-danger {
  background: #fff;
  border-color: #e53935;
  color: #e53935;
}

.btn-danger:hover {
  background: #ffebee;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 13px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.stat-card .label {
  font-size: 12px;
  color: #666;
  margin-bottom: 4px;
}

.stat-card .value {
  font-size: 1.4rem;
  font-weight: 600;
}

.stat-card .value.red {
  color: #c62828;
}

.card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
  gap: 12px;
  flex-wrap: wrap;
}

.card-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar input,
.toolbar select {
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid #eee;
  white-space: nowrap;
}

th {
  font-weight: 600;
  font-size: 13px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

thead.products th {
  background: #fff9c4;
}

thead.overview th {
  background: #e3f2fd;
}

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

td.red,
tfoot td.red {
  color: #c62828;
  font-weight: 600;
}

tfoot td {
  font-weight: 600;
  background: #fafafa;
  border-top: 2px solid #ddd;
}

tbody tr:hover {
  background: #f9f9f9;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.badge-yes {
  background: #e8f5e9;
  color: #2e7d32;
}

.badge-no {
  background: #ffebee;
  color: #c62828;
}

.btn-success {
  background: #2e7d32;
  border-color: #2e7d32;
  color: #fff;
}

.btn-success:hover {
  background: #1b5e20;
}

.btn-success:disabled,
.btn-muted {
  background: #e8f5e9;
  border-color: #c8e6c9;
  color: #2e7d32;
  cursor: default;
}

.btn-success:disabled:hover,
.btn-muted:hover {
  background: #e8f5e9;
}

.btn-profit {
  background: #6a1b9a;
  border-color: #6a1b9a;
  color: #fff;
}

.btn-profit:hover {
  background: #4a148c;
}

.btn-profit-muted {
  background: #f3e5f5;
  border-color: #e1bee7;
  color: #6a1b9a;
  cursor: default;
}

.btn-profit-muted:hover {
  background: #f3e5f5;
}

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: #666;
}

.empty-state p {
  margin: 8px 0;
}

/* Order form layout */
.order-ref-bar {
  background: #e3f2fd;
  padding: 10px 16px;
  border-radius: 8px 8px 0 0;
  font-weight: 600;
  font-size: 15px;
  border-bottom: 1px solid #bbdefb;
}

.order-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 0;
}

@media (max-width: 900px) {
  .order-layout {
    grid-template-columns: 1fr;
  }
}

.order-products {
  padding: 16px;
  border-right: 1px solid #eee;
}

.order-meta {
  padding: 16px;
  background: #fafafa;
}

.meta-section {
  margin-bottom: 16px;
}

.meta-section h3 {
  margin: 0 0 8px;
  padding: 6px 10px;
  background: #e8f5e9;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
}

.field {
  margin-bottom: 10px;
}

.login-error {
  color: #c62828;
  font-size: 13px;
  margin-bottom: 12px;
  min-height: 18px;
}

.field label {
  display: block;
  font-size: 12px;
  color: #555;
  margin-bottom: 3px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
}

.field textarea {
  resize: vertical;
  min-height: 60px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: #1565c0;
  box-shadow: 0 0 0 2px rgba(21, 101, 192, 0.15);
}

.line-input {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: 3px;
  font-size: 14px;
  font-family: inherit;
  background: transparent;
}

.line-input:hover {
  border-color: #ddd;
  background: #fff;
}

.line-input:focus {
  outline: none;
  border-color: #1565c0;
  background: #fff;
}

.line-input.num-input {
  text-align: right;
  width: 90px;
}

.order-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-top: 1px solid #eee;
  gap: 12px;
  flex-wrap: wrap;
}

.order-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding-top: 4px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.modal-box {
  position: relative;
  background: #fff;
  border-radius: 10px;
  padding: 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.modal-box h3 {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

.modal-box p {
  margin: 0 0 20px;
  color: #555;
}

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

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

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #323232;
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 100;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.hidden {
  display: none !important;
}

#import-file {
  display: none;
}

#import-excel-file {
  display: none;
}

.model-cell {
  position: relative;
  min-width: 180px;
}

.model-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 50;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  max-height: 220px;
  overflow-y: auto;
}

.model-suggestion {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-bottom: 1px solid #eee;
  background: #fff;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}

.model-suggestion:last-child {
  border-bottom: none;
}

.model-suggestion:hover,
.model-suggestion.active {
  background: #e3f2fd;
}

.model-suggestion-name {
  font-weight: 600;
}

.model-suggestion-meta {
  font-size: 12px;
  color: #666;
  margin-top: 2px;
}

.nav-links {
  display: flex;
  gap: 8px;
  align-items: center;
}
