:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #d1d5db;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem;
}

header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 0;
}

header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

nav {
  display: flex;
  gap: 1rem;
  align-items: center;
}

nav a, nav button {
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
}

nav button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

h1, h2 {
  margin-top: 0;
}

.card {
  background: var(--card);
  border-radius: 0.5rem;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  margin-bottom: 1rem;
}

a.card {
  display: block;
  color: inherit;
  text-decoration: none;
}

a.card:hover {
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.grid {
  display: grid;
  gap: 1rem;
}

.grid.stats {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.grid.menu {
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

input, select, textarea, button {
  font: inherit;
}

input, textarea {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
}

button {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  cursor: pointer;
}

button:hover {
  background: var(--primary-dark);
}

.inline {
  display: inline;
}

#search {
  max-width: 400px;
  margin-bottom: 1rem;
}

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

th, td {
  text-align: left;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
}

th {
  background: #f9fafb;
}

.w-16 { width: 4rem; }
.w-32 { width: 8rem; }

.status-active { color: var(--success); font-weight: 600; }
.status-inactive { color: var(--danger); }

.tag {
  display: inline-block;
  background: #e5e7eb;
  padding: 0.2rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.8rem;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

button.secondary {
  background: #e5e7eb;
  color: var(--text);
}

button.secondary:hover {
  background: #d1d5db;
}

button.danger {
  background: var(--danger);
}

button.danger:hover {
  background: #b91c1c;
}

#draft-prompt {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  margin-bottom: 1rem;
}

#draft-prompt p {
  margin-top: 0;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-top: 1rem;
  flex-wrap: wrap;
}

#draft-info {
  margin-bottom: 1rem;
  background: #dbeafe;
  color: #1e40af;
}

.filters {
  align-items: end;
}

.bulk-actions {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.bulk-actions button {
  background: var(--muted);
}

.bulk-actions button:hover {
  background: #4b5563;
}

#products-table tr.family-header {
  background: #f9fafb;
}

#products-table tr.family-header td {
  border-top: 2px solid var(--border);
}

#products-table tr.family-header strong {
  margin-right: 1rem;
}

#products-table tr.assigned td {
  background: #ecfdf5;
}

#products-table tr.not-assigned td {
  background: #ffffff;
}

#products-table td .bulk-family-activate,
#products-table td .bulk-family-deactivate {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  margin-left: 0.5rem;
}

#count-msg {
  color: var(--muted);
  font-size: 0.9rem;
}

.order-detail-row td {
  padding: 0;
  border-bottom: 2px solid var(--border);
}

.order-detail-content {
  padding: 1rem;
  background: #f9fafb;
}

.order-detail-content h4 {
  margin-top: 0;
}

.detail-table {
  margin-top: 0.75rem;
  background: white;
}

.detail-table th,
.detail-table td {
  padding: 0.5rem 0.75rem;
}

.order-row:hover {
  background: #eff6ff;
}

th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable:hover {
  background: #e5e7eb;
}

.sort-icon {
  font-size: 0.7rem;
  color: var(--primary);
}

.dt-pagination {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.dt-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.dt-toolbar input {
  max-width: 320px;
}

.dt-page-size {
  font-size: 0.85rem;
}

@media (max-width: 600px) {
  header .container {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  nav {
    flex-wrap: wrap;
  }
}

.erp-client-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.erp-client-toolbar #erp-client-search {
  flex: 1 1 220px;
  min-width: 180px;
}

.erp-client-select {
  width: 100%;
  padding: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.9rem;
  background: var(--surface, #fff);
}

.erp-client-select option {
  padding: 0.25rem;
}

.company-select-mini {
  width: auto !important;
  min-width: 160px;
  max-width: 220px;
  padding: 0.3rem 0.5rem !important;
  font-size: 0.85rem !important;
  border-radius: 0.3rem !important;
}

#erp-client-info {
  flex: 1 1 100%;
  font-size: 0.85rem;
}

.password-gen {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.password-gen input {
  flex: 1;
  background: var(--surface, #f5f5f5);
  font-family: monospace;
}

.password-gen button {
  white-space: nowrap;
}

.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-content {
  background: var(--card);
  border-radius: 8px;
  padding: 1.5rem;
  max-width: 800px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}

.modal-content h2 {
  margin-top: 0;
}

#summary-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
}

#summary-table th,
#summary-table td {
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

#summary-table th {
  background: var(--bg);
  font-size: 0.85rem;
  text-transform: uppercase;
  color: var(--muted);
}

.text-right {
  text-align: right;
}

.detail-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.75rem;
}

.detail-table th,
.detail-table td {
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.detail-table th {
  background: var(--bg);
  font-size: 0.85rem;
  text-transform: uppercase;
  color: var(--muted);
}

.w-16 {
  width: 4rem;
}

.order-detail-cell {
  padding: 1rem;
  background: var(--bg);
}

.order-detail-content {
  background: var(--card);
  padding: 1rem;
  border-radius: 6px;
}
