@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

:root {
  --primary: #1a73e8;
  --primary-dark: #0d47a1;
  --primary-light: #e8f0fe;
  --sidebar-bg: #1a1f2e;
  --sidebar-hover: #252d40;
  --sidebar-active: #1a73e8;
  --sidebar-text: #b0bec5;
  --sidebar-text-active: #fff;
  --sidebar-width: 260px;
  --header-height: 60px;
  --bg: #f0f2f5;
  --card-bg: #fff;
  --border: #e0e0e0;
  --text: #1e293b;
  --text-muted: #64748b;
  --success: #34a853;
  --warning: #fbbc04;
  --danger: #ea4335;
  --orange: #ed6c02;
  --purple: #9c27b0;
  --teal: #0288d1;
  --green: #2e7d32;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --radius: 8px;
  --radius-lg: 12px;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
}

/* ─── SIDEBAR ─── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  min-height: 100vh;
  position: fixed;
  left: 0; top: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: width 0.3s;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-brand {
  padding: 20px 16px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-brand h2 {
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.5px;
}

.sidebar-brand p {
  color: rgba(255,255,255,0.7);
  font-size: 10px;
  margin-top: 2px;
}

.sidebar-section {
  padding: 8px 0;
}

.sidebar-section-title {
  color: rgba(255,255,255,0.35);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 12px 16px 4px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
  border-left: 3px solid transparent;
  white-space: nowrap;
}

.sidebar-item:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.sidebar-item.active {
  background: rgba(26,115,232,0.15);
  color: var(--primary);
  border-left-color: var(--primary);
}

.sidebar-item .icon {
  width: 20px;
  text-align: center;
  font-size: 15px;
  flex-shrink: 0;
}

/* ─── MAIN CONTENT ─── */
.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--header-height);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.topbar h1 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

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

.content { padding: 24px; flex: 1; }

/* ─── CARDS ─── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fafbfd;
}

.card-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body { padding: 20px; }

/* ─── STAT CARDS ─── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 16px;
  transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.stat-icon {
  width: 52px; height: 52px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.stat-icon.blue { background: #e8f0fe; }
.stat-icon.green { background: #e6f4ea; }
.stat-icon.orange { background: #fef3e2; }
.stat-icon.purple { background: #f3e8fd; }

.stat-info h2 {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.stat-info p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ─── BUTTONS ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
.btn:active { transform: translateY(0); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #2d7a47; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #c62828; }
.btn-warning { background: var(--warning); color: #333; }
.btn-secondary { background: #e0e0e0; color: #333; }
.btn-secondary:hover { background: #bdbdbd; }
.btn-sm { padding: 5px 10px; font-size: 11px; }
.btn-lg { padding: 12px 28px; font-size: 15px; }

/* ─── FORMS ─── */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: #fff;
  color: var(--text);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,115,232,0.1);
}

.form-control[readonly] {
  background: #f8f9fc;
  cursor: default;
}

select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 60px; }

.field-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.field-label {
  width: 130px;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  flex-shrink: 0;
}

.field-value { flex: 1; }
.field-value .form-control { margin: 0; }

/* ─── TABLES ─── */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 12px 0;
}

.table-wrapper.scrollable { max-height: 480px; overflow-y: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

table th {
  padding: 10px 8px;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  border: 1px solid rgba(255,255,255,0.2);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 5;
}

table td {
  padding: 7px 6px;
  border: 1px solid var(--border);
  vertical-align: middle;
}

table td input, table td select {
  width: 100%;
  padding: 5px 4px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 11px;
  font-family: 'Inter', sans-serif;
}

table td input:focus, table td select:focus {
  outline: none;
  border-color: var(--primary);
}

table td input[readonly] {
  background: #f0f7ff;
  font-weight: 600;
  color: var(--primary);
  text-align: center;
}

.th-gray { background: #455a64; color: #fff; }
.th-green { background: var(--green); color: #fff; }
.th-orange { background: var(--orange); color: #fff; }
.th-purple { background: var(--purple); color: #fff; }
.th-red { background: #d32f2f; color: #fff; }
.th-blue { background: var(--teal); color: #fff; }
.th-primary { background: var(--primary); color: #fff; }

/* ─── COMPANY HEADER (Sales Order form) ─── */
.company-header {
  text-align: center;
  padding: 22px 20px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
}

.company-header h1 { font-size: 26px; font-weight: 700; margin-bottom: 6px; }
.company-header p { font-size: 12px; opacity: 0.88; line-height: 1.6; }

.form-title {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  padding: 14px;
  background: #f8f9fc;
  border-bottom: 2px solid var(--primary);
}

/* ─── INFO BOX ─── */
.info-box {
  border: 1px solid var(--border);
  padding: 16px 18px;
  background: #fafbfd;
  border-radius: var(--radius);
}

.info-box-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary);
}

.info-row { display: flex; gap: 20px; flex-wrap: wrap; margin-bottom: 16px; }
.info-col { flex: 1; min-width: 280px; }

/* ─── DISCOUNT / TOTAL SECTION ─── */
.discount-section {
  background: var(--primary-light);
  border: 1px solid #c8d8f8;
  border-radius: var(--radius);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 24px;
  flex-wrap: wrap;
  margin: 12px 0;
}

.discount-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--primary);
}

.discount-field input {
  width: 100px;
  padding: 8px;
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  font-size: 14px;
  text-align: center;
  font-family: 'Inter', sans-serif;
}

.total-bar {
  text-align: right;
  font-size: 16px;
  font-weight: 600;
  padding: 12px 20px;
  background: #e8f0fe;
  border-radius: var(--radius);
  margin: 8px 0;
  color: var(--text);
}

.grand-total-bar {
  text-align: right;
  font-size: 20px;
  font-weight: 700;
  padding: 14px 20px;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius);
  margin: 8px 0;
}

.amount-words {
  font-style: italic;
  font-size: 13px;
  color: #555;
  padding: 10px 16px;
  background: #f8f9fc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 8px 0;
}

/* ─── LEGEND ─── */
.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 11px;
  padding: 8px 12px;
  background: #f5f5f5;
  border-radius: var(--radius);
  margin-bottom: 10px;
  color: #555;
}

.legend span { display: flex; align-items: center; gap: 6px; }

.legend-dot {
  width: 14px; height: 14px;
  border-radius: 3px;
  display: inline-block;
}

/* ─── SIGNATURE ─── */
.signature-section {
  display: flex;
  justify-content: space-between;
  margin: 24px 0 16px;
}

.signature-box {
  text-align: center;
  width: 200px;
}

.signature-line {
  margin-top: 40px;
  border-top: 1px solid #333;
  padding-top: 6px;
  font-size: 11px;
  color: #555;
}

/* ─── BADGES ─── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-pending { background: #fff3e0; color: #e65100; }
.badge-approved { background: #e6f4ea; color: #1b5e20; }
.badge-new { background: #e3f2fd; color: #0d47a1; }
.badge-progress { background: #fef3e2; color: #e65100; }
.badge-completed { background: #e6f4ea; color: #1b5e20; }
.badge-hold { background: #fce4ec; color: #880e4f; }

/* ─── LOADING OVERLAY ─── */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.88);
  z-index: 9999;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  gap: 16px;
}

.loading-overlay.active { display: flex; }

.spinner {
  width: 48px; height: 48px;
  border: 5px solid #e0e0e0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── MODAL ─── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 8000;
  justify-content: center;
  align-items: center;
}

.modal-overlay.active { display: flex; }

.modal-box {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 30px;
  max-width: 480px;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-box h3 { font-size: 18px; margin-bottom: 10px; }
.modal-buttons { display: flex; gap: 12px; justify-content: center; margin-top: 20px; }

/* ─── ALERTS ─── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from { transform: translateY(-10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }

/* ─── TABLE LISTS ─── */
.table-list th {
  background: var(--primary);
  color: #fff;
  padding: 12px 10px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.table-list td { padding: 10px; }

.table-list tbody tr:nth-child(even) { background: #fafbfd; }
.table-list tbody tr:hover { background: var(--primary-light); }

/* ─── RESPONSIVE ─── */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-brand h2, .sidebar-section-title,
  .sidebar-item span:not(.icon) { display: none; }
  .main { margin-left: 60px; }
  .info-row { flex-direction: column; }
  .content { padding: 12px; }
}

/* ─── PRINT ─── */
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}

/* ─── AUTO-PRICE INPUT ─── */
.auto-price {
  background: #fff8e1 !important;
  border-color: #ffc107 !important;
}

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 4px; }
::-webkit-scrollbar-thumb { background: #bdbdbd; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }
