:root {
  --hf-navy: #1a2b4a;
  --hf-blue: #2563eb;
  --hf-orange: #e87722;
  --hf-bg: #f4f6fa;
  --hf-card: #ffffff;
  --hf-border: #e6e9ef;
  --hf-border-strong: #cdd3dd;
  --hf-text: #1f2937;
  --hf-muted: #6b7280;
  --hf-label: #475569;
  --hf-section-title: #2563eb;
  --hf-danger: #dc2626;
  --hf-success: #16a34a;
  --hf-sidebar-width: 240px;
  --hf-card-radius: 10px;
  --hf-input-radius: 6px;
  --hf-input-h: 38px;
  --hf-input-h-sm: 34px;
}

body {
  background: var(--hf-bg);
  color: var(--hf-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

.hf-shell {
  display: flex;
  min-height: 100vh;
}

#sidebar {
  width: var(--hf-sidebar-width);
  background: var(--hf-navy);
  color: #fff;
  flex-shrink: 0;
  padding: 1rem 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

#sidebar .sidebar-brand {
  padding: 0 1rem 1rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 0.5rem;
}

#sidebar .brand-name {
  font-weight: 600;
  color: #fff;
}

#sidebar .nav-section {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
  padding: 0.75rem 1rem 0.25rem 1rem;
  letter-spacing: 0.05em;
}

#sidebar .nav-link {
  color: rgba(255,255,255,0.75);
  font-size: 0.875rem;
  padding: 0.45rem 1rem;
  border-left: 3px solid transparent;
}

#sidebar .nav-link:hover,
#sidebar .nav-link.active {
  color: #fff;
  background: rgba(232, 119, 34, 0.2);
  border-left-color: var(--hf-orange);
}

#sidebar .nav-link i {
  margin-right: 0.5rem;
}

.hf-main {
  flex-grow: 1;
  padding: 1rem 1.5rem 5rem 1.5rem;
}

.hf-topbar {
  background: #fff;
  border-bottom: 1px solid var(--hf-border);
  margin: -1rem -1.5rem 1rem -1.5rem;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hf-breadcrumbs a {
  color: var(--hf-muted);
  text-decoration: none;
  font-size: 0.875rem;
}

.page-header {
  border-bottom: 1px solid var(--hf-border);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
}

.btn-primary {
  background-color: var(--hf-blue);
  border-color: var(--hf-blue);
}
.btn-primary:hover, .btn-primary:focus {
  background-color: #1d4ed8;
  border-color: #1d4ed8;
}

.btn-warning {
  background-color: var(--hf-orange);
  border-color: var(--hf-orange);
  color: #fff;
}
.btn-warning:hover {
  background-color: #c5631a;
  border-color: #c5631a;
  color: #fff;
}

/* ============================================================
   DENSE FORM DESIGN SYSTEM
   Used by _form_section.html, _form_field.html, _form_actions.html
   ============================================================ */

.hf-form {
  max-width: 1400px;
}

.hf-form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
}

@media (min-width: 1100px) {
  .hf-form-grid.hf-form-grid-with-aside {
    grid-template-columns: minmax(0, 1fr) 360px;
    align-items: start;
  }
}

.hf-form-main,
.hf-form-aside {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.hf-section {
  background: var(--hf-card);
  border: 1px solid var(--hf-border);
  border-radius: var(--hf-card-radius);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  padding: 1.25rem 1.25rem 1rem 1.25rem;
}

.hf-section + .hf-section {
  margin-top: 0;
}

.hf-section-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--hf-section-title);
  margin-bottom: 1rem;
}

.hf-section-title i {
  font-size: 0.95rem;
  opacity: 0.9;
}

.hf-section-title .hf-section-meta {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--hf-muted);
}

.hf-section-title .hf-section-meta a {
  color: var(--hf-blue);
  text-decoration: none;
  font-weight: 600;
}

.hf-section-title .hf-section-meta a:hover {
  text-decoration: underline;
}

.hf-section-subtitle {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--hf-text);
  background: #f8fafc;
  border: 1px solid var(--hf-border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hf-section-subtitle .hf-subtitle-action {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--hf-blue);
  text-decoration: none;
}

.hf-section-subtitle .hf-subtitle-action:hover {
  text-decoration: underline;
}

.hf-row {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 0.75rem 0.9rem;
}

.hf-row + .hf-row {
  margin-top: 0.75rem;
}

.hf-col-12 { grid-column: span 12; }
.hf-col-9  { grid-column: span 12; }
.hf-col-8  { grid-column: span 12; }
.hf-col-6  { grid-column: span 12; }
.hf-col-4  { grid-column: span 12; }
.hf-col-3  { grid-column: span 12; }
.hf-col-2  { grid-column: span 6; }

@media (min-width: 640px) {
  .hf-col-6 { grid-column: span 6; }
  .hf-col-4 { grid-column: span 6; }
  .hf-col-3 { grid-column: span 6; }
}

@media (min-width: 900px) {
  .hf-col-9 { grid-column: span 9; }
  .hf-col-8 { grid-column: span 8; }
  .hf-col-6 { grid-column: span 6; }
  .hf-col-4 { grid-column: span 4; }
  .hf-col-3 { grid-column: span 3; }
  .hf-col-2 { grid-column: span 2; }
}

.hf-field {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.hf-field-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--hf-label);
  margin-bottom: 0.3rem;
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.hf-field-label .hf-required {
  color: var(--hf-danger);
  font-weight: 700;
}

.hf-field-control input[type="text"],
.hf-field-control input[type="email"],
.hf-field-control input[type="password"],
.hf-field-control input[type="number"],
.hf-field-control input[type="tel"],
.hf-field-control input[type="url"],
.hf-field-control input[type="date"],
.hf-field-control input[type="datetime-local"],
.hf-field-control input[type="time"],
.hf-field-control input[type="search"],
.hf-field-control input:not([type]),
.hf-field-control textarea,
.hf-field-control select,
.hf-field-control .form-control,
.hf-field-control .form-select {
  width: 100%;
  height: var(--hf-input-h);
  padding: 0.4rem 0.65rem;
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--hf-text);
  background: #fff;
  border: 1px solid var(--hf-border-strong);
  border-radius: var(--hf-input-radius);
  transition: border-color .15s ease, box-shadow .15s ease;
}

.hf-field-control textarea,
.hf-field-control .form-control[rows] {
  height: auto;
  min-height: calc(var(--hf-input-h) * 1.6);
  resize: vertical;
}

.hf-field-control select,
.hf-field-control .form-select {
  padding-right: 1.8rem;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .55rem center;
  background-size: 14px 14px;
  appearance: none;
  -webkit-appearance: none;
}

.hf-field-control input:focus,
.hf-field-control textarea:focus,
.hf-field-control select:focus,
.hf-field-control .form-control:focus,
.hf-field-control .form-select:focus {
  border-color: var(--hf-blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
  outline: none;
}

.hf-field-control input[type="checkbox"],
.hf-field-control input[type="radio"] {
  width: auto;
  height: auto;
  margin-right: 0.4rem;
}

.hf-field-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: var(--hf-input-h);
  font-size: 0.875rem;
  color: var(--hf-text);
}

.hf-field-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
}

.hf-field-help {
  font-size: 0.72rem;
  color: var(--hf-muted);
  margin-top: 0.25rem;
  line-height: 1.35;
}

.hf-field-errors {
  font-size: 0.75rem;
  color: var(--hf-danger);
  margin-top: 0.25rem;
}

.hf-field-errors ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.hf-field.is-invalid input,
.hf-field.is-invalid textarea,
.hf-field.is-invalid select {
  border-color: var(--hf-danger);
  background-color: #fef2f2;
}

.hf-form-errors {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  border-radius: 6px;
  padding: 0.6rem 0.9rem;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.hf-form-errors ul {
  margin: 0;
  padding-left: 1.2rem;
}

/* Action footer */
.hf-form-actions {
  position: sticky;
  bottom: 0;
  background: var(--hf-card);
  border-top: 1px solid var(--hf-border);
  margin: 1rem -1.5rem -2rem -1.5rem;
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
  z-index: 5;
  box-shadow: 0 -2px 6px rgba(15, 23, 42, 0.04);
}

.hf-form-actions .hf-form-actions-left {
  margin-right: auto;
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.hf-form-actions .btn {
  font-size: 0.85rem;
  padding: 0.45rem 1rem;
  font-weight: 500;
}

.hf-form-actions .btn-primary {
  background: var(--hf-blue);
  border-color: var(--hf-blue);
  font-weight: 600;
}

/* Right-aside summary card style */
.hf-aside-card {
  background: var(--hf-card);
  border: 1px solid var(--hf-border);
  border-radius: var(--hf-card-radius);
  padding: 1.25rem 1.25rem 1rem 1.25rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.hf-aside-card .hf-aside-title {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--hf-section-title);
  margin-bottom: 0.85rem;
}

.hf-summary-row {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0;
  font-size: 0.85rem;
  border-bottom: 1px dashed var(--hf-border);
}

.hf-summary-row:last-child { border-bottom: none; }

.hf-summary-label { color: var(--hf-muted); }
.hf-summary-value { color: var(--hf-text); font-weight: 500; text-align: right; }

.hf-summary-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 2px solid var(--hf-border);
  font-weight: 700;
  color: var(--hf-blue);
}

.hf-summary-total .hf-summary-total-value { font-size: 1.2rem; }

.hf-divider {
  border: none;
  border-top: 1px dashed var(--hf-border);
  margin: 0.6rem 0;
}

/* Page header tweaks for forms */
.hf-page-head {
  margin-bottom: 1rem;
}

.hf-page-head h1 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
  color: var(--hf-text);
}

.hf-page-head .hf-breadcrumb {
  font-size: 0.78rem;
  color: var(--hf-muted);
  margin-top: 0.15rem;
}

.hf-page-head .hf-breadcrumb a {
  color: var(--hf-muted);
  text-decoration: none;
}

.hf-page-head .hf-breadcrumb a:hover { color: var(--hf-blue); }

/* ============================================================
   Global Bootstrap form-control styling so legacy templates
   (card + row.g-2 + col-md-*) inherit the dense look.
   ============================================================ */
.form-control, .form-select {
  border-color: var(--hf-border-strong);
  border-radius: var(--hf-input-radius);
  font-size: 0.875rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--hf-blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.form-control-sm, .form-select-sm {
  height: var(--hf-input-h-sm);
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
}
.form-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--hf-label);
  margin-bottom: 0.3rem;
}
.form-label.small {
  font-size: 0.75rem;
  font-weight: 500;
}
.card {
  border-radius: var(--hf-card-radius);
}
.card.shadow-sm {
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04) !important;
  border: 1px solid var(--hf-border);
}
.card-header.bg-white {
  font-size: 0.85rem;
  font-weight: 600;
  border-bottom: 1px solid var(--hf-border);
  letter-spacing: 0.02em;
}

/* Status badge tweaks */
.badge-status-draft     { background:#6c757d; color:#fff; }
.badge-status-sent      { background:#0d6efd; color:#fff; }
.badge-status-accepted  { background:#198754; color:#fff; }
.badge-status-rejected  { background:#dc3545; color:#fff; }
.badge-status-converted { background:#6610f2; color:#fff; }
.badge-status-expired   { background:#adb5bd; color:#fff; }
.badge-status-confirmed { background:#0d6efd; color:#fff; }
.badge-status-in_production { background:#fd7e14; color:#fff; }
.badge-status-ready     { background:#20c997; color:#fff; }
.badge-status-dispatched{ background:#6610f2; color:#fff; }
.badge-status-completed { background:#198754; color:#fff; }
.badge-status-cancelled { background:#dc3545; color:#fff; }
.badge-status-pending   { background:#ffc107; color:#212529; }
.badge-status-cutting,
.badge-status-crimping,
.badge-status-testing,
.badge-status-qc        { background:#fd7e14; color:#fff; }
.badge-status-complete  { background:#198754; color:#fff; }
.badge-status-paid      { background:#198754; color:#fff; }
.badge-status-partial   { background:#ffc107; color:#212529; }
.badge-status-unpaid    { background:#dc3545; color:#fff; }
.badge-status-preparing { background:#6c757d; color:#fff; }
.badge-status-in_transit{ background:#0dcaf0; color:#212529; }
.badge-status-delivered { background:#198754; color:#fff; }
.badge-status-returned  { background:#dc3545; color:#fff; }
.badge-status-received  { background:#198754; color:#fff; }
.badge-status-superseded{ background:#adb5bd; color:#fff; }
.badge-status-pending_approval { background:#fd7e14; color:#fff; }
.badge-status-open      { background:#6c757d; color:#fff; }
.badge-status-qualified { background:#0d6efd; color:#fff; }
.badge-status-quoted    { background:#6610f2; color:#fff; }
.badge-status-won       { background:#198754; color:#fff; }
.badge-status-lost      { background:#dc3545; color:#fff; }
.badge-status-dropped   { background:#adb5bd; color:#fff; }

.hf-login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  width: 100%;
}

.hf-login-card {
  width: 380px;
  max-width: 90%;
}

.hf-error {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--hf-muted);
}

@media (max-width: 768px) {
  #sidebar { display: none; }
  .hf-main { padding: 1rem 1rem 5rem 1rem; }
  .hf-form-actions { margin: 1rem -1rem -2rem -1rem; padding: 0.85rem 1rem; }
}
